Skip to content

Commit 556388a

Browse files
committed
fix: improve snowflake ID test with explicit large ID and clearer naming
Address Copilot review feedback: - Test with actual snowflake-sized ID (420533451316027392) and assert exact match - Remove unused variables and rename test to reflect what it verifies
1 parent 2f83575 commit 556388a

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

tests/Feature/SnowflakeIdPrecisionTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,26 @@
1717
test('formatBoardRecord casts record ID to string to prevent JS precision loss', function () {
1818
$task = Task::factory()->todo()->withPosition('65535.0000000000')->create();
1919

20+
// Use a snowflake-like ID above Number.MAX_SAFE_INTEGER to exercise precision edge case
21+
$task->id = 420533451316027392;
22+
2023
$board = app(TestBoard::class)->getBoard();
2124
$formatted = $board->formatBoardRecord($task);
2225

2326
// The ID must be a string so @js() emits a JSON string ("123") not a number (123)
2427
// This prevents JavaScript precision loss for large IDs like snowflakes
2528
expect($formatted['id'])->toBeString();
29+
expect($formatted['id'])->toBe('420533451316027392');
2630
});
2731

28-
test('card blade renders recordKey as string in wire:click for large IDs', function () {
29-
$task = Task::factory()->todo()->withPosition('65535.0000000000')->create();
30-
31-
// Simulate what @js() does: json_encode the record ID
32-
// If ID is an integer, json_encode produces a number literal which JS truncates
33-
$idAsInt = (int) $task->id;
34-
$jsonFromInt = json_encode(['recordKey' => $idAsInt]);
35-
36-
// If ID is a string, json_encode produces a quoted string which JS preserves
37-
$idAsString = (string) $task->id;
38-
$jsonFromString = json_encode(['recordKey' => $idAsString]);
39-
32+
test('json_encode emits quoted recordKey for large string IDs', function () {
4033
// For a snowflake like 420533451316027392:
4134
// json_encode(int) -> {"recordKey":420533451316027392} <- JS reads as 420533451316027400 (WRONG)
4235
// json_encode(string) -> {"recordKey":"420533451316027392"} <- JS reads correctly
4336
$snowflakeId = 420533451316027392;
44-
$jsonSnowflakeInt = json_encode(['recordKey' => $snowflakeId]);
37+
4538
$jsonSnowflakeStr = json_encode(['recordKey' => (string) $snowflakeId]);
39+
$jsonSnowflakeInt = json_encode(['recordKey' => $snowflakeId]);
4640

4741
// The string version wraps in quotes, preserving exact value
4842
expect($jsonSnowflakeStr)->toContain('"420533451316027392"');

0 commit comments

Comments
 (0)