Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 330f63e

Browse files
authored
chore(lobbies): fix tests with stricter validation (#162)
1 parent 88c0be5 commit 330f63e

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

modules/lobbies/scripts/list.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ interface LobbyListEntry {
1919
id: string;
2020
version: string;
2121
tags: Record<string, string>;
22+
createdAt: string;
23+
players: number;
24+
maxPlayers: number;
25+
maxPlayersDirect: number;
2226
}
2327

2428
export async function run(
@@ -46,11 +50,11 @@ export async function run(
4650
id: lobby.id,
4751
version: lobby.version,
4852
tags: lobby.tags,
49-
createdAt: lobby.createdAt,
53+
createdAt: new Date(lobby.createdAt).toISOString(),
5054
players: lobby.players,
5155
maxPlayers: lobby.maxPlayers,
5256
maxPlayersDirect: lobby.maxPlayersDirect,
53-
}));
57+
} satisfies LobbyListEntry));
5458

5559
return { lobbies: lobbyList };
5660
}

modules/lobbies/tests/e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ test("lobby tags", async (ctx: TestContext) => {
8282
{
8383
version: VERSION,
8484
region: REGION,
85-
tags: { gameMode: "a", region: "atl" },
85+
tags: { gameMode: "a" },
8686
players: [{}],
8787
maxPlayers: 8,
8888
maxPlayersDirect: 8,

modules/tokens/scripts/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ScriptContext, Database, Query } from "../module.gen.ts";
2-
import { TokenWithSecret, tokenFromRow } from "../utils/types.ts";
2+
import { TokenWithSecret, tokenFromRow, tokenWithSecretFromRow } from "../utils/types.ts";
33

44
export interface Request {
55
type: string;
@@ -28,7 +28,7 @@ export async function run(
2828
.returning();
2929

3030
return {
31-
token: tokenFromRow(rows[0]!),
31+
token: tokenWithSecretFromRow(rows[0]!),
3232
};
3333
}
3434

modules/tokens/scripts/extend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ScriptContext, Query, Database } from "../module.gen.ts";
2-
import { tokenFromRow, TokenWithSecret } from "../utils/types.ts";
2+
import { tokenFromRow, TokenWithSecret, tokenWithSecretFromRow } from "../utils/types.ts";
33

44
export interface Request {
55
token: string;
@@ -27,6 +27,6 @@ export async function run(
2727

2828
// Return the updated token
2929
return {
30-
token: tokenFromRow(rows[0]!),
30+
token: tokenWithSecretFromRow(rows[0]!),
3131
};
3232
}

modules/tokens/scripts/revoke.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface Request {
55
}
66

77
export interface Response {
8-
updates: { [key: string]: TokenUpdate };
8+
updates: Record<string, TokenUpdate>;
99
}
1010

1111
export enum TokenUpdate {

modules/tokens/tests/validate.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
assertEquals,
44
assertGreater,
55
assertRejects,
6-
} from "https://deno.land/[email protected]/assert/mod.ts";
6+
} from "jsr:@std/assert";
7+
import { omit } from "jsr:@std/collections";
78

89
test(
910
"validate token not found",
@@ -95,7 +96,7 @@ test(
9596
...validateResAfterWait.token,
9697
expireAt: null,
9798
}, {
98-
...token,
99+
...omit(token, ["token"]),
99100
expireAt: null,
100101
});
101102
},

modules/tokens/utils/types.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,22 @@ export interface TokenWithSecret extends Token {
1515

1616
export function tokenFromRow(
1717
row: typeof Database.tokens.$inferSelect
18-
): TokenWithSecret {
18+
): Token {
1919
return {
20-
...row,
20+
id: row.id,
21+
type: row.type,
22+
meta: row.meta,
2123
createdAt: row.createdAt.toISOString(),
2224
expireAt: row.expireAt?.toISOString() ?? null,
2325
revokedAt: row.revokedAt?.toISOString() ?? null,
2426
};
2527
}
28+
29+
export function tokenWithSecretFromRow(
30+
row: typeof Database.tokens.$inferSelect
31+
): TokenWithSecret {
32+
return {
33+
...tokenFromRow(row),
34+
token: row.token,
35+
};
36+
}

0 commit comments

Comments
 (0)