-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from classbinu/jinhwan
Jinhwan
- Loading branch information
Showing
5 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
|
||
import { UsersController } from '../users.controller'; | ||
import { UsersService } from '../users.service'; | ||
import { CreateUserDto } from '../dto/create-user.dto'; | ||
|
||
describe('UsersController', () => { | ||
let controller: UsersController; | ||
let service: UsersService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [UsersController], | ||
providers: [ | ||
{ | ||
provide: UsersService, | ||
useValue: { | ||
createUser: jest | ||
.fn() | ||
.mockResolvedValue({ id: '1', userId: 'test', password: 'test' }), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
controller = module.get<UsersController>(UsersController); | ||
service = module.get<UsersService>(UsersService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
describe('createUser', () => { | ||
it('should return a user', async () => { | ||
const createUserDto: CreateUserDto = { | ||
userId: 'test', | ||
password: 'test', | ||
}; | ||
expect(await controller.createUser(createUserDto)).toEqual({ | ||
id: '1', | ||
userId: 'test', | ||
password: 'test', | ||
}); | ||
expect(service.createUser).toHaveBeenCalledWith(createUserDto); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import { IsNotEmpty, IsString, Matches } from 'class-validator'; | ||
import { | ||
IsNotEmpty, | ||
IsString, | ||
Matches, | ||
MaxLength, | ||
MinLength, | ||
} from 'class-validator'; | ||
|
||
export class CreateUserDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
@MinLength(3, { message: '아이디를 3글자 이상 입력해 주세요.' }) | ||
@MaxLength(10, { message: '아이디를 10글자 이내로 입력해 주세요.' }) | ||
@Matches(/^[A-Za-z0-9]*$/, { | ||
message: 'userId should not contain spaces or special characters', | ||
}) | ||
userId: string; | ||
|
||
@IsString() | ||
@MinLength(4, { message: '비밀번호를 4글자 이상 입력해 주세요.' }) | ||
@IsNotEmpty() | ||
password: string; | ||
|
||
// @IsString() | ||
// @IsEmail() | ||
// @IsOptional() | ||
// email: string; | ||
|
||
// @IsOptional() | ||
// refreshToken?: string | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters