Skip to content

Commit a665aa8

Browse files
auth jwt sample Fix test cases
1 parent a0a5130 commit a665aa8

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { AppController } from './app.controller';
33
import { AppService } from './app.service';
4+
import { AuthModule } from './auth/auth.module';
5+
import { UsersModule } from './users/users.module';
46

57
describe('AppController', () => {
68
let appController: AppController;
79

810
beforeEach(async () => {
911
const app: TestingModule = await Test.createTestingModule({
12+
imports: [AuthModule, UsersModule],
1013
controllers: [AppController],
1114
providers: [AppService],
1215
}).compile();
1316

1417
appController = app.get<AppController>(AppController);
1518
});
1619

17-
describe('root', () => {
18-
it('should return "Hello World!"', () => {
19-
expect(appController.getHello()).toBe('Hello World!');
20+
describe('app controller', () => {
21+
it('should be defined', () => {
22+
expect(appController).toBeDefined();
2023
});
2124
});
2225
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { AppController } from './app.controller';
3+
import { AppService } from './app.service';
4+
import { UsersModule } from './users/users.module';
5+
import { AuthModule } from './auth/auth.module';
6+
7+
describe('AppService', () => {
8+
let appService: AppService;
9+
10+
beforeEach(async () => {
11+
const app: TestingModule = await Test.createTestingModule({
12+
imports: [AuthModule, UsersModule],
13+
controllers: [AppController],
14+
providers: [AppService],
15+
}).compile();
16+
17+
appService = app.get<AppService>(AppService);
18+
});
19+
20+
describe('app service', () => {
21+
it('should return "Hello World!"', () => {
22+
expect(appService.getHello()).toBe('Hello World!');
23+
});
24+
});
25+
});

sample/19-auth-jwt/src/auth/auth.service.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { AuthService } from './auth.service';
3+
import { LocalStrategy } from './local.strategy';
4+
import { JwtStrategy } from './jwt.strategy';
5+
import { UsersModule } from '../users/users.module';
6+
import { PassportModule } from '@nestjs/passport';
7+
import { JwtModule } from '@nestjs/jwt';
8+
import { jwtConstants } from './constants';
39

410
describe('AuthService', () => {
511
let service: AuthService;
612

713
beforeEach(async () => {
814
const module: TestingModule = await Test.createTestingModule({
9-
providers: [AuthService],
15+
imports: [
16+
UsersModule,
17+
PassportModule,
18+
JwtModule.register({
19+
secret: jwtConstants.secret,
20+
signOptions: { expiresIn: '60s' },
21+
}),
22+
],
23+
providers: [AuthService, LocalStrategy, JwtStrategy],
1024
}).compile();
1125

1226
service = module.get<AuthService>(AuthService);

0 commit comments

Comments
 (0)