diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e50547e8..d3e86468d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ how this file is formatted and how the process works. ### Fixed - JTB: ignore units without availability calendar +- Add `:property_not_instant_bookable` and `:max_guests_exceeded` errors to `ERROR_CODES_WITH_SUCCESS_RESPONSE` ### Changed - Refactor reading `suppliers.yml`, extract all logic in `Concierge::SupplierConfig` class diff --git a/lib/concierge/errors/quote.rb b/lib/concierge/errors/quote.rb index 8c50d914c..099d5b8ce 100644 --- a/lib/concierge/errors/quote.rb +++ b/lib/concierge/errors/quote.rb @@ -2,7 +2,8 @@ # for constructing common quote errors module Concierge::Errors::Quote - ERROR_CODES_WITH_SUCCESS_RESPONSE = [:check_in_too_near, :check_in_too_far, :stay_too_short] + ERROR_CODES_WITH_SUCCESS_RESPONSE = [:check_in_too_near, :check_in_too_far, :stay_too_short, + :property_not_instant_bookable, :max_guests_exceeded] def check_in_too_near Result.error(:check_in_too_near, "Selected check-in date is too near") diff --git a/spec/api/controllers/atleisure/quote_spec.rb b/spec/api/controllers/atleisure/quote_spec.rb index 6f3b361af..d9533177c 100644 --- a/spec/api/controllers/atleisure/quote_spec.rb +++ b/spec/api/controllers/atleisure/quote_spec.rb @@ -56,7 +56,7 @@ def provoke_failure! stub_call(:post, endpoint) { [200, {}, jsonrpc_fixture("atleisure/on_request.json")] } response = parse_response(described_class.new.call(params)) - expect(response.status).to eq 503 + expect(response.status).to eq 200 expect(response.body["status"]).to eq "error" expect(response.body["errors"]["quote"]).to eq "Instant booking is not supported for the given period" end diff --git a/spec/api/controllers/shared/quote_call.rb b/spec/api/controllers/shared/quote_call.rb index 51b103035..42906c1ca 100644 --- a/spec/api/controllers/shared/quote_call.rb +++ b/spec/api/controllers/shared/quote_call.rb @@ -44,6 +44,27 @@ end end + context "client returns property_not_instant_bookable" do + it "returns proper error messages" do + expect_any_instance_of(described_class).to receive(:quote_price).and_return(not_instant_bookable) + response = parse_response(subject) + expect(response.status).to eq 200 + expect(response.body["status"]).to eq "error" + expect(response.body["errors"]["quote"]).to eq "Instant booking is not supported for the given period" + end + end + + context "client returns max_guests_exceeded" do + it "returns proper error messages" do + expect_any_instance_of(described_class).to receive(:quote_price).and_return(max_guests_exceeded(5)) + response = parse_response(subject) + expect(response.status).to eq 200 + expect(response.body["status"]).to eq "error" + expect(response.body["errors"]["quote"]).to eq "The maximum number of guests to book this apartment is 5" + end + end + + it "returns unavailable quotation" do unavailable_quotation = Quotation.new({ property_id: params[:property_id],