Skip to content

Commit 20d49e6

Browse files
bug: fix getSeasons for during and season_name queries, add tests for during
1 parent ba9e364 commit 20d49e6

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export async function getSeasons(
1616
query.where({ season_id });
1717
}
1818
if (season_name) {
19-
query.whereILike(season_name, "%season_name%");
19+
query.whereILike(season_name, `%{season_name}%`);
2020
}
2121
if (during) {
22-
query.where("end_at", "<=", during).where("start_at", "<=", during);
22+
query.where("end_at", ">=", during).where("start_at", "<=", during);
2323
}
2424
return await query;
2525
}

apps/backend/src/v1/season/test/integration.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ describe("Season table operations", () => {
4444
});
4545
describe("Use `getSeasons`", () => {
4646
test("Typical", async () => {
47+
const past_season = pastSeasonRecordFactory();
48+
const current_season = currentSeasonRecordFactory();
49+
const future_season = futureSeasonRecordFactory();
4750
await seed_db(
48-
new TestSeedSource({ season_records: [currentSeasonRecordFactory()] }),
51+
new TestSeedSource({
52+
season_records: [past_season, current_season, future_season],
53+
}),
4954
test_knexDb,
5055
);
51-
const result = await getSeasons({ during: Date() }, test_knexDb);
52-
console.log(result);
56+
57+
const result = await getSeasons({ during: (new Date()).toISOString() }, test_knexDb);
58+
59+
expect(result).toHaveLength(1);
60+
expect(result[0]).toMatchObject(current_season);
5361

5462
// const match_id = await createMatch(mockMatchReport.guild_id, test_knexDb);
5563
// const created_match = await test_knexDb("Match")

0 commit comments

Comments
 (0)