@@ -21,7 +21,7 @@ import {
21
21
CrawlerCheckService ,
22
22
RedirectService ,
23
23
} from '../services'
24
- // import { RedirectDestination } from '../../../repositories/types'
24
+ import { RedirectDestination } from '../../../repositories/types'
25
25
26
26
const redisMockClient = redisMock . createClient ( )
27
27
const sequelizeMock = new SequelizeMock ( )
@@ -520,50 +520,40 @@ describe('redirect API tests', () => {
520
520
test ( 'url does exists in cache but not db' , async ( ) => {
521
521
const req = createRequestWithShortUrl ( 'Aaa' )
522
522
const res = httpMocks . createResponse ( )
523
- // FIXME: Update to use the new RedirectDestination type
524
- // const redirectDestination: RedirectDestination = {
525
- // longUrl: 'aa',
526
- // isFile: false,
527
- // safeBrowsingExpiry: new Date(Date.now() + 1000).toISOString(),
528
- // }
529
-
530
- // redisMockClient.set('aaa', JSON.stringify(redirectDestination))
531
- redisMockClient . set ( 'aaa' , 'aa' )
523
+ const redirectDestination : RedirectDestination = {
524
+ longUrl : 'aa' ,
525
+ isFile : false ,
526
+ safeBrowsingExpiry : new Date ( Date . now ( ) + 1000 ) . toISOString ( ) ,
527
+ }
528
+
529
+ redisMockClient . set ( 'aaa' , JSON . stringify ( redirectDestination ) )
532
530
mockDbEmpty ( )
533
531
534
532
await container
535
533
. get < RedirectController > ( DependencyIds . redirectController )
536
534
. redirect ( req , res )
537
535
538
- // expect(res.statusCode).toBe(302)
539
- // NOTE: This is 404 now as the safe browsing repository needs to be updated
540
- // but it will be 302 once the safe browsing expiry is stored in redis
541
- expect ( res . statusCode ) . toBe ( 404 )
542
- // expect(res._getRedirectUrl()).toBe('aa')
536
+ expect ( res . statusCode ) . toBe ( 302 )
537
+ expect ( res . _getRedirectUrl ( ) ) . toBe ( 'aa' )
543
538
} )
544
539
545
540
test ( 'url in cache and db is down' , async ( ) => {
546
541
const req = createRequestWithShortUrl ( 'Aaa' )
547
542
const res = httpMocks . createResponse ( )
548
- // FIXME: Update to use the new RedirectDestination type
549
- // const redirectDestination: RedirectDestination = {
550
- // longUrl: 'aa',
551
- // isFile: false,
552
- // safeBrowsingExpiry: new Date(Date.now() + 1000).toISOString(),
553
- // }
543
+ const redirectDestination : RedirectDestination = {
544
+ longUrl : 'aa' ,
545
+ isFile : false ,
546
+ safeBrowsingExpiry : new Date ( Date . now ( ) + 1000 ) . toISOString ( ) ,
547
+ }
554
548
555
549
mockDbDown ( )
556
- // redisMockClient.set('aaa', JSON.stringify(redirectDestination))
557
- redisMockClient . set ( 'aaa' , 'aa' )
550
+ redisMockClient . set ( 'aaa' , JSON . stringify ( redirectDestination ) )
558
551
559
552
await container
560
553
. get < RedirectController > ( DependencyIds . redirectController )
561
554
. redirect ( req , res )
562
- // expect(res.statusCode).toBe(302)
563
- // NOTE: This is 404 now as the safe browsing repository needs to be updated
564
- // but it will be 302 once the safe browsing expiry is stored in redis
565
- expect ( res . statusCode ) . toBe ( 404 )
566
- // expect(res._getRedirectUrl()).toBe('aa')
555
+ expect ( res . statusCode ) . toBe ( 302 )
556
+ expect ( res . _getRedirectUrl ( ) ) . toBe ( 'aa' )
567
557
} )
568
558
569
559
test ( 'retrieval of gtag for transition page' , async ( ) => {
0 commit comments