Skip to content

Commit

Permalink
ADM-1009 [frontend]: fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-yinyuan committed Sep 19, 2024
1 parent 437c903 commit 6d70dd6
Show file tree
Hide file tree
Showing 9 changed files with 474 additions and 21 deletions.
57 changes: 57 additions & 0 deletions frontend/__tests__/hooks/useGetMetricsStepsEffect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ describe('use get steps effect', () => {
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailed4xx);
});

it('should get the steps failed status when partial 4xx response from steps res and code type is string', async () => {
metricsClient.getSteps = jest
.fn()
.mockReturnValueOnce({
response: ['a', 'b', 'c'],
haveStep: true,
branches: ['branchA', 'branchB'],
pipelineCrews: ['crewA', 'crewB'],
})
.mockRejectedValue({
code: '404',
});
const { result } = renderHook(() => useGetMetricsStepsEffect());
await act(async () => {
await result.current.getSteps(params, buildId, organizationId, pipelineType, token);
});
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailed4xx);
});

it('should get the steps failed status when partial timeout response from steps res', async () => {
metricsClient.getSteps = jest
.fn()
Expand All @@ -106,6 +125,44 @@ describe('use get steps effect', () => {
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailedTimeout);
});

it('should get the steps failed status when partial timeout response from steps res and code is null', async () => {
metricsClient.getSteps = jest
.fn()
.mockReturnValueOnce({
response: ['a', 'b', 'c'],
haveStep: true,
branches: ['branchA', 'branchB'],
pipelineCrews: ['crewA', 'crewB'],
})
.mockRejectedValue({
code: null,
});
const { result } = renderHook(() => useGetMetricsStepsEffect());
await act(async () => {
await result.current.getSteps(params, buildId, organizationId, pipelineType, token);
});
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailedTimeout);
});

it('should get the steps failed status when partial timeout response from steps res and code is undefined', async () => {
metricsClient.getSteps = jest
.fn()
.mockReturnValueOnce({
response: ['a', 'b', 'c'],
haveStep: true,
branches: ['branchA', 'branchB'],
pipelineCrews: ['crewA', 'crewB'],
})
.mockRejectedValue({
code: undefined,
});
const { result } = renderHook(() => useGetMetricsStepsEffect());
await act(async () => {
await result.current.getSteps(params, buildId, organizationId, pipelineType, token);
});
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailedTimeout);
});

it('should set error message when get steps throw error', async () => {
jest.useFakeTimers();
metricsClient.getSteps = jest.fn().mockImplementation(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ describe('use get source control configuration branch info side effect', () => {
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailed4xx);
});

it('should set error step failed status to AllFailed4xx when getting branch response is failed and client return 4xx', async () => {
it('should set error step failed status to AllFailed4xx when getting branch response is failed and client return 4xx and type is string', async () => {
const { result } = renderHook(() => useGetSourceControlConfigurationBranchEffect(), { wrapper: Wrapper });
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
sourceControlClient.getBranch = jest.fn().mockImplementation(() => {
return Promise.resolve({
code: 404,
code: '404',
});
});
await act(async () => {
Expand All @@ -128,4 +128,38 @@ describe('use get source control configuration branch info side effect', () => {
expect(sourceControlClient.getBranch).toBeCalled();
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailedTimeout);
});

it('should set error step failed status to AllFailedTimeout when getting branch response is failed and code is null', async () => {
const { result } = renderHook(() => useGetSourceControlConfigurationBranchEffect(), { wrapper: Wrapper });
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
sourceControlClient.getBranch = jest.fn().mockImplementation(() => {
return Promise.resolve({
code: null,
});
});
await act(async () => {
result.current.getSourceControlBranchInfo(mockOrganization, mockRepo, 1);
});

expect(sourceControlClient.getBranch).toBeCalled();
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailedTimeout);
});

it('should set error step failed status to AllFailedTimeout when getting branch response is failed and code is undefined', async () => {
const { result } = renderHook(() => useGetSourceControlConfigurationBranchEffect(), { wrapper: Wrapper });
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
sourceControlClient.getBranch = jest.fn().mockImplementation(() => {
return Promise.resolve({
code: undefined,
});
});
await act(async () => {
result.current.getSourceControlBranchInfo(mockOrganization, mockRepo, 1);
});

expect(sourceControlClient.getBranch).toBeCalled();
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailedTimeout);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,41 @@ describe('use get source control configuration crew info side effect', () => {
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailed4xx);
});

it('should set error step failed status to PartialFailed4xx when one of getting repo response is failed and code is 4xx and type is string', async () => {
sourceControlClient.getCrew = jest
.fn()
.mockImplementationOnce(() => {
return Promise.reject({
code: '404',
});
})
.mockImplementationOnce(() => {
return Promise.resolve({
crews: ['crew1'],
});
});
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
const mockBranch = 'mockBranch';
const dateRanges: DateRange[] = [
{
startDate: '2024-07-31T00:00:00.000+08:00',
endDate: '2024-08-02T23:59:59.999+08:00',
},
{
startDate: '2024-07-15T00:00:00.000+08:00',
endDate: '2024-07-28T23:59:59.999+08:00',
},
];
const { result } = renderHook(() => useGetSourceControlConfigurationCrewEffect(), { wrapper: Wrapper });

await act(async () => {
result.current.getSourceControlCrewInfo(mockOrganization, mockRepo, mockBranch, dateRanges);
});

expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailed4xx);
});

it('should set error step failed status to PartialFailedTimeout when one of getting repo responses is failed and code is not 4xx', async () => {
sourceControlClient.getCrew = jest
.fn()
Expand Down Expand Up @@ -140,6 +175,76 @@ describe('use get source control configuration crew info side effect', () => {
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailedTimeout);
});

it('should set error step failed status to PartialFailedTimeout when one of getting repo responses is failed and code is null', async () => {
sourceControlClient.getCrew = jest
.fn()
.mockImplementationOnce(() => {
return Promise.reject({
code: null,
});
})
.mockImplementationOnce(() => {
return Promise.resolve({
crews: ['crew1'],
});
});
const { result } = renderHook(() => useGetSourceControlConfigurationCrewEffect(), { wrapper: Wrapper });
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
const mockBranch = 'mockBranch';
const dateRanges: DateRange[] = [
{
startDate: '2024-07-31T00:00:00.000+08:00',
endDate: '2024-08-02T23:59:59.999+08:00',
},
{
startDate: '2024-07-15T00:00:00.000+08:00',
endDate: '2024-07-28T23:59:59.999+08:00',
},
];

await act(async () => {
result.current.getSourceControlCrewInfo(mockOrganization, mockRepo, mockBranch, dateRanges);
});

expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailedTimeout);
});

it('should set error step failed status to PartialFailedTimeout when one of getting repo responses is failed and code is undefined', async () => {
sourceControlClient.getCrew = jest
.fn()
.mockImplementationOnce(() => {
return Promise.reject({
code: undefined,
});
})
.mockImplementationOnce(() => {
return Promise.resolve({
crews: ['crew1'],
});
});
const { result } = renderHook(() => useGetSourceControlConfigurationCrewEffect(), { wrapper: Wrapper });
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
const mockBranch = 'mockBranch';
const dateRanges: DateRange[] = [
{
startDate: '2024-07-31T00:00:00.000+08:00',
endDate: '2024-08-02T23:59:59.999+08:00',
},
{
startDate: '2024-07-15T00:00:00.000+08:00',
endDate: '2024-07-28T23:59:59.999+08:00',
},
];

await act(async () => {
result.current.getSourceControlCrewInfo(mockOrganization, mockRepo, mockBranch, dateRanges);
});

expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.PartialFailedTimeout);
});

it('should set error step failed status to AllFailed4xx when all getting repo responses are failed and code is 4xx', async () => {
sourceControlClient.getCrew = jest.fn().mockImplementation(() => {
return Promise.reject({
Expand Down Expand Up @@ -168,6 +273,34 @@ describe('use get source control configuration crew info side effect', () => {
expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailed4xx);
});

it('should set error step failed status to AllFailed4xx when all getting repo responses are failed and code is type is string', async () => {
sourceControlClient.getCrew = jest.fn().mockImplementation(() => {
return Promise.reject({
code: '404',
});
});
const { result } = renderHook(() => useGetSourceControlConfigurationCrewEffect(), { wrapper: Wrapper });
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
const mockBranch = 'mockBranch';
const dateRanges: DateRange[] = [
{
startDate: '2024-07-31T00:00:00.000+08:00',
endDate: '2024-08-02T23:59:59.999+08:00',
},
{
startDate: '2024-07-15T00:00:00.000+08:00',
endDate: '2024-07-28T23:59:59.999+08:00',
},
];

await act(async () => {
result.current.getSourceControlCrewInfo(mockOrganization, mockRepo, mockBranch, dateRanges);
});

expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailed4xx);
});

it('should set error step failed status to AllFailedTimeout when all getting repo responses are failed and code is not 4xx', async () => {
sourceControlClient.getCrew = jest.fn().mockImplementation(() => {
return Promise.reject({
Expand Down Expand Up @@ -195,4 +328,60 @@ describe('use get source control configuration crew info side effect', () => {

expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailedTimeout);
});

it('should set error step failed status to AllFailedTimeout when all getting repo responses are failed and code is null', async () => {
sourceControlClient.getCrew = jest.fn().mockImplementation(() => {
return Promise.reject({
code: null,
});
});
const { result } = renderHook(() => useGetSourceControlConfigurationCrewEffect(), { wrapper: Wrapper });
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
const mockBranch = 'mockBranch';
const dateRanges: DateRange[] = [
{
startDate: '2024-07-31T00:00:00.000+08:00',
endDate: '2024-08-02T23:59:59.999+08:00',
},
{
startDate: '2024-07-15T00:00:00.000+08:00',
endDate: '2024-07-28T23:59:59.999+08:00',
},
];

await act(async () => {
result.current.getSourceControlCrewInfo(mockOrganization, mockRepo, mockBranch, dateRanges);
});

expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailedTimeout);
});

it('should set error step failed status to AllFailedTimeout when all getting repo responses are failed and code is undefined', async () => {
sourceControlClient.getCrew = jest.fn().mockImplementation(() => {
return Promise.reject({
code: undefined,
});
});
const { result } = renderHook(() => useGetSourceControlConfigurationCrewEffect(), { wrapper: Wrapper });
const mockOrganization = 'mockOrg';
const mockRepo = 'mockRepo';
const mockBranch = 'mockBranch';
const dateRanges: DateRange[] = [
{
startDate: '2024-07-31T00:00:00.000+08:00',
endDate: '2024-08-02T23:59:59.999+08:00',
},
{
startDate: '2024-07-15T00:00:00.000+08:00',
endDate: '2024-07-28T23:59:59.999+08:00',
},
];

await act(async () => {
result.current.getSourceControlCrewInfo(mockOrganization, mockRepo, mockBranch, dateRanges);
});

expect(result.current.stepFailedStatus).toEqual(MetricsDataFailStatus.AllFailedTimeout);
});
});
Loading

0 comments on commit 6d70dd6

Please sign in to comment.