Skip to content

Commit

Permalink
Specify order addresses in some OrderSyncer specs
Browse files Browse the repository at this point in the history
This is to check that we are using the correct address data in
assertions.

This also clarifies the scenario for one of the specs.
  • Loading branch information
kristinalim committed Mar 14, 2019
1 parent c8a5e6f commit 3755fbc
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions spec/services/order_syncer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,17 @@
describe "changing the billing address" do
let!(:distributor_address) { create(:address, address1: "Distributor Address") }
let!(:distributor) { create(:distributor_enterprise, address: distributor_address) }
let!(:original_ship_address) { create(:address) }
let!(:original_bill_address) do
create(:address, firstname: "Walter", lastname: "Wolf", address1: "White")
end
let!(:original_ship_address) do
create(:address, firstname: "Melanie", lastname: "Miller", address1: "Magenta")
end

let(:subscription) do
create(:subscription, shop: distributor, ship_address: original_ship_address,
with_items: true, with_proxy_orders: true)
create(:subscription, shop: distributor, bill_address: original_bill_address,
ship_address: original_ship_address, with_items: true,
with_proxy_orders: true)
end

let(:shipping_method) { subscription.shipping_method }
Expand All @@ -156,7 +162,7 @@
expect(order.bill_address.address1).to eq "123 abc st"
expect(order.bill_address.phone).to eq "1123581321"
expect(order.ship_address.firstname).to eq "Bill"
expect(order.ship_address.lastname).to eq ship_address_attrs["lastname"]
expect(order.ship_address.lastname).to eq bill_address_attrs["lastname"]
expect(order.ship_address.address1).to eq distributor_address.address1
expect(order.ship_address.phone).to eq "1123581321"
end
Expand All @@ -174,7 +180,7 @@
expect(order.bill_address.address1).to eq bill_address_attrs["address1"]
expect(order.bill_address.phone).to eq bill_address_attrs["phone"]
expect(order.ship_address.firstname).to eq "Jane"
expect(order.ship_address.lastname).to eq ship_address_attrs["lastname"]
expect(order.ship_address.lastname).to eq bill_address_attrs["lastname"]
expect(order.ship_address.address1).to eq distributor_address.address1
expect(order.ship_address.phone).to eq ship_address_attrs["phone"]
end
Expand Down Expand Up @@ -225,11 +231,17 @@
describe "changing the ship address" do
let!(:distributor_address) { create(:address, address1: "Distributor Address") }
let!(:distributor) { create(:distributor_enterprise, address: distributor_address) }
let!(:original_ship_address) { create(:address) }
let!(:original_bill_address) do
create(:address, firstname: "Walter", lastname: "Wolf", address1: "White")
end
let!(:original_ship_address) do
create(:address, firstname: "Melanie", lastname: "Miller", address1: "Magenta")
end

let(:subscription) do
create(:subscription, shop: distributor, ship_address: original_ship_address,
with_items: true, with_proxy_orders: true)
create(:subscription, shop: distributor, bill_address: original_bill_address,
ship_address: original_ship_address, with_items: true,
with_proxy_orders: true)
end

let(:shipping_method) { subscription.shipping_method }
Expand All @@ -247,8 +259,8 @@
expect(syncer.sync!).to be true
expect(syncer.order_update_issues.keys).to_not include order.id
order.reload;
expect(order.ship_address.firstname).to eq ship_address_attrs["firstname"]
expect(order.ship_address.lastname).to eq ship_address_attrs["lastname"]
expect(order.ship_address.firstname).to eq bill_address_attrs["firstname"]
expect(order.ship_address.lastname).to eq bill_address_attrs["lastname"]
expect(order.ship_address.address1).to eq distributor_address.address1
expect(order.ship_address.phone).to eq ship_address_attrs["phone"]
end
Expand All @@ -258,8 +270,12 @@

before { params.merge!(shipping_method_id: new_shipping_method.id) }

context "when the original ship address is the same as the distributor address" do
let!(:original_ship_address) { create(:address, address1: distributor_address.address1) }
context "when the original ship address is the bill contact using distributor address" do
let!(:original_ship_address) do
create(:address, firstname: original_bill_address.firstname,
lastname: original_bill_address.lastname,
address1: distributor_address.address1)
end

it "updates ship_address attrs" do
subscription.assign_attributes(params)
Expand Down

0 comments on commit 3755fbc

Please sign in to comment.