add stable secondary sorting based on id to the tests to avoid flakyness

This commit is contained in:
Gregor Vostrak
2026-07-08 18:24:04 +02:00
parent 4a5ba9ff28
commit 65fbb43aa6
3 changed files with 8 additions and 5 deletions

View File

@@ -45,7 +45,7 @@ class ClientEndpointTest extends ApiEndpointTestAbstract
// Assert
$response->assertStatus(200);
$response->assertJsonCount(4, 'data');
$clients = Client::query()->orderBy('created_at', 'desc')->get();
$clients = Client::query()->orderBy('created_at', 'desc')->orderBy('id')->get();
$response->assertJson(fn (AssertableJson $json) => $json
->has('data')
->has('links')
@@ -84,9 +84,12 @@ class ClientEndpointTest extends ApiEndpointTestAbstract
->has('links')
->has('meta')
->count('data', 2)
->where('data.0.id', $clients->get(0)->getKey())
->where('data.1.id', $clients->get(1)->getKey())
);
// Both clients share the same created_at, so their relative order is not defined.
$this->assertEqualsCanonicalizing([
$clients->get(0)->getKey(),
$clients->get(1)->getKey(),
], $response->json('data.*.id'));
}
public function test_index_endpoint_without_filter_archived_returns_only_non_archived_clients(): void

View File

@@ -51,7 +51,7 @@ class ReportEndpointTest extends ApiEndpointTestAbstract
// Assert
$response->assertStatus(200);
$response->assertJsonCount(4, 'data');
$reports = Report::query()->orderBy('created_at', 'desc')->get();
$reports = Report::query()->orderBy('created_at', 'desc')->orderBy('id')->get();
$response->assertJson(fn (AssertableJson $json) => $json
->has('data')
->has('links')

View File

@@ -44,7 +44,7 @@ class TagEndpointTest extends ApiEndpointTestAbstract
// Assert
$response->assertStatus(200);
$response->assertJsonCount(4, 'data');
$tags = Tag::query()->orderBy('created_at', 'desc')->get();
$tags = Tag::query()->orderBy('created_at', 'desc')->orderBy('id')->get();
$response->assertJson(fn (AssertableJson $json) => $json
->has('data')
->has('links')