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
Importer#fetch_properties works
  • Loading branch information
choonkeat committed Aug 11, 2016
commit d7822d573501df06cb3139b6928d06177ba3f688
45 changes: 45 additions & 0 deletions lib/concierge/suppliers/audit/importer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Audit
# +Audit::Importer+
#
# This class wraps supplier API and provides data for building properties.
#
# Usage
#
# importer = Audit::Importer.new(credentials)
# importer.fetch_properties
#
# => #<Result:0x007ff5fc624dd8 @result=[{'HouseCode' => 'XX-12345-67', ...}, ...]
class Importer
attr_reader :credentials

def initialize(credentials)
@credentials = credentials
end

# retrieves the list of properties
def fetch_properties
client = Concierge::HTTPClient.new("http://localhost:9292")
result = client.get("/fetch_properties")
if result.success?
json = JSON.parse(result.value.body)
Result.new(json['result'])
else
result
end
end

def json_to_property(json)
Roomorama::Property.load(Concierge::SafeAccessHash.new json).tap do |property_result|
if property_result.success?
property = property_result.value
property.update_calendar(json['availability_dates'])
property.units.each do |unit|
if unitjson = json['units'].find {|h| h['identifier'] == unit.identifier }
unit.update_calendar(unitjson['availability_dates'])
end
end
end
end
end
end
end
44 changes: 44 additions & 0 deletions spec/fixtures/audit/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"result": [
{
"identifier": "audit-property-1",
"title": "Audit Property #1",
"max_guests": 2,
"nightly_rate": 100,
"images": [
{
"identifier": "audit-image1",
"url": "https://www.example.org/img1",
"caption": "Barbecue Pit"
}
],
"units": [
{
"identifier": "audit-unit1",
"title": "Audit Unit 1",
"number_of_units": 2,
"images": [
{
"identifier": "audit-unit1img1",
"url": "https://www.example.org/unit1img1"
},
{
"identifier": "audit-unit1img2",
"url": "https://www.example.org/unit1img2"
}
]
},
{
"identifier": "audit-unit2",
"title": "Audit Unit 2",
"images": [
{
"identifier": "audit-unit2img1",
"url": "https://www.example.org/unit2img1"
}
]
}
]
}
]
}
51 changes: 51 additions & 0 deletions spec/lib/concierge/suppliers/audit/importer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

RSpec.describe Audit::Importer do
include Support::Fixtures
include Support::HTTPStubbing

let(:credentials) { Concierge::Credentials.for('audit') }
let(:importer) { described_class.new(credentials) }

describe '#fetch_properties' do

subject { importer.fetch_properties }

context 'success' do
before do
allow_any_instance_of(Faraday::Connection).to receive(:get) do
Faraday::Response.new(method: :get, status: 200, body: IO.binread('spec/fixtures/audit/properties.json'))
end
end

it 'should return Result of array of Hash' do
is_expected.to be_success
expect(subject.value).to be_kind_of(Array)
expect(subject.value.collect(&:class).uniq).to eq([Hash])
end
end

context 'error' do
before do
allow_any_instance_of(Faraday::Connection).to receive(:get) do
raise Faraday::Error.new("oops123")
end
end

it 'should return Result with errors' do
is_expected.not_to be_success
expect(subject.error.code).to eq :network_failure
end
end
end

describe '#json_to_property' do
let(:json) { JSON.parse(IO.binread('spec/fixtures/audit/properties.json'))['result'].sample }

it 'should return Result of Roomorama::Property' do
result = importer.json_to_property(json)
expect(result).to be_kind_of(Result)
expect(result.value).to be_kind_of(Roomorama::Property)
end
end
end