Skip to content

Commit

Permalink
user modules/service/controller/specを作成
Browse files Browse the repository at this point in the history
  • Loading branch information
rinonkia committed Mar 8, 2022
1 parent a5a3ed1 commit be5c857
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/app.module.ts
@@ -1,8 +1,7 @@
import { Module } from '@nestjs/common';
import { UserModule } from './modules/user/user.module';

@Module({
imports: [],
controllers: [],
providers: [],
imports: [UserModule],
})
export class AppModule {}
18 changes: 18 additions & 0 deletions src/modules/user/user.controller.spec.ts
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UserController } from './user.controller';

describe('UserController', () => {
let controller: UserController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UserController],
}).compile();

controller = module.get<UserController>(UserController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
17 changes: 17 additions & 0 deletions src/modules/user/user.controller.ts
@@ -0,0 +1,17 @@
import { Controller, Get, Post } from '@nestjs/common';
import { UserService } from './user.service';

@Controller('users')
export class UserController {
constructor(private readonly userService: UserService) {}

@Get()
findAll() {
return this.userService.findAll();
}

@Post()
create() {
return this.userService.create();
}
}
9 changes: 9 additions & 0 deletions src/modules/user/user.module.ts
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { UserController } from './user.controller';
import { UserService } from './user.service';

@Module({
controllers: [UserController],
providers: [UserService],
})
export class UserModule {}
18 changes: 18 additions & 0 deletions src/modules/user/user.service.spec.ts
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UserService } from './user.service';

describe('UserService', () => {
let service: UserService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UserService],
}).compile();

service = module.get<UserService>(UserService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
12 changes: 12 additions & 0 deletions src/modules/user/user.service.ts
@@ -0,0 +1,12 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class UserService {
findAll() {
return 'findAll users';
}

create() {
return 'create user';
}
}

0 comments on commit be5c857

Please sign in to comment.