|
36 | 36 | describe '.create' do |
37 | 37 | it 'makes a new POST request using the correct API endpoint' do |
38 | 38 | expect(Shipcloud).to receive(:request). |
39 | | - with(:post, "addresses", valid_attributes, api_key: nil).and_return("data" => {}) |
| 39 | + with(:post, "addresses", valid_attributes, api_key: nil, affiliate_id: nil). |
| 40 | + and_return("data" => {}) |
40 | 41 |
|
41 | 42 | Shipcloud::Address.create(valid_attributes) |
42 | 43 | end |
43 | 44 |
|
44 | 45 | it "returns an address containing an id" do |
45 | 46 | expect(Shipcloud).to receive(:request). |
46 | | - with(:post, "addresses", valid_attributes, api_key: nil). |
| 47 | + with(:post, "addresses", valid_attributes, api_key: nil, affiliate_id: nil). |
47 | 48 | and_return(returned_address) |
48 | 49 |
|
49 | 50 | address = Shipcloud::Address.create(valid_attributes) |
50 | 51 |
|
51 | 52 | expect(address.id).to eq("1c81efb7-9b95-4dd8-92e3-cac1bca3df6f") |
52 | 53 | end |
| 54 | + |
| 55 | + it "use the affiliate ID provided for the request" do |
| 56 | + expect(Shipcloud).to receive(:request). |
| 57 | + with(:post, "addresses", valid_attributes, api_key: nil, affiliate_id: "affiliate_id"). |
| 58 | + and_return(returned_address) |
| 59 | + |
| 60 | + address = Shipcloud::Address.create(valid_attributes, affiliate_id: "affiliate_id") |
| 61 | + |
| 62 | + expect(address.id).to eq("1c81efb7-9b95-4dd8-92e3-cac1bca3df6f") |
| 63 | + end |
53 | 64 | end |
54 | 65 |
|
55 | 66 | describe '.find' do |
56 | 67 | it 'makes a new GET request using the correct API endpoint to receive a specific address' do |
57 | 68 | expect(Shipcloud).to receive(:request).with( |
58 | | - :get, "addresses/123", {}, api_key: nil).and_return("id" => "123") |
| 69 | + :get, "addresses/123", {}, api_key: nil, affiliate_id: nil).and_return("id" => "123") |
59 | 70 |
|
60 | 71 | Shipcloud::Address.find("123") |
61 | 72 | end |
| 73 | + |
| 74 | + it "use the affiliate ID provided for the request" do |
| 75 | + expect(Shipcloud).to receive(:request).with( |
| 76 | + :get, "addresses/123", {}, api_key: nil, affiliate_id: "affiliate_id" |
| 77 | + ).and_return("id" => "123") |
| 78 | + |
| 79 | + Shipcloud::Address.find("123", affiliate_id: "affiliate_id") |
| 80 | + end |
62 | 81 | end |
63 | 82 |
|
64 | 83 | describe '.update' do |
65 | 84 | it 'makes a new PUT request using the correct API endpoint' do |
66 | 85 | expect(Shipcloud).to receive(:request).with( |
67 | | - :put, "addresses/123", { street: "Mittelweg" }, api_key: nil).and_return("data" => {}) |
| 86 | + :put, "addresses/123", { street: "Mittelweg" }, api_key: nil, affiliate_id: nil |
| 87 | + ).and_return("data" => {}) |
68 | 88 |
|
69 | 89 | Shipcloud::Address.update("123", street: "Mittelweg") |
70 | 90 | end |
| 91 | + |
| 92 | + it "use the affiliate ID provided for the request" do |
| 93 | + expect(Shipcloud).to receive(:request).with( |
| 94 | + :put, "addresses/123", { street: "Mittelweg" }, api_key: nil, affiliate_id: "affiliate_id" |
| 95 | + ).and_return("data" => {}) |
| 96 | + |
| 97 | + Shipcloud::Address.update("123", { street: "Mittelweg" }, affiliate_id: "affiliate_id") |
| 98 | + end |
71 | 99 | end |
72 | 100 |
|
73 | 101 | describe '.all' do |
74 | 102 | it 'makes a new Get request using the correct API endpoint' do |
75 | 103 | expect(Shipcloud).to receive(:request). |
76 | | - with(:get, "addresses", {}, api_key: nil).and_return([]) |
| 104 | + with(:get, "addresses", {}, api_key: nil, affiliate_id: nil).and_return([]) |
77 | 105 |
|
78 | 106 | Shipcloud::Address.all |
79 | 107 | end |
|
87 | 115 | expect(address).to be_a Shipcloud::Address |
88 | 116 | end |
89 | 117 | end |
| 118 | + |
| 119 | + it "use the affiliate ID provided for the request" do |
| 120 | + stub_addresses_request(affiliate_id: "affiliate_id") |
| 121 | + |
| 122 | + addresses = Shipcloud::Address.all(affiliate_id: "affiliate_id") |
| 123 | + |
| 124 | + addresses.each do |address| |
| 125 | + expect(address).to be_a Shipcloud::Address |
| 126 | + end |
| 127 | + end |
90 | 128 | end |
91 | 129 |
|
92 | | - def stub_addresses_request |
| 130 | + def stub_addresses_request(affiliate_id: nil) |
93 | 131 | allow(Shipcloud).to receive(:request). |
94 | | - with(:get, "addresses", {}, api_key: nil). |
| 132 | + with(:get, "addresses", {}, api_key: nil, affiliate_id: affiliate_id). |
95 | 133 | and_return( |
96 | 134 | [ |
97 | 135 | { |
|
0 commit comments