77 currentSeasonRecordFactory ,
88 futureSeasonRecordFactory ,
99 pastSeasonRecordFactory ,
10- seasonRecordFactory ,
1110} from "@v1/season/test/models.factories" ;
1211import type { Knex } from "knex" ;
1312import { afterEach , beforeEach , describe , expect , test } from "vitest" ;
@@ -43,7 +42,7 @@ describe("Season table operations", () => {
4342 await teardown ( test_knexDb ) ;
4443 } ) ;
4544 describe ( "Use `getSeasons`" , ( ) => {
46- test ( "Typical " , async ( ) => {
45+ test ( "Based on `after` and `before` arguments " , async ( ) => {
4746 const past_season = pastSeasonRecordFactory ( ) ;
4847 const current_season = currentSeasonRecordFactory ( ) ;
4948 const future_season = futureSeasonRecordFactory ( ) ;
@@ -54,19 +53,46 @@ describe("Season table operations", () => {
5453 test_knexDb ,
5554 ) ;
5655
57- const result = await getSeasons ( { during : ( new Date ( ) ) . toISOString ( ) } , test_knexDb ) ;
56+ const current_result = await getSeasons (
57+ { before : new Date ( ) . toISOString ( ) , after : new Date ( ) . toISOString ( ) } ,
58+ test_knexDb ,
59+ ) ;
60+ expect ( current_result , "Returns only the ongoing Season" ) . toHaveLength ( 1 ) ;
61+ expect ( current_result [ 0 ] ) . toMatchObject ( current_season ) ;
5862
59- expect ( result ) . toHaveLength ( 1 ) ;
60- expect ( result [ 0 ] ) . toMatchObject ( current_season ) ;
63+ const reverse_result = await getSeasons (
64+ {
65+ before : new Date ( Date . now ( ) - 1000 ) . toISOString ( ) ,
66+ after : new Date ( Date . now ( ) + 1000 ) . toISOString ( ) ,
67+ } ,
68+ test_knexDb ,
69+ ) ;
70+ expect ( reverse_result , "`after` > `before`" ) . toHaveLength ( 1 ) ;
71+ expect ( reverse_result [ 0 ] ) . toMatchObject ( current_season ) ;
6172
62- // const match_id = await createMatch(mockMatchReport.guild_id, test_knexDb);
63- // const created_match = await test_knexDb("Match")
64- // .first()
65- // .where({ match_id });
66- // expect(
67- // created_match.guild_id,
68- // "When retrieved, the Match record has the same data as is provided",
69- // ).toEqual(mockMatchReport.guild_id);
73+ const current_future_result = await getSeasons (
74+ { after : new Date ( ) . toISOString ( ) } ,
75+ test_knexDb ,
76+ ) ;
77+ expect ( current_future_result , "Returns current and future" ) . toHaveLength ( 2 ) ;
78+ expect ( current_future_result ) . toEqual (
79+ expect . arrayContaining ( [
80+ expect . objectContaining ( current_season ) ,
81+ expect . objectContaining ( future_season ) ,
82+ ] ) ,
83+ ) ;
84+
85+ const current_past_result = await getSeasons (
86+ { before : new Date ( ) . toISOString ( ) } ,
87+ test_knexDb ,
88+ ) ;
89+ expect ( current_past_result , "Returns current and past" ) . toHaveLength ( 2 ) ;
90+ expect ( current_past_result ) . toEqual (
91+ expect . arrayContaining ( [
92+ expect . objectContaining ( current_season ) ,
93+ expect . objectContaining ( past_season ) ,
94+ ] ) ,
95+ ) ;
7096 } ) ;
7197 } ) ;
7298} ) ;
0 commit comments