@@ -129,4 +129,93 @@ describe('Certification | Configuration | Integration | Repository | sessions-re
129
129
} ) ;
130
130
} ) ;
131
131
} ) ;
132
+
133
+ describe ( 'updateV2SessionsWithNoCourses' , function ( ) {
134
+ it ( 'should update v2 sessions with no courses of v3 centers' , async function ( ) {
135
+ // given
136
+ const certificationCenterId = databaseBuilder . factory . buildCertificationCenter ( {
137
+ isV3Pilot : true ,
138
+ } ) . id ;
139
+ const activeSessionId = databaseBuilder . factory . buildSession ( {
140
+ version : 2 ,
141
+ certificationCenterId,
142
+ } ) . id ;
143
+ databaseBuilder . factory . buildCertificationCourse ( { sessionId : activeSessionId } ) ;
144
+ const inactiveSessionId = databaseBuilder . factory . buildSession ( {
145
+ version : 2 ,
146
+ certificationCenterId,
147
+ } ) . id ;
148
+ await databaseBuilder . commit ( ) ;
149
+
150
+ // when
151
+ const count = await configurationRepositories . sessionsRepository . updateV2SessionsWithNoCourses ( ) ;
152
+
153
+ // then
154
+ expect ( count ) . to . equal ( 1 ) ;
155
+ const sessions = await knex ( 'sessions' ) . select ( 'id' , 'version' ) . orderBy ( 'version' ) ;
156
+ expect ( sessions ) . to . deep . equal ( [
157
+ { id : activeSessionId , version : 2 } ,
158
+ { id : inactiveSessionId , version : 3 } ,
159
+ ] ) ;
160
+ } ) ;
161
+
162
+ it ( 'should not update v2 sessions with no courses of v2 centers' , async function ( ) {
163
+ // given
164
+ const certificationCenterId = databaseBuilder . factory . buildCertificationCenter ( {
165
+ isV3Pilot : false ,
166
+ } ) . id ;
167
+ const activeSessionId = databaseBuilder . factory . buildSession ( {
168
+ version : 2 ,
169
+ certificationCenterId,
170
+ } ) . id ;
171
+ databaseBuilder . factory . buildCertificationCourse ( { sessionId : activeSessionId } ) ;
172
+ const inactiveSessionId = databaseBuilder . factory . buildSession ( {
173
+ version : 2 ,
174
+ certificationCenterId,
175
+ } ) . id ;
176
+ await databaseBuilder . commit ( ) ;
177
+
178
+ // when
179
+ const count = await configurationRepositories . sessionsRepository . updateV2SessionsWithNoCourses ( ) ;
180
+
181
+ // then
182
+ expect ( count ) . to . equal ( 0 ) ;
183
+ const sessions = await knex ( 'sessions' ) . select ( 'id' , 'version' ) . orderBy ( 'version' ) ;
184
+ expect ( sessions ) . to . deep . equal ( [
185
+ { id : activeSessionId , version : 2 } ,
186
+ { id : inactiveSessionId , version : 2 } ,
187
+ ] ) ;
188
+ } ) ;
189
+ } ) ;
190
+
191
+ describe ( 'findV2SessionIdsWithNoCourses' , function ( ) {
192
+ it ( 'should return v2 session ids with no courses of v3 centers' , async function ( ) {
193
+ // given
194
+ const certificationCenterId = databaseBuilder . factory . buildCertificationCenter ( {
195
+ isV3Pilot : true ,
196
+ } ) . id ;
197
+ const activeSessionId = databaseBuilder . factory . buildSession ( {
198
+ version : 2 ,
199
+ certificationCenterId,
200
+ } ) . id ;
201
+ databaseBuilder . factory . buildCertificationCourse ( { sessionId : activeSessionId } ) ;
202
+ const inactiveSessionId = databaseBuilder . factory . buildSession ( {
203
+ version : 2 ,
204
+ certificationCenterId,
205
+ } ) . id ;
206
+ const v2CertificationCenterId = databaseBuilder . factory . buildCertificationCenter ( {
207
+ isV2Pilot : true ,
208
+ } ) . id ;
209
+ databaseBuilder . factory . buildSession ( {
210
+ version : 2 ,
211
+ certificationCenterId : v2CertificationCenterId ,
212
+ } ) . id ;
213
+ await databaseBuilder . commit ( ) ;
214
+
215
+ // when
216
+ const sessionIds = await configurationRepositories . sessionsRepository . findV2SessionIdsWithNoCourses ( ) ;
217
+
218
+ expect ( sessionIds ) . to . deep . equal ( [ inactiveSessionId ] ) ;
219
+ } ) ;
220
+ } ) ;
132
221
} ) ;
0 commit comments