-
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.
feat:impl ghost auction item controller [ISSUE-76]
- Loading branch information
1 parent
57e15f4
commit 08f7bdc
Showing
10 changed files
with
391 additions
and
22 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
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,67 @@ | ||
import {AuctionService} from '../../app/auction/auction.service'; | ||
import {instance, mock, when} from 'ts-mockito'; | ||
import {AuctionController} from './auction.controller'; | ||
import {Auction, AuctionType} from '../../domain/auction/auction.entity'; | ||
import {Test, TestingModule} from '@nestjs/testing'; | ||
|
||
describe('Auction Controller', () => { | ||
const mockAuctionService = mock(AuctionService); | ||
let controller: AuctionController; | ||
let saleAuction: Auction; | ||
let specialAuction: Auction; | ||
|
||
beforeEach(() => { | ||
saleAuction = new Auction( | ||
'AA239BE27', | ||
'user1', | ||
60, | ||
AuctionType.SALE_AUCTION, | ||
'user3', | ||
2000, | ||
); | ||
|
||
specialAuction = new Auction( | ||
'EB2820AC1', | ||
'user2', | ||
120, | ||
AuctionType.SPECIAL_AUCTION, | ||
); | ||
}); | ||
|
||
describe('dependency resolve', () => { | ||
it('should be defined', async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AuctionController], | ||
providers: [{ | ||
provide: 'AuctionService', | ||
useValue: instance(mockAuctionService), | ||
}], | ||
}).compile(); | ||
|
||
controller = module.get<AuctionController>(AuctionController); | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('#findOne()', () => { | ||
it('should find one auction', async () => { | ||
when(mockAuctionService.findOne(1)).thenReturn(new Promise((resolve) => { | ||
resolve(saleAuction); | ||
})); | ||
controller = new AuctionController(instance(mockAuctionService)); | ||
|
||
expect(await controller.findOne(1)).toBe(saleAuction); | ||
}); | ||
}); | ||
|
||
describe('#findOneByGene()', () => { | ||
it('should find one auction by gene', async () => { | ||
when(mockAuctionService.findOneByGene('AA239BE27')).thenReturn(new Promise((resolve) => { | ||
resolve(saleAuction); | ||
})); | ||
controller = new AuctionController(instance(mockAuctionService)); | ||
|
||
expect(await controller.findOneByGene('AA239BE27')).toBe(saleAuction); | ||
}); | ||
}); | ||
}); |
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,19 @@ | ||
import {Controller, Get, Inject, Injectable, Param, Query} from '@nestjs/common'; | ||
import {AuctionService} from '../../app/auction/auction.service'; | ||
import {Auction} from '../../domain/auction/auction.entity'; | ||
|
||
@Injectable() | ||
@Controller('auction') | ||
export class AuctionController { | ||
constructor(@Inject('AuctionService') private service: AuctionService) {} | ||
|
||
@Get(':id') | ||
async findOne(@Param('id') id: number): Promise<Auction> { | ||
return await this.service.findOne(id); | ||
} | ||
|
||
@Get() | ||
async findOneByGene(@Query('gene') gene): Promise<Auction> { | ||
return await this.service.findOneByGene(gene); | ||
} | ||
} |
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,18 +1,79 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { GhostController } from './ghost.controller'; | ||
import {instance, mock, when} from 'ts-mockito'; | ||
import {GhostService} from '../../app/ghost/ghost.service'; | ||
import {Ghost} from '../../domain/ghost/ghost.entity'; | ||
|
||
describe('Ghost Controller', () => { | ||
const mockGhostService = mock(GhostService); | ||
let ghost: Ghost; | ||
let controller: GhostController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [GhostController], | ||
}).compile(); | ||
beforeEach(() => { | ||
ghost = new Ghost( | ||
'EE398A811', | ||
0, | ||
'user1', | ||
); | ||
}); | ||
|
||
describe('dependency resolve', () => { | ||
it('should be defined', async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [GhostController], | ||
providers: [{ | ||
provide: 'GhostService', | ||
useValue: instance(mockGhostService), | ||
}], | ||
}).compile(); | ||
|
||
controller = module.get<GhostController>(GhostController); | ||
controller = module.get<GhostController>(GhostController); | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
describe('#findOne()', () => { | ||
it('should find one ghost', async () => { | ||
when(mockGhostService.findOne(1)).thenReturn(new Promise((resolve) => { | ||
resolve(ghost); | ||
})); | ||
controller = new GhostController(instance(mockGhostService)); | ||
|
||
expect(await controller.findOne(1)).toBe(ghost); | ||
}); | ||
}); | ||
|
||
describe('#findOneByGene', () => { | ||
it('should find one ghost by gene', async () => { | ||
when(mockGhostService.findOneByGene('EE398A811')).thenReturn(new Promise((resolve) => { | ||
resolve(ghost); | ||
})); | ||
controller = new GhostController(instance(mockGhostService)); | ||
|
||
expect(await controller.findOneByGene('EE398A811')).toBe(ghost); | ||
}); | ||
}); | ||
|
||
describe('#findAllByUser()', () => { | ||
it('should find ghosts by ID of user', async () => { | ||
when(mockGhostService.findAllByUser('user1')).thenReturn(new Promise((resolve) => { | ||
resolve([ghost]); | ||
})); | ||
controller = new GhostController(instance(mockGhostService)); | ||
|
||
expect(await controller.findAllByUser('user1')).toEqual([ghost]); | ||
}); | ||
}); | ||
|
||
describe('#findAll()', () => { | ||
it('should find page 1 ghosts', async () => { | ||
|
||
when(mockGhostService.findAll(1)).thenReturn(new Promise((resolve) => { | ||
resolve([ghost]); | ||
})); | ||
controller = new GhostController(instance(mockGhostService)); | ||
|
||
expect(await controller.findAll(1)).toEqual([ghost]); | ||
}); | ||
}); | ||
}); |
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,29 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import {Controller, Get, Inject, Injectable, Param, Query} from '@nestjs/common'; | ||
import {Ghost} from '../../domain/ghost/ghost.entity'; | ||
import {GhostService} from '../../app/ghost/ghost.service'; | ||
|
||
@Injectable() | ||
@Controller('ghost') | ||
export class GhostController {} | ||
export class GhostController { | ||
constructor(@Inject('GhostService') private service: GhostService) {} | ||
|
||
@Get(':id') | ||
async findOne(@Param('id') id: number): Promise<Ghost> { | ||
return await this.service.findOne(id); | ||
} | ||
|
||
@Get() | ||
async findOneByGene(@Query('gene') gene): Promise<Ghost> { | ||
return await this.service.findOneByGene(gene); | ||
} | ||
|
||
@Get() | ||
async findAllByUser(@Query('userId') userId): Promise<Ghost[]> { | ||
return await this.service.findAllByUser(userId); | ||
} | ||
|
||
@Get(':page') | ||
async findAll(@Param('page') page: number): Promise<Ghost[]> { | ||
return await this.service.findAll(page); | ||
} | ||
} |
Oops, something went wrong.