@@ -215,77 +215,44 @@ describe('Unit | Shared | Domain | Services | Token Service', function () {
215
215
} ) ;
216
216
217
217
describe ( '#extractCertificationResultsLink' , function ( ) {
218
- context ( 'when FT_ENABLE_CERTIF_TOKEN_SCOPE is true' , function ( ) {
219
- beforeEach ( function ( ) {
220
- sinon . stub ( settings . featureToggles , 'isCertificationTokenScopeEnabled' ) . value ( true ) ;
221
- } ) ;
218
+ context ( 'when the scope is valid' , function ( ) {
219
+ it ( 'should return the session id' , function ( ) {
220
+ // given
221
+ const token = jsonwebtoken . sign (
222
+ {
223
+ session_id : 12345 ,
224
+ scope : 'certificationResultsLink' ,
225
+ } ,
226
+ settings . authentication . secret ,
227
+ { expiresIn : config . jwtConfig . certificationResults . tokenLifespan } ,
228
+ ) ;
222
229
223
- context ( 'when the scope is valid' , function ( ) {
224
- it ( 'should return the session id' , function ( ) {
225
- // given
226
- const token = jsonwebtoken . sign (
227
- {
228
- session_id : 12345 ,
229
- scope : 'certificationResultsLink' ,
230
- } ,
231
- settings . authentication . secret ,
232
- { expiresIn : config . jwtConfig . certificationResults . tokenLifespan } ,
233
- ) ;
234
-
235
- // when
236
- const tokenData = tokenService . extractCertificationResultsLink ( token ) ;
237
-
238
- // then
239
- expect ( tokenData ) . to . deep . equal ( {
240
- sessionId : 12345 ,
241
- } ) ;
242
- } ) ;
243
- } ) ;
230
+ // when
231
+ const tokenData = tokenService . extractCertificationResultsLink ( token ) ;
244
232
245
- context ( 'when the scope is invalid' , function ( ) {
246
- it ( 'should throw an InvalidSessionResultTokenError' , async function ( ) {
247
- // given
248
- const invalidToken = jsonwebtoken . sign (
249
- {
250
- session_id : 12345 ,
251
- } ,
252
- settings . authentication . secret ,
253
- { expiresIn : '30d' } ,
254
- ) ;
255
-
256
- // when
257
- const error = await catchErr ( tokenService . extractCertificationResultsLink ) ( invalidToken ) ;
258
-
259
- // then
260
- expect ( error ) . to . be . an . instanceof ( InvalidSessionResultTokenError ) ;
233
+ // then
234
+ expect ( tokenData ) . to . deep . equal ( {
235
+ sessionId : 12345 ,
261
236
} ) ;
262
237
} ) ;
263
238
} ) ;
264
239
265
- context ( 'when FT_ENABLE_CERTIF_TOKEN_SCOPE is false' , function ( ) {
266
- beforeEach ( function ( ) {
267
- sinon . stub ( settings . featureToggles , 'isCertificationTokenScopeEnabled' ) . value ( false ) ;
268
- } ) ;
240
+ context ( 'when the scope is invalid' , function ( ) {
241
+ it ( 'should throw an InvalidSessionResultTokenError' , async function ( ) {
242
+ // given
243
+ const invalidToken = jsonwebtoken . sign (
244
+ {
245
+ session_id : 12345 ,
246
+ } ,
247
+ settings . authentication . secret ,
248
+ { expiresIn : '30d' } ,
249
+ ) ;
269
250
270
- context ( 'when there is no scope' , function ( ) {
271
- it ( 'should return the session id' , function ( ) {
272
- // given
273
- const token = jsonwebtoken . sign (
274
- {
275
- session_id : 12345 ,
276
- } ,
277
- settings . authentication . secret ,
278
- { expiresIn : '30d' } ,
279
- ) ;
280
-
281
- // when
282
- const tokenData = tokenService . extractCertificationResultsLink ( token ) ;
283
-
284
- // then
285
- expect ( tokenData ) . to . deep . equal ( {
286
- sessionId : 12345 ,
287
- } ) ;
288
- } ) ;
251
+ // when
252
+ const error = await catchErr ( tokenService . extractCertificationResultsLink ) ( invalidToken ) ;
253
+
254
+ // then
255
+ expect ( error ) . to . be . an . instanceof ( InvalidSessionResultTokenError ) ;
289
256
} ) ;
290
257
} ) ;
291
258
@@ -322,76 +289,44 @@ describe('Unit | Shared | Domain | Services | Token Service', function () {
322
289
} ) ;
323
290
324
291
describe ( '#extractCertificationResultsByRecipientEmailLink' , function ( ) {
325
- context ( 'when FT_ENABLE_CERTIF_TOKEN_SCOPE is true' , function ( ) {
326
- beforeEach ( function ( ) {
327
- sinon . stub ( settings . featureToggles , 'isCertificationTokenScopeEnabled' ) . value ( true ) ;
328
- } ) ;
329
-
330
- context ( 'when the scope is valid' , function ( ) {
331
- it ( 'should return the session id and result recipient email if the token is valid' , function ( ) {
332
- // given
333
- const token = jsonwebtoken . sign (
334
- {
335
- result_recipient_email : 'recipientEmail@example.net' ,
336
- session_id : 12345 ,
337
- scope : 'certificationResultsByRecipientEmailLink' ,
338
- } ,
339
- settings . authentication . secret ,
340
- { expiresIn : '30d' } ,
341
- ) ;
342
-
343
- // when
344
- const tokenData = tokenService . extractCertificationResultsByRecipientEmailLink ( token ) ;
345
-
346
- // then
347
- expect ( tokenData ) . to . deep . equal ( {
348
- resultRecipientEmail : 'recipientEmail@example.net' ,
349
- sessionId : 12345 ,
350
- } ) ;
351
- } ) ;
352
- } ) ;
353
-
354
- context ( 'when the scope is invalid' , function ( ) {
355
- it ( 'should throw an InvalidResultRecipientTokenError' , async function ( ) {
356
- // given
357
- const invalidToken = jsonwebtoken . sign (
358
- { result_recipient_email : 'recipientEmail@example.net' , session_id : 12345 } ,
359
- settings . authentication . secret ,
360
- { expiresIn : '30d' } ,
361
- ) ;
292
+ context ( 'when the scope is valid' , function ( ) {
293
+ it ( 'should return the session id and result recipient email if the token is valid' , function ( ) {
294
+ // given
295
+ const token = jsonwebtoken . sign (
296
+ {
297
+ result_recipient_email : 'recipientEmail@example.net' ,
298
+ session_id : 12345 ,
299
+ scope : 'certificationResultsByRecipientEmailLink' ,
300
+ } ,
301
+ settings . authentication . secret ,
302
+ { expiresIn : '30d' } ,
303
+ ) ;
362
304
363
- // when
364
- const error = await catchErr ( tokenService . extractCertificationResultsByRecipientEmailLink ) ( invalidToken ) ;
305
+ // when
306
+ const tokenData = tokenService . extractCertificationResultsByRecipientEmailLink ( token ) ;
365
307
366
- // then
367
- expect ( error ) . to . be . an . instanceof ( InvalidResultRecipientTokenError ) ;
308
+ // then
309
+ expect ( tokenData ) . to . deep . equal ( {
310
+ resultRecipientEmail : 'recipientEmail@example.net' ,
311
+ sessionId : 12345 ,
368
312
} ) ;
369
313
} ) ;
370
314
} ) ;
371
315
372
- context ( 'when FT_ENABLE_CERTIF_TOKEN_SCOPE is false' , function ( ) {
373
- beforeEach ( function ( ) {
374
- sinon . stub ( settings . featureToggles , 'isCertificationTokenScopeEnabled' ) . value ( false ) ;
375
- } ) ;
316
+ context ( 'when the scope is invalid' , function ( ) {
317
+ it ( 'should throw an InvalidResultRecipientTokenError' , async function ( ) {
318
+ // given
319
+ const invalidToken = jsonwebtoken . sign (
320
+ { result_recipient_email : 'recipientEmail@example.net' , session_id : 12345 } ,
321
+ settings . authentication . secret ,
322
+ { expiresIn : '30d' } ,
323
+ ) ;
376
324
377
- context ( 'when there is no scope' , function ( ) {
378
- it ( 'should return the session id' , function ( ) {
379
- // given
380
- const token = jsonwebtoken . sign (
381
- { result_recipient_email : 'recipientEmail@example.net' , session_id : 12345 } ,
382
- settings . authentication . secret ,
383
- { expiresIn : '30d' } ,
384
- ) ;
385
-
386
- // when
387
- const tokenData = tokenService . extractCertificationResultsByRecipientEmailLink ( token ) ;
388
-
389
- // then
390
- expect ( tokenData ) . to . deep . equal ( {
391
- resultRecipientEmail : 'recipientEmail@example.net' ,
392
- sessionId : 12345 ,
393
- } ) ;
394
- } ) ;
325
+ // when
326
+ const error = await catchErr ( tokenService . extractCertificationResultsByRecipientEmailLink ) ( invalidToken ) ;
327
+
328
+ // then
329
+ expect ( error ) . to . be . an . instanceof ( InvalidResultRecipientTokenError ) ;
395
330
} ) ;
396
331
} ) ;
397
332
0 commit comments