-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
240 additions
and
37 deletions.
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); | ||
} | ||
} |