Skip to content

Commit 852f65f

Browse files
EL-532: Implement QA Testing Strategies and Framework (#41)
* initial commit * finished citizen-portals * added tests for platform-api * working on platform-web * added more tests * added tests for routes files in platform-web * finished component tests for platform-web * finish coverage for citizen-portal-web * finish coverage for citizen-portal-api * small fix test error * fix test error * added more citizen-portal-api tests * added more citizen-portal-web tests * added more tests to platform-api * added more tests to platform-web * organized test folders and files * fixed test case * fixed tests after merging main * organized files and folders
1 parent 8e5667b commit 852f65f

351 files changed

Lines changed: 52435 additions & 9699 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/citizen-portal-api/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"lint": "oxlint",
1010
"start": "node dist/src/main.js",
1111
"test": "vitest run",
12+
"test:cov": "vitest run --coverage",
13+
"test:e2e": "vitest run test/e2e \"e2e.test.ts\"",
14+
"test:unit": "vitest run test/unit \"test.ts\"",
1215
"typecheck": "tsc --noEmit"
1316
},
1417
"dependencies": {
@@ -40,6 +43,7 @@
4043
"@types/express-session": "^1.19.0",
4144
"@types/node": "26.0.0",
4245
"@types/supertest": "7.2.0",
46+
"@vitest/coverage-v8": "^4.1.10",
4347
"supertest": "7.2.2",
4448
"unplugin-swc": "1.5.9"
4549
}

apps/citizen-portal-api/src/modules/notifications/controllers/my-notifications-v1.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Body, Controller, Get, HttpCode, Param, Post, Put, Query, Req, Res } from '@nestjs/common';
2+
import { ApiTags } from '@nestjs/swagger';
23
import type { Request, Response } from 'express';
34
import { CurrentUser, type AuthUser } from '@repo/nestjs/auth';
45
import { ZodSerializerDto } from 'nestjs-zod';
@@ -26,6 +27,7 @@ import { NotificationsProxyService } from '../services/notifications-proxy.servi
2627
* scoped to `@CurrentUser().id` — the browser never names a recipient and never sees the
2728
* m2m token or the notification-service.
2829
*/
30+
@ApiTags('Notifications')
2931
@Controller({ path: 'me', version: '1' })
3032
export class MyNotificationsV1Controller {
3133
constructor(private readonly proxy: NotificationsProxyService) {}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Citizen Portal API Project Quality Assurance Testing Documentation
2+
3+
## Vitest
4+
5+
The Citizen Portal API project uses Vitest for QA testing, which is the preferred framework for its zero-config setup, mocking capabilities, and broad ecosystem support for this Node.js based project. The main focuses of QA testing for the Citizen Portal API application are unit and integration tests. Coverage test is also available with coverage threshold that increases as the project expands.
6+
7+
## Files and Folders
8+
9+
Unit test files with file name suffix `**/*.test.ts` should be placed inside the [`unit`](./unit) folder, whereas integration test files with file name suffix `**/*.e2e.test.ts` should be placed inside the [integration](./integration/) folder.
10+
11+
| Testing Content | File Format | Folder (example) |
12+
| :--------------: | :----------------: | :--------------: |
13+
| Unit test | `**/*.test.ts` | [unit](./unit/) |
14+
| Integration test | `**/*.e2e.test.ts` | [e2e](./e2e/) |
15+
16+
## Configuration
17+
18+
Vitest is available to use with low-to-zero configurations. Refer to file [`vitest.config.ts`](./vitest.config.ts) for configuration.
19+
20+
## Local Testing
21+
22+
The API project offers three methods to run tests using Vitest. These tests are categorized into three main methods: using command lines in terminal, VSCode debugger or VScode Vitest extension.
23+
24+
### Terminal Testing
25+
26+
Scripts are added to `package.json` for quick access.
27+
28+
Run unit test on all files with the following command line:
29+
30+
```bash
31+
npm run test:unit
32+
```
33+
34+
Run integration test on integration files with the following command line:
35+
36+
```bash
37+
npm run test:e2e
38+
```
39+
40+
Change directory to `apps/api` and run unit test on a specific test file (same for integration test) with the following command line:
41+
42+
```bash
43+
npm run test "path/to/your/testfile.spec.ts"
44+
```
45+
46+
Run coverage test with the following command line:
47+
48+
```bash
49+
npm run test:cov
50+
```
51+
52+
### VSCode Vitest Extension
53+
54+
VSCode Vitest extension (vscode-jest) supports full jest features in vscode environment to make testing accessible for developers. Install [`Vitest`](https://marketplace.visualstudio.com/items?itemName=vitest.explorer) from the VSCode extension marketplace, and it should be available to use. Restart VSCode after installation in case it is not available.
55+
56+
Open a test file and click on the green Run button next any test suite or test case to run tests.
57+
58+
## CI/CD Testing
59+
60+
CI/CD workflows for API quality assurance testing are added to the file [qa-testing.yml](/.github/workflows/qa-testing.yml) for GitHub actions. Automated workflows will be triggered upon creating a pull request from devs' current working branch into the `develop` branch.

apps/citizen-portal-api/test/applications.e2e.test.ts renamed to apps/citizen-portal-api/test/e2e/applications.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AuthUser } from '@repo/nestjs/auth';
44
import type { NextFunction, Request, Response } from 'express';
55
import request from 'supertest';
66
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
7-
import { AppModule } from '../src/app.module';
7+
import { AppModule } from '../../src/app.module';
88

99
/**
1010
* Auth + validation posture for the citizen application surface (feature 63). The test DATABASE_URL

apps/citizen-portal-api/test/auth-wiring.e2e.test.ts renamed to apps/citizen-portal-api/test/e2e/auth-wiring.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Test } from '@nestjs/testing';
33
import { AUTH_OPTIONS } from '@repo/nestjs/auth';
44
import request from 'supertest';
55
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
6-
import { AppModule } from '../src/app.module';
6+
import { AppModule } from '../../src/app.module';
77

88
// Under NODE_ENV=test the AuthModule factory injects a stub config and skips OIDC discovery, so
99
// AppModule boots without a running Keycloak. The live login round-trip is verified separately.

apps/citizen-portal-api/test/catalog.e2e.test.ts renamed to apps/citizen-portal-api/test/e2e/catalog.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AuthUser } from '@repo/nestjs/auth';
44
import type { NextFunction, Request, Response } from 'express';
55
import request from 'supertest';
66
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
7-
import { AppModule } from '../src/app.module';
7+
import { AppModule } from '../../src/app.module';
88

99
/**
1010
* Auth + validation posture for the citizen catalog (feature 60). The test DATABASE_URL is an

apps/citizen-portal-api/test/consent.e2e.test.ts renamed to apps/citizen-portal-api/test/e2e/consent.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AuthUser } from '@repo/nestjs/auth';
44
import type { NextFunction, Request, Response } from 'express';
55
import request from 'supertest';
66
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
7-
import { AppModule } from '../src/app.module';
7+
import { AppModule } from '../../src/app.module';
88

99
/**
1010
* Auth + validation posture for the citizen consent surface (feature 89). The test DATABASE_URL is

apps/citizen-portal-api/test/database-wiring.e2e.test.ts renamed to apps/citizen-portal-api/test/e2e/database-wiring.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Test } from '@nestjs/testing';
33
import { DATABASE_CLIENT } from '@repo/nestjs/database';
44
import request from 'supertest';
55
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
6-
import { AppModule } from '../src/app.module';
6+
import { AppModule } from '../../src/app.module';
77

88
// DATABASE_URL is provided by test/setup.ts; createDatabase() is lazy, so no real Postgres
99
// is needed — a socket is only opened on the first query.
File renamed without changes.

apps/citizen-portal-api/test/health.e2e.test.ts renamed to apps/citizen-portal-api/test/e2e/health.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { VersioningType, type INestApplication } from '@nestjs/common';
22
import { Test } from '@nestjs/testing';
33
import request from 'supertest';
44
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
5-
import { AppModule } from '../src/app.module';
5+
import { AppModule } from '../../src/app.module';
66

77
describe('citizen-portal-api health (e2e)', () => {
88
let app: INestApplication;

0 commit comments

Comments
 (0)