From b70655f777d54522e4ce35a3c89bdc6e7200e357 Mon Sep 17 00:00:00 2001 From: Carlos Esteban Lopez Date: Fri, 17 Nov 2023 16:37:09 -0500 Subject: [PATCH] tests: Fix tests for msw 2.x Signed-off-by: Carlos Esteban Lopez --- .../src/authenticator.test.ts | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/plugins/auth-backend-module-vmware-csp-provider/src/authenticator.test.ts b/plugins/auth-backend-module-vmware-csp-provider/src/authenticator.test.ts index 8421c82db7..d2c276d257 100644 --- a/plugins/auth-backend-module-vmware-csp-provider/src/authenticator.test.ts +++ b/plugins/auth-backend-module-vmware-csp-provider/src/authenticator.test.ts @@ -25,8 +25,8 @@ import { OAuthState, } from '@backstage/plugin-auth-node'; import { SignJWT } from 'jose'; -import { rest } from 'msw'; -import { setupServer } from 'msw'; +import { http, HttpResponse } from 'msw'; +import { setupServer } from 'msw/node'; import { vmWareCSPAuthenticator, @@ -76,14 +76,12 @@ describe('VMwareCloudServicesAuthenticator', () => { beforeEach(() => { server.use( - rest.post( + http.post( 'https://console.cloud.vmware.com/csp/gateway/am/api/auth/token', - (req, res, ctx) => - res( - req.headers.get('Authorization') - ? ctx.json(authResponse) - : ctx.status(401), - ), + ({ request }) => + request.headers.get('Authorization') + ? HttpResponse.json(authResponse) + : HttpResponse.json(null, { status: 500 }), ), ); @@ -325,15 +323,13 @@ describe('VMwareCloudServicesAuthenticator', () => { .sign(Buffer.from('signing key')); server.use( - rest.post( + http.post( 'https://console.cloud.vmware.com/csp/gateway/am/api/auth/token', - (_, res, ctx) => - res( - ctx.json({ - access_token: 'accessToken', - id_token: inadequateIdToken, - }), - ), + () => + HttpResponse.json({ + access_token: 'accessToken', + id_token: inadequateIdToken, + }), ), );