Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/shared
44 changes: 11 additions & 33 deletions server/test/student-crud.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
Comment on lines 22 to 24

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair catch on the wording — "same behavior" referred to the CRUD lifecycle assertions (create/list/update/delete), not teardown error handling, which does change here. TestAppHelper.cleanup()'s swallow-and-warn is pre-existing behavior in nra-server (predates this PR — the baseline app.e2e-spec.ts in every app already goes through it via createSharedAppE2eTests), not something introduced by this change.

Whether teardown failures should fail the suite is a real question, but it's a TestAppHelper design change in the shared nra-server repo, affecting every consumer of cleanup() across all 5 apps — bigger scope than this PR. Leaving it as a follow-up rather than bundling it in here.


Generated by Claude Code


it('runs a full create -> list -> update -> delete lifecycle over real HTTP', async () => {
Expand Down
Loading