|
@@ -1,6 +1,20 @@
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { AppController } from './app.controller';
|
|
import { AppController } from './app.controller';
|
|
-import { AppService } from './app.service';
|
|
|
|
|
|
+import { AuthService } from './auth/auth.service';
|
|
|
|
+
|
|
|
|
+const testUser = {
|
|
|
|
+ userId: 1,
|
|
|
|
+ username: 'milvus',
|
|
|
|
+ password: 'milvus-admin',
|
|
|
|
+}
|
|
|
|
+class AuthServiceMock {
|
|
|
|
+ login = () => testUser;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const AuthServiceProvider = {
|
|
|
|
+ provide: AuthService,
|
|
|
|
+ useClass: AuthServiceMock,
|
|
|
|
+};
|
|
|
|
|
|
describe('AppController', () => {
|
|
describe('AppController', () => {
|
|
let appController: AppController;
|
|
let appController: AppController;
|
|
@@ -8,15 +22,20 @@ describe('AppController', () => {
|
|
beforeEach(async () => {
|
|
beforeEach(async () => {
|
|
const app: TestingModule = await Test.createTestingModule({
|
|
const app: TestingModule = await Test.createTestingModule({
|
|
controllers: [AppController],
|
|
controllers: [AppController],
|
|
- providers: [AppService],
|
|
|
|
|
|
+ providers: [AuthServiceProvider],
|
|
}).compile();
|
|
}).compile();
|
|
|
|
|
|
appController = app.get<AppController>(AppController);
|
|
appController = app.get<AppController>(AppController);
|
|
});
|
|
});
|
|
|
|
|
|
describe('root', () => {
|
|
describe('root', () => {
|
|
- it('should return "Hello World!"', () => {
|
|
|
|
- expect(appController.getHello()).toBe('Hello World!');
|
|
|
|
|
|
+ it('should defined', () => {
|
|
|
|
+ expect(appController).toBeDefined();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it('should return result', async () => {
|
|
|
|
+ const data = await appController.login(1);
|
|
|
|
+ expect(data).toBe(testUser);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|