diff --git a/.github/actions/acceptance-tests-components/action.yml b/.github/actions/acceptance-tests-components/action.yml index 0071d20d1..e7ad35724 100644 --- a/.github/actions/acceptance-tests-components/action.yml +++ b/.github/actions/acceptance-tests-components/action.yml @@ -44,5 +44,8 @@ runs: env: TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }} TARGET_ACCOUNT_GROUP: ${{ inputs.targetAccountGroup }} + SUPPLIER_API_URL_SANDBOX: ${{ github.event_name == 'workflow_dispatch' && inputs.testType == 'sandbox' && format('https://internal-dev-sandbox.api.service.nhs.uk/nhs-notify-supplier-PR-{0}', github.event.pull_request.number) || inputs.testType == 'sandbox' && 'http://127.0.0.1:9000' || 'https://internal-dev-sandbox.api.service.nhs.uk/nhs-notify-supplier' }} run: | + echo "VLASIS - event_name = ${{ github.event_name }}" + echo "VLASIS - SUPPLIER_API_URL_SANDBOX = $SUPPLIER_API_URL_SANDBOX" make test-${{ inputs.testType }} diff --git a/.github/actions/acceptance-tests-e2e/action.yml b/.github/actions/acceptance-tests-e2e/action.yml index 3a67aa7d9..44edf6103 100644 --- a/.github/actions/acceptance-tests-e2e/action.yml +++ b/.github/actions/acceptance-tests-e2e/action.yml @@ -25,7 +25,6 @@ runs: else echo "pr_number=$env" >> $GITHUB_OUTPUT fi - - name: Determine if proxy has been deployed id: check_proxy_deployed env: diff --git a/.github/actions/build-proxies/action.yml b/.github/actions/build-proxies/action.yml index 5563a3332..bd6dabe15 100644 --- a/.github/actions/build-proxies/action.yml +++ b/.github/actions/build-proxies/action.yml @@ -45,6 +45,14 @@ runs: name: api-oas-specification-${{ inputs.apimEnv }}${{ inputs.version != '' && format('-{0}', inputs.version) || '' }} path: ./build + # should I hard-code it to internal-dev-sandbox? What about int/prod? + - name: Download Sandbox OAS Spec artifact from workflow + if: ${{ inputs.buildSandbox == 'true' && inputs.isRelease == 'false' }} + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: api-oas-specification-internal-dev-sandbox${{ inputs.version != '' && format('-{0}', inputs.version) || '' }} + path: ./build-sandbox + - name: Download OAS Spec artifact from release if: ${{ inputs.isRelease == 'true' }} shell: bash @@ -99,6 +107,14 @@ runs: name: ${{ env.APIM_ENV }}-build-output path: ./build + - name: Upload Sandbox OAS Spec + if: ${{ inputs.buildSandbox == 'true' }} + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: ${{ env.APIM_ENV }}-build-output-sandbox + path: ./build-sandbox + + # NOTE TO SELF: remove --internalRef after internal is merged into main - name: Trigger deploy proxy env: APP_CLIENT_ID: ${{ env.APP_CLIENT_ID }} @@ -116,4 +132,5 @@ runs: --apimEnvironment "${{ env.APIM_ENV }}" \ --boundedContext "notify-supplier" \ --targetDomain "$TARGET_DOMAIN" \ - --version "${{ inputs.version }}" + --version "${{ inputs.version }}" \ + --internalRef "fix/CCM-22538_deploy_sandbox_server" diff --git a/.github/actions/test-types.json b/.github/actions/test-types.json index 6ae115da8..fe18d5da7 100644 --- a/.github/actions/test-types.json +++ b/.github/actions/test-types.json @@ -1,4 +1,5 @@ [ "component", - "e2e" + "e2e", + "sandbox" ] diff --git a/.github/workflows/stage-3-build.yaml b/.github/workflows/stage-3-build.yaml index 382e16ee8..acbae76b5 100644 --- a/.github/workflows/stage-3-build.yaml +++ b/.github/workflows/stage-3-build.yaml @@ -118,7 +118,7 @@ jobs: artefact-oas-spec: name: "OAS spec ready" runs-on: ubuntu-latest - needs: [artefact-oas-spec-pr, artefact-oas-spec-main] + needs: [artefact-oas-spec-pr, artefact-oas-spec-main, artefact-oas-spec-sandbox] if: always() && !failure() steps: - run: echo "OAS spec build complete" diff --git a/.github/workflows/stage-4-acceptance.yaml b/.github/workflows/stage-4-acceptance.yaml index 098f7451b..1cc78062d 100644 --- a/.github/workflows/stage-4-acceptance.yaml +++ b/.github/workflows/stage-4-acceptance.yaml @@ -66,6 +66,7 @@ jobs: echo "ENVIRONMENT=main" >> $GITHUB_ENV fi + # NOTE TO SELF: Remove --internalRef after internal is merged into main - name: Trigger Acceptance Tests shell: bash env: @@ -80,4 +81,5 @@ jobs: --targetEnvironment "$ENVIRONMENT" \ --targetAccountGroup "nhs-notify-supplier-api-dev" \ --targetComponent "api" \ - --extraSecretNames '["/dev/e2e/keys/apim/main","/dev/e2e/keys/apim/pr","/dev/e2e/keys/apim/pr/secondary","/dev/e2e/keys/apim/status","/dev/e2e/keys/private"]' + --extraSecretNames '["/dev/e2e/keys/apim/main","/dev/e2e/keys/apim/pr","/dev/e2e/keys/apim/pr/secondary","/dev/e2e/keys/apim/status","/dev/e2e/keys/private"]' \ + --internalRef "fix/CCM-22538_deploy_sandbox_server" diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 000000000..85e502778 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22.22.0 diff --git a/README.md b/README.md index ba063dff1..d1cb4ce1e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ + # NHS Notify Supplier API [![1. CI/CD pull request](https://github.com/NHSDigital/nhs-notify-supplier-api/actions/workflows/cicd-1-pull-request.yaml/badge.svg)](https://github.com/NHSDigital/nhs-notify-supplier-api/actions/workflows/cicd-1-pull-request.yaml) @@ -29,6 +30,7 @@ This repository documents the Supplier API specification and provides an SDK wit - [Prerequisites and Configuration](#prerequisites-and-configuration) - [SDKs](#sdks) - [Build](#build) + - [Unit Testing](#unit-testing) - [Documentation](#documentation-1) - [GitHub Actions CI/CD](#github-actions-cicd) - [CI (Automatic)](#ci-automatic) @@ -99,14 +101,14 @@ New developers of the NHS Notify Supplier API should understand the below. - In the project's root directory create an `.env` file based on the `.env.template` file and fill variables as needed. - Create the file `~/.npmrc` with the contents: - ```dsconfig - # Authenticate to GitHub Packages for github.com - //npm.pkg.github.com/:_authToken= + ```dsconfig + # Authenticate to GitHub Packages for github.com + //npm.pkg.github.com/:_authToken= - # Package is scoped under @org, set registry for that scope - @nhsdigital:registry=https://npm.pkg.github.com - ``` + # Package is scoped under @org, set registry for that scope + @nhsdigital:registry=https://npm.pkg.github.com + ``` - Install `node` (to run `npm install` and build the project) - Install `aws cli` to be able to connect to AWS (needed for some tests) diff --git a/sandbox/package.json b/sandbox/package.json index 87c6b6fd4..f8892fde8 100644 --- a/sandbox/package.json +++ b/sandbox/package.json @@ -18,10 +18,15 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "eslint": "^9.27.0", - "eslint-config-airbnb-base": "^14.0.0", + "eslint-config-airbnb-base": "^15.0.0", "eslint-plugin-import": "^2.17.2", "mocha": "^11.8.0" }, + "overrides": { + "eslint-config-airbnb-base": { + "eslint": "^9.27.0" + } + }, "eslintConfig": { "env": { "node": true diff --git a/specification/api/components/schemas/apiGatewayError.yml b/specification/api/components/schemas/apiGatewayError.yml index a36048f67..ac1de3f8b 100644 --- a/specification/api/components/schemas/apiGatewayError.yml +++ b/specification/api/components/schemas/apiGatewayError.yml @@ -1,9 +1,6 @@ +type: object description: API gateway error response -content: - application/json: - schema: - type: object - properties: - message: - type: string - example: "Bad Gateway" +properties: + message: + type: string + example: Bad Gateway diff --git a/tests/README.md b/tests/README.md index cf34ec667..873ab857b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -24,7 +24,12 @@ Test suites that validate the supplier API beyond individual package unit tests. 2. In the root level create an `.env` file and setup the `GITHUB_TOKEN` and `TARGET_ENVIRONMENT` variables (use `.env.template` as a guide) 3. Source the env file by running `set -a` -> `source .env` -> `set +a` 4. Login to your AWS account by running `aws sso login` in the terminal -- **Sandbox tests** require a sandbox server. +- **Sandbox tests**: We need to start the sandbox server from the `/sandbox` folder in the root directory (read /sandbox/README.md for more information). + - Run locally: + 1. from project's root directory `cd sandbox && npm install && npm start` + 2. from project's root directory `make test-sandbox` or `cd tests && npm install && npm run test:sandbox` + - Run in Pipeline: + 1. You need to deploy the proxies in your Pull Request with the label `deploy-proxy`. This should then build the sandbox server, deploy the artifact and deploy the sandbox proxy via proxygen (you might need to re-run the acceptance tests stage in the pipeline, as the server might take some time to deploy and be unreachable from the tests). - **Performance and E2E tests** require AWS credentials, deployed infrastructure, and seeded test data. See `scripts/test-data/` for test data generation and `tests/e2e-tests/README.md` for environment-specific setup. 1. Deploy a dynamic environment (can be achieved by creating a Pull Request). Take a note of the environment e.g. pr1234. 2. Build proxies in the dynamic environment by setting the label `deploy_proxy` (ask a member of the team if you need help) diff --git a/tests/constants/api-constants.ts b/tests/constants/api-constants.ts index f2d9df297..72efefa5a 100644 --- a/tests/constants/api-constants.ts +++ b/tests/constants/api-constants.ts @@ -1,6 +1,7 @@ export const SUPPLIER_LETTERS = "letters"; +const DEFAULT_SUPPLIER_API_URL_SANDBOX = "http://127.0.0.1:9000"; export const SUPPLIER_API_URL_SANDBOX = - "https://internal-dev-sandbox.api.service.nhs.uk/nhs-notify-supplier"; + process.env.SUPPLIER_API_URL_SANDBOX ?? DEFAULT_SUPPLIER_API_URL_SANDBOX; export const AWS_REGION = "eu-west-2"; export const envName = process.env.TARGET_ENVIRONMENT ?? "main"; export const API_NAME = `nhs-${envName}-supapi`; diff --git a/tests/sandbox/testCases/get-letter-status-test-cases.ts b/tests/sandbox/testCases/get-letter-status-test-cases.ts index 1e039b922..4f8ec2808 100644 --- a/tests/sandbox/testCases/get-letter-status-test-cases.ts +++ b/tests/sandbox/testCases/get-letter-status-test-cases.ts @@ -29,6 +29,7 @@ type GetLetterData = { attributes: { specificationId: string; groupId: string; + sha256Hash: string; status: string; }; }; @@ -39,6 +40,7 @@ type RejectedLetterData = { attributes: { specificationId: string; groupId: string; + sha256Hash: string; status: string; reasonCode: string; reasonText: string; @@ -74,6 +76,8 @@ export const apiSandboxGetLetterStatusTestData: ApiSandboxGetLetterStatusTestCas attributes: { specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg", groupId: "c5d93f917f5546d08beccf770a915d96", + sha256Hash: + "3a7bd3e2360a3d29eea436fcfb7e44c735d117c8f2f1d2d1e4f6e8f7e6e8f7e6", status: "ACCEPTED", }, }, @@ -91,6 +95,8 @@ export const apiSandboxGetLetterStatusTestData: ApiSandboxGetLetterStatusTestCas attributes: { specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg", groupId: "c5d93f917f5546d08beccf770a915d96", + sha256Hash: + "3a7bd3e2360a3d29eea436fcfb7e44c735d117c8f2f1d2d1e4f6e8f7e6e8f7e6", status: "REJECTED", reasonCode: "R01", reasonText: "failed validation", @@ -110,6 +116,8 @@ export const apiSandboxGetLetterStatusTestData: ApiSandboxGetLetterStatusTestCas attributes: { specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg", groupId: "c5d93f917f5546d08beccf770a915d96", + sha256Hash: + "3a7bd3e2360a3d29eea436fcfb7e44c735d117c8f2f1d2d1e4f6e8f7e6e8f7e6", status: "CANCELLED", reasonCode: "R01", }, diff --git a/tests/sandbox/testCases/get-list-of-letters-test-cases.ts b/tests/sandbox/testCases/get-list-of-letters-test-cases.ts index b41534b37..c26daae04 100644 --- a/tests/sandbox/testCases/get-list-of-letters-test-cases.ts +++ b/tests/sandbox/testCases/get-list-of-letters-test-cases.ts @@ -22,6 +22,7 @@ type ApiData = { attributes: { specificationId: string; groupId: string; + sha256Hash: string; status: string; }; }; @@ -59,6 +60,8 @@ export const apiSandboxGetLettersRequestTestData: ApiSandboxGetLettersRequestTes attributes: { specificationId: "2WL5eYSWGzCHlGmzNxuqVusPxDg", groupId: "c5d93f917f5546d08beccf770a915d96", + sha256Hash: + "3a7bd3e2360a3d29eea436fcfb7e44c735d117c8f2f1d2d1e4f6e8f7e6e8f7e6", status: "PENDING", }, },