From 95f1741264b9695c6150d427f7f0ad4bf4f30fb9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 12 Aug 2026 18:43:58 +0000 Subject: [PATCH 1/2] Bump server/shared, adopt registerAndAuthenticate()/asList() in Student CRUD e2e Per CONSUMER_CHANGES.md row 28a61f5 in nra-server: swap the hand-rolled Test.createTestingModule/cookie-parser/cookie-regex/teardown boilerplate for the new shared helpers (createTestApp + registerAndAuthenticate + asList). 73 lines -> 56, same behavior. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_017YepEQ4PfrEhS2L8imLLRe --- server/shared | 2 +- server/test/student-crud.e2e-spec.ts | 44 +++++++--------------------- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/server/shared b/server/shared index 6cfe6fb4..c754a7f6 160000 --- a/server/shared +++ b/server/shared @@ -1 +1 @@ -Subproject commit 6cfe6fb4c70655fe0544da7d2b94055f00555cf0 +Subproject commit c754a7f672d540c37d79b7501410d02796b58276 diff --git a/server/test/student-crud.e2e-spec.ts b/server/test/student-crud.e2e-spec.ts index 569dd57b..11dfd1c1 100644 --- a/server/test/student-crud.e2e-spec.ts +++ b/server/test/student-crud.e2e-spec.ts @@ -1,48 +1,26 @@ import '@shared/config/crud.config'; -import * as cookieParser from 'cookie-parser'; -import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; -import { DataSource } from 'typeorm'; +import { createTestApp, TestAppHelper } from '@shared/utils/testing/e2e/test-app.helper'; +import { HttpTestUtils, registerAndAuthenticate, asList } from '@shared/utils/testing/e2e/test-utils'; import { AppModule } from 'src/app.module'; -import { HttpTestUtils } from '@shared/utils/testing/e2e/test-utils'; - -// The CRUD list endpoint returns a plain array by default, or a paginated -// { data: [...] } object once pagination kicks in (e.g. a page/limit query param). -// Normalize so list assertions below don't depend on which shape came back. -const asList = (body: any): any[] => (Array.isArray(body) ? body : body.data); describe('student CRUD (e2e)', () => { - let app: INestApplication; - let dataSource: DataSource; + let testApp: TestAppHelper; let httpUtils: HttpTestUtils; let cookie: string; - let moduleFixture: TestingModule; beforeAll(async () => { - moduleFixture = await Test.createTestingModule({ imports: [AppModule] }).compile(); - app = moduleFixture.createNestApplication(); - app.use(cookieParser()); - await app.init(); - dataSource = moduleFixture.get(DataSource); + testApp = createTestApp(AppModule); + const app = await testApp.initializeApp(); httpUtils = new HttpTestUtils(app); - - const registerRes = await httpUtils - .post('/auth/register', { username: 'e2e_student_user', password: 'TestPass_123', name: 'E2E' }) - .expect(200); - const setCookieHeader = registerRes.headers['set-cookie']; - const authCookie = setCookieHeader?.[0]?.match(/Authentication=[^;]+/)?.[0]; - if (!authCookie) { - throw new Error(`Expected an Authentication cookie from /auth/register, got Set-Cookie: ${JSON.stringify(setCookieHeader)}`); - } - cookie = authCookie; + cookie = await registerAndAuthenticate(httpUtils, { + username: 'e2e_student_user', + password: 'TestPass_123', + name: 'E2E', + }); }); afterAll(async () => { - if (dataSource?.isInitialized) { - await dataSource.destroy(); - } - await app?.close(); - await moduleFixture?.close(); + await testApp.cleanup(); }); it('runs a full create -> list -> update -> delete lifecycle over real HTTP', async () => { From 15a717530fb3974d20d9a77e3037f430655fd23d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 12 Aug 2026 18:50:42 +0000 Subject: [PATCH 2/2] Guard afterAll's testApp.cleanup() call with optional chaining MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If beforeAll throws before testApp is assigned, Jest still runs afterAll — testApp?.cleanup() avoids a TypeError there masking the real beforeAll failure. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_017YepEQ4PfrEhS2L8imLLRe --- server/test/student-crud.e2e-spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/test/student-crud.e2e-spec.ts b/server/test/student-crud.e2e-spec.ts index 11dfd1c1..128fd166 100644 --- a/server/test/student-crud.e2e-spec.ts +++ b/server/test/student-crud.e2e-spec.ts @@ -20,7 +20,7 @@ describe('student CRUD (e2e)', () => { }); afterAll(async () => { - await testApp.cleanup(); + await testApp?.cleanup(); }); it('runs a full create -> list -> update -> delete lifecycle over real HTTP', async () => {