@@ -320,13 +320,15 @@ describe('Application Controller Tests', () => {
320320
321321 expect ( res . body . items . length ) . toBeGreaterThanOrEqual ( 2 ) ;
322322 const resApplicationA = res . body . items . find (
323- ( item ) => item . applicant . firstName === applicationA . applicant . firstName ,
323+ ( item ) =>
324+ item . applicant ?. firstName === applicationA . applicant . firstName ,
324325 ) ;
325326 expect ( resApplicationA ) . not . toBeNull ( ) ;
326- res . body . items . find (
327- ( item ) => item . applicant . firstName === applicationB . applicant . firstName ,
327+ const resApplicationB = res . body . items . find (
328+ ( item ) =>
329+ item . applicant ?. firstName === applicationB . applicant . firstName ,
328330 ) ;
329- expect ( resApplicationA ) . not . toBeNull ( ) ;
331+ expect ( resApplicationB ) . not . toBeNull ( ) ;
330332 } ) ;
331333
332334 it ( 'should get stored applications when no params sent' , async ( ) => {
@@ -359,13 +361,15 @@ describe('Application Controller Tests', () => {
359361
360362 expect ( res . body . items . length ) . toBeGreaterThanOrEqual ( 2 ) ;
361363 const resApplicationA = res . body . items . find (
362- ( item ) => item . applicant . firstName === applicationA . applicant . firstName ,
364+ ( item ) =>
365+ item . applicant ?. firstName === applicationA . applicant . firstName ,
363366 ) ;
364367 expect ( resApplicationA ) . not . toBeNull ( ) ;
365- res . body . items . find (
366- ( item ) => item . applicant . firstName === applicationB . applicant . firstName ,
368+ const resApplicationB = res . body . items . find (
369+ ( item ) =>
370+ item . applicant ?. firstName === applicationB . applicant . firstName ,
367371 ) ;
368- expect ( resApplicationA ) . not . toBeNull ( ) ;
372+ expect ( resApplicationB ) . not . toBeNull ( ) ;
369373 } ) ;
370374 } ) ;
371375
@@ -2078,14 +2082,32 @@ describe('Application Controller Tests', () => {
20782082 } ) ;
20792083
20802084 describe ( 'publicAppsView endpoint' , ( ) => {
2085+ const createAndLoginUser = async ( ) => {
2086+ const user = await prisma . userAccounts . create ( {
2087+ data : await userFactory ( {
2088+ mfaEnabled : false ,
2089+ confirmedAt : new Date ( ) ,
2090+ } ) ,
2091+ } ) ;
2092+
2093+ const resLogIn = await request ( app . getHttpServer ( ) )
2094+ . post ( '/auth/login' )
2095+ . set ( { passkey : process . env . API_PASS_KEY || '' } )
2096+ . send ( {
2097+ email : user . email ,
2098+ password : 'Abcdef12345!' ,
2099+ } as Login )
2100+ . expect ( 201 ) ;
2101+
2102+ return { user, cookies : resLogIn . headers [ 'set-cookie' ] } ;
2103+ } ;
2104+
20812105 it ( 'should retrieve applications and counts when they exist' , async ( ) => {
20822106 const unitTypeA = await unitTypeFactorySingle (
20832107 prisma ,
20842108 UnitTypeEnum . oneBdrm ,
20852109 ) ;
2086- const user = await prisma . userAccounts . create ( {
2087- data : await userFactory ( ) ,
2088- } ) ;
2110+ const { user, cookies } = await createAndLoginUser ( ) ;
20892111 const juris = await prisma . jurisdictions . create ( {
20902112 data : jurisdictionFactory ( ) ,
20912113 } ) ;
@@ -2152,7 +2174,7 @@ describe('Application Controller Tests', () => {
21522174 const res = await request ( app . getHttpServer ( ) )
21532175 . get ( `/applications/publicAppsView?${ query } ` )
21542176 . set ( { passkey : process . env . API_PASS_KEY || '' } )
2155- . set ( 'Cookie' , adminCookies )
2177+ . set ( 'Cookie' , cookies )
21562178 . expect ( 200 ) ;
21572179
21582180 expect ( res . body . applicationsCount . total ) . toEqual ( 3 ) ;
@@ -2168,12 +2190,10 @@ describe('Application Controller Tests', () => {
21682190 } ) ;
21692191
21702192 it ( 'should not retrieve applications nor error when none exist' , async ( ) => {
2171- const userA = await prisma . userAccounts . create ( {
2172- data : await userFactory ( ) ,
2173- } ) ;
2193+ const { user, cookies } = await createAndLoginUser ( ) ;
21742194
21752195 const queryParams : PublicAppsViewQueryParams = {
2176- userId : userA . id ,
2196+ userId : user . id ,
21772197 filterType : ApplicationsFilterEnum . all ,
21782198 includeLotteryApps : true ,
21792199 page : 1 ,
@@ -2184,7 +2204,7 @@ describe('Application Controller Tests', () => {
21842204 const res = await request ( app . getHttpServer ( ) )
21852205 . get ( `/applications/publicAppsView?${ query } ` )
21862206 . set ( { passkey : process . env . API_PASS_KEY || '' } )
2187- . set ( 'Cookie' , adminCookies )
2207+ . set ( 'Cookie' , cookies )
21882208 . expect ( 200 ) ;
21892209
21902210 expect ( res . body . applicationsCount . total ) . toEqual ( 0 ) ;
0 commit comments