-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adm 793 [frontend] Reduce the time of timeout to 10 minutes #1141
Changes from 26 commits
e6b9ee1
fc01550
2354ced
01ab2ed
12f8c26
a59dfb5
f619f9c
d38f126
4e3917c
49ff6a8
67817c1
e132606
c6eb632
8bc183b
3345b5b
4ac618e
7b7b851
666654c
638dada
c9640dd
92ffd21
87265f8
ff5045e
5e7a7bf
e3558f4
6fafbe2
ae3c971
09cf8cd
e0dd764
575e9bd
94899f5
210c6ea
e06a936
267c51a
7683e22
7512069
c5f66ee
9f0b012
5e626a8
b331d3c
76df053
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,11 @@ describe('verify sourceControl request', () => { | |
afterAll(() => server.close()); | ||
|
||
it('should return isSourceControlVerify true when sourceControl verify response status is 204', async () => { | ||
const result = await sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS); | ||
const result = await sourceControlClient.verifyToken( | ||
MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS, | ||
jest.fn(), | ||
jest.fn(), | ||
); | ||
|
||
expect(result.code).toEqual(204); | ||
}); | ||
|
@@ -27,7 +31,7 @@ describe('verify sourceControl request', () => { | |
), | ||
); | ||
|
||
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS).catch((e) => { | ||
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS, jest.fn(), jest.fn()).catch((e) => { | ||
expect(e).toBeInstanceOf(Error); | ||
expect((e as Error).message).toMatch(VERIFY_ERROR_MESSAGE.BAD_REQUEST); | ||
}); | ||
|
@@ -40,7 +44,7 @@ describe('verify sourceControl request', () => { | |
), | ||
); | ||
|
||
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS).catch((e) => { | ||
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS, jest.fn(), jest.fn()).catch((e) => { | ||
expect(e).toBeInstanceOf(Error); | ||
expect((e as Error).message).toMatch(VERIFY_ERROR_MESSAGE.NOT_FOUND); | ||
}); | ||
|
@@ -58,7 +62,7 @@ describe('verify sourceControl request', () => { | |
), | ||
); | ||
|
||
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS).catch((e) => { | ||
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS, jest.fn(), jest.fn()).catch((e) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一样的问题 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 原则:测试不要出现类似try catch的代码 |
||
expect(e).toBeInstanceOf(Error); | ||
expect((e as Error).message).toMatch(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ConfigButtonGrop } from '@src/containers/ConfigStep/ConfigButton'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
describe('ConfigButtonGroup', () => { | ||
const setup = (isVerified: boolean, isLoading: boolean, isHBTimeOut: boolean, isDisableVerifyButton: boolean) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IsHBTimeout?isConfigTimeout?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 收到,我理解是尽量避免变量名不涉及项目信息?比如IsHBTimeout中HB涉及到了,应换个普通点的名称? |
||
return render( | ||
<ConfigButtonGrop | ||
isHBTimeOut={isHBTimeOut} | ||
isVerified={isVerified} | ||
isLoading={isLoading} | ||
isDisableVerifyButton={isDisableVerifyButton} | ||
/>, | ||
); | ||
}; | ||
|
||
it('should render a disabled VerifyButton with "Verified" text when isVerified is true and isLoading is false', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When - given,看一哈should given when 分别写什么 |
||
setup(true, false, false, false); // Use a different moduleType for clarity | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
expect(screen.getByText('Verified')).toBeInTheDocument(); | ||
expect(screen.getByText('Reset')).toBeInTheDocument(); | ||
expect(screen.getByText('Verified')).toBeDisabled(); | ||
}); | ||
it('should render a VerifyButton with "Reverify" text when isHBTimeOut is true', () => { | ||
setup(false, false, true, false); // Use a different moduleType for clarity | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
expect(screen.getByText('Reverify')).toBeInTheDocument(); | ||
expect(screen.getByText('Reverify')).toHaveAttribute('type', 'submit'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TimeoutAlert } from '@src/containers/ConfigStep/TimeoutAlert'; | ||
import { act, render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
describe('TimeoutAlert', () => { | ||
const setIsShowAlert = jest.fn(); | ||
const setup = ( | ||
setIsShowAlert: (value: boolean) => void, | ||
isShowAlert: boolean, | ||
isHBTimeOut: boolean, | ||
moduleType: string, | ||
) => { | ||
return render( | ||
<TimeoutAlert | ||
setIsShowAlert={setIsShowAlert} | ||
isShowAlert={isShowAlert} | ||
isHBTimeOut={isHBTimeOut} | ||
moduleType={moduleType} | ||
/>, | ||
); | ||
}; | ||
|
||
it('should render the correct message when given the moduleType', () => { | ||
setup(setIsShowAlert, true, true, 'Board'); // Use a different moduleType for clarity | ||
guzhongren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const message = screen.getByText('Board'); // Use a regex for flexibility | ||
expect(message).toBeInTheDocument(); | ||
}); | ||
it('should not render the alert when isHBTimeOut or isShowAlert is false', () => { | ||
setup(setIsShowAlert, false, true, 'Board'); | ||
expect(screen.queryByText('Board')).not.toBeInTheDocument(); | ||
|
||
setup(setIsShowAlert, true, false, 'Board'); | ||
expect(screen.queryByText('Board')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should call setIsShowAlert with false and hides the alert when click the close icon', async () => { | ||
setup(setIsShowAlert, true, true, 'any'); // Ensure alert is visible | ||
const closeIcon = screen.getByTestId('CloseIcon'); | ||
act(() => { | ||
userEvent.click(closeIcon); | ||
}); | ||
await waitFor(() => { | ||
expect(setIsShowAlert).toHaveBeenCalledTimes(1); | ||
expect(setIsShowAlert).toHaveBeenCalledWith(false); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { useVerifyBoardEffect, useVerifyBoardStateInterface } from '@src/hooks/useVerifyBoardEffect'; | ||
import { MOCK_BOARD_URL_FOR_JIRA, FAKE_TOKEN } from '@test/fixtures'; | ||
import { act, renderHook, waitFor } from '@testing-library/react'; | ||
import { setupServer } from 'msw/node'; | ||
import { FAKE_TOKEN } from '@test/fixtures'; | ||
import { HttpStatusCode } from 'axios'; | ||
|
||
import { InternalServerException } from '@src/exceptions/InternalServerException'; | ||
import { UnauthorizedException } from '@src/exceptions/UnauthorizedException'; | ||
import { NotFoundException } from '@src/exceptions/NotFoundException'; | ||
import { TimeoutException } from '@src/exceptions/TimeoutException'; | ||
import { HEARTBEAT_EXCEPTION_CODE } from '@src/constants/resources'; | ||
import { boardClient } from '@src/clients/board/BoardClient'; | ||
import { BOARD_TYPES } from '@test/fixtures'; | ||
import { rest } from 'msw'; | ||
|
||
const mockDispatch = jest.fn(); | ||
jest.mock('react-redux', () => ({ | ||
|
@@ -18,8 +22,6 @@ jest.mock('@src/hooks/useAppDispatch', () => ({ | |
useAppDispatch: jest.fn(() => jest.fn()), | ||
})); | ||
|
||
const server = setupServer(); | ||
|
||
const updateFields = (result: { current: useVerifyBoardStateInterface }) => { | ||
result.current.updateField('Board Id', '1'); | ||
result.current.updateField('Email', 'fake@qq.com'); | ||
|
@@ -28,10 +30,8 @@ const updateFields = (result: { current: useVerifyBoardStateInterface }) => { | |
}; | ||
|
||
describe('use verify board state', () => { | ||
beforeAll(() => server.listen()); | ||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
server.close(); | ||
}); | ||
it('should got initial data state when hook render given none input', async () => { | ||
const { result } = renderHook(() => useVerifyBoardEffect()); | ||
|
@@ -41,16 +41,13 @@ describe('use verify board state', () => { | |
}); | ||
|
||
it('should got email and token fields error message when call verify function given a invalid token', async () => { | ||
server.use( | ||
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => { | ||
return res(ctx.status(HttpStatusCode.Unauthorized)); | ||
}), | ||
); | ||
const mockedError = new UnauthorizedException('', HttpStatusCode.Unauthorized, ''); | ||
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError)); | ||
|
||
const { result } = renderHook(() => useVerifyBoardEffect()); | ||
await act(() => { | ||
updateFields(result); | ||
result.current.verifyJira(); | ||
await act(async () => { | ||
await updateFields(result); | ||
await result.current.verifyJira(); | ||
}); | ||
|
||
const emailFiled = result.current.fields.find((field) => field.key === 'Email'); | ||
|
@@ -61,22 +58,34 @@ describe('use verify board state', () => { | |
); | ||
}); | ||
|
||
it('when call verify function given a invalid site then should got site field error message', async () => { | ||
server.use( | ||
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => { | ||
return res( | ||
ctx.status(HttpStatusCode.NotFound), | ||
ctx.json({ | ||
message: 'site is incorrect', | ||
}), | ||
); | ||
}), | ||
); | ||
it('should clear email validatedError when updateField by Email', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should Given when |
||
const mockedError = new UnauthorizedException('', HttpStatusCode.Unauthorized, ''); | ||
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError)); | ||
|
||
const { result } = renderHook(() => useVerifyBoardEffect()); | ||
await act(() => { | ||
updateFields(result); | ||
result.current.verifyJira(); | ||
await act(async () => { | ||
await updateFields(result); | ||
await result.current.verifyJira(); | ||
}); | ||
|
||
const emailFiled = result.current.fields.find((field) => field.key === 'Email'); | ||
expect(emailFiled?.verifiedError).toBe('Email is incorrect!'); | ||
|
||
await act(async () => { | ||
await result.current.updateField('Email', 'fake@qq.com'); | ||
}); | ||
const emailText = result.current.fields.find((field) => field.key === 'Email'); | ||
expect(emailText?.verifiedError).toBe(''); | ||
}); | ||
|
||
it('should got site field error message when call verify function given a invalid site', async () => { | ||
const mockedError = new NotFoundException('site is incorrect', HttpStatusCode.NotFound, 'site is incorrect'); | ||
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError)); | ||
|
||
const { result } = renderHook(() => useVerifyBoardEffect()); | ||
await act(async () => { | ||
await updateFields(result); | ||
await result.current.verifyJira(); | ||
}); | ||
|
||
await waitFor(() => { | ||
|
@@ -87,16 +96,8 @@ describe('use verify board state', () => { | |
}); | ||
|
||
it('should got board id field error message when call verify function given a invalid board id', async () => { | ||
server.use( | ||
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => { | ||
return res( | ||
ctx.status(HttpStatusCode.NotFound), | ||
ctx.json({ | ||
message: 'boardId is incorrect', | ||
}), | ||
); | ||
}), | ||
); | ||
const mockedError = new NotFoundException('boardId is incorrect', HttpStatusCode.NotFound, 'boardId is incorrect'); | ||
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError)); | ||
|
||
const { result } = renderHook(() => useVerifyBoardEffect()); | ||
await act(() => { | ||
|
@@ -111,28 +112,22 @@ describe('use verify board state', () => { | |
}); | ||
|
||
it('should got token fields error message when call verify function given a unknown error', async () => { | ||
server.use( | ||
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => { | ||
return res(ctx.status(HttpStatusCode.ServiceUnavailable)); | ||
}), | ||
); | ||
const mockedError = new InternalServerException('', HttpStatusCode.ServiceUnavailable, ''); | ||
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError)); | ||
|
||
const { result } = renderHook(() => useVerifyBoardEffect()); | ||
await act(() => { | ||
updateFields(result); | ||
result.current.verifyJira(); | ||
await act(async () => { | ||
await updateFields(result); | ||
await result.current.verifyJira(); | ||
}); | ||
|
||
const tokenField = result.current.fields.find((field) => field.key === 'Token'); | ||
expect(tokenField?.verifiedError).toBe('Unknown error'); | ||
}); | ||
|
||
it('should clear all verified error messages when update a verified error field', async () => { | ||
server.use( | ||
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => { | ||
return res(ctx.status(HttpStatusCode.Unauthorized)); | ||
}), | ||
); | ||
const mockedError = new UnauthorizedException('', HttpStatusCode.Unauthorized, ''); | ||
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError)); | ||
|
||
const { result } = renderHook(() => useVerifyBoardEffect()); | ||
await act(() => { | ||
|
@@ -148,4 +143,19 @@ describe('use verify board state', () => { | |
expect(emailFiled?.verifiedError).toBe(''); | ||
expect(tokenField?.verifiedError).toBe(''); | ||
}); | ||
|
||
it('should set timeout is true when getVerifyBoard api is timeout', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given |
||
const mockedError = new TimeoutException('', HEARTBEAT_EXCEPTION_CODE.TIMEOUT); | ||
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError)); | ||
|
||
const { result } = renderHook(() => useVerifyBoardEffect()); | ||
await act(() => { | ||
result.current.verifyJira(); | ||
}); | ||
|
||
await waitFor(() => { | ||
const isHBTimeOut = result.current.isHBTimeOut; | ||
expect(isHBTimeOut).toBe(true); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用catch接,用reject.throw接错误