This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) All right... my task is to sync hotels with Cloudbeds. So probably this will be a rake task, but | |
# for simplicity I will just choose service as my outermost layer! Lets's dive in! I love BDD! | |
module Cloudbeds | |
describe SyncHotels do | |
# 2) it is a service, so to keep convention I'll test .call method | |
# Some small description of what I want it to do won't hurt as well. | |
# Scratch that! Description is essential! | |
describe '.call' do | |
it 'upserts hotels based on data returned from CloudBeds' do | |
# 7) Uh oh! I have realized that we will need to refresh a token once in a while. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To make it easier to find descriptions and add exceptions | |
AllCops: | |
DisplayCopNames: true | |
Exclude: | |
- 'bin/**/*' | |
- 'vendor/**/*' | |
- 'db/schema.rb' | |
- 'tmp/**/*' | |
- 'node_modules/**/*' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Support | |
module RequestHelpers | |
def get_json(path) | |
get path, headers: headers | |
end | |
def json_response | |
@json_response ||= HashWithIndifferentAccess.new(JSON.parse(response.body)) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_json '/v1/days' | |
expect(json_response[:data]).to include( | |
{ date: '2018-04-20', sunset_at: '19:47' }, | |
{ date: '2018-04-21', sunset_at: '19:48' }, | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allow(ENV).to receive(:fetch).with('API_KEY') { '123' } | |
get '/v1/days', { 'Content-Type' => 'application/json', 'X-Api-Key' => api_key } | |
expect(JSON.parse(response.body)['data']).to include( | |
{ 'date' => '2018-04-20', 'sunset_at' => '19:47' }, | |
{ 'date' => '2018-04-21', 'sunset_at' => '19:48' }, | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stub_request(:get, 'https://hotels.cloudbeds.com/api/v1.1/getRoomTypes') { { | |
body: | |
{ | |
'success' => true, | |
'data' => [{ | |
'roomTypeID' => '713', 'propertyID' => '276', 'roomTypeName' => 'AAA', | |
'roomTypeNameShort' => 'AAA', 'roomTypeDescription' => 'asdfa', 'isPrivate' => false, | |
'maxGuests' => '1', 'adultsIncluded' => '1', 'childrenIncluded' => 0, | |
'roomsAvailable' => 3, 'roomRate' => 120, 'roomTypeUnits' => 10 | |
}], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stub_request(:get, 'https://hotels.cloudbeds.com/api/v1.1/getRoomTypes') { { | |
body: | |
{ | |
'success' => true, | |
'data' => [ | |
{ | |
'roomTypeID' => '713', | |
'propertyID' => '276', | |
'roomTypeName' => 'AAA', | |
'roomTypeNameShort' => 'AAA', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe '#nightly_price_for' do | |
context 'when given night is not booked' do | |
context 'when given night is weekend night' do | |
context 'when weekend nightly rate is available for period' do | |
it 'returns weekend nightly rate for period' do | |
rates_table = <<~RATE_PLAN | |
Rate period | Nightly | Weekend Night | Weekly | Monthly | |
--------------------------------------------------------------------- | |
2017/07/20 - 2017/07/31 | 500 | 600 | 2800 | 30000 | |
2017/08/01 - 2017/08/10 | 200 | 400 (Sat,Sun) | 1400 | 20000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context 'when notifications service is disabled' do | |
it 'does not create project deletion notification for user' do | |
allow(notifier_client_double).to receive(:active?) { false } | |
user = create(:user) | |
project = create(:project, name: "Zebra", owner: user) | |
expect { DestroyProject.call(project) }.to_not change { Notification.count } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context 'when notifications service is disabled' do | |
it 'does not create project deletion notification for user' do | |
api_user = create(:user, :api) | |
api_user_account = create(:account, user: api_user) | |
notifier_client = instance_double(NotifierClient) | |
allow(NotifierClient).to receive(:for).with(api_user_account) { notifier_client } | |
allow(notifier_client).to receive(:active?) { false } | |
user = create(:user) | |
project = create(:project, name: "Zebra", owner: user) |