Skip to content

Commit

Permalink
add int test
Browse files Browse the repository at this point in the history
  • Loading branch information
4H1R committed Aug 24, 2022
1 parent 5f380ee commit 60a5c1f
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 59 deletions.
10 changes: 9 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
version: '3.8'
services:
database:
dev-db:
image: postgres:13
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
test-db:
image: postgres:13
ports:
- 5435:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
12 changes: 12 additions & 0 deletions jest-int.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".int-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"src/(.*)": "<rootDir>/src/$1"
}
}
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:int": "jest -i --no-cache --watch --config ./jest-int.json"
},
"dependencies": {
"@nestjs/common": "^9.0.11",
Expand Down Expand Up @@ -91,4 +92,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}
2 changes: 1 addition & 1 deletion prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as bcrypt from 'bcrypt';
const prisma = new PrismaClient();

const user = async () => ({
name: faker.name.findName(),
name: faker.name.fullName(),
email: faker.unique(faker.internet.email).toLowerCase(),
password: await bcrypt.hash('password', 10),
emailVerifiedAt: faker.datatype.boolean() ? new Date() : null,
Expand Down
7 changes: 7 additions & 0 deletions src/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ export class PrismaService
async onModuleDestroy() {
await this.$disconnect();
}

async cleanDatabase() {
if (process.env.NODE_ENV === 'production') return;
const models = Reflect.ownKeys(this).filter((key) => key[0] !== '_');

return Promise.all(models.map((modelKey) => this[modelKey].deleteMany()));
}
}
24 changes: 0 additions & 24 deletions test/app.e2e-spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
}

0 comments on commit 60a5c1f

Please sign in to comment.