|
9 | 9 | use Illuminate\Database\ConnectionResolver;
|
10 | 10 | use Kitar\Dynamodb\Model\KeyMissingException;
|
11 | 11 | use BadMethodCallException;
|
| 12 | +use Kitar\Dynamodb\Helpers\Collection; |
12 | 13 |
|
13 | 14 | class ModelTest extends TestCase
|
14 | 15 | {
|
@@ -36,6 +37,15 @@ protected function newConnectionMock()
|
36 | 37 | return $connection;
|
37 | 38 | }
|
38 | 39 |
|
| 40 | + protected function sampleAwsResult() |
| 41 | + { |
| 42 | + return new Result([ |
| 43 | + 'Items' => [], |
| 44 | + 'LastEvaluatedKey' => ['id' => ['S' => '1']], |
| 45 | + '@metadata' => ['statusCode' => 200], |
| 46 | + ]); |
| 47 | + } |
| 48 | + |
39 | 49 | protected function sampleAwsResultEmpty()
|
40 | 50 | {
|
41 | 51 | return new Result([
|
@@ -400,14 +410,39 @@ public function it_can_process_all()
|
400 | 410 | ];
|
401 | 411 |
|
402 | 412 | $return = new Result([
|
403 |
| - 'Items' => [] |
| 413 | + 'Items' => [ |
| 414 | + ['name' => ['S' => 'User 1']], |
| 415 | + ['name' => ['S' => 'User 2']] |
| 416 | + ] |
404 | 417 | ]);
|
405 | 418 |
|
406 | 419 | $connection = $this->newConnectionMock();
|
407 | 420 | $connection->shouldReceive('scan')->with($params)->andReturn($return)->once();
|
408 | 421 | $this->setConnectionResolver($connection);
|
409 | 422 |
|
410 |
| - UserA::all(); |
| 423 | + $res = UserA::all(); |
| 424 | + |
| 425 | + $this->assertSame(2, $res->count()); |
| 426 | + $this->assertInstanceOf(Collection::class, $res); |
| 427 | + $this->assertInstanceOf(UserA::class, $res->first()); |
| 428 | + $this->assertSame('User 1', $res->first()->name); |
| 429 | + $this->assertNull($res->getLastEvaluatedKey()); |
| 430 | + } |
| 431 | + |
| 432 | + /** @test */ |
| 433 | + public function it_can_get_last_evaluated_key() |
| 434 | + { |
| 435 | + $params = [ |
| 436 | + 'TableName' => 'User' |
| 437 | + ]; |
| 438 | + |
| 439 | + $connection = $this->newConnectionMock(); |
| 440 | + $connection->shouldReceive('scan')->with($params)->andReturn($this->sampleAwsResult())->once(); |
| 441 | + $this->setConnectionResolver($connection); |
| 442 | + |
| 443 | + $res = UserA::all(); |
| 444 | + |
| 445 | + $this->assertSame(['id' => ['S' => '1']], $res->getLastEvaluatedKey()); |
411 | 446 | }
|
412 | 447 |
|
413 | 448 | /** @test */
|
|
0 commit comments