Skip to content

Commit

Permalink
Merge branch 'main' into ADM-1000
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-yinyuan committed Sep 20, 2024
2 parents 4008e55 + 03564e6 commit 544fe03
Show file tree
Hide file tree
Showing 43 changed files with 1,247 additions and 901 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install
run: |
npm install -g pnpm
pnpm install --no-frozen-lockfile
pnpm install --no-frozen-lockfile --ignore-scripts
- name: Lint
run: pnpm run lint
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: |
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
-v "${PWD}:/path" \
ghcr.io/gitleaks/gitleaks:latest \
ghcr.io/gitleaks/gitleaks:v8.18.4 \
detect \
--source="/path" \
-v --redact
Expand Down
4 changes: 4 additions & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ CVE-2023-50387
CVE-2023-50868
CVE-2024-34750
CVE-2024-5171
CVE-2024-38816
CVE-2024-45490
CVE-2024-45491
CVE-2024-45492
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
- [Apr 2 2024 - Release heartbeat - 1.1.6](release-notes/20240402.md)
- [June 6 2024 - Release heartbeat - 1.1.7](release-notes/20240605.md)
- [July 15 2024 - Release heartbeat - 1.2.0](release-notes/20240715.md)
- [Sep 11 2024 - Release heartbeat - 1.3.0](release-notes/20240911.md)

# 1 About Heartbeat

Expand Down
153 changes: 74 additions & 79 deletions frontend/__tests__/client/SourceControlClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
MOCK_SOURCE_CONTROL_VERIFY_TOKEN_URL,
} from '../fixtures';
import { sourceControlClient } from '@src/clients/sourceControl/SourceControlClient';
import { InternalServerError } from '@src/errors/InternalServerError';
import { UnauthorizedError } from '@src/errors/UnauthorizedError';
import { SourceControlTypes } from '@src/constants/resources';
import { ForbiddenError } from '@src/errors/ForbiddenError';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import { HttpStatusCode } from 'axios';
Expand Down Expand Up @@ -164,8 +167,7 @@ describe('verify sourceControl request', () => {
endTime: 123,
});

expect(result.code).toEqual(200);
expect(result.data?.name).toEqual(expectedNames);
expect(result.name).toEqual(expectedNames);
});

it('should set default error title when get repositories api return 401', async () => {
Expand All @@ -177,17 +179,16 @@ describe('verify sourceControl request', () => {
}),
);

const result = await sourceControlClient.getRepo({
type: SourceControlTypes.GitHub,
token: 'mock-token',
organization: 'org',
endTime: 123,
});

expect(result.code).toEqual(401);
expect(result.errorMessage).toEqual(
'Please go back to the previous page and change your source control token with correct access permission.',
);
try {
await sourceControlClient.getRepo({
type: SourceControlTypes.GitHub,
token: 'mock-token',
organization: 'org',
endTime: 123,
});
} catch (error) {
expect(error).toBeInstanceOf(UnauthorizedError);
}
});

it('should set default error title when get repositories api return 403', async () => {
Expand All @@ -199,17 +200,16 @@ describe('verify sourceControl request', () => {
}),
);

const result = await sourceControlClient.getRepo({
type: SourceControlTypes.GitHub,
token: 'mock-token',
organization: 'org',
endTime: 123,
});

expect(result.code).toEqual(403);
expect(result.errorMessage).toEqual(
'Please go back to the previous page and change your source control token with correct access permission.',
);
try {
await sourceControlClient.getRepo({
type: SourceControlTypes.GitHub,
token: 'mock-token',
organization: 'org',
endTime: 123,
});
} catch (error) {
expect(error).toBeInstanceOf(ForbiddenError);
}
});

it('should set default error title when get repositories api return 500', async () => {
Expand All @@ -221,17 +221,16 @@ describe('verify sourceControl request', () => {
}),
);

const result = await sourceControlClient.getRepo({
type: SourceControlTypes.GitHub,
token: 'mock-token',
organization: 'org',
endTime: 123,
});

expect(result.code).toEqual(500);
expect(result.errorMessage).toEqual(
'Please go back to the previous page and change your source control token with correct access permission.',
);
try {
await sourceControlClient.getRepo({
type: SourceControlTypes.GitHub,
token: 'mock-token',
organization: 'org',
endTime: 123,
});
} catch (error) {
expect(error).toBeInstanceOf(InternalServerError);
}
});

it('should return branches when get branches api return ok', async () => {
Expand Down Expand Up @@ -351,8 +350,7 @@ describe('verify sourceControl request', () => {
endTime: 123,
});

expect(result.code).toEqual(200);
expect(result.data?.crews).toEqual(expectedNames);
expect(result.crews).toEqual(expectedNames);
});

it('should set default error title when get crews api return 401', async () => {
Expand All @@ -364,20 +362,19 @@ describe('verify sourceControl request', () => {
}),
);

const result = await sourceControlClient.getCrew({
type: SourceControlTypes.GitHub,
token: 'mock-token',
repo: 'repo',
organization: 'org',
branch: 'branch',
startTime: 123,
endTime: 123,
});

expect(result.code).toEqual(401);
expect(result.errorMessage).toEqual(
'Please go back to the previous page and change your source control token with correct access permission.',
);
try {
await sourceControlClient.getCrew({
type: SourceControlTypes.GitHub,
token: 'mock-token',
repo: 'repo',
organization: 'org',
branch: 'branch',
startTime: 123,
endTime: 123,
});
} catch (error) {
expect(error).toBeInstanceOf(UnauthorizedError);
}
});

it('should set default error title when get crews api return 403', async () => {
Expand All @@ -389,20 +386,19 @@ describe('verify sourceControl request', () => {
}),
);

const result = await sourceControlClient.getCrew({
type: SourceControlTypes.GitHub,
repo: 'repo',
branch: 'branch',
startTime: 123,
endTime: 123,
token: 'mock-token',
organization: 'org',
});

expect(result.code).toEqual(403);
expect(result.errorMessage).toEqual(
'Please go back to the previous page and change your source control token with correct access permission.',
);
try {
await sourceControlClient.getCrew({
type: SourceControlTypes.GitHub,
repo: 'repo',
branch: 'branch',
startTime: 123,
endTime: 123,
token: 'mock-token',
organization: 'org',
});
} catch (error) {
expect(error).toBeInstanceOf(ForbiddenError);
}
});

it('should set default error title when get crews api return 500', async () => {
Expand All @@ -414,19 +410,18 @@ describe('verify sourceControl request', () => {
}),
);

const result = await sourceControlClient.getCrew({
type: SourceControlTypes.GitHub,
token: 'mock-token',
repo: 'repo',
branch: 'branch',
startTime: 123,
endTime: 123,
organization: 'org',
});

expect(result.code).toEqual(500);
expect(result.errorMessage).toEqual(
'Please go back to the previous page and change your source control token with correct access permission.',
);
try {
await sourceControlClient.getCrew({
type: SourceControlTypes.GitHub,
token: 'mock-token',
repo: 'repo',
branch: 'branch',
startTime: 123,
endTime: 123,
organization: 'org',
});
} catch (error) {
expect(error).toBeInstanceOf(InternalServerError);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ describe('<PresentationForErrorCases />', () => {
it.each(commonErrors)(
'should properly render error UI with title:$title and corresponding message',
({ code, title: errorTitle }) => {
const props = { code, errorTitle, errorMessage, isLoading: false, retry: () => '' };
const props: IPresentationForErrorCasesProps = {
code,
errorTitle,
errorMessage,
isLoading: false,
retry: () => Promise.resolve(),
};
setup(props);

const titleNode = screen.getByText(errorTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Provider } from 'react-redux';

const mockInitSourceControlSettings = [
{ id: 0, organization: 'mockOrgName', repo: 'mockRepoName', branches: ['mockBranch1'] },
{ id: 1, organization: '', repo: '', steps: '', branches: [] },
{ id: 1, organization: '', repo: '', branches: [] },
];
const mockInitOrganizationEffectResponse = {
isFirstFetch: false,
Expand All @@ -37,10 +37,7 @@ const mockInitRepoEffectResponse = {
isLoading: false,
getSourceControlRepoInfo: jest.fn(),
info: {
code: 200,
data: undefined,
errorTitle: '',
errorMessage: '',
name: [],
},
stepFailedStatus: MetricsDataFailStatus.NotFailed,
};
Expand All @@ -49,10 +46,7 @@ const mockInitBranchEffectResponse = {
getSourceControlBranchInfo: jest.fn(),
isGetBranch: true,
info: {
code: 200,
data: undefined,
errorTitle: '',
errorMessage: '',
name: [],
},
stepFailedStatus: MetricsDataFailStatus.NotFailed,
};
Expand All @@ -61,10 +55,7 @@ const mockInitCrewEffectResponse = {
getSourceControlCrewInfo: jest.fn(),
isGetAllCrews: true,
info: {
code: 200,
data: undefined,
errorTitle: '',
errorMessage: '',
crews: [],
},
stepFailedStatus: MetricsDataFailStatus.NotFailed,
};
Expand Down Expand Up @@ -144,6 +135,7 @@ describe('SourceControlConfiguration', () => {
mockBranchEffectResponse = mockInitBranchEffectResponse;
mockCrewEffectResponse = mockInitCrewEffectResponse;
});

it('should show loading when isLoading is true', () => {
mockOrganizationEffectResponse = {
...mockOrganizationEffectResponse,
Expand Down Expand Up @@ -257,4 +249,80 @@ describe('SourceControlConfiguration', () => {

expect(screen.getByLabelText('Error UI for pipeline settings')).toBeInTheDocument();
});

it('should display error UI and retry when get repo failed status returns AllFailedTimeout', async () => {
const getSourceControlInfo = jest.fn();
mockRepoEffectResponse = {
...mockInitRepoEffectResponse,
stepFailedStatus: MetricsDataFailStatus.AllFailedTimeout,
};
mockOrganizationEffectResponse = {
...mockInitOrganizationEffectResponse,
getSourceControlInfo,
};
setup();

const retryButton = screen.getByLabelText('retry button');

expect(screen.getByLabelText('Error UI for pipeline settings')).toBeInTheDocument();
expect(retryButton).toBeInTheDocument();

await act(async () => {
await userEvent.click(retryButton);
});

expect(getSourceControlInfo).toHaveBeenCalledTimes(1);
});

it('should display error UI and retry when get branch failed status returns AllFailedTimeout', async () => {
const getSourceControlInfo = jest.fn();
mockBranchEffectResponse = {
...mockInitBranchEffectResponse,
stepFailedStatus: MetricsDataFailStatus.AllFailedTimeout,
};
mockOrganizationEffectResponse = {
...mockInitOrganizationEffectResponse,
getSourceControlInfo,
};
setup();

const retryButton = screen.getByLabelText('retry button');

expect(screen.getByLabelText('Error UI for pipeline settings')).toBeInTheDocument();
expect(retryButton).toBeInTheDocument();

await act(async () => {
await userEvent.click(retryButton);
});

expect(getSourceControlInfo).toHaveBeenCalledTimes(1);
});

it('should display error UI and retry when get crew failed status returns AllFailedTimeout', async () => {
const getSourceControlInfo = jest.fn();
mockCrewEffectResponse = {
...mockInitCrewEffectResponse,
stepFailedStatus: MetricsDataFailStatus.AllFailedTimeout,
};
mockOrganizationEffectResponse = {
...mockInitOrganizationEffectResponse,
getSourceControlInfo,
};
mockSourceControlSettings = [
{ id: 0, organization: 'mockOrgName', repo: 'mockRepoName', branches: ['mockBranch1'] },
{ id: 1, organization: 'mockOrgName', repo: 'mockRepoName', branches: ['mockBranch2'] },
];
setup();

const retryButton = screen.getByLabelText('retry button');

expect(screen.getByLabelText('Error UI for pipeline settings')).toBeInTheDocument();
expect(retryButton).toBeInTheDocument();

await act(async () => {
await userEvent.click(retryButton);
});

expect(getSourceControlInfo).toHaveBeenCalledTimes(1);
});
});
Loading

0 comments on commit 544fe03

Please sign in to comment.