|
205 | 205 | end |
206 | 206 | end |
207 | 207 |
|
| 208 | + context 'when an empty page is received, but with a cursor' do |
| 209 | + before do |
| 210 | + stub_fetch_all("https://#{host}/xrpc/com.example.service.fetchAll", [ |
| 211 | + { "feed": ["one", "two", "three"] }, |
| 212 | + { "feed": [] }, |
| 213 | + { "feed": ["six"] }, |
| 214 | + ]) |
| 215 | + end |
| 216 | + |
| 217 | + it 'should continue fetching until the cursor is nil' do |
| 218 | + result = subject.fetch_all('com.example.service.fetchAll', field: 'feed') |
| 219 | + result.should == ['one', 'two', 'three', 'six'] |
| 220 | + end |
| 221 | + end |
| 222 | + |
| 223 | + context 'when field is not passed' do |
| 224 | + before do |
| 225 | + stub_fetch_all("https://#{host}/xrpc/com.example.service.fetchAll", [ |
| 226 | + { "thingies": ["one", "two", "three"], "best": "two", "foobars": ["foo", "bar"], "total": 6 }, |
| 227 | + { "items": ["four", "five"] }, |
| 228 | + ]) |
| 229 | + end |
| 230 | + |
| 231 | + it 'should make one request and raise an error with list of array fields' do |
| 232 | + expect { subject.fetch_all('com.example.service.fetchAll') }.to raise_error { |err| |
| 233 | + err.should be_a(Minisky::FieldNotSetError) |
| 234 | + err.fields.should == ['thingies', 'foobars'] |
| 235 | + } |
| 236 | + |
| 237 | + WebMock.should have_requested(:get, @stubbed_urls[0]).once |
| 238 | + WebMock.should_not have_requested(:get, @stubbed_urls[1]) |
| 239 | + end |
| 240 | + end |
| 241 | + |
| 242 | + context 'when field is nil' do |
| 243 | + before do |
| 244 | + stub_fetch_all("https://#{host}/xrpc/com.example.service.fetchAll", [ |
| 245 | + { "thingies": ["one", "two", "three"], "best": "two", "foobars": ["foo", "bar"], "total": 6 }, |
| 246 | + { "items": ["four", "five"] }, |
| 247 | + ]) |
| 248 | + end |
| 249 | + |
| 250 | + it 'should make one request and raise an error with list of array fields' do |
| 251 | + expect { subject.fetch_all('com.example.service.fetchAll', field: nil) }.to raise_error { |err| |
| 252 | + err.should be_a(Minisky::FieldNotSetError) |
| 253 | + err.fields.should == ['thingies', 'foobars'] |
| 254 | + } |
| 255 | + |
| 256 | + WebMock.should have_requested(:get, @stubbed_urls[0]).once |
| 257 | + WebMock.should_not have_requested(:get, @stubbed_urls[1]) |
| 258 | + end |
| 259 | + end |
| 260 | + |
208 | 261 | describe 'progress param' do |
209 | 262 | before do |
210 | 263 | stub_request(:get, "https://#{host}/xrpc/com.example.service.fetchAll") |
|
0 commit comments