-
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
6 changed files
with
151 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3.3' | ||
|
||
services: | ||
db: | ||
image: postgres | ||
restart: always | ||
environment: | ||
POSTGRES_USER: test | ||
POSTGRES_DB: hatchout | ||
POSTGRES_PASSWORD: test | ||
ports: | ||
- 5432:5432 |
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,131 @@ | ||
import {INestApplication} from '@nestjs/common'; | ||
import {Test} from '@nestjs/testing'; | ||
import request from 'supertest'; | ||
import {UserModule} from '../../src/port/module/user.module'; | ||
import {User} from '../../src/domain/user/user.entity'; | ||
import {DatabaseModule} from '../../src/port/module/database.module'; | ||
import {ConfigModule, ConfigService} from 'nestjs-config'; | ||
import * as path from 'path'; | ||
|
||
describe('User', () => { | ||
let app: INestApplication; | ||
|
||
beforeAll(async () => { | ||
ConfigService.rootPath = path.resolve(__dirname, '../../src'); | ||
const module = await Test.createTestingModule({ | ||
imports: [ | ||
ConfigModule.resolveRootPath(__dirname).load('config/**/!(*.d).{ts,js}'), | ||
UserModule, | ||
DatabaseModule, | ||
], | ||
}) | ||
.compile(); | ||
|
||
app = module.createNestApplication(); | ||
await app.init(); | ||
|
||
}); | ||
|
||
afterAll(async () => await app.close()); | ||
|
||
describe('#create()', () => { | ||
const url = '/users'; | ||
let response; | ||
it('should return 201', async () => { | ||
response = { address: 'testAddress', name: 'testName', point: 0, level: 0, id: 1}; | ||
|
||
return request(app.getHttpServer()) | ||
.post(url) | ||
.send({ | ||
address: 'testAddress', | ||
name: 'testName', | ||
}) | ||
.expect(201) | ||
.expect(response); | ||
|
||
}); | ||
it('should return 500 without address', async () => { | ||
|
||
return request(app.getHttpServer()) | ||
.post(url) | ||
.send({ | ||
name: 'testName', | ||
}) | ||
.expect(500) | ||
.expect({ | ||
statusCode: 500, | ||
message: 'Internal server error', | ||
}); | ||
|
||
}); | ||
it('should return 500 without name', async () => { | ||
|
||
return request(app.getHttpServer()) | ||
.post(url) | ||
.send({ | ||
address: 'testAddress', | ||
}) | ||
.expect(500) | ||
.expect({ statusCode: 500, message: 'Internal server error' }); | ||
|
||
}); | ||
}); | ||
|
||
describe('#get()', () => { | ||
let url: string; | ||
let response; | ||
|
||
it('should return 200', async () => { | ||
url = '/users/1'; | ||
response = { address: 'testAddress', name: 'testName', point: 0, level: 0, id: 1 }; | ||
|
||
return request(app.getHttpServer()) | ||
.get(url) | ||
.expect(200) | ||
.expect(response); | ||
}); | ||
it('should return 400', async () => { | ||
url = '/users/2'; | ||
response = { statusCode: 400, error: 'Bad Request', message: 'no user with the id' }; | ||
|
||
return request(app.getHttpServer()) | ||
.get(url) | ||
.expect(400) | ||
.expect(response); | ||
}); | ||
}); | ||
describe('#increaseLevel', () => { | ||
let url: string; | ||
let response; | ||
|
||
it('should return 200', async () => { | ||
url = '/users/1/increase-level?amount=1'; | ||
response = { address: 'testAddress', name: 'testName', point: 0, level: 1, id: 1 }; | ||
|
||
return request(app.getHttpServer()) | ||
.put(url) | ||
.expect(200) | ||
.expect(response); | ||
}); | ||
}); | ||
|
||
describe('#delete()', () => { | ||
let url: string; | ||
it('should return 200 and affected 1', async () => { | ||
url = '/users/1'; | ||
|
||
return request(app.getHttpServer()) | ||
.delete(url) | ||
.expect(200) | ||
.expect({ raw: [], affected: 1 }); | ||
}); | ||
it('should return 200 but affected 0', async () => { | ||
url = '/users/2'; | ||
|
||
return request(app.getHttpServer()) | ||
.delete(url) | ||
.expect(200) | ||
.expect({ raw: [], affected: 0 }); | ||
}); | ||
}); | ||
}); |