diff --git a/plugins/scaffolder-backend-module-sentry/package.json b/plugins/scaffolder-backend-module-sentry/package.json index 999cc7114c..9429fd0252 100644 --- a/plugins/scaffolder-backend-module-sentry/package.json +++ b/plugins/scaffolder-backend-module-sentry/package.json @@ -37,7 +37,7 @@ "@backstage/backend-test-utils": "workspace:^", "@backstage/cli": "workspace:^", "@backstage/types": "workspace:^", - "msw": "^1.0.0" + "msw": "^2.0.0" }, "files": [ "dist" diff --git a/plugins/scaffolder-backend-module-sentry/src/actions/createProject.test.ts b/plugins/scaffolder-backend-module-sentry/src/actions/createProject.test.ts index 0486012760..972b0f1e8e 100644 --- a/plugins/scaffolder-backend-module-sentry/src/actions/createProject.test.ts +++ b/plugins/scaffolder-backend-module-sentry/src/actions/createProject.test.ts @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { setupRequestMockHandlers } from '@backstage/backend-test-utils'; import { ConfigReader } from '@backstage/config'; import { InputError } from '@backstage/errors'; import { ActionContext } from '@backstage/plugin-scaffolder-node'; import { JsonObject } from '@backstage/types'; import { randomBytes } from 'crypto'; -import { rest } from 'msw'; import { setupServer } from 'msw/node'; +import { HttpResponse, http } from 'msw'; import { createSentryCreateProjectAction } from './createProject'; describe('sentry:project:create action', () => { @@ -62,21 +63,19 @@ describe('sentry:project:create action', () => { const actionContext = getActionContext(); worker.use( - rest.post( + http.post( `https://sentry.io/api/0/teams/${actionContext.input.organizationSlug}/${actionContext.input.teamSlug}/projects/`, - async (req, res, ctx) => { - expect(req.headers.get('Authorization')).toBe( + async ({ request }) => { + expect(request.headers.get('Authorization')).toBe( `Bearer ${actionContext.input.authToken}`, ); - expect(req.headers.get('Content-Type')).toBe(`application/json`); - await expect(req.json()).resolves.toEqual({ + expect(request.headers.get('Content-Type')).toBe(`application/json`); + await expect(request.json()).resolves.toEqual({ name: actionContext.input.name, }); - return res( - ctx.status(201), - ctx.json({ - detail: 'project creation mocked result', - }), + return HttpResponse.json( + { detail: 'project creation mocked result' }, + { status: 201 }, ); }, ), @@ -93,22 +92,20 @@ describe('sentry:project:create action', () => { actionContext.input = { ...actionContext.input, slug: 'project-slug' }; worker.use( - rest.post( + http.post( `https://sentry.io/api/0/teams/${actionContext.input.organizationSlug}/${actionContext.input.teamSlug}/projects/`, - async (req, res, ctx) => { - expect(req.headers.get('Authorization')).toBe( + async ({ request }) => { + expect(request.headers.get('Authorization')).toBe( `Bearer ${actionContext.input.authToken}`, ); - expect(req.headers.get('Content-Type')).toBe(`application/json`); - await expect(req.json()).resolves.toEqual({ + expect(request.headers.get('Content-Type')).toBe(`application/json`); + await expect(request.json()).resolves.toEqual({ name: actionContext.input.name, slug: actionContext.input.slug, }); - return res( - ctx.status(201), - ctx.json({ - detail: 'project creation mocked result', - }), + return HttpResponse.json( + { detail: 'project creation mocked result' }, + { status: 201 }, ); }, ), @@ -132,21 +129,19 @@ describe('sentry:project:create action', () => { actionContext.input.authToken = undefined; worker.use( - rest.post( + http.post( `https://sentry.io/api/0/teams/${actionContext.input.organizationSlug}/${actionContext.input.teamSlug}/projects/`, - async (req, res, ctx) => { - expect(req.headers.get('Authorization')).toBe( + async ({ request }) => { + expect(request.headers.get('Authorization')).toBe( `Bearer ${sentryScaffolderConfigToken}`, ); - expect(req.headers.get('Content-Type')).toBe(`application/json`); - await expect(req.json()).resolves.toEqual({ + expect(request.headers.get('Content-Type')).toBe(`application/json`); + await expect(request.json()).resolves.toEqual({ name: actionContext.input.name, }); - return res( - ctx.status(201), - ctx.json({ - detail: 'project creation mocked result', - }), + return HttpResponse.json( + { detail: 'project creation mocked result' }, + { status: 201 }, ); }, ), @@ -161,21 +156,19 @@ describe('sentry:project:create action', () => { actionContext.input.authToken = undefined; worker.use( - rest.post( + http.post( `https://sentry.io/api/0/teams/${actionContext.input.organizationSlug}/${actionContext.input.teamSlug}/projects/`, - async (req, res, ctx) => { - expect(req.headers.get('Authorization')).toBe( + async ({ request }) => { + expect(request.headers.get('Authorization')).toBe( `Bearer ${actionContext.input.authToken}`, ); - expect(req.headers.get('Content-Type')).toBe(`application/json`); - await expect(req.json()).resolves.toEqual({ + expect(request.headers.get('Content-Type')).toBe(`application/json`); + await expect(request.json()).resolves.toEqual({ name: actionContext.input.name, }); - return res( - ctx.status(201), - ctx.json({ - detail: 'project creation mocked result', - }), + return HttpResponse.json( + { detail: 'project creation mocked result' }, + { status: 201 }, ); }, ), @@ -191,10 +184,10 @@ describe('sentry:project:create action', () => { const actionContext = getActionContext(); worker.use( - rest.post( + http.post( `https://sentry.io/api/0/teams/${actionContext.input.organizationSlug}/${actionContext.input.teamSlug}/projects/`, - async (_, res, ctx) => { - return res(ctx.status(201), ctx.text('Bad response')); + async () => { + return HttpResponse.text('Bad response', { status: 201 }); }, ), ); @@ -209,10 +202,10 @@ describe('sentry:project:create action', () => { const actionContext = getActionContext(); worker.use( - rest.post( + http.post( `https://sentry.io/api/0/teams/${actionContext.input.organizationSlug}/${actionContext.input.teamSlug}/projects/`, - async (_, res, ctx) => { - return res(ctx.status(400), ctx.json({ detail: 'OUCH' })); + async () => { + return HttpResponse.json({ detail: 'OUCH' }, { status: 400 }); }, ), ); diff --git a/yarn.lock b/yarn.lock index 3000d86b7f..8690082630 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8664,7 +8664,7 @@ __metadata: "@backstage/errors": "workspace:^" "@backstage/plugin-scaffolder-node": "workspace:^" "@backstage/types": "workspace:^" - msw: ^1.0.0 + msw: ^2.0.0 yaml: ^2.3.3 languageName: unknown linkType: soft @@ -34768,7 +34768,7 @@ __metadata: languageName: node linkType: hard -"msw@npm:^2.0.8": +"msw@npm:^2.0.0, msw@npm:^2.0.8": version: 2.0.9 resolution: "msw@npm:2.0.9" dependencies: