Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/audit supplier #172

Open
wants to merge 22 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2593028
config changes to add Audit
choonkeat Jul 11, 2016
d7822d5
Importer#fetch_properties works
choonkeat Jul 9, 2016
d0f46aa
Workers::Suppliers::Audit works
choonkeat Jul 11, 2016
68efc07
Use Support::HTTPStubbing, Support::Fixtures, Concierge::Credentials
choonkeat Jul 11, 2016
cc6c111
Setup mock Audit supplier server
choonkeat Jul 12, 2016
3429b67
Fill up missing info required by Roomorama API
choonkeat Jul 13, 2016
40f0312
Add optional fields too -- be complete
choonkeat Jul 13, 2016
30dcf3a
Remove Property#update_calendar code; see #125 9600f7b3
choonkeat Jul 15, 2016
72c4d3e
Fixup be192ba stub Workers::CalendarSynchronisation#run_operation
choonkeat Jul 20, 2016
a90f4f4
Add common integration parts
choonkeat Jul 15, 2016
536437c
Bare minimum support for audit APIs quote, booking, cancel
choonkeat Jul 15, 2016
46e06d9
Add mock audit server to respond to scenarios:
choonkeat Jul 20, 2016
291a4c4
See a415f7c renaming to reservation.reference_number
choonkeat Jul 22, 2016
d4ee04d
Implements shared specs spec/lib/concierge/suppliers/shared
choonkeat Jul 22, 2016
0d6c233
Extracted rack middleware logic to lib/concierge/suppliers/audit/serv…
choonkeat Jul 25, 2016
544ef88
Add "REPLACEME" replacement logic to Audit::Server
choonkeat Jul 25, 2016
ec75de9
Respond with "success" when requesting "sample" (roomorama test reque…
choonkeat Jul 26, 2016
19421e6
Change fetch_properties API endpoint to be "properties.json"
choonkeat Jul 26, 2016
030320f
Fix to make MoneyExchanger#convert happy
choonkeat Jul 26, 2016
a1e479e
Extract possible scenarios to Audit::Server::SCENARIOS array
choonkeat Jul 26, 2016
ad39d2a
Prettify output
choonkeat Jul 26, 2016
f142eed
Update CalendarSynchronisation usage based on bbaa974
choonkeat Aug 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Respond with "success" when requesting "sample" (roomorama test reque…
…sts)

Return proper 404 response when 404
  • Loading branch information
choonkeat committed Aug 11, 2016
commit ec75de9b140ebbfc334650fae3b2a40530ab0c1f
1 change: 1 addition & 0 deletions apps/api/config/environment_variables.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- ROOMORAMA_SECRET_AUDIT
- ROOMORAMA_SECRET_JTB
- ROOMORAMA_SECRET_KIGO_LEGACY
- ROOMORAMA_SECRET_KIGO
Expand Down
21 changes: 15 additions & 6 deletions lib/concierge/suppliers/audit/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,37 @@ def initialize(app)

def call(env)
status, headers, body = @app.call(env)
status, headers, body = handle_404(env) if status == 404
status, headers, body = handle_404(env) || [status, headers, body] if status == 404

if File.basename(env['PATH_INFO']) =~ /booking/
[status, headers, [replace_response_body(body)]]
new_body = replace_response_body(body)
[status, headers.merge('Content-Length' => new_body.length.to_s), [new_body]]
else
[status, headers, body]
end
end

private

def retry_with(env, old_string, new_string)
@app.call(env.merge({
'PATH_INFO' => env['PATH_INFO'].gsub(old_string, new_string),
'REQUEST_PATH' => env['REQUEST_PATH'] && env['REQUEST_PATH'].gsub(old_string, new_string),
}))
end

def handle_404(env)
case File.basename(env['PATH_INFO'])
when /sample/
# sample = success
retry_with(env, 'sample', 'success')

when /connection_timeout/
# First we wait
sleep Concierge::HTTPClient::CONNECTION_TIMEOUT + 1

# Then we return the requested info (Concierge::HTTPClient should have errored out by now)
@app.call(env.merge({
'PATH_INFO' => env['PATH_INFO'].gsub('connection_timeout', 'success'),
'REQUEST_PATH' => env['REQUEST_PATH'] && env['REQUEST_PATH'].gsub('connection_timeout', 'success'),
}))
retry_with(env, 'connection_timeout', 'success')

when /wrong_json/
[200, {}, ["[1, 2, 3]"]]
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/concierge/suppliers/audit/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
expect(response_body_as_string(response)).to eq(IO.read file)
end

it "serves sample requests as success" do
file = %w[
spec/fixtures/audit/cancel.success.json
spec/fixtures/audit/quotation.success.json
].sample
code, env, response = middleware.call Rack::MockRequest.env_for("http://admin.example.com/#{file.gsub("success", "sample")}", {})
expect(code).to eq(200)
expect(response_body_as_string(response)).to eq(IO.read file)
end

it "serves connection_timeout with correct content but after CONNECTION_TIMEOUT seconds delay" do
# we could do a start/end check.. but that'll make test slower
expect(middleware).to receive(:sleep).with(Concierge::HTTPClient::CONNECTION_TIMEOUT + 1).and_return(nil)
Expand Down Expand Up @@ -53,6 +63,12 @@
expect(response_body_as_string(response)).to eq("{")
end

it "serves unknown as 404" do
file = Dir["spec/fixtures/audit/*.success.json"].sample.gsub("success", "unknown")
code, env, response = middleware.call Rack::MockRequest.env_for("http://admin.example.com/#{file}", {})
expect(code).to eq(404)
end

def result_without_key(hash, key)
hash['result'].delete(key)
hash
Expand Down