-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
userController&test #56
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
import {SignUpDto} from './signUp.dto'; | ||
|
||
describe('SignUpPayload', () => { | ||
it('should be defined', () => { | ||
expect(new SignUpDto({address: 'address', message: 'message'}, 'signature')).toBeDefined(); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
server/src/app/user/dto/signUp.payload.ts → server/src/app/user/dto/signUp.dto.ts
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,4 +1,4 @@ | ||
export class SignUpPayload { | ||
export class SignUpDto { | ||
|
||
data: { | ||
address: string, | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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
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,5 +1,3 @@ | ||
import {Data} from './data'; | ||
|
||
export interface ValidationService { | ||
verify(data: Data, signature: string): boolean; | ||
verify(data: {address: string, message: string}, signature: string): boolean; | ||
} |
1 change: 0 additions & 1 deletion
1
server/src/port/adapter/service/blockchain/ethereum/web3/web3.bridge.service.ts
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,150 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserController } from './user.controller'; | ||
import {instance, mock, when} from 'ts-mockito'; | ||
import {UserService} from '../../app/user/user.service'; | ||
import {UserServiceImpl} from '../../app/user/user.service.impl'; | ||
import {User} from '../../domain/user/user.entity'; | ||
import {UserDto} from '../../app/user/dto/user.dto'; | ||
import {BadRequestException} from '@nestjs/common'; | ||
|
||
describe('User Controller', () => { | ||
const mockUserService = mock(UserServiceImpl); | ||
const address = 'testAddress'; | ||
const name = 'name'; | ||
let user: User; | ||
let controller: UserController; | ||
|
||
beforeEach(() => { | ||
user = new User(address, name); | ||
}); | ||
|
||
describe('dependency resolve', () => { | ||
it('should be defined', async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [ | ||
UserController, | ||
], | ||
providers: [ | ||
{ | ||
provide: 'UserService', | ||
useValue: instance(mockUserService), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
controller = module.get<UserController>(UserController); | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); | ||
describe('#get()', () => { | ||
const id = 1; | ||
|
||
it('should return user', async () => { | ||
when(mockUserService.get(id)).thenReturn(new Promise((resolve) => { | ||
resolve(user); | ||
})); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
expect(await controller.get(id)).toBe(user); | ||
|
||
}); | ||
it('should return undefined', async () => { | ||
when(mockUserService.get(id)).thenThrow(new BadRequestException('no user with the id')); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
await expect(controller.get(id)) | ||
.rejects | ||
.toThrowError(BadRequestException); | ||
}); | ||
}); | ||
describe('#create()', () => { | ||
let userDto: UserDto; | ||
|
||
it('should return user', async () => { | ||
userDto = new UserDto(address, name); | ||
when(mockUserService.create(userDto)).thenReturn(new Promise((resolve => { | ||
resolve(user); | ||
}))); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
expect(await controller.create(userDto)).toBe(user); | ||
|
||
}); | ||
it('should return undefined', async () => { | ||
userDto = new UserDto(); | ||
when(mockUserService.create(userDto)).thenThrow(new Error('some errors')); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
await expect(controller.create(userDto)) | ||
.rejects | ||
.toThrowError('some errors'); | ||
}); | ||
}); | ||
describe('#delete()', () => { | ||
const id = 1; | ||
|
||
it('should return undefined', async () => { | ||
when(mockUserService.delete(id)).thenReturn(new Promise((resolve => resolve(undefined)))); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
expect(await controller.delete(id)).toBe(undefined); | ||
}); | ||
}); | ||
describe('#increaseLevel()', () => { | ||
const id = 1; | ||
const amount = 10; | ||
|
||
it('should return user', async () => { | ||
when(mockUserService.increaseLevel(id, amount)).thenReturn(new Promise((resolve => resolve(user)))); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
expect(await controller.increaseLevel(id, {amount})).toBe(user); | ||
}); | ||
it('should throw error', async () => { | ||
when(mockUserService.increaseLevel(id, amount)).thenThrow(new Error('some errors')); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
await expect(controller.increaseLevel(id, {amount})) | ||
.rejects | ||
.toThrowError('some errors'); | ||
}); | ||
}); | ||
describe('#increasePoint()', () => { | ||
const id = 1; | ||
const amount = 10; | ||
|
||
it('should return user', async () => { | ||
when(mockUserService.increasePoint(id, amount)).thenReturn(new Promise((resolve => resolve(user)))); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
expect(await controller.increasePoint(id, {amount})).toBe(user); | ||
}); | ||
it('should throw error', async () => { | ||
when(mockUserService.increasePoint(id, amount)).thenThrow(new Error('some errors')); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
await expect(controller.increasePoint(id, {amount})) | ||
.rejects | ||
.toThrowError('some errors'); | ||
}); | ||
}); | ||
describe('#decreasePoint()', () => { | ||
const id = 1; | ||
const amount = 10; | ||
|
||
it('should return user', async () => { | ||
when(mockUserService.decreasePoint(id, amount)).thenReturn(new Promise((resolve => resolve(user)))); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
expect(await controller.decreasePoint(id, {amount})).toBe(user); | ||
}); | ||
it('should throw error', async () => { | ||
when(mockUserService.decreasePoint(id, amount)).thenThrow(new Error('some errors')); | ||
controller = new UserController(instance(mockUserService)); | ||
|
||
await expect(controller.decreasePoint(id, {amount})) | ||
.rejects | ||
.toThrowError('some errors'); | ||
}); | ||
}); | ||
}); |
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,46 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Inject, | ||
Injectable, | ||
Param, | ||
Post, Put, | ||
Query, | ||
} from '@nestjs/common'; | ||
import {User} from '../../domain/user/user.entity'; | ||
import {UserDto} from '../../app/user/dto/user.dto'; | ||
import {DeleteResult} from 'typeorm'; | ||
import {UserService} from '../../app/user/user.service'; | ||
|
||
@Injectable() | ||
@Controller('users') | ||
export class UserController { | ||
constructor(@Inject('UserService') private service: UserService) {} | ||
|
||
@Get(':id') | ||
async get(@Param('id') id: number): Promise<User> { | ||
return await this.service.get(id); | ||
} | ||
@Post() | ||
async create(@Body() userDto: UserDto): Promise<User> { | ||
return await this.service.create(userDto); | ||
} | ||
@Delete(':id') | ||
async delete(@Param('id') id: number): Promise<DeleteResult> { | ||
return await this.service.delete(id); | ||
} | ||
@Put(':id/increase-level') | ||
async increaseLevel(@Param('id') id: number, @Query() query): Promise<User> { | ||
return await this.service.increaseLevel(id, query.amount); | ||
} | ||
@Put(':id/increase-point') | ||
async increasePoint(@Param('id') id: number, @Query() query): Promise<User> { | ||
return await this.service.increasePoint(id, query.amount); | ||
} | ||
@Put(':id/decrease-point') | ||
async decreasePoint(@Param('id') id: number, @Query() query): Promise<User> { | ||
return await this.service.decreasePoint(id, query.amount); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need Comment: @junbeomlee
not sure http method and url is good.
i referenced: github-api
PUT /repos/:owner/:repo/pulls/:pull_number/update-branch
it was using verb in url