From ca06e2cb26c872e4facb58023cfacdea17bf36f2 Mon Sep 17 00:00:00 2001 From: Radoslaw Krzemien Date: Tue, 28 Mar 2023 12:53:43 +0200 Subject: [PATCH] Add tests Added tests for `testBuild` workflow See: https://github.com/Expensify/App/issues/13604 --- .github/workflows/testBuild.yml | 46 +- .../assertions/testBuildAssertions.js | 525 +++++++++ workflow_tests/mocks/testBuildMocks.js | 379 +++++++ workflow_tests/testBuild.test.js | 1001 +++++++++++++++++ 4 files changed, 1935 insertions(+), 16 deletions(-) create mode 100644 workflow_tests/assertions/testBuildAssertions.js create mode 100644 workflow_tests/mocks/testBuildMocks.js create mode 100644 workflow_tests/testBuild.test.js diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml index cee2ad4c3b83..e71377e092ae 100644 --- a/.github/workflows/testBuild.yml +++ b/.github/workflows/testBuild.yml @@ -19,7 +19,8 @@ jobs: outputs: READY_TO_BUILD: ${{ fromJSON(steps.isUserTeamMember.outputs.isTeamMember) && fromJSON(steps.hasReadyToBuildLabel.outputs.HAS_READY_TO_BUILD_LABEL) }} steps: - - id: isUserTeamMember + - name: Is team member + id: isUserTeamMember uses: tspascoal/get-user-teams-membership@baf2e6adf4c3b897bd65a7e3184305c165aec872 with: GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} @@ -67,7 +68,8 @@ jobs: PULL_REQUEST_NUMBER: ${{ github.event.number || github.event.inputs.PULL_REQUEST_NUMBER }} steps: # This action checks-out the repository, so the workflow can access it. - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - name: Checkout + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 with: ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }} @@ -77,9 +79,11 @@ jobs: sed -i 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" >> .env.adhoc - - uses: Expensify/App/.github/actions/composite/setupNode@main + - name: Setup Node + uses: Expensify/App/.github/actions/composite/setupNode@main - - uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7 + - name: Setup Ruby + uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7 with: ruby-version: '2.7' bundler-cache: true @@ -109,7 +113,8 @@ jobs: S3_BUCKET: ad-hoc-expensify-cash S3_REGION: us-east-1 - - uses: actions/upload-artifact@v3 + - name: Upload Artifact + uses: actions/upload-artifact@v3 with: name: android path: ./android_paths.json @@ -123,7 +128,8 @@ jobs: runs-on: macos-12-xl steps: # This action checks-out the repository, so the workflow can access it. - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - name: Checkout + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 with: ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }} @@ -133,9 +139,11 @@ jobs: sed -i '' 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" >> .env.adhoc - - uses: Expensify/App/.github/actions/composite/setupNode@main + - name: Setup Node + uses: Expensify/App/.github/actions/composite/setupNode@main - - uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7 + - name: Setup Ruby + uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7 with: ruby-version: '2.7' bundler-cache: true @@ -171,7 +179,8 @@ jobs: S3_BUCKET: ad-hoc-expensify-cash S3_REGION: us-east-1 - - uses: actions/upload-artifact@v3 + - name: Upload Artifact + uses: actions/upload-artifact@v3 with: name: ios path: ./ios_paths.json @@ -185,7 +194,8 @@ jobs: runs-on: macos-12 steps: # This action checks-out the repository, so the workflow can access it. - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - name: Checkout + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 with: ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }} fetch-depth: 0 @@ -196,7 +206,8 @@ jobs: sed -i '' 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" >> .env.adhoc - - uses: Expensify/App/.github/actions/composite/setupNode@main + - name: Setup Node + uses: Expensify/App/.github/actions/composite/setupNode@main - name: Decrypt Developer ID Certificate run: cd desktop && gpg --quiet --batch --yes --decrypt --passphrase="$DEVELOPER_ID_SECRET_PASSPHRASE" --output developer_id.p12 developer_id.p12.gpg @@ -227,7 +238,8 @@ jobs: PULL_REQUEST_NUMBER: ${{ github.event.number || github.event.inputs.PULL_REQUEST_NUMBER }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - name: Checkout + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 with: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }} @@ -238,7 +250,8 @@ jobs: sed -i 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" >> .env.adhoc - - uses: Expensify/App/.github/actions/composite/setupNode@main + - name: Setup Node + uses: Expensify/App/.github/actions/composite/setupNode@main - name: Configure AWS Credentials uses: Expensify/App/.github/actions/composite/configureAwsCredentials@main @@ -259,7 +272,7 @@ jobs: postGithubComment: runs-on: ubuntu-latest name: Post a GitHub comment with app download links for testing - needs: [validateActor, getBranchRef, android, ios, desktop, web] + needs: [validateActor, getBranchRef, android, iOS, desktop, web] if: ${{ always() }} env: PULL_REQUEST_NUMBER: ${{ github.event.number || github.event.inputs.PULL_REQUEST_NUMBER }} @@ -270,7 +283,8 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }} - - uses: actions/download-artifact@v3 + - name: Download Artifact + uses: actions/download-artifact@v3 if: ${{ fromJSON(needs.validateActor.outputs.READY_TO_BUILD) }} - name: Read JSONs with android paths @@ -286,7 +300,7 @@ jobs: - name: Read JSONs with iOS paths id: get_ios_path - if: ${{ needs.ios.result == 'success' }} + if: ${{ needs.iOS.result == 'success' }} run: | content_ios="$(cat ./ios/ios_paths.json)" content_ios="${content_ios//'%'/'%25'}" diff --git a/workflow_tests/assertions/testBuildAssertions.js b/workflow_tests/assertions/testBuildAssertions.js new file mode 100644 index 000000000000..19034740562d --- /dev/null +++ b/workflow_tests/assertions/testBuildAssertions.js @@ -0,0 +1,525 @@ +const utils = require('../utils/utils'); + +const assertValidateActorJobExecuted = (workflowResult, actor = 'Dummy Actor', pullRequestNumber = '1234', didExecute = true) => { + const steps = [ + utils.getStepAssertion( + 'Is team member', + true, + null, + 'VALIDATEACTOR', + 'Is team member', + [{key: 'GITHUB_TOKEN', value: '***'}, {key: 'username', value: actor}, {key: 'team', value: 'Expensify/expensify'}], + [], + ), + utils.getStepAssertion( + 'Set HAS_READY_TO_BUILD_LABEL flag', + true, + null, + 'VALIDATEACTOR', + 'Set HAS_READY_TO_BUILD_LABEL flag', + [], + [{key: 'PULL_REQUEST_NUMBER', value: pullRequestNumber}, {key: 'GITHUB_TOKEN', value: '***'}], + ), + ]; + + for (const expectedStep of steps) { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } +}; +const assertGetBranchRefJobExecuted = (workflowResult, didExecute = true) => { + const steps = [ + utils.getStepAssertion( + 'Checkout', + true, + null, + 'GETBRANCHREF', + 'Checkout', + [], + [], + ), + utils.getStepAssertion( + 'Check if pull request number is correct', + true, + null, + 'GETBRANCHREF', + 'Check if pull request number is correct', + [], + [{key: 'GITHUB_TOKEN', value: '***'}], + ), + ]; + + for (const expectedStep of steps) { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } +}; +const assertAndroidJobExecuted = (workflowResult, ref = '', didExecute = true, failsAt = -1) => { + const steps = [ + utils.getStepAssertion( + 'Checkout', + true, + null, + 'ANDROID', + 'Checkout', + [{key: 'ref', value: ref}], + [], + ), + utils.getStepAssertion( + 'Setup Node', + true, + null, + 'ANDROID', + 'Setup Node', + [], + [], + ), + utils.getStepAssertion( + 'Setup Ruby', + true, + null, + 'ANDROID', + 'Setup Ruby', + [{key: 'ruby-version', value: '2.7'}, {key: 'bundler-cache', value: true}], + [], + ), + utils.getStepAssertion( + 'Decrypt keystore', + true, + null, + 'ANDROID', + 'Decrypt keystore', + [], + [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}], + ), + utils.getStepAssertion( + 'Decrypt json key', + true, + null, + 'ANDROID', + 'Decrypt json key', + [], + [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}], + ), + utils.getStepAssertion( + 'Configure AWS Credentials', + true, + null, + 'ANDROID', + 'Configure AWS Credentials', + [{key: 'AWS_ACCESS_KEY_ID', value: '***'}, {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}], + [], + ), + utils.getStepAssertion( + 'Run Fastlane beta test', + true, + null, + 'ANDROID', + 'Run Fastlane beta test', + [], + [ + {key: 'S3_ACCESS_KEY', value: '***'}, + {key: 'S3_SECRET_ACCESS_KEY', value: '***'}, + {key: 'S3_BUCKET', value: 'ad-hoc-expensify-cash'}, + {key: 'S3_REGION', value: 'us-east-1'}, + ], + ), + utils.getStepAssertion( + 'Upload Artifact', + true, + null, + 'ANDROID', + 'Upload Artifact', + [{key: 'name', value: 'android'}, {key: 'path', value: './android_paths.json'}], + [], + ), + ]; + + for (const [i, expectedStep] of steps.entries()) { + if (didExecute) { + if (failsAt === -1 || i < failsAt) { + // either whole job is successful, or steps up to this point are successful + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else if (i === failsAt) { + // this is the failing step + expectedStep.status = 1; + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + // steps after failed one do not execute + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } +}; +const assertIOSJobExecuted = (workflowResult, ref = '', didExecute = true, failsAt = -1) => { + const steps = [ + utils.getStepAssertion( + 'Checkout', + true, + null, + 'IOS', + 'Checkout', + [{key: 'ref', value: ref}], + [], + ), + utils.getStepAssertion( + 'Setup Node', + true, + null, + 'IOS', + 'Setup Node', + [], + [], + ), + utils.getStepAssertion( + 'Setup Ruby', + true, + null, + 'IOS', + 'Setup Ruby', + [{key: 'ruby-version', value: '2.7'}, {key: 'bundler-cache', value: true}], + [], + ), + utils.getStepAssertion( + 'Install cocoapods', + true, + null, + 'IOS', + 'Install cocoapods', + [ + {key: 'timeout_minutes', value: '10'}, + {key: 'max_attempts', value: '5'}, + {key: 'command', value: 'cd ios && pod install'}, + ], + [], + ), + utils.getStepAssertion( + 'Decrypt profile', + true, + null, + 'IOS', + 'Decrypt profile', + [], + [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}], + ), + utils.getStepAssertion( + 'Decrypt certificate', + true, + null, + 'IOS', + 'Decrypt certificate', + [], + [{key: 'LARGE_SECRET_PASSPHRASE', value: '***'}], + ), + utils.getStepAssertion( + 'Configure AWS Credentials', + true, + null, + 'IOS', + 'Configure AWS Credentials', + [{key: 'AWS_ACCESS_KEY_ID', value: '***'}, {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}], + [], + ), + utils.getStepAssertion( + 'Run Fastlane', + true, + null, + 'IOS', + 'Run Fastlane', + [], + [ + {key: 'S3_ACCESS_KEY', value: '***'}, + {key: 'S3_SECRET_ACCESS_KEY', value: '***'}, + {key: 'S3_BUCKET', value: 'ad-hoc-expensify-cash'}, + {key: 'S3_REGION', value: 'us-east-1'}, + ], + ), + utils.getStepAssertion( + 'Upload Artifact', + true, + null, + 'IOS', + 'Upload Artifact', + [{key: 'name', value: 'ios'}, {key: 'path', value: './ios_paths.json'}], + [], + ), + ]; + + for (const [i, expectedStep] of steps.entries()) { + if (didExecute) { + if (failsAt === -1 || i < failsAt) { + // either whole job is successful, or steps up to this point are successful + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else if (i === failsAt) { + // this is the failing step + expectedStep.status = 1; + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + // steps after failed one do not execute + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } +}; +const assertDesktopJobExecuted = (workflowResult, ref = '', didExecute = true, failsAt = -1) => { + const steps = [ + utils.getStepAssertion( + 'Checkout', + true, + null, + 'DESKTOP', + 'Checkout', + [{key: 'ref', value: ref}, {key: 'fetch-depth', value: '0'}], + [], + ), + utils.getStepAssertion( + 'Setup Node', + true, + null, + 'DESKTOP', + 'Setup Node', + [], + [], + ), + utils.getStepAssertion( + 'Decrypt Developer ID Certificate', + true, + null, + 'DESKTOP', + 'Decrypt Developer ID Certificate', + [], + [{key: 'DEVELOPER_ID_SECRET_PASSPHRASE', value: '***'}], + ), + utils.getStepAssertion( + 'Configure AWS Credentials', + true, + null, + 'DESKTOP', + 'Configure AWS Credentials', + [{key: 'AWS_ACCESS_KEY_ID', value: '***'}, {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}], + [], + ), + utils.getStepAssertion( + 'Build desktop app for testing', + true, + null, + 'DESKTOP', + 'Build desktop app for testing', + [], + [ + {key: 'CSC_LINK', value: '***'}, + {key: 'CSC_KEY_PASSWORD', value: '***'}, + {key: 'APPLE_ID', value: '***'}, + {key: 'APPLE_ID_PASSWORD', value: '***'}, + {key: 'AWS_ACCESS_KEY_ID', value: '***'}, + {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}, + ], + ), + ]; + + for (const [i, expectedStep] of steps.entries()) { + if (didExecute) { + if (failsAt === -1 || i < failsAt) { + // either whole job is successful, or steps up to this point are successful + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else if (i === failsAt) { + // this is the failing step + expectedStep.status = 1; + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + // steps after failed one do not execute + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } +}; +const assertWebJobExecuted = (workflowResult, ref = '', didExecute = true, failsAt = -1) => { + const steps = [ + utils.getStepAssertion( + 'Checkout', + true, + null, + 'WEB', + 'Checkout', + [{key: 'fetch-depth', value: '0'}, {key: 'ref', value: ref}], + [], + ), + utils.getStepAssertion( + 'Setup Node', + true, + null, + 'WEB', + 'Setup Node', + [], + [], + ), + utils.getStepAssertion( + 'Configure AWS Credentials', + true, + null, + 'WEB', + 'Configure AWS Credentials', + [{key: 'AWS_ACCESS_KEY_ID', value: '***'}, {key: 'AWS_SECRET_ACCESS_KEY', value: '***'}], + [], + ), + utils.getStepAssertion( + 'Build web for testing', + true, + null, + 'WEB', + 'Build web for testing', + [], + [], + ), + utils.getStepAssertion( + 'Build docs', + true, + null, + 'WEB', + 'Build docs', + [], + [], + ), + utils.getStepAssertion( + 'Deploy to S3 for internal testing', + true, + null, + 'WEB', + 'Deploy to S3 for internal testing', + [], + [], + ), + ]; + + for (const [i, expectedStep] of steps.entries()) { + if (didExecute) { + if (failsAt === -1 || i < failsAt) { + // either whole job is successful, or steps up to this point are successful + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else if (i === failsAt) { + // this is the failing step + expectedStep.status = 1; + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + // steps after failed one do not execute + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } +}; +const assertPostGithubCommentJobExecuted = (workflowResult, ref = '', pullRequestNumber = '1234', didExecute = true, androidStatus = 'success', iOSStatus = 'success', desktopStatus = 'success', webStatus = 'success') => { + const steps = [ + utils.getStepAssertion( + 'Checkout', + true, + null, + 'POSTGITHUBCOMMENT', + 'Checkout', + [{key: 'ref', value: ref}], + [], + ), + utils.getStepAssertion( + 'Download Artifact', + true, + null, + 'POSTGITHUBCOMMENT', + 'Download Artifact', + [], + [], + ), + ]; + if (androidStatus === 'success') { + steps.push( + utils.getStepAssertion( + 'Read JSONs with android paths', + true, + null, + 'POSTGITHUBCOMMENT', + 'Read JSONs with android paths', + [], + [], + ), + ); + } + if (iOSStatus === 'success') { + steps.push( + utils.getStepAssertion( + 'Read JSONs with iOS paths', + true, + null, + 'POSTGITHUBCOMMENT', + 'Read JSONs with iOS paths', + [], + [], + ), + ); + } + steps.push( + utils.getStepAssertion( + 'maintain-comment', + true, + null, + 'POSTGITHUBCOMMENT', + 'maintain-comment', + [ + {key: 'token', value: '***'}, + {key: 'body-include', value: 'Use the links below to test this build in android and iOS. Happy testing!'}, + {key: 'number', value: pullRequestNumber}, + {key: 'delete', value: true}, + ], + [], + ), + utils.getStepAssertion( + 'Publish links to apps for download', + true, + null, + 'POSTGITHUBCOMMENT', + 'Publish links to apps for download', + [ + {key: 'PR_NUMBER', value: pullRequestNumber}, + {key: 'GITHUB_TOKEN', value: '***'}, + {key: 'ANDROID', value: androidStatus}, + {key: 'DESKTOP', value: desktopStatus}, + {key: 'IOS', value: iOSStatus}, + {key: 'WEB', value: webStatus}, + {key: 'ANDROID_LINK', value: androidStatus === 'success' ? 'http://dummy.android.link' : ''}, + {key: 'DESKTOP_LINK', value: `https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/${pullRequestNumber}/NewExpensify.dmg`}, + {key: 'IOS_LINK', value: iOSStatus === 'success' ? 'http://dummy.ios.link' : ''}, + {key: 'WEB_LINK', value: `https://${pullRequestNumber}.pr-testing.expensify.com`}, + ], + [], + ), + ); + + for (const expectedStep of steps) { + if (didExecute) { + expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); + } else { + expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); + } + } +}; + +module.exports = { + assertValidateActorJobExecuted, + assertGetBranchRefJobExecuted, + assertAndroidJobExecuted, + assertIOSJobExecuted, + assertDesktopJobExecuted, + assertWebJobExecuted, + assertPostGithubCommentJobExecuted, +}; diff --git a/workflow_tests/mocks/testBuildMocks.js b/workflow_tests/mocks/testBuildMocks.js new file mode 100644 index 000000000000..b63c35cff452 --- /dev/null +++ b/workflow_tests/mocks/testBuildMocks.js @@ -0,0 +1,379 @@ +const utils = require('../utils/utils'); + +// validateactor +const TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__TRUE__STEP_MOCK = utils.getMockStep( + 'Is team member', + 'Is team member', + 'VALIDATEACTOR', + ['GITHUB_TOKEN', 'username', 'team'], + [], + {isTeamMember: true}, +); +const TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__FALSE__STEP_MOCK = utils.getMockStep( + 'Is team member', + 'Is team member', + 'VALIDATEACTOR', + ['GITHUB_TOKEN', 'username', 'team'], + [], + {isTeamMember: false}, +); +const TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__TRUE__STEP_MOCK = utils.getMockStep( + 'Set HAS_READY_TO_BUILD_LABEL flag', + 'Set HAS_READY_TO_BUILD_LABEL flag', + 'VALIDATEACTOR', + [], + ['PULL_REQUEST_NUMBER', 'GITHUB_TOKEN'], + {HAS_READY_TO_BUILD_LABEL: true}, +); +const TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__FALSE__STEP_MOCK = utils.getMockStep( + 'Set HAS_READY_TO_BUILD_LABEL flag', + 'Set HAS_READY_TO_BUILD_LABEL flag', + 'VALIDATEACTOR', + [], + ['PULL_REQUEST_NUMBER', 'GITHUB_TOKEN'], + {HAS_READY_TO_BUILD_LABEL: false}, +); +const TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS = [ + TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__TRUE__STEP_MOCK, + TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__TRUE__STEP_MOCK, +]; +const TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS = [ + TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__TRUE__STEP_MOCK, + TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__FALSE__STEP_MOCK, +]; +const TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS = [ + TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__FALSE__STEP_MOCK, + TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__TRUE__STEP_MOCK, +]; +const TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS = [ + TESTBUILD__VALIDATEACTOR__IS_TEAM_MEMBER__FALSE__STEP_MOCK, + TESTBUILD__VALIDATEACTOR__SET_HAS_READY_TO_BUILD_LABEL_FLAG__FALSE__STEP_MOCK, +]; + +// getbranchref +const TESTBUILD__GETBRANCHREF__CHECKOUT__STEP_MOCK = utils.getMockStep( + 'Checkout', + 'Checkout', + 'GETBRANCHREF', + [], + [], +); +const TESTBUILD__GETBRANCHREF__CHECK_IF_PULL_REQUEST_NUMBER_IS_CORRECT__STEP_MOCK = utils.getMockStep( + 'Check if pull request number is correct', + 'Check if pull request number is correct', + 'GETBRANCHREF', + [], + ['GITHUB_TOKEN'], + {REF: 'test-ref'}, +); +const TESTBUILD__GETBRANCHREF__STEP_MOCKS = [ + TESTBUILD__GETBRANCHREF__CHECKOUT__STEP_MOCK, + TESTBUILD__GETBRANCHREF__CHECK_IF_PULL_REQUEST_NUMBER_IS_CORRECT__STEP_MOCK, +]; + +// android +const TESTBUILD__ANDROID__CHECKOUT__STEP_MOCK = utils.getMockStep( + 'Checkout', + 'Checkout', + 'ANDROID', + ['ref'], + [], +); +const TESTBUILD__ANDROID__SETUP_NODE__STEP_MOCK = utils.getMockStep( + 'Setup Node', + 'Setup Node', + 'ANDROID', + [], + [], +); +const TESTBUILD__ANDROID__SETUP_RUBY__STEP_MOCK = utils.getMockStep( + 'Setup Ruby', + 'Setup Ruby', + 'ANDROID', + ['ruby-version', 'bundler-cache'], + [], +); +const TESTBUILD__ANDROID__DECRYPT_KEYSTORE__STEP_MOCK = utils.getMockStep( + 'Decrypt keystore', + 'Decrypt keystore', + 'ANDROID', + [], + ['LARGE_SECRET_PASSPHRASE'], +); +const TESTBUILD__ANDROID__DECRYPT_JSON_KEY__STEP_MOCK = utils.getMockStep( + 'Decrypt json key', + 'Decrypt json key', + 'ANDROID', + [], + ['LARGE_SECRET_PASSPHRASE'], +); +const TESTBUILD__ANDROID__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = utils.getMockStep( + 'Configure AWS Credentials', + 'Configure AWS Credentials', + 'ANDROID', + ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + [], +); +const TESTBUILD__ANDROID__RUN_FASTLANE_BETA_TEST__STEP_MOCK = utils.getMockStep( + 'Run Fastlane beta test', + 'Run Fastlane beta test', + 'ANDROID', + [], + ['S3_ACCESS_KEY', 'S3_SECRET_ACCESS_KEY', 'S3_BUCKET', 'S3_REGION'], +); +const TESTBUILD__ANDROID__UPLOAD_ARTIFACT__STEP_MOCK = utils.getMockStep( + 'Upload Artifact', + 'Upload Artifact', + 'ANDROID', + ['name', 'path'], + [], +); +const TESTBUILD__ANDROID__STEP_MOCKS = [ + TESTBUILD__ANDROID__CHECKOUT__STEP_MOCK, + TESTBUILD__ANDROID__SETUP_NODE__STEP_MOCK, + TESTBUILD__ANDROID__SETUP_RUBY__STEP_MOCK, + TESTBUILD__ANDROID__DECRYPT_KEYSTORE__STEP_MOCK, + TESTBUILD__ANDROID__DECRYPT_JSON_KEY__STEP_MOCK, + TESTBUILD__ANDROID__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK, + TESTBUILD__ANDROID__RUN_FASTLANE_BETA_TEST__STEP_MOCK, + TESTBUILD__ANDROID__UPLOAD_ARTIFACT__STEP_MOCK, +]; + +// ios +const TESTBUILD__IOS__CHECKOUT__STEP_MOCK = utils.getMockStep( + 'Checkout', + 'Checkout', + 'IOS', + ['ref'], + [], +); +const TESTBUILD__IOS__SETUP_NODE__STEP_MOCK = utils.getMockStep( + 'Setup Node', + 'Setup Node', + 'IOS', + [], + [], +); +const TESTBUILD__IOS__SETUP_RUBY__STEP_MOCK = utils.getMockStep( + 'Setup Ruby', + 'Setup Ruby', + 'IOS', + ['ruby-version', 'bundler-cache'], + [], +); +const TESTBUILD__IOS__INSTALL_COCOAPODS__STEP_MOCK = utils.getMockStep( + 'Install cocoapods', + 'Install cocoapods', + 'IOS', + ['timeout_minutes', 'max_attempts', 'command'], + [], +); +const TESTBUILD__IOS__DECRYPT_PROFILE__STEP_MOCK = utils.getMockStep( + 'Decrypt profile', + 'Decrypt profile', + 'IOS', + [], + ['LARGE_SECRET_PASSPHRASE'], +); +const TESTBUILD__IOS__DECRYPT_CERTIFICATE__STEP_MOCK = utils.getMockStep( + 'Decrypt certificate', + 'Decrypt certificate', + 'IOS', + [], + ['LARGE_SECRET_PASSPHRASE'], +); +const TESTBUILD__IOS__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = utils.getMockStep( + 'Configure AWS Credentials', + 'Configure AWS Credentials', + 'IOS', + ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + [], +); +const TESTBUILD__IOS__RUN_FASTLANE__STEP_MOCK = utils.getMockStep( + 'Run Fastlane', + 'Run Fastlane', + 'IOS', + [], + ['S3_ACCESS_KEY', 'S3_SECRET_ACCESS_KEY', 'S3_BUCKET', 'S3_REGION'], +); +const TESTBUILD__IOS__UPLOAD_ARTIFACT__STEP_MOCK = utils.getMockStep( + 'Upload Artifact', + 'Upload Artifact', + 'IOS', + ['name', 'path'], + [], +); +const TESTBUILD__IOS__STEP_MOCKS = [ + TESTBUILD__IOS__CHECKOUT__STEP_MOCK, + TESTBUILD__IOS__SETUP_NODE__STEP_MOCK, + TESTBUILD__IOS__SETUP_RUBY__STEP_MOCK, + TESTBUILD__IOS__INSTALL_COCOAPODS__STEP_MOCK, + TESTBUILD__IOS__DECRYPT_PROFILE__STEP_MOCK, + TESTBUILD__IOS__DECRYPT_CERTIFICATE__STEP_MOCK, + TESTBUILD__IOS__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK, + TESTBUILD__IOS__RUN_FASTLANE__STEP_MOCK, + TESTBUILD__IOS__UPLOAD_ARTIFACT__STEP_MOCK, +]; + +// desktop +const TESTBUILD__DESKTOP__CHECKOUT__STEP_MOCK = utils.getMockStep( + 'Checkout', + 'Checkout', + 'DESKTOP', + ['ref', 'fetch-depth'], + [], +); +const TESTBUILD__DESKTOP__SETUP_NODE__STEP_MOCK = utils.getMockStep( + 'Setup Node', + 'Setup Node', + 'DESKTOP', + [], + [], +); +const TESTBUILD__DESKTOP__DECRYPT_DEVELOPER_ID_CERTIFICATE__STEP_MOCK = utils.getMockStep( + 'Decrypt Developer ID Certificate', + 'Decrypt Developer ID Certificate', + 'DESKTOP', + [], + ['DEVELOPER_ID_SECRET_PASSPHRASE'], +); +const TESTBUILD__DESKTOP__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = utils.getMockStep( + 'Configure AWS Credentials', + 'Configure AWS Credentials', + 'DESKTOP', + ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + [], +); +const TESTBUILD__DESKTOP__BUILD_DESKTOP_APP_FOR_TESTING__STEP_MOCK = utils.getMockStep( + 'Build desktop app for testing', + 'Build desktop app for testing', + 'DESKTOP', + [], + ['CSC_LINK', 'CSC_KEY_PASSWORD', 'APPLE_ID', 'APPLE_ID_PASSWORD', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], +); +const TESTBUILD__DESKTOP__STEP_MOCKS = [ + TESTBUILD__DESKTOP__CHECKOUT__STEP_MOCK, + TESTBUILD__DESKTOP__SETUP_NODE__STEP_MOCK, + TESTBUILD__DESKTOP__DECRYPT_DEVELOPER_ID_CERTIFICATE__STEP_MOCK, + TESTBUILD__DESKTOP__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK, + TESTBUILD__DESKTOP__BUILD_DESKTOP_APP_FOR_TESTING__STEP_MOCK, +]; + +// web +const TESTBUILD__WEB__CHECKOUT__STEP_MOCK = utils.getMockStep( + 'Checkout', + 'Checkout', + 'WEB', + ['fetch-depth', 'ref'], + [], +); +const TESTBUILD__WEB__SETUP_NODE__STEP_MOCK = utils.getMockStep( + 'Setup Node', + 'Setup Node', + 'WEB', + [], + [], +); +const TESTBUILD__WEB__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK = utils.getMockStep( + 'Configure AWS Credentials', + 'Configure AWS Credentials', + 'WEB', + ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + [], +); +const TESTBUILD__WEB__BUILD_WEB_FOR_TESTING__STEP_MOCK = utils.getMockStep( + 'Build web for testing', + 'Build web for testing', + 'WEB', + [], + [], +); +const TESTBUILD__WEB__BUILD_DOCS__STEP_MOCK = utils.getMockStep( + 'Build docs', + 'Build docs', + 'WEB', + [], + [], +); +const TESTBUILD__WEB__DEPLOY_TO_S3_FOR_INTERNAL_TESTING__STEP_MOCK = utils.getMockStep( + 'Deploy to S3 for internal testing', + 'Deploy to S3 for internal testing', + 'WEB', + [], + [], +); +const TESTBUILD__WEB__STEP_MOCKS = [ + TESTBUILD__WEB__CHECKOUT__STEP_MOCK, + TESTBUILD__WEB__SETUP_NODE__STEP_MOCK, + TESTBUILD__WEB__CONFIGURE_AWS_CREDENTIALS__STEP_MOCK, + TESTBUILD__WEB__BUILD_WEB_FOR_TESTING__STEP_MOCK, + TESTBUILD__WEB__BUILD_DOCS__STEP_MOCK, + TESTBUILD__WEB__DEPLOY_TO_S3_FOR_INTERNAL_TESTING__STEP_MOCK, +]; + +// postgithubcomment +const TESTBUILD__POSTGITHUBCOMMENT__CHECKOUT__STEP_MOCK = utils.getMockStep( + 'Checkout', + 'Checkout', + 'POSTGITHUBCOMMENT', + ['ref'], + [], +); +const TESTBUILD__POSTGITHUBCOMMENT__DOWNLOAD_ARTIFACT__STEP_MOCK = utils.getMockStep( + 'Download Artifact', + 'Download Artifact', + 'POSTGITHUBCOMMENT', + [], + [], +); +const TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_ANDROID_PATHS__STEP_MOCK = utils.getMockStep( + 'Read JSONs with android paths', + 'Read JSONs with android paths', + 'POSTGITHUBCOMMENT', + [], + [], + {android_paths: '{\\"html_path\\": \\"http://dummy.android.link\\"}'}, +); +const TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_IOS_PATHS__STEP_MOCK = utils.getMockStep( + 'Read JSONs with iOS paths', + 'Read JSONs with iOS paths', + 'POSTGITHUBCOMMENT', + [], + [], + {ios_paths: '{\\"html_path\\": \\"http://dummy.ios.link\\"}'}, +); +const TESTBUILD__POSTGITHUBCOMMENT__MAINTAIN_COMMENT__STEP_MOCK = utils.getMockStep( + 'maintain-comment', + 'maintain-comment', + 'POSTGITHUBCOMMENT', + ['token', 'body-include', 'number', 'delete'], + [], +); +const TESTBUILD__POSTGITHUBCOMMENT__PUBLISH_LINKS_TO_APPS_FOR_DOWNLOAD__STEP_MOCK = utils.getMockStep( + 'Publish links to apps for download', + 'Publish links to apps for download', + 'POSTGITHUBCOMMENT', + ['PR_NUMBER', 'GITHUB_TOKEN', 'ANDROID', 'DESKTOP', 'IOS', 'WEB', 'ANDROID_LINK', 'DESKTOP_LINK', 'IOS_LINK', 'WEB_LINK'], + [], +); +const TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS = [ + TESTBUILD__POSTGITHUBCOMMENT__CHECKOUT__STEP_MOCK, + TESTBUILD__POSTGITHUBCOMMENT__DOWNLOAD_ARTIFACT__STEP_MOCK, + TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_ANDROID_PATHS__STEP_MOCK, + TESTBUILD__POSTGITHUBCOMMENT__READ_JSONS_WITH_IOS_PATHS__STEP_MOCK, + TESTBUILD__POSTGITHUBCOMMENT__MAINTAIN_COMMENT__STEP_MOCK, + TESTBUILD__POSTGITHUBCOMMENT__PUBLISH_LINKS_TO_APPS_FOR_DOWNLOAD__STEP_MOCK, +]; + +module.exports = { + TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + TESTBUILD__GETBRANCHREF__STEP_MOCKS, + TESTBUILD__ANDROID__STEP_MOCKS, + TESTBUILD__IOS__STEP_MOCKS, + TESTBUILD__DESKTOP__STEP_MOCKS, + TESTBUILD__WEB__STEP_MOCKS, + TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, +}; diff --git a/workflow_tests/testBuild.test.js b/workflow_tests/testBuild.test.js new file mode 100644 index 000000000000..d9dca51e2d07 --- /dev/null +++ b/workflow_tests/testBuild.test.js @@ -0,0 +1,1001 @@ +const path = require('path'); +const kieMockGithub = require('@kie/mock-github'); +const utils = require('./utils/utils'); +const assertions = require('./assertions/testBuildAssertions'); +const mocks = require('./mocks/testBuildMocks'); +const eAct = require('./utils/ExtendedAct'); + +jest.setTimeout(60 * 1000); +let mockGithub; +const FILES_TO_COPY_INTO_TEST_REPO = [ + { + src: path.resolve(__dirname, '..', '.github', 'actions'), + dest: '.github/actions', + }, + { + src: path.resolve(__dirname, '..', '.github', 'libs'), + dest: '.github/libs', + }, + { + src: path.resolve(__dirname, '..', '.github', 'scripts'), + dest: '.github/scripts', + }, + { + src: path.resolve(__dirname, '..', '.github', 'workflows', 'testBuild.yml'), + dest: '.github/workflows/testBuild.yml', + }, +]; + +describe('test workflow testBuild', () => { + const githubToken = 'dummy_github_token'; + const actor = 'Dummy Actor'; + const secrets = { + OS_BOTIFY_TOKEN: 'dummy_osbotify_token', + LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd', + AWS_ACCESS_KEY_ID: 'dummy_aws_access_kry_id', + AWS_SECRET_ACCESS_KEY: 'dummy_aws_secret_access_key', + DEVELOPER_ID_SECRET_PASSPHRASE: 'dummy_developer_id_secret_passphrase', + CSC_LINK: 'dummy_csc_link', + CSC_KEY_PASSWORD: 'dummy_csc_key_password', + APPLE_ID_PASSWORD: 'dummy_apple_id_password', + APPLE_ID: 'dummy_apple_id_value', + }; + beforeEach(async () => { + // create a local repository and copy required files + mockGithub = new kieMockGithub.MockGithub({ + repo: { + testTestBuildWorkflowRepo: { + files: FILES_TO_COPY_INTO_TEST_REPO, + }, + }, + }); + + await mockGithub.setup(); + }); + + afterEach(async () => { + await mockGithub.teardown(); + }); + describe('event is workflow_dispatch', () => { + const event = 'workflow_dispatch'; + const inputs = { + PULL_REQUEST_NUMBER: '1234', + }; + it('executes workflow', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + {}, + secrets, + githubToken, + {}, + inputs, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result); + assertions.assertAndroidJobExecuted(result, 'test-ref'); + assertions.assertIOSJobExecuted(result, 'test-ref'); + assertions.assertDesktopJobExecuted(result, 'test-ref'); + assertions.assertWebJobExecuted(result, 'test-ref'); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref'); + }); + describe('actor is not a team member', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + {}, + secrets, + githubToken, + {}, + inputs, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('PR does not have READY_TO_BUILD label', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + {}, + secrets, + githubToken, + {}, + inputs, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + {}, + secrets, + githubToken, + {}, + inputs, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('android fails', () => { + it('executes workflow, failure reflected', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + {}, + secrets, + githubToken, + {}, + inputs, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: utils.deepCopy(mocks.TESTBUILD__ANDROID__STEP_MOCKS), + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + testMockSteps.android[3] = utils.getMockStep( + 'Decrypt keystore', + 'Decrypt keystore', + 'ANDROID', + [], + ['LARGE_SECRET_PASSPHRASE'], + {}, + {}, + false, + ); + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result); + assertions.assertAndroidJobExecuted(result, 'test-ref', true, 3); + assertions.assertIOSJobExecuted(result, 'test-ref'); + assertions.assertDesktopJobExecuted(result, 'test-ref'); + assertions.assertWebJobExecuted(result, 'test-ref'); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', true, 'failure', 'success', 'success', 'success'); + }); + }); + describe('iOS fails', () => { + it('executes workflow, failure reflected', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + {}, + secrets, + githubToken, + {}, + inputs, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: utils.deepCopy(mocks.TESTBUILD__IOS__STEP_MOCKS), + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + testMockSteps.iOS[3] = utils.getMockStep( + 'Install cocoapods', + 'Install cocoapods', + 'IOS', + ['timeout_minutes', 'max_attempts', 'command'], + [], + {}, + {}, + false, + ); + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result); + assertions.assertAndroidJobExecuted(result, 'test-ref'); + assertions.assertIOSJobExecuted(result, 'test-ref', true, 3); + assertions.assertDesktopJobExecuted(result, 'test-ref'); + assertions.assertWebJobExecuted(result, 'test-ref'); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', true, 'success', 'failure', 'success', 'success'); + }); + }); + describe('desktop fails', () => { + it('executes workflow, failure reflected', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + {}, + secrets, + githubToken, + {}, + inputs, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: utils.deepCopy(mocks.TESTBUILD__DESKTOP__STEP_MOCKS), + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + testMockSteps.desktop[2] = utils.getMockStep( + 'Decrypt Developer ID Certificate', + 'Decrypt Developer ID Certificate', + 'DESKTOP', + [], + ['DEVELOPER_ID_SECRET_PASSPHRASE'], + {}, + {}, + false, + ); + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result); + assertions.assertAndroidJobExecuted(result, 'test-ref'); + assertions.assertIOSJobExecuted(result, 'test-ref'); + assertions.assertDesktopJobExecuted(result, 'test-ref', true, 2); + assertions.assertWebJobExecuted(result, 'test-ref'); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', true, 'success', 'success', 'failure', 'success'); + }); + }); + describe('web fails', () => { + it('executes workflow, failure reflected', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + {}, + secrets, + githubToken, + {}, + inputs, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: utils.deepCopy(mocks.TESTBUILD__WEB__STEP_MOCKS), + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + testMockSteps.web[2] = utils.getMockStep( + 'Configure AWS Credentials', + 'Configure AWS Credentials', + 'WEB', + ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'], + [], + {}, + {}, + false, + ); + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result); + assertions.assertAndroidJobExecuted(result, 'test-ref'); + assertions.assertIOSJobExecuted(result, 'test-ref'); + assertions.assertDesktopJobExecuted(result, 'test-ref'); + assertions.assertWebJobExecuted(result, 'test-ref', true, 2); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', true, 'success', 'success', 'success', 'failure'); + }); + }); + }); + describe('pull request opened', () => { + const event = 'pull_request_target'; + const eventOptions = { + action: 'opened', + number: '1234', + pull_request: { + head: { + sha: 'test-ref', + }, + }, + }; + it('executes workflow, withuout getBranchRef', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref'); + assertions.assertIOSJobExecuted(result, 'test-ref'); + assertions.assertDesktopJobExecuted(result, 'test-ref'); + assertions.assertWebJobExecuted(result, 'test-ref'); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref'); + }); + describe('actor is not a team member', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('PR does not have READY_TO_BUILD label', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + }); + describe('pull request synchronized', () => { + const event = 'pull_request_target'; + const eventOptions = { + action: 'synchronize', + number: '1234', + pull_request: { + head: { + sha: 'test-ref', + }, + }, + }; + it('executes workflow, withuout getBranchRef', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref'); + assertions.assertIOSJobExecuted(result, 'test-ref'); + assertions.assertDesktopJobExecuted(result, 'test-ref'); + assertions.assertWebJobExecuted(result, 'test-ref'); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref'); + }); + describe('actor is not a team member', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('PR does not have READY_TO_BUILD label', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + }); + describe('pull request labeled', () => { + const event = 'pull_request_target'; + const eventOptions = { + action: 'labeled', + number: '1234', + pull_request: { + head: { + sha: 'test-ref', + }, + }, + }; + it('executes workflow, withuout getBranchRef', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref'); + assertions.assertIOSJobExecuted(result, 'test-ref'); + assertions.assertDesktopJobExecuted(result, 'test-ref'); + assertions.assertWebJobExecuted(result, 'test-ref'); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref'); + }); + describe('actor is not a team member', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_HAS_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('PR does not have READY_TO_BUILD label', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + describe('actor is not a team member and PR does not have READY_TO_BUILD label', () => { + it('stops the workflow after validation', async () => { + const repoPath = mockGithub.repo.getPath('testTestBuildWorkflowRepo') || ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'testBuild.yml'); + let act = new eAct.ExtendedAct(repoPath, workflowPath); + act = utils.setUpActParams( + act, + event, + eventOptions, + secrets, + githubToken, + {}, + ); + act = utils.setJobRunners( + act, + {iOS: 'ubuntu-latest', desktop: 'ubuntu-latest'}, + workflowPath, + ); + const testMockSteps = { + validateActor: mocks.TESTBUILD__VALIDATEACTOR__NO_TEAM_MEMBER_NO_FLAG__STEP_MOCKS, + getBranchRef: mocks.TESTBUILD__GETBRANCHREF__STEP_MOCKS, + android: mocks.TESTBUILD__ANDROID__STEP_MOCKS, + iOS: mocks.TESTBUILD__IOS__STEP_MOCKS, + desktop: mocks.TESTBUILD__DESKTOP__STEP_MOCKS, + web: mocks.TESTBUILD__WEB__STEP_MOCKS, + postGithubComment: mocks.TESTBUILD__POSTGITHUBCOMMENT__STEP_MOCKS, + }; + const result = await act + .runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows'), + mockSteps: testMockSteps, + actor, + }); + + assertions.assertValidateActorJobExecuted(result, actor, '1234'); + assertions.assertGetBranchRefJobExecuted(result, false); + assertions.assertAndroidJobExecuted(result, 'test-ref', false); + assertions.assertIOSJobExecuted(result, 'test-ref', false); + assertions.assertDesktopJobExecuted(result, 'test-ref', false); + assertions.assertWebJobExecuted(result, 'test-ref', false); + assertions.assertPostGithubCommentJobExecuted(result, 'test-ref', '1234', false); + }); + }); + }); +});