@@ -17,40 +17,40 @@ jest.mock("@src/utils/config");
1717const middlewareRegex = new RegExp ( config . matcher [ 0 ] ) ;
1818const otherExcludedPaths = [ "/favicon.ico" , "/assets" , "/js" , "/css" , "/_next" ] ;
1919
20- function getMockRequest ( testUrl : URL ) {
20+ function getMockRequest ( testUrl : string ) {
2121 return {
2222 nextUrl : {
23- origin : testUrl . origin ,
24- pathname : testUrl . pathname ,
23+ origin : new URL ( testUrl ) . origin ,
24+ pathname : new URL ( testUrl ) . pathname ,
2525 } ,
26- url : testUrl . href ,
26+ url : testUrl ,
2727 } ;
2828}
2929
3030describe ( "middleware" , ( ) => {
3131 beforeEach ( ( ) => {
3232 ( configProvider as jest . Mock ) . mockImplementation (
3333 ( ) : Partial < AppConfig > => ( {
34- NHS_APP_REDIRECT_LOGIN_URL : new URL ( "https://nhs-app-redirect-login-url" ) ,
34+ NHS_APP_REDIRECT_LOGIN_URL : "https://nhs-app-redirect-login-url" ,
3535 } ) ,
3636 ) ;
3737 jest . clearAllMocks ( ) ;
3838 } ) ;
3939
4040 it ( "redirects users without active session to session-logout page" , async ( ) => {
41- const testUrl = new URL ( "https://nhs-app-redirect-login-url/" ) ;
41+ const testUrl = "https://nhs-app-redirect-login-url/" ;
4242 const mockRequest = getMockRequest ( testUrl ) ;
4343
4444 ( auth as jest . Mock ) . mockResolvedValue ( null ) ; // No authenticated session
4545
4646 const result = await middleware ( mockRequest as NextRequest ) ;
4747
4848 expect ( result . status ) . toBe ( 307 ) ;
49- expect ( result . headers . get ( "Location" ) ) . toEqual ( testUrl . href ) ;
49+ expect ( result . headers . get ( "Location" ) ) . toEqual ( testUrl ) ;
5050 } ) ;
5151
5252 it ( "pass through for users with active session" , async ( ) => {
53- const testUrl = new URL ( "https://testurl/abc" ) ;
53+ const testUrl = "https://testurl/abc" ;
5454 const mockRequest = getMockRequest ( testUrl ) ;
5555
5656 ( auth as jest . Mock ) . mockResolvedValue ( { user : "test" } ) ;
0 commit comments