Skip to content

Commit

Permalink
Action linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jnowakow committed Dec 2, 2024
1 parent 7ad51a8 commit d7a73ca
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .github/actions/javascript/postTestBuildComment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11533,11 +11533,11 @@ function getTestBuildMessage() {
const message = `:test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! :test_tube::test_tube:
| Android :robot: | iOS :apple: |
| ------------- | ------------- |
| ${result['ANDROID'].link} | ${result['IOS'].link} |
| ${result['ANDROID'].qrCode} | ${result['IOS'].qrCode} |
| ${result.ANDROID.link} | ${result.IOS.link} |
| ${result.ANDROID.qrCode} | ${result.IOS.qrCode} |
| Desktop :computer: | Web :spider_web: |
| ${result['DESKTOP'].link} | ${result['WEB'].link} |
| ${result['DESKTOP'].qrCode} | ${result['WEB'].qrCode} |
| ${result.DESKTOP.link} | ${result.WEB.link} |
| ${result.DESKTOP.qrCode} | ${result.WEB.qrCode} |

---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import {context} from '@actions/github';
import {TupleToUnion} from 'type-fest';

Check failure on line 3 in .github/actions/javascript/postTestBuildComment/postTestBuildComment.ts

View workflow job for this annotation

GitHub Actions / ESLint check

All imports in the declaration are only used as types. Use `import type`

Check failure on line 3 in .github/actions/javascript/postTestBuildComment/postTestBuildComment.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

All imports in the declaration are only used as types. Use `import type`
import CONST from '@github/libs/CONST';
import GithubUtils from '@github/libs/GithubUtils';

Expand Down Expand Up @@ -36,16 +37,16 @@ function getTestBuildMessage(): string {
qrCode,
},
};
}, {} as Record<(typeof inputs)[number], {link: string; qrCode: string}>);
}, {} as Record<TupleToUnion<typeof inputs>, {link: string; qrCode: string}>);

const message = `:test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! :test_tube::test_tube:
| Android :robot: | iOS :apple: |
| ------------- | ------------- |
| ${result['ANDROID'].link} | ${result['IOS'].link} |
| ${result['ANDROID'].qrCode} | ${result['IOS'].qrCode} |
| ${result.ANDROID.link} | ${result.IOS.link} |
| ${result.ANDROID.qrCode} | ${result.IOS.qrCode} |
| Desktop :computer: | Web :spider_web: |
| ${result['DESKTOP'].link} | ${result['WEB'].link} |
| ${result['DESKTOP'].qrCode} | ${result['WEB'].qrCode} |
| ${result.DESKTOP.link} | ${result.WEB.link} |
| ${result.DESKTOP.qrCode} | ${result.WEB.qrCode} |
---
Expand Down
56 changes: 52 additions & 4 deletions tests/unit/postTestBuildComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,34 @@ const message = `:test_tube::test_tube: Use the links below to test this adhoc b
:eyes: [View the workflow run that generated this build](https://github.com/Expensify/App/actions/runs/1234) :eyes:
`;

const onlyAndroidMessage = `:test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! :test_tube::test_tube:
| Android :robot: | iOS :apple: |
| ------------- | ------------- |
| ${androidLink} | N/A |
| ${androidQRCode} | N/A |
| Desktop :computer: | Web :spider_web: |
| N/A | N/A |
| N/A | N/A |
---
:eyes: [View the workflow run that generated this build](https://github.com/Expensify/App/actions/runs/1234) :eyes:
`;

describe('Post test build comments action tests', () => {
beforeAll(() => {
// Mock core module
asMutable(core).getInput = mockGetInput;
});

beforeEach(() => jest.clearAllMocks());

test('Test GH action', async () => {
when(core.getInput).calledWith('PR_NUMBER', {required: true}).mockReturnValue('12');
when(core.getInput).calledWith('ANDROID', {required: true}).mockReturnValue('success');
when(core.getInput).calledWith('IOS', {required: true}).mockReturnValue('success');
when(core.getInput).calledWith('WEB', {required: true}).mockReturnValue('success');
when(core.getInput).calledWith('DESKTOP', {required: true}).mockReturnValue('success');
when(core.getInput).calledWith('ANDROID', {required: false}).mockReturnValue('success');
when(core.getInput).calledWith('IOS', {required: false}).mockReturnValue('success');
when(core.getInput).calledWith('WEB', {required: false}).mockReturnValue('success');
when(core.getInput).calledWith('DESKTOP', {required: false}).mockReturnValue('success');
when(core.getInput).calledWith('ANDROID_LINK').mockReturnValue('https://expensify.app/ANDROID_LINK');
when(core.getInput).calledWith('IOS_LINK').mockReturnValue('https://expensify.app/IOS_LINK');
when(core.getInput).calledWith('WEB_LINK').mockReturnValue('https://expensify.app/WEB_LINK');
Expand Down Expand Up @@ -102,4 +118,36 @@ describe('Post test build comments action tests', () => {
expect(createCommentMock).toBeCalledTimes(1);
expect(createCommentMock).toBeCalledWith('App', 12, message);
});

test('Test GH action when input is not complete', async () => {
when(core.getInput).calledWith('PR_NUMBER', {required: true}).mockReturnValue('12');
when(core.getInput).calledWith('ANDROID', {required: false}).mockReturnValue('success');
when(core.getInput).calledWith('IOS', {required: false}).mockReturnValue('');
when(core.getInput).calledWith('WEB', {required: false}).mockReturnValue('');
when(core.getInput).calledWith('DESKTOP', {required: false}).mockReturnValue('');
when(core.getInput).calledWith('ANDROID_LINK').mockReturnValue('https://expensify.app/ANDROID_LINK');
createCommentMock.mockResolvedValue({} as CreateCommentResponse);
mockListComments.mockResolvedValue({
data: [
{
body: ':test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing!',
// eslint-disable-next-line @typescript-eslint/naming-convention
node_id: 'IC_abcd',
},
],
});
await ghAction();
expect(mockGraphql).toBeCalledTimes(1);
expect(mockGraphql).toBeCalledWith(`
mutation {
minimizeComment(input: {classifier: OUTDATED, subjectId: "IC_abcd"}) {
minimizedComment {
minimizedReason
}
}
}
`);
expect(createCommentMock).toBeCalledTimes(1);
expect(createCommentMock).toBeCalledWith('App', 12, onlyAndroidMessage);
});
});

0 comments on commit d7a73ca

Please sign in to comment.