@@ -42,100 +42,135 @@ afterEach(async () => {
4242} ) ;
4343
4444describe ( "Season table operations" , ( ) => {
45- let past_season : Omit < SeasonRecord , "season_id" > ;
46- let current_season : Omit < SeasonRecord , "season_id" > ;
47- let future_season : Omit < SeasonRecord , "season_id" > ;
4845 describe ( "Use `getSeasons`" , ( ) => {
49- beforeEach ( async ( ) => {
50- past_season = pastSeasonRecordFactory ( ) ;
51- current_season = currentSeasonRecordFactory ( ) ;
52- future_season = futureSeasonRecordFactory ( ) ;
53- await seed_db (
54- new TestSeedSource ( {
55- season_records : [ past_season , current_season , future_season ] ,
56- } ) ,
57- test_knexDb ,
58- ) ;
59- } ) ;
60- test ( "Based on `after` and `before` arguments" , async ( ) => {
61- const current_result = await getSeasons (
62- { before : new Date ( ) . toISOString ( ) , after : new Date ( ) . toISOString ( ) } ,
63- test_knexDb ,
64- ) ;
65- expect ( current_result , "Returns only the ongoing Season" ) . toHaveLength ( 1 ) ;
66- expect ( current_result [ 0 ] ) . toMatchObject ( current_season ) ;
46+ describe ( "Based on `after` and `before` arguments" , async ( ) => {
47+ let past_season : Omit < SeasonRecord , "season_id" > ;
48+ let current_season : Omit < SeasonRecord , "season_id" > ;
49+ let future_season : Omit < SeasonRecord , "season_id" > ;
50+ beforeEach ( async ( ) => {
51+ past_season = pastSeasonRecordFactory ( ) ;
52+ current_season = currentSeasonRecordFactory ( ) ;
53+ future_season = futureSeasonRecordFactory ( ) ;
54+ await seed_db (
55+ new TestSeedSource ( {
56+ season_records : [ past_season , current_season , future_season ] ,
57+ } ) ,
58+ test_knexDb ,
59+ ) ;
60+ } ) ;
61+ test ( "Nominal" , async ( ) => {
62+ const current_result = await getSeasons (
63+ {
64+ before : new Date ( ) . toISOString ( ) ,
65+ after : new Date ( ) . toISOString ( ) ,
66+ } ,
67+ test_knexDb ,
68+ ) ;
69+ expect ( current_result , "Returns only the ongoing Season" ) . toHaveLength (
70+ 1 ,
71+ ) ;
72+ expect ( current_result [ 0 ] ) . toMatchObject ( current_season ) ;
6773
68- const reverse_result = await getSeasons (
69- {
70- before : new Date ( Date . now ( ) - 1000 ) . toISOString ( ) ,
71- after : new Date ( Date . now ( ) + 1000 ) . toISOString ( ) ,
72- } ,
73- test_knexDb ,
74- ) ;
75- expect ( reverse_result , "`after` > `before`" ) . toHaveLength ( 1 ) ;
76- expect ( reverse_result [ 0 ] ) . toMatchObject ( current_season ) ;
74+ const reverse_result = await getSeasons (
75+ {
76+ before : new Date ( Date . now ( ) - 1000 ) . toISOString ( ) ,
77+ after : new Date ( Date . now ( ) + 1000 ) . toISOString ( ) ,
78+ } ,
79+ test_knexDb ,
80+ ) ;
81+ expect ( reverse_result , "`after` > `before`" ) . toHaveLength ( 1 ) ;
82+ expect ( reverse_result [ 0 ] ) . toMatchObject ( current_season ) ;
7783
78- const current_future_result = await getSeasons (
79- { after : new Date ( ) . toISOString ( ) } ,
80- test_knexDb ,
81- ) ;
82- expect ( current_future_result , "Returns current and future" ) . toHaveLength ( 2 ) ;
83- expect ( current_future_result ) . toEqual (
84- expect . arrayContaining ( [
85- expect . objectContaining ( current_season ) ,
86- expect . objectContaining ( future_season ) ,
87- ] ) ,
88- ) ;
84+ const current_future_result = await getSeasons (
85+ { after : new Date ( ) . toISOString ( ) } ,
86+ test_knexDb ,
87+ ) ;
88+ expect (
89+ current_future_result ,
90+ "Returns current and future" ,
91+ ) . toHaveLength ( 2 ) ;
92+ expect ( current_future_result ) . toEqual (
93+ expect . arrayContaining ( [
94+ expect . objectContaining ( current_season ) ,
95+ expect . objectContaining ( future_season ) ,
96+ ] ) ,
97+ ) ;
8998
90- const current_past_result = await getSeasons (
91- { before : new Date ( ) . toISOString ( ) } ,
92- test_knexDb ,
93- ) ;
94- expect ( current_past_result , "Returns current and past" ) . toHaveLength ( 2 ) ;
95- expect ( current_past_result ) . toEqual (
96- expect . arrayContaining ( [
97- expect . objectContaining ( current_season ) ,
98- expect . objectContaining ( past_season ) ,
99- ] ) ,
100- ) ;
99+ const current_past_result = await getSeasons (
100+ { before : new Date ( ) . toISOString ( ) } ,
101+ test_knexDb ,
102+ ) ;
103+ expect ( current_past_result , "Returns current and past" ) . toHaveLength ( 2 ) ;
104+ expect ( current_past_result ) . toEqual (
105+ expect . arrayContaining ( [
106+ expect . objectContaining ( current_season ) ,
107+ expect . objectContaining ( past_season ) ,
108+ ] ) ,
109+ ) ;
110+ } ) ;
111+ test ( "Boundary" , async ( ) => {
112+ const before_at_start_result = await getSeasons (
113+ {
114+ before : new Date (
115+ new Date ( current_season . start_at ) . getTime ( ) ,
116+ ) . toISOString ( ) ,
117+ } ,
118+ test_knexDb ,
119+ ) ;
120+ expect (
121+ before_at_start_result ,
122+ "Set `before` to a Season's `start_at`" ,
123+ ) . toHaveLength ( 2 ) ;
124+ expect ( before_at_start_result ) . toEqual (
125+ expect . arrayContaining ( [
126+ expect . objectContaining ( current_season ) ,
127+ expect . objectContaining ( past_season ) ,
128+ ] ) ,
129+ ) ;
130+ const after_on_end_result = await getSeasons (
131+ {
132+ after : new Date (
133+ new Date ( current_season . end_at ) . getTime ( ) ,
134+ ) . toISOString ( ) ,
135+ } ,
136+ test_knexDb ,
137+ ) ;
138+ expect (
139+ after_on_end_result ,
140+ "Set `before` to a Season's `start_at`" ,
141+ ) . toHaveLength ( 2 ) ;
142+ expect ( after_on_end_result ) . toEqual (
143+ expect . arrayContaining ( [
144+ expect . objectContaining ( current_season ) ,
145+ expect . objectContaining ( future_season ) ,
146+ ] ) ,
147+ ) ;
148+ } ) ;
101149 } ) ;
102- test ( "Boundary" , async ( ) => {
103- const before_at_start_result = await getSeasons (
104- {
105- before : new Date (
106- new Date ( current_season . start_at ) . getTime ( ) ,
107- ) . toISOString ( ) ,
108- } ,
109- test_knexDb ,
110- ) ;
111- expect (
112- before_at_start_result ,
113- "Set `before` to a Season's `start_at`" ,
114- ) . toHaveLength ( 2 ) ;
115- expect ( before_at_start_result ) . toEqual (
116- expect . arrayContaining ( [
117- expect . objectContaining ( current_season ) ,
118- expect . objectContaining ( past_season ) ,
119- ] ) ,
120- ) ;
121- const after_on_end_result = await getSeasons (
122- {
123- after : new Date (
124- new Date ( current_season . end_at ) . getTime ( ) ,
125- ) . toISOString ( ) ,
126- } ,
127- test_knexDb ,
128- ) ;
129- expect (
130- after_on_end_result ,
131- "Set `before` to a Season's `start_at`" ,
132- ) . toHaveLength ( 2 ) ;
133- expect ( after_on_end_result ) . toEqual (
134- expect . arrayContaining ( [
135- expect . objectContaining ( current_season ) ,
136- expect . objectContaining ( future_season ) ,
137- ] ) ,
138- ) ;
150+ describe ( "Based on `season_name`" , async ( ) => {
151+ let named_season : Omit < SeasonRecord , "season_id" > ;
152+ beforeEach ( async ( ) => {
153+ named_season = currentSeasonRecordFactory ( {
154+ season_name : "Real's Arena #64" ,
155+ } ) ;
156+ await seed_db (
157+ new TestSeedSource ( {
158+ season_records : [ named_season ] ,
159+ } ) ,
160+ test_knexDb ,
161+ ) ;
162+ } ) ;
163+ test ( "Nominal" , async ( ) => {
164+ expect (
165+ await getSeasons (
166+ { season_name : named_season . season_name } ,
167+ test_knexDb ,
168+ ) ,
169+ "Full name match" ,
170+ ) . toEqual (
171+ expect . arrayContaining ( [ expect . objectContaining ( named_season ) ] ) ,
172+ ) ;
173+ } ) ;
139174 } ) ;
140175 } ) ;
141176} ) ;
0 commit comments