From be5fd8ddac47f8e3193b81673e652198564db1fb Mon Sep 17 00:00:00 2001 From: Eugene P Date: Tue, 29 Oct 2024 15:03:34 +0200 Subject: [PATCH 1/9] feat(apps-backend): add e2e tests. --- apps/apps-backend/jest-e2e.json | 13 +++++++++ apps/apps-backend/package.json | 5 ++-- apps/apps-backend/src/app.module.ts | 2 ++ .../src/health/health.controller.ts | 12 ++++++++ apps/apps-backend/src/health/health.module.ts | 10 +++++++ apps/apps-backend/test/health.e2e-spec.ts | 28 +++++++++++++++++++ 6 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 apps/apps-backend/jest-e2e.json create mode 100644 apps/apps-backend/src/health/health.controller.ts create mode 100644 apps/apps-backend/src/health/health.module.ts create mode 100644 apps/apps-backend/test/health.e2e-spec.ts diff --git a/apps/apps-backend/jest-e2e.json b/apps/apps-backend/jest-e2e.json new file mode 100644 index 00000000000..8a02f0e8a41 --- /dev/null +++ b/apps/apps-backend/jest-e2e.json @@ -0,0 +1,13 @@ +{ + "moduleFileExtensions": ["js", "json", "ts"], + "rootDir": "./", + "testRegex": ".e2e-spec.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "testEnvironment": "node", + "moduleNameMapper": { + "^src/(.*)$": "/dist/$1", + "^@iota/core/(.*)$": "/dist/core/src/$1" + } +} diff --git a/apps/apps-backend/package.json b/apps/apps-backend/package.json index eb94045a4f5..149cc6fd9fc 100644 --- a/apps/apps-backend/package.json +++ b/apps/apps-backend/package.json @@ -6,8 +6,9 @@ "format": "prettier --write \"src/**/*.ts\"", "dev": "nest start --watch", "debug": "nest start --debug --watch", - "preview": "pnpm run build && node dist/main", - "lint": "eslint --max-warnings=0 \"{src,apps,libs,test}/**/*.ts\"" + "preview": "pnpm run build && node dist/apps-backend/src/main", + "lint": "eslint --max-warnings=0 \"{src,apps,libs,test}/**/*.ts\"", + "test:e2e": "jest --config ./jest-e2e.json" }, "dependencies": { "@iota/core": "workspace:*", diff --git a/apps/apps-backend/src/app.module.ts b/apps/apps-backend/src/app.module.ts index 0dc2844e50e..b7fd88272e7 100644 --- a/apps/apps-backend/src/app.module.ts +++ b/apps/apps-backend/src/app.module.ts @@ -11,6 +11,7 @@ import { FeaturesModule } from './features/features.module'; import { MonitorNetworkModule } from './monitor-network/monitor-network.module'; import { PricesModule } from './prices/prices.module'; import { RestrictedModule } from './restricted/restricted.module'; +import { HealthModule } from './health/health.module'; @Module({ imports: [ @@ -30,6 +31,7 @@ import { RestrictedModule } from './restricted/restricted.module'; ttl: 3600, max: 100, }), + HealthModule, ], }) export class AppModule {} diff --git a/apps/apps-backend/src/health/health.controller.ts b/apps/apps-backend/src/health/health.controller.ts new file mode 100644 index 00000000000..c86fdd5fc40 --- /dev/null +++ b/apps/apps-backend/src/health/health.controller.ts @@ -0,0 +1,12 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Controller, Get } from '@nestjs/common'; + +@Controller('health') +export class HealthController { + @Get() + check() { + return { status: 'ok' }; + } +} diff --git a/apps/apps-backend/src/health/health.module.ts b/apps/apps-backend/src/health/health.module.ts new file mode 100644 index 00000000000..e6394484ac5 --- /dev/null +++ b/apps/apps-backend/src/health/health.module.ts @@ -0,0 +1,10 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Module } from '@nestjs/common'; +import { HealthController } from './health.controller'; + +@Module({ + controllers: [HealthController], +}) +export class HealthModule {} diff --git a/apps/apps-backend/test/health.e2e-spec.ts b/apps/apps-backend/test/health.e2e-spec.ts new file mode 100644 index 00000000000..cde735e7a57 --- /dev/null +++ b/apps/apps-backend/test/health.e2e-spec.ts @@ -0,0 +1,28 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import * as request from 'supertest'; +import { AppModule } from '../src/app.module'; + +describe('Health Check (e2e)', () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + }); + + afterAll(async () => { + await app.close(); + }); + + it('/health (GET)', () => { + return request(app.getHttpServer()).get('/health').expect(200).expect({ status: 'ok' }); + }); +}); From 3afc18ecaefa4aad41b315fe230721178d051ccb Mon Sep 17 00:00:00 2001 From: Eugene P Date: Tue, 29 Oct 2024 15:31:41 +0200 Subject: [PATCH 2/9] feat(apps-backend): add e2e tests to CI for testing. --- .github/workflows/_e2e.yml | 7 ++++++- .github/workflows/hierarchy.yml | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/_e2e.yml b/.github/workflows/_e2e.yml index 8956e3e8293..1b256bf6294 100644 --- a/.github/workflows/_e2e.yml +++ b/.github/workflows/_e2e.yml @@ -18,6 +18,9 @@ on: isGraphQlTransport: type: boolean required: true + isAppsBackend: + type: boolean + required: true isDevelop: type: boolean required: true @@ -69,7 +72,9 @@ jobs: - name: Run TS SDK e2e tests if: inputs.isTypescriptSDK || inputs.isRust || inputs.isDevelop run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/iota-sdk test:e2e' - + - name: Run Apps Backend e2e tests + if: inputs.isAppsBackend + run: pnpm --filter apps-backend test:e2e - name: Run RPC/GraphQL compatibility e2e tests if: inputs.isGraphQlTransport || inputs.isRust || inputs.isDevelop run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/graphql-transport test:e2e' diff --git a/.github/workflows/hierarchy.yml b/.github/workflows/hierarchy.yml index 47d92c4ce92..1bf23ce0228 100644 --- a/.github/workflows/hierarchy.yml +++ b/.github/workflows/hierarchy.yml @@ -134,7 +134,7 @@ jobs: isRust: ${{ needs.diff.outputs.isRust == 'true' }} e2e: - if: (!cancelled() && !failure() && (!github.event.pull_request.draft || github.ref_name == 'develop')) + if: (!cancelled() && !failure() && (github.event.pull_request.draft || github.ref_name == 'develop')) needs: - diff - dprint-format @@ -147,6 +147,7 @@ jobs: isExplorer: ${{ needs.diff.outputs.isExplorer == 'true' }} isTypescriptSDK: ${{ needs.diff.outputs.isTypescriptSDK == 'true' }} isGraphQlTransport: ${{ needs.diff.outputs.isGraphQlTransport == 'true' }} + isAppsBackend: ${{ needs.diff.outputs.isAppsBackend == 'true' }} isDevelop: ${{ github.ref_name == 'develop' }} vercel-deploy: From ea0543936e61d5e055d99010b0c6a132af7fcff4 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Tue, 29 Oct 2024 19:16:19 +0200 Subject: [PATCH 3/9] feat(apps-backend): move e2e tests to another config. --- .github/workflows/_e2e.yml | 7 +------ .github/workflows/apps_backend_deploy.yml | 2 ++ .github/workflows/hierarchy.yml | 5 ++--- apps/apps-backend/test/health.e2e-spec.ts | 10 ++++++++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/_e2e.yml b/.github/workflows/_e2e.yml index 1b256bf6294..8956e3e8293 100644 --- a/.github/workflows/_e2e.yml +++ b/.github/workflows/_e2e.yml @@ -18,9 +18,6 @@ on: isGraphQlTransport: type: boolean required: true - isAppsBackend: - type: boolean - required: true isDevelop: type: boolean required: true @@ -72,9 +69,7 @@ jobs: - name: Run TS SDK e2e tests if: inputs.isTypescriptSDK || inputs.isRust || inputs.isDevelop run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/iota-sdk test:e2e' - - name: Run Apps Backend e2e tests - if: inputs.isAppsBackend - run: pnpm --filter apps-backend test:e2e + - name: Run RPC/GraphQL compatibility e2e tests if: inputs.isGraphQlTransport || inputs.isRust || inputs.isDevelop run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/graphql-transport test:e2e' diff --git a/.github/workflows/apps_backend_deploy.yml b/.github/workflows/apps_backend_deploy.yml index 38c919e73f5..5ab404ad0d7 100644 --- a/.github/workflows/apps_backend_deploy.yml +++ b/.github/workflows/apps_backend_deploy.yml @@ -62,6 +62,8 @@ jobs: id: deploy_url if: ${{ inputs.isProd == false }} run: echo "DEPLOY_URL=$(cat vercel_output.txt | awk 'END{print}')" >> $GITHUB_OUTPUT + - name: E2E tests for deployed URL + run: DEPLOY_URL=${{ steps.deploy_url.outputs.DEPLOY_URL }} pnpm --filter apps-backend test:e2e - name: Comment on pull request if: ${{ inputs.isProd == false }} uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # pin@v7 diff --git a/.github/workflows/hierarchy.yml b/.github/workflows/hierarchy.yml index 1bf23ce0228..271ca95fc5d 100644 --- a/.github/workflows/hierarchy.yml +++ b/.github/workflows/hierarchy.yml @@ -134,7 +134,7 @@ jobs: isRust: ${{ needs.diff.outputs.isRust == 'true' }} e2e: - if: (!cancelled() && !failure() && (github.event.pull_request.draft || github.ref_name == 'develop')) + if: (!cancelled() && !failure() && (!github.event.pull_request.draft || github.ref_name == 'develop')) needs: - diff - dprint-format @@ -147,7 +147,6 @@ jobs: isExplorer: ${{ needs.diff.outputs.isExplorer == 'true' }} isTypescriptSDK: ${{ needs.diff.outputs.isTypescriptSDK == 'true' }} isGraphQlTransport: ${{ needs.diff.outputs.isGraphQlTransport == 'true' }} - isAppsBackend: ${{ needs.diff.outputs.isAppsBackend == 'true' }} isDevelop: ${{ github.ref_name == 'develop' }} vercel-deploy: @@ -160,7 +159,7 @@ jobs: uses: ./.github/workflows/_vercel_deploy.yml secrets: inherit with: - shouldDeployPreview: ${{github.event_name == 'pull_request' && github.event.pull_request.draft == false}} + shouldDeployPreview: ${{github.event_name == 'pull_request' && github.event.pull_request.draft == true}} isExplorer: ${{ needs.diff.outputs.isExplorer == 'true' }} isTypescriptSDK: ${{ needs.diff.outputs.isTypescriptSDK == 'true' }} isAppsBackend: ${{ needs.diff.outputs.isAppsBackend == 'true' }} diff --git a/apps/apps-backend/test/health.e2e-spec.ts b/apps/apps-backend/test/health.e2e-spec.ts index cde735e7a57..6811fed853f 100644 --- a/apps/apps-backend/test/health.e2e-spec.ts +++ b/apps/apps-backend/test/health.e2e-spec.ts @@ -22,7 +22,13 @@ describe('Health Check (e2e)', () => { await app.close(); }); - it('/health (GET)', () => { - return request(app.getHttpServer()).get('/health').expect(200).expect({ status: 'ok' }); + it('/health (GET)', async () => { + const DEPLOYED_URL = process.env.DEPLOYED_URL || null; + + if (DEPLOYED_URL) { + await request(DEPLOYED_URL).get('/health').expect(200).expect({ status: 'ok' }); + } else { + await request(app.getHttpServer()).get('/health').expect(200).expect({ status: 'ok' }); + } }); }); From 2d0e56087e3bdf49f8e104f3e179b334b51acec1 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Wed, 30 Oct 2024 11:01:35 +0200 Subject: [PATCH 4/9] feat(apps-backend): revert hierarchy. --- .github/workflows/hierarchy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/hierarchy.yml b/.github/workflows/hierarchy.yml index 271ca95fc5d..47d92c4ce92 100644 --- a/.github/workflows/hierarchy.yml +++ b/.github/workflows/hierarchy.yml @@ -159,7 +159,7 @@ jobs: uses: ./.github/workflows/_vercel_deploy.yml secrets: inherit with: - shouldDeployPreview: ${{github.event_name == 'pull_request' && github.event.pull_request.draft == true}} + shouldDeployPreview: ${{github.event_name == 'pull_request' && github.event.pull_request.draft == false}} isExplorer: ${{ needs.diff.outputs.isExplorer == 'true' }} isTypescriptSDK: ${{ needs.diff.outputs.isTypescriptSDK == 'true' }} isAppsBackend: ${{ needs.diff.outputs.isAppsBackend == 'true' }} From 21955ef9fb0cca1a95bddfeadcfb531b3cfa41e2 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Wed, 30 Oct 2024 12:40:35 +0200 Subject: [PATCH 5/9] feat(apps-backend): remove DEPLOY_URL --- .github/workflows/apps_backend_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/apps_backend_deploy.yml b/.github/workflows/apps_backend_deploy.yml index 5ab404ad0d7..ea99142cbb1 100644 --- a/.github/workflows/apps_backend_deploy.yml +++ b/.github/workflows/apps_backend_deploy.yml @@ -63,7 +63,7 @@ jobs: if: ${{ inputs.isProd == false }} run: echo "DEPLOY_URL=$(cat vercel_output.txt | awk 'END{print}')" >> $GITHUB_OUTPUT - name: E2E tests for deployed URL - run: DEPLOY_URL=${{ steps.deploy_url.outputs.DEPLOY_URL }} pnpm --filter apps-backend test:e2e + run: pnpm --filter apps-backend test:e2e - name: Comment on pull request if: ${{ inputs.isProd == false }} uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # pin@v7 From f5750b4a46a01588bf06f14acd0d64c231f48ab2 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Thu, 31 Oct 2024 10:04:46 +0200 Subject: [PATCH 6/9] feat(apps-backend): remove DEPLOY_URL from e2e test --- apps/apps-backend/test/health.e2e-spec.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/apps-backend/test/health.e2e-spec.ts b/apps/apps-backend/test/health.e2e-spec.ts index 6811fed853f..f8ea44ed7cc 100644 --- a/apps/apps-backend/test/health.e2e-spec.ts +++ b/apps/apps-backend/test/health.e2e-spec.ts @@ -23,12 +23,6 @@ describe('Health Check (e2e)', () => { }); it('/health (GET)', async () => { - const DEPLOYED_URL = process.env.DEPLOYED_URL || null; - - if (DEPLOYED_URL) { - await request(DEPLOYED_URL).get('/health').expect(200).expect({ status: 'ok' }); - } else { - await request(app.getHttpServer()).get('/health').expect(200).expect({ status: 'ok' }); - } + await request(app.getHttpServer()).get('/health').expect(200).expect({ status: 'ok' }); }); }); From 9ee99fc1fa16e13d6d12cd5f8e7688c4db6a9f67 Mon Sep 17 00:00:00 2001 From: Eugene P Date: Wed, 6 Nov 2024 13:01:26 +0200 Subject: [PATCH 7/9] feat(tooling-ci): move e2e tests for apps-backend to e2e.yml --- .github/workflows/_e2e.yml | 7 +++++++ .github/workflows/apps_backend_deploy.yml | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/_e2e.yml b/.github/workflows/_e2e.yml index 8956e3e8293..1fe279d0a0d 100644 --- a/.github/workflows/_e2e.yml +++ b/.github/workflows/_e2e.yml @@ -74,6 +74,13 @@ jobs: if: inputs.isGraphQlTransport || inputs.isRust || inputs.isDevelop run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/graphql-transport test:e2e' + - name: Build apps-backend + if: inputs.isTypescriptSDK || inputs.isExplorer || inputs.isRust || inputs.isDevelop + run: pnpm --filter apps-backend build + + - name: Run apps-backend e2e tests + run: pnpm --filter apps-backend test:e2e + - name: Build explorer if: inputs.isTypescriptSDK || inputs.isExplorer || inputs.isRust || inputs.isDevelop run: pnpm turbo --filter=iota-explorer build diff --git a/.github/workflows/apps_backend_deploy.yml b/.github/workflows/apps_backend_deploy.yml index ea99142cbb1..38c919e73f5 100644 --- a/.github/workflows/apps_backend_deploy.yml +++ b/.github/workflows/apps_backend_deploy.yml @@ -62,8 +62,6 @@ jobs: id: deploy_url if: ${{ inputs.isProd == false }} run: echo "DEPLOY_URL=$(cat vercel_output.txt | awk 'END{print}')" >> $GITHUB_OUTPUT - - name: E2E tests for deployed URL - run: pnpm --filter apps-backend test:e2e - name: Comment on pull request if: ${{ inputs.isProd == false }} uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # pin@v7 From 5884b0f085b93a5b6080f731e447068ea605bf33 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Tue, 12 Nov 2024 10:43:11 +0100 Subject: [PATCH 8/9] feat(apps-backend): Run apps-backend e2e tests conditionally on apps-backend changes --- .github/workflows/_e2e.yml | 6 +++++- .github/workflows/hierarchy.yml | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/_e2e.yml b/.github/workflows/_e2e.yml index 1fe279d0a0d..eab0b02bd35 100644 --- a/.github/workflows/_e2e.yml +++ b/.github/workflows/_e2e.yml @@ -9,6 +9,9 @@ on: isExplorer: type: boolean required: true + isAppsBackend: + type: boolean + required: true isTypescriptSDK: type: boolean required: true @@ -75,10 +78,11 @@ jobs: run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/graphql-transport test:e2e' - name: Build apps-backend - if: inputs.isTypescriptSDK || inputs.isExplorer || inputs.isRust || inputs.isDevelop + if: inputs.isAppsBackend run: pnpm --filter apps-backend build - name: Run apps-backend e2e tests + if: inputs.isAppsBackend run: pnpm --filter apps-backend test:e2e - name: Build explorer diff --git a/.github/workflows/hierarchy.yml b/.github/workflows/hierarchy.yml index 47d92c4ce92..612d35b03a0 100644 --- a/.github/workflows/hierarchy.yml +++ b/.github/workflows/hierarchy.yml @@ -145,6 +145,7 @@ jobs: isRust: ${{ needs.diff.outputs.isRust == 'true' }} isWallet: ${{ needs.diff.outputs.isWallet == 'true' }} isExplorer: ${{ needs.diff.outputs.isExplorer == 'true' }} + isAppsBackend: ${{ needs.diff.outputs.isAppsBackend == 'true' }} isTypescriptSDK: ${{ needs.diff.outputs.isTypescriptSDK == 'true' }} isGraphQlTransport: ${{ needs.diff.outputs.isGraphQlTransport == 'true' }} isDevelop: ${{ github.ref_name == 'develop' }} From 64886e3f823545f248f696753e32dcf845a72f9f Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Tue, 12 Nov 2024 10:44:13 +0100 Subject: [PATCH 9/9] feat(apps-backend): Run apps-backend e2e tests also on merge to develop --- .github/workflows/_e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/_e2e.yml b/.github/workflows/_e2e.yml index eab0b02bd35..c23f946f99c 100644 --- a/.github/workflows/_e2e.yml +++ b/.github/workflows/_e2e.yml @@ -78,11 +78,11 @@ jobs: run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @iota/graphql-transport test:e2e' - name: Build apps-backend - if: inputs.isAppsBackend + if: inputs.isAppsBackend || inputs.isDevelop run: pnpm --filter apps-backend build - name: Run apps-backend e2e tests - if: inputs.isAppsBackend + if: inputs.isAppsBackend || inputs.isDevelop run: pnpm --filter apps-backend test:e2e - name: Build explorer