11import { Test , TestingModule } from '@nestjs/testing' ;
22import { ShortenUrlController } from './shorten-url.controller' ;
3- import { ShortenUrlUsecase } from './shorten-url.usecase' ;
4- import { ShortenUrlIdGeneratorService } from './shorten-url.id-generator.service' ;
53import { ConfigModule } from '@nestjs/config' ;
4+ import { ShortenUrlModule } from './shorten-url.module' ;
65
76describe ( 'ShortenUrl controller' , ( ) => {
87 let underTest : ShortenUrlController ;
98
109 beforeEach ( async ( ) => {
1110 const app : TestingModule = await Test . createTestingModule ( {
12- imports : [ await ConfigModule . forRoot ( ) ] ,
13- controllers : [ ShortenUrlController ] ,
14- providers : [ ShortenUrlIdGeneratorService , ShortenUrlUsecase ] ,
11+ imports : [ await ConfigModule . forRoot ( ) , ShortenUrlModule ] ,
1512 } ) . compile ( ) ;
1613
1714 underTest = app . get < ShortenUrlController > ( ShortenUrlController ) ;
@@ -21,13 +18,13 @@ describe('ShortenUrl controller', () => {
2118 it ( 'should return a valid Base62 short URL with 10 chars length' , async ( ) => {
2219 const longUrl =
2320 'https://zapper.xyz/very-long-url/very-long-url/very-long-url' ;
24- const shortenedUrl = await underTest . shortenUrl ( longUrl ) ; // Assuming it's async
21+ const response = await underTest . shortenUrl ( { url : longUrl } ) ;
2522
2623 // Extract the unique ID part of the URL
27- const urlPattern = / ^ h t t p s : \/ \/ z a p p e r \. x y z \/ ( [ A - Z a - z 0 - 9 ] { 10 } ) $ / ;
28- const match = shortenedUrl . match ( urlPattern ) ;
24+ const urlPattern = / ^ h t t p : \/ \/ l o c a l h o s t : 3 0 0 0 \/ ( [ A - Z a - z 0 - 9 ] { 10 } ) $ / ;
25+ const match = response ?. shortenedUrl . match ( urlPattern ) ;
2926
30- expect ( shortenedUrl ) . not . toBeNull ( ) ;
27+ expect ( response ) . not . toBeNull ( ) ;
3128 expect ( match ) . not . toBeNull ( ) ; // Ensure it matches the pattern
3229 expect ( match ! [ 1 ] . length ) . toBe ( 10 ) ; // Validate the ID part has 10 characters
3330 } ) ;
0 commit comments