Skip to content

Commit

Permalink
test: ensure generated uuids are sequential/monotonic and correct tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Haddow committed Jun 27, 2024
1 parent 9e8242b commit 06ee7ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tests/app/Models/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Video extends Model
protected static function booting()
{
self::creating(static function (Video $video) {
$video->uuid = $video->uuid ?: Str::uuid()->toString();
$video->uuid = $video->uuid ?: Str::orderedUuid()->toString();
});
}

Expand Down
17 changes: 4 additions & 13 deletions tests/lib/Acceptance/Pagination/CursorPaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,31 +411,28 @@ public function testDeterministicOrder(): void
]);

$second = Video::factory()->create([
'uuid' => 'f3b3bea3-dca0-4ef9-b06c-43583a7e6118',
'created_at' => Carbon::now()->subHour(),
]);

$third = Video::factory()->create([
'uuid' => 'd215f35c-feb7-4cc5-9631-61742f00d0b2',
'created_at' => $second->created_at,
]);

$fourth = Video::factory()->create([
'uuid' => 'cbe17134-d7e2-4509-ba2c-3b3b5e3b2cbe',
'created_at' => $second->created_at,
]);

$page = $this->videos->repository()->queryAll()
->sort('createdAt')
->paginate(['limit' => '3']);

$this->assertPage([$first, $second, $third], $page);
$this->assertPage([$first, $fourth, $third], $page);

$page = $this->videos->repository()->queryAll()
->sort('-createdAt')
->paginate(['limit' => '3']);

$this->assertPage([$second, $third, $fourth], $page);
$this->assertPage([$fourth, $third, $second], $page);
}

public function testMultipleSorts(): void
Expand All @@ -447,33 +444,30 @@ public function testMultipleSorts(): void

$second = Video::factory()->create([
'title' => 'a',
'uuid' => 'f3b3bea3-dca0-4ef9-b06c-43583a7e6118',
'created_at' => Carbon::now()->subHour(),
]);

$third = Video::factory()->create([
'title' => 'b',
'uuid' => 'd215f35c-feb7-4cc5-9631-61742f00d0b2',
'created_at' => $second->created_at,
]);

$fourth = Video::factory()->create([
'title' => 'a',
'uuid' => 'cbe17134-d7e2-4509-ba2c-3b3b5e3b2cbe',
'created_at' => $second->created_at,
]);

$page = $this->videos->repository()->queryAll()
->sort('title,createdAt')
->paginate(['limit' => '3']);

$this->assertPage([$second, $fourth, $first], $page);
$this->assertPage([$fourth, $second, $first], $page);

$page = $this->videos->repository()->queryAll()
->sort('title,-createdAt')
->paginate(['limit' => '3']);

$this->assertPage([$second, $fourth, $third], $page);
$this->assertPage([$fourth, $second, $third], $page);
}

public function testWithoutKeySort(): void
Expand All @@ -486,17 +480,14 @@ public function testWithoutKeySort(): void

$second = Video::factory()->create([
'title' => 'a',
'uuid' => 'f3b3bea3-dca0-4ef9-b06c-43583a7e6118',
]);

$third = Video::factory()->create([
'title' => 'c',
'uuid' => 'd215f35c-feb7-4cc5-9631-61742f00d0b2',
]);

$fourth = Video::factory()->create([
'title' => 'b',
'uuid' => 'cbe17134-d7e2-4509-ba2c-3b3b5e3b2cbe',
]);

$page = $this->videos->repository()->queryAll()
Expand Down

0 comments on commit 06ee7ad

Please sign in to comment.