Skip to content

Commit 30fc2bd

Browse files
[style] Run biome check --fix, use more destructuring in unit tests for match
1 parent 7df7784 commit 30fc2bd

10 files changed

Lines changed: 29 additions & 35 deletions

File tree

apps/backend/seeds/SSBUCharacters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Knex} from "knex";
1+
import type { Knex } from "knex";
22

33
export const ssbu_character_names = [
44
"Mario",

apps/backend/src/db/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const SQLiteDateTimeToISODateTime = z.codec(
1010
{
1111
decode: (sqlite_datetime: string) => {
1212
if (z.iso.datetime().safeParse(sqlite_datetime).success) {
13-
return sqlite_datetime
13+
return sqlite_datetime;
1414
}
1515
const withT = sqlite_datetime.replace(" ", "T");
1616
const hasTz = /([zZ]|[+-]\d{2}:\d{2})$/.test(withT);

apps/backend/src/test/MockSeedSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class MockSeedSource {
2626
},
2727
};
2828
default:
29-
throw new Error(`Invalid seed: "${seed}"`)
29+
throw new Error(`Invalid seed: "${seed}"`);
3030
}
3131
}
3232
}

apps/backend/src/v1/match/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { z } from "zod";
21
import type { Knex } from "knex";
2+
import { z } from "zod";
33

44
export const MatchRecord = z.object({
55
match_id: z.int(),
@@ -50,7 +50,7 @@ export type MatchCharacterRecord = z.infer<typeof MatchCharacterRecord>;
5050
export const MatchCharacterTable = {
5151
table_name: "MatchCharacter",
5252
initialize(table: Knex.TableBuilder) {
53-
table.primary(["match_id", "user_id", "fighter_number"])
53+
table.primary(["match_id", "user_id", "fighter_number"]);
5454

5555
table.integer("match_id").unsigned();
5656
table.string("user_id");

apps/backend/src/v1/match/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { knexDb } from "@db/knexfile";
2-
import type { MatchPlayer, MatchQuery, MatchReport } from "@v1/match/schemas";
3-
import type { Knex } from "knex";
2+
import type { MatchQuery, MatchReport } from "@v1/match/schemas";
43
import type { MatchReportDerivedRow } from "@v1/match/views";
4+
import type { Knex } from "knex";
55

66
/** Report a match.
77
* Transactionally, create a record in the Match table, then create the matching pair

apps/backend/src/v1/match/test/unit.test.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { init_tables, init_views, teardown } from "@db/init_tables";
22
import { test_knexDb } from "@test/test_knexfile";
3-
import type { MatchPlayer, MatchQuery, MatchReport } from "@v1/match/schemas";
3+
import type { MatchCharacterRecord } from "@v1/match/models";
4+
import type { MatchQuery, MatchReport } from "@v1/match/schemas";
45
import {
56
createMatch,
67
createMatchCharacter,
@@ -9,9 +10,8 @@ import {
910
reportMatch,
1011
} from "@v1/match/service";
1112
import { mock_MatchReport } from "@v1/match/test/mock.schemas";
13+
import { MatchReportDerivedRow } from "@v1/match/views";
1214
import { afterEach, beforeEach, describe, expect, test } from "vitest";
13-
import type { MatchCharacterRecord, MatchPlayerRecord } from "../models";
14-
import { MatchReportDerivedRow } from "../views";
1515

1616
// const _mockMatchReport = MatchReport.parse({
1717
// guild_id: "19283746",
@@ -122,12 +122,12 @@ describe("Match DB operations", () => {
122122
const expected_match_characters = () => {
123123
const result = [];
124124
for (let p_i = 0; p_i < mockMatchReport.players.length; p_i++) {
125-
const player = mockMatchReport.players[p_i];
126-
for (let c_i = 0; c_i < player.character.length; c_i++) {
127-
const fighter_number = player.character[c_i];
125+
const { user_id, character } = mockMatchReport.players[p_i];
126+
for (let c_i = 0; c_i < character.length; c_i++) {
127+
const fighter_number = character[c_i];
128128
result.push({
129129
match_id,
130-
user_id: player.user_id,
130+
user_id,
131131
fighter_number,
132132
});
133133
}
@@ -165,15 +165,15 @@ describe("Match DB operations", () => {
165165
describe("Insert all records for an entire MatchReport (covers all insertion tests)", async () => {
166166
test("Report a match", async () => {
167167
const match_id = await reportMatch(mockMatchReport, test_knexDb);
168-
const match_record = await test_knexDb("Match").first().where({ match_id });
168+
const { guild_id } = mockMatchReport;
169169
const match_player_records = await test_knexDb("MatchPlayer")
170170
.select()
171171
.where({ match_id });
172172
const match_character_records = await test_knexDb("MatchCharacter")
173173
.select()
174174
.where({ match_id });
175175
const expected: MatchReport = {
176-
guild_id: match_record.guild_id,
176+
guild_id,
177177
players: match_player_records.map(({ user_id, win_count }) => ({
178178
user_id,
179179
win_count,
@@ -203,25 +203,23 @@ describe("Match DB operations", () => {
203203
describe("Retrieve a full written MatchReport record", async () => {
204204
test("Retrieve a derived row from MatchReportView by match_id", async () => {
205205
const match_id = await reportMatch(mockMatchReport, test_knexDb);
206-
const match_record = await test_knexDb("Match")
207-
.select()
208-
.where({ match_id });
206+
const { guild_id } = mockMatchReport;
209207

210208
const match_query: MatchQuery = { match_id };
211209
const result = await getMatches(match_query, test_knexDb);
212210
const created_at = result[0].created_at;
213211

214212
const expected = [];
215213
for (let p_i = 0; p_i < mockMatchReport.players.length; p_i++) {
216-
const player = mockMatchReport.players[p_i];
217-
for (let c_i = 0; c_i < player.character.length; c_i++) {
218-
const fighter_number = player.character[c_i];
214+
const { user_id, win_count, character } = mockMatchReport.players[p_i];
215+
for (let c_i = 0; c_i < character.length; c_i++) {
216+
const fighter_number = character[c_i];
219217
expected.push(
220218
MatchReportDerivedRow.parse({
221219
match_id,
222-
guild_id: mockMatchReport.guild_id,
223-
user_id: player.user_id,
224-
win_count: player.win_count,
220+
guild_id,
221+
user_id,
222+
win_count,
225223
fighter_number,
226224
created_at,
227225
}),

apps/backend/src/v1/match/views.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { SQLiteDateTimeToISODateTime } from "@db/schemas";
12
import { SSBUCharFighterNumber } from "@v1/match/schemas";
23
import type { Knex } from "knex";
3-
import { SQLiteDateTimeToISODateTime } from "@db/schemas";
44
import { z } from "zod";
55

66
export const MatchWinnerView = (db: Knex) => ({
@@ -27,7 +27,7 @@ export const MatchReportDerivedRow = z.object({
2727
user_id: z.string(),
2828
win_count: z.int(),
2929
fighter_number: SSBUCharFighterNumber,
30-
created_at: SQLiteDateTimeToISODateTime
30+
created_at: SQLiteDateTimeToISODateTime,
3131
});
3232
export type MatchReportDerivedRow = z.infer<typeof MatchReportDerivedRow>;
3333
export const MatchReportView = (db: Knex) => ({
@@ -51,7 +51,7 @@ export const MatchReportView = (db: Knex) => ({
5151
"MatchPlayer.user_id as user_id",
5252
"MatchPlayer.win_count as win_count",
5353
"MatchCharacter.fighter_number as fighter_number",
54-
"Match.created_at as created_at"
54+
"Match.created_at as created_at",
5555
),
5656
);
5757
},

apps/backend/src/v1/user/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export async function getLeaderboard(
88
guild_id: string,
99
tier: number,
1010
): Promise<Array<string>> {
11-
return ["B", "A"]
11+
return ["B", "A"];
1212
}

apps/backend/tsconfig.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,5 @@
2424
"@v1/*": ["v1/*"]
2525
}
2626
},
27-
"exclude": [
28-
"vitest.config.ts",
29-
"dist",
30-
"node_modules"
31-
]
27+
"exclude": ["vitest.config.ts", "dist", "node_modules"]
3228
}

apps/backend/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default defineConfig({
1919
include: ["src/**/*.test.ts"],
2020
typecheck: {
2121
include: ["src/**/*"],
22-
enabled: true
22+
enabled: true,
2323
},
2424
name: { label: "unit" },
2525
},

0 commit comments

Comments
 (0)