ok try msw2 then

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-11-24 15:50:29 +01:00
parent 2c776eb024
commit 88c4747ce6
3 changed files with 43 additions and 50 deletions
@@ -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"
@@ -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 });
},
),
);
+2 -2
View File
@@ -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: