Skip to content

Commit

Permalink
Extract possible scenarios to Audit::Server::SCENARIOS array
Browse files Browse the repository at this point in the history
  • Loading branch information
choonkeat committed Jul 26, 2016
1 parent 7795012 commit 3b3f7e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/concierge/suppliers/audit/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ module Audit
# For more information on how to interact with Audit, check the project Wiki.
class Server

SCENARIOS = [
'success',
'connection_timeout',
'wrong_json',
'invalid_json',
]

def initialize(app)
@app = app
end
Expand Down Expand Up @@ -38,12 +45,7 @@ def handle_404(env)
case File.basename(env['PATH_INFO'])
when /properties/
property_json = JSON.parse(IO.read 'spec/fixtures/audit/property.json')
result = [
'success',
'connection_timeout',
'wrong_json',
'invalid_json',
].collect {|k| property_json.merge('identifier' => k, 'title' => "#{property_json['title']} (#{k})") }
result = SCENARIOS.collect {|k| property_json.merge('identifier' => k, 'title' => "#{property_json['title']} (#{k})") }
new_body = Hash(result: result).to_json
[200, {}, [new_body]]

Expand Down Expand Up @@ -74,10 +76,7 @@ def replace_response_body(body)
body.join("")
end

body_string.gsub("REPLACEME", [
"success",
"connection_timeout"
].sample)
body_string.gsub("REPLACEME", SCENARIOS.sample)
end
end
end
1 change: 1 addition & 0 deletions spec/lib/concierge/suppliers/audit/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
file_json = JSON.parse(IO.read file)
resp_json = JSON.parse(response_body_as_string(response))
expect(resp_json).not_to eq(file_json)
expect(Audit::Server::SCENARIOS).to include(resp_json['result']['reference_number'])
expect(result_without_key resp_json, 'reference_number').to eq(result_without_key file_json, 'reference_number')
end

Expand Down

0 comments on commit 3b3f7e5

Please sign in to comment.