Skip to content

Commit

Permalink
feat(apps-backend, tooling-ci): Add e2e tests to apps backend (#3760)
Browse files Browse the repository at this point in the history
* feat(apps-backend): add e2e tests.

* feat(apps-backend): add e2e tests to CI for testing.

* feat(apps-backend): move e2e tests to another config.

* feat(apps-backend): revert hierarchy.

* feat(apps-backend): remove DEPLOY_URL

* feat(apps-backend): remove DEPLOY_URL from e2e test

* feat(tooling-ci): move e2e tests for apps-backend to e2e.yml

* feat(apps-backend): Run apps-backend e2e tests conditionally on apps-backend changes

* feat(apps-backend): Run apps-backend e2e tests also on merge to develop

---------

Co-authored-by: Mario Sarcevic <[email protected]>
Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent 7796881 commit a7d4447
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
isExplorer:
type: boolean
required: true
isAppsBackend:
type: boolean
required: true
isTypescriptSDK:
type: boolean
required: true
Expand Down Expand Up @@ -74,6 +77,14 @@ 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.isAppsBackend || inputs.isDevelop
run: pnpm --filter apps-backend build

- name: Run apps-backend e2e tests
if: inputs.isAppsBackend || inputs.isDevelop
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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/hierarchy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
13 changes: 13 additions & 0 deletions apps/apps-backend/jest-e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": "./",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/dist/$1",
"^@iota/core/(.*)$": "<rootDir>/dist/core/src/$1"
}
}
5 changes: 3 additions & 2 deletions apps/apps-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 2 additions & 0 deletions apps/apps-backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -30,6 +31,7 @@ import { RestrictedModule } from './restricted/restricted.module';
ttl: 3600,
max: 100,
}),
HealthModule,
],
})
export class AppModule {}
12 changes: 12 additions & 0 deletions apps/apps-backend/src/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -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' };
}
}
10 changes: 10 additions & 0 deletions apps/apps-backend/src/health/health.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
28 changes: 28 additions & 0 deletions apps/apps-backend/test/health.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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)', async () => {
await request(app.getHttpServer()).get('/health').expect(200).expect({ status: 'ok' });
});
});

0 comments on commit a7d4447

Please sign in to comment.