|
86 | 86 | end |
87 | 87 |
|
88 | 88 | describe "#all" do |
89 | | - let!(:first_response_stub) do |
90 | | - stub_request(:get, "https://api.duffel.com/air/airlines").to_return( |
91 | | - body: first_page_response_body, |
92 | | - headers: response_headers, |
93 | | - ) |
94 | | - end |
95 | | - |
96 | 89 | let(:first_page_response_body) { load_fixture("airlines/list.json") } |
97 | 90 |
|
98 | 91 | let(:last_page_response_body) do |
99 | 92 | convert_list_response_to_last_page(first_page_response_body) |
100 | 93 | end |
101 | 94 |
|
| 95 | + let(:expected_query_params) do |
| 96 | + { limit: 200 } |
| 97 | + end |
| 98 | + |
| 99 | + let!(:first_response_stub) do |
| 100 | + stub_request(:get, "https://api.duffel.com/air/airlines"). |
| 101 | + with(query: expected_query_params). |
| 102 | + to_return( |
| 103 | + body: first_page_response_body, |
| 104 | + headers: response_headers, |
| 105 | + ) |
| 106 | + end |
| 107 | + |
102 | 108 | let!(:second_response_stub) do |
103 | 109 | stub_request(:get, "https://api.duffel.com/air/airlines"). |
104 | | - with(query: { "after" => "g3QAAAACZAACaWRtAAAAGmFybF8wMDAwOVZNRTd" \ |
105 | | - "EQUdpSmp3b21odjM1ZAAEbmFtZW0AAAARQWZyaX" \ |
106 | | - "FpeWFoIEFpcndheXM=" }). |
| 110 | + with(query: expected_query_params.merge( |
| 111 | + after: "g3QAAAACZAACaWRtAAAAGmFybF8wMDAwOVZNRTdEQUdpSmp3b21odjM1ZAAEbmFtZW0AA" \ |
| 112 | + "AARQWZyaXFpeWFoIEFpcndheXM=", |
| 113 | + )). |
107 | 114 | to_return( |
108 | 115 | body: last_page_response_body, |
109 | 116 | headers: response_headers, |
110 | 117 | ) |
111 | 118 | end |
112 | 119 |
|
113 | | - it "automatically makes the extra requests to load all the pages" do |
| 120 | + it "automatically makes the requests to load all pages, 200 results at a time" do |
114 | 121 | expect(client.airlines.all.to_a.length).to eq(100) |
115 | 122 | expect(first_response_stub).to have_been_requested |
116 | 123 | expect(second_response_stub).to have_been_requested |
|
137 | 144 | expect(api_response.request_id).to eq(response_headers["x-request-id"]) |
138 | 145 | expect(api_response.status_code).to eq(200) |
139 | 146 | end |
| 147 | + |
| 148 | + context "customising the limit per page" do |
| 149 | + let(:expected_query_params) do |
| 150 | + { limit: 33 } |
| 151 | + end |
| 152 | + |
| 153 | + it "requests the requested number of items per page from the API" do |
| 154 | + client.airlines. |
| 155 | + all(params: { limit: 33 }). |
| 156 | + to_a |
| 157 | + |
| 158 | + expect(first_response_stub).to have_been_requested |
| 159 | + expect(second_response_stub).to have_been_requested |
| 160 | + end |
| 161 | + end |
140 | 162 | end |
141 | 163 |
|
142 | 164 | describe "#get" do |
|
0 commit comments