Skip to content

Commit 2426e0f

Browse files
committed
style(testing): Simplified session setup code
1 parent 1b89c6f commit 2426e0f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

apps/nest/src/app.controller.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ describe('AppController', () => {
1919
const response = await supertest.get('/');
2020
expect(response.statusCode).toBe(200);
2121
expect(response.body.message).toBe('Hello there!');
22+
expect(response.body.session).toBe('Not logged in');
23+
});
24+
25+
it('should indicate the current session', async () => {
26+
const response = await supertest.get('/', {
27+
session: {
28+
sub: '123',
29+
name: 'John Doe',
30+
email: 'john.doe@example.com',
31+
},
32+
});
33+
expect(response.statusCode).toBe(200);
34+
expect(response.body.session).toBe('Logged in as John Doe');
2235
});
2336
});
2437

packages/nest-utils/src/testing/container/test-container.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { INestApplication } from '@nestjs/common';
22
import { Test, TestingModule } from '@nestjs/testing';
33
import { type OmitFunctionMembers } from '@spuxx/js-utils';
4-
import { AuthOptions, SessionResource } from '../../auth';
4+
import { AuthOptions } from '../../auth';
55
import { AuthModule } from '../../auth/auth.module';
66
import { Supertest } from '../supertest';
77
import { createEndToEndNestApplication } from './private/end-to-end';
@@ -96,12 +96,10 @@ export class TestContainer {
9696
// Enable end-to-end testing if requested
9797
let app: INestApplication | undefined;
9898
let supertest: Supertest | undefined;
99-
let session: Partial<SessionResource> | undefined;
10099
if (enableEndToEnd) {
101100
app = await createEndToEndNestApplication(module);
102-
session = { ...options.session };
103101
await AuthModule.bootstrap(app, authOptions as AuthOptions);
104-
supertest = new Supertest(app, session);
102+
supertest = new Supertest(app, options.session);
105103
}
106104
// Return the test container
107105
return new TestContainer({ module, app, supertest });

0 commit comments

Comments
 (0)