Skip to content

Commit

Permalink
chore(deps): update dependency msw to v2 (#1374)[frontend]
Browse files Browse the repository at this point in the history
* chore(deps): update dependency msw to v2

* fix(e2e): setup and fix 1 test

* fix(e2e): fix csvClient test

* fix(e2e): fix HearderClient test

* fix(e2e): fix MetricsClient.test test

* fix(e2e): fix PipelineToolClient.test test

* fix(e2e): fix ReportClient.test test

* fix(e2e): fix SourceControlClient.test test

* fix(e2e): fix all est

* fix(e2e): fix security and format

* fix(e2e): fix security and format

* fix(e2e): fix e2e case

* fix(e2e): upgrade

* fix(e2e): upgrade

* fix(e2e): ignore test cov

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: guzhongren <guzhongren@live.cn>
  • Loading branch information
renovate[bot] and guzhongren authored May 3, 2024
1 parent 79fe2d6 commit dae9844
Show file tree
Hide file tree
Showing 24 changed files with 7,195 additions and 5,596 deletions.
1 change: 1 addition & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ CVE-2024-22259
CVE-2024-28085
CVE-2024-22262
CVE-2024-2961
CVE-2019-10744
88 changes: 65 additions & 23 deletions frontend/__tests__/client/BoardClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import {
AXIOS_ERROR_MESSAGE,
} from '../fixtures';
import { boardClient } from '@src/clients/board/BoardClient';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import { HttpStatusCode } from 'axios';
import { rest } from 'msw';

const server = setupServer(rest.post(MOCK_BOARD_URL_FOR_JIRA, (req, res, ctx) => res(ctx.status(HttpStatusCode.Ok))));
const server = setupServer(
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse('', {
status: HttpStatusCode.Ok,
});
}),
);

describe('verify board request', () => {
beforeAll(() => server.listen());
Expand All @@ -29,7 +35,13 @@ describe('verify board request', () => {
});

it('should isNoDoneCard is true when board verify response status 204', async () => {
server.use(rest.post(MOCK_BOARD_URL_FOR_JIRA, (req, res, ctx) => res(ctx.status(HttpStatusCode.NoContent))));
server.use(
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(null, {
status: HttpStatusCode.NoContent,
});
}),
);

const result = await boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS);

Expand All @@ -39,9 +51,16 @@ describe('verify board request', () => {

it('should throw error when board verify response status 400', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (req, res, ctx) =>
res(ctx.status(HttpStatusCode.BadRequest), ctx.json({ hintInfo: VERIFY_ERROR_MESSAGE.BAD_REQUEST })),
),
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.BAD_REQUEST,
}),
{
status: HttpStatusCode.BadRequest,
},
);
}),
);

boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS).catch((e) => {
Expand All @@ -52,9 +71,16 @@ describe('verify board request', () => {

it('should throw error when board verify response status 401', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (req, res, ctx) =>
res(ctx.status(HttpStatusCode.Unauthorized), ctx.json({ hintInfo: VERIFY_ERROR_MESSAGE.UNAUTHORIZED })),
),
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.UNAUTHORIZED,
}),
{
status: HttpStatusCode.Unauthorized,
},
);
}),
);

await expect(async () => {
Expand All @@ -64,14 +90,16 @@ describe('verify board request', () => {

it('should throw error when board verify response status 500', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (req, res, ctx) =>
res(
ctx.status(HttpStatusCode.InternalServerError),
ctx.json({
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
}),
),
),
{
status: HttpStatusCode.InternalServerError,
},
);
}),
);

await expect(async () => {
Expand All @@ -81,12 +109,16 @@ describe('verify board request', () => {

it('should throw error when board verify response status 503', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (req, res, ctx) =>
res(
ctx.status(HttpStatusCode.ServiceUnavailable),
ctx.json({ hintInfo: VERIFY_ERROR_MESSAGE.REQUEST_TIMEOUT }),
),
),
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.REQUEST_TIMEOUT,
}),
{
status: HttpStatusCode.ServiceUnavailable,
},
);
}),
);

await expect(async () => {
Expand All @@ -95,15 +127,25 @@ describe('verify board request', () => {
});

it('should throw error when board verify response status 300', async () => {
server.use(rest.post(MOCK_BOARD_URL_FOR_JIRA, (req, res, ctx) => res(ctx.status(HttpStatusCode.MultipleChoices))));
server.use(
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse('', {
status: HttpStatusCode.MultipleChoices,
});
}),
);

await expect(async () => {
await boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.UNKNOWN);
});

it('should throw `Network Error` when board verify encountered netwrok error', async () => {
server.use(rest.post(MOCK_BOARD_URL_FOR_JIRA, (req, res) => res.networkError('Network Error')));
server.use(
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return HttpResponse.error();
}),
);

await expect(async () => {
await boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS);
Expand Down
21 changes: 15 additions & 6 deletions frontend/__tests__/client/CSVClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { MOCK_EXPORT_CSV_REQUEST_PARAMS, MOCK_EXPORT_CSV_URL, VERIFY_ERROR_MESSAGE } from '../fixtures';
import { csvClient } from '@src/clients/report/CSVClient';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import { HttpStatusCode } from 'axios';
import { rest } from 'msw';

const server = setupServer(rest.get(MOCK_EXPORT_CSV_URL, (req, res, ctx) => res(ctx.status(HttpStatusCode.Ok))));
const server = setupServer(
http.get(MOCK_EXPORT_CSV_URL, () => {
return new HttpResponse(null, {
status: HttpStatusCode.NoContent,
});
}),
);

describe('verify export csv', () => {
beforeAll(() => server.listen());
afterAll(() => server.close());

it('should download the pipeline CSV file when export csv request status 200', async () => {
const mockBlob = new Blob(['CSV data'], { type: 'text/csv' });
const mockBlob = new Blob([''], { type: 'application/octet-stream' });
const mockResponse = { data: mockBlob };
const mockGet = jest.fn().mockResolvedValue(mockResponse);
const mockCreateObjectURL = jest.fn().mockImplementation((blob) => {
Expand All @@ -31,9 +37,12 @@ describe('verify export csv', () => {

it('should throw error when export csv request status 500', async () => {
server.use(
rest.get(MOCK_EXPORT_CSV_URL, (req, res, ctx) =>
res(ctx.status(HttpStatusCode.InternalServerError, VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR)),
),
http.get(MOCK_EXPORT_CSV_URL, () => {
return new HttpResponse(null, {
status: HttpStatusCode.InternalServerError,
statusText: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
});
}),
);

await expect(async () => {
Expand Down
32 changes: 21 additions & 11 deletions frontend/__tests__/client/HeaderClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { MOCK_VERSION_URL, VERIFY_ERROR_MESSAGE, VERSION_RESPONSE } from '../fixtures';
import { headerClient } from '@src/clients/header/HeaderClient';
import { HttpResponse, http } from 'msw';
import { setupServer } from 'msw/node';
import { HttpStatusCode } from 'axios';
import { rest } from 'msw';

const server = setupServer(rest.get(MOCK_VERSION_URL, (req, res, ctx) => res(ctx.status(HttpStatusCode.Ok))));
const server = setupServer(
http.get(MOCK_VERSION_URL, () => {
return new HttpResponse(null, {
status: HttpStatusCode.Ok,
});
}),
);

describe('header client', () => {
beforeAll(() => server.listen());
Expand All @@ -14,24 +20,28 @@ describe('header client', () => {
it('should get response when get header status 200', async () => {
const excepted = '1.11';
server.use(
rest.get(MOCK_VERSION_URL, (req, res, ctx) =>
res(ctx.status(HttpStatusCode.Accepted), ctx.json(VERSION_RESPONSE)),
),
http.get(MOCK_VERSION_URL, () => {
return new HttpResponse(JSON.stringify(VERSION_RESPONSE), {
status: HttpStatusCode.Accepted,
});
}),
);

await expect(headerClient.getVersion()).resolves.toEqual(excepted);
});

it('should throw error when get version response status 500', () => {
server.use(
rest.get(MOCK_VERSION_URL, (req, res, ctx) =>
res(
ctx.status(HttpStatusCode.InternalServerError),
ctx.json({
http.get(MOCK_VERSION_URL, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
}),
),
),
{
status: HttpStatusCode.InternalServerError,
},
);
}),
);

expect(async () => {
Expand Down
37 changes: 22 additions & 15 deletions frontend/__tests__/client/MetricsClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BASE_URL, MOCK_GET_STEPS_PARAMS, VERIFY_ERROR_MESSAGE } from '../fixtures';
import { metricsClient } from '@src/clients/MetricsClient';
import { HttpResponse, http } from 'msw';
import { setupServer } from 'msw/node';
import { HttpStatusCode } from 'axios';
import { rest } from 'msw';

describe('get steps from metrics response', () => {
const { params, buildId, organizationId, pipelineType, token } = MOCK_GET_STEPS_PARAMS;
Expand All @@ -13,8 +13,10 @@ describe('get steps from metrics response', () => {

it('should return steps when getSteps response status 200', async () => {
server.use(
rest.get(getStepsUrl, (req, res, ctx) => {
return res(ctx.status(HttpStatusCode.Ok), ctx.json({ steps: ['step1'] }));
http.get(getStepsUrl, () => {
return new HttpResponse(JSON.stringify({ steps: ['step1'] }), {
status: HttpStatusCode.Ok,
});
}),
);

Expand All @@ -25,14 +27,11 @@ describe('get steps from metrics response', () => {

it('should throw error when getSteps response status 500', async () => {
server.use(
rest.get(getStepsUrl, (req, res, ctx) =>
res(
ctx.status(HttpStatusCode.InternalServerError),
ctx.json({
hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
}),
),
),
http.get(getStepsUrl, () => {
return new HttpResponse(JSON.stringify({ hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR }), {
status: HttpStatusCode.InternalServerError,
});
}),
);

await expect(async () => {
Expand All @@ -42,9 +41,11 @@ describe('get steps from metrics response', () => {

it('should throw error when getSteps response status 400', async () => {
server.use(
rest.get(getStepsUrl, (req, res, ctx) =>
res(ctx.status(HttpStatusCode.BadRequest), ctx.json({ hintInfo: VERIFY_ERROR_MESSAGE.BAD_REQUEST })),
),
http.get(getStepsUrl, () => {
return new HttpResponse(JSON.stringify({ hintInfo: VERIFY_ERROR_MESSAGE.BAD_REQUEST }), {
status: HttpStatusCode.BadRequest,
});
}),
);

await expect(async () => {
Expand All @@ -53,7 +54,13 @@ describe('get steps from metrics response', () => {
});

it('should show isNoStep True when getSteps response status 204', async () => {
server.use(rest.get(getStepsUrl, (req, res, ctx) => res(ctx.status(HttpStatusCode.NoContent))));
server.use(
http.get(getStepsUrl, () => {
return new HttpResponse(null, {
status: HttpStatusCode.NoContent,
});
}),
);

const result = await metricsClient.getSteps(params[0], buildId, organizationId, pipelineType, token);

Expand Down
Loading

0 comments on commit dae9844

Please sign in to comment.