From d7a73ca217891bb948ebe78d7b9ab09579401d1f Mon Sep 17 00:00:00 2001 From: Jan Nowakowski Date: Mon, 2 Dec 2024 09:45:14 +0100 Subject: [PATCH] Action linter --- .../javascript/postTestBuildComment/index.js | 8 +-- .../postTestBuildComment.ts | 11 ++-- tests/unit/postTestBuildComment.ts | 56 +++++++++++++++++-- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/.github/actions/javascript/postTestBuildComment/index.js b/.github/actions/javascript/postTestBuildComment/index.js index b8110f2152ec..056981465e1e 100644 --- a/.github/actions/javascript/postTestBuildComment/index.js +++ b/.github/actions/javascript/postTestBuildComment/index.js @@ -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} | --- diff --git a/.github/actions/javascript/postTestBuildComment/postTestBuildComment.ts b/.github/actions/javascript/postTestBuildComment/postTestBuildComment.ts index d85149c5a7e7..5b56a2420f37 100644 --- a/.github/actions/javascript/postTestBuildComment/postTestBuildComment.ts +++ b/.github/actions/javascript/postTestBuildComment/postTestBuildComment.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core'; import {context} from '@actions/github'; +import {TupleToUnion} from 'type-fest'; import CONST from '@github/libs/CONST'; import GithubUtils from '@github/libs/GithubUtils'; @@ -36,16 +37,16 @@ function getTestBuildMessage(): string { qrCode, }, }; - }, {} as Record<(typeof inputs)[number], {link: string; qrCode: string}>); + }, {} as Record, {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} | --- diff --git a/tests/unit/postTestBuildComment.ts b/tests/unit/postTestBuildComment.ts index 6a7f8182be1e..6d6815b9a600 100644 --- a/tests/unit/postTestBuildComment.ts +++ b/tests/unit/postTestBuildComment.ts @@ -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'); @@ -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); + }); });