Skip to content
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

e2e tests and config initial setup #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
APP_ENV=development
DATABASE_URL="file:./dev.db"
47 changes: 45 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
"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 --runInBand --config ./test/jest-e2e.json --verbose --passWithNoTests --detectOpenHandles",
"migrate": "prisma migrate dev"
},
"dependencies": {
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.3.4",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@prisma/client": "^4.15.0",
Expand Down
7 changes: 7 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Module, ValidationPipe } from '@nestjs/common';
import { APP_PIPE } from '@nestjs/core';
import { CardsModule } from './cards/cards.module';
import { ConfigModule } from '@nestjs/config';
import configs from './configs';

@Module({
imports: [
CardsModule,
ConfigModule.forRoot({
load: configs,
envFilePath: '.env',
isGlobal: true,
}),
],
providers: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/cards/cards.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { CardsController } from './cards.controller';
import { CardsService } from './cards.service';
import { PrismaModule } from 'prisma/prisma.module';
import { PrismaModule } from './../../prisma/prisma.module';

@Module({
controllers: [CardsController],
Expand Down
2 changes: 1 addition & 1 deletion src/cards/cards.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { CreateCardDto } from './dtos/create-card.dto';
import { CardType } from './cards.enum';
import { PrismaService } from 'prisma/prisma.service';
import { PrismaService } from './../../prisma/prisma.service';
import {
BugCard as BugCardModel,
IssueCard as IssueCardModel,
Expand Down
8 changes: 8 additions & 0 deletions src/configs/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerAs } from "@nestjs/config";

export default registerAs(
'app',
(): Record<string, any> => ({
env: process.env.APP_ENV || 'development',
})
);
5 changes: 5 additions & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import AppConfig from './app.config';

export default [
AppConfig
]
24 changes: 0 additions & 24 deletions test/app.e2e-spec.ts

This file was deleted.

221 changes: 221 additions & 0 deletions test/cards.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from '../src/app.module';

describe('Cards API Test', () => {
let app: INestApplication;

beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
})

const issueCard = {
"type": "issue",
"title": "Test Issue Title",
"description": "Test Issue Description"
};

const taskCard = {
"type": "task",
"title": "Test Task Title",
"category": "test"
};

const bugCard = {
"type": "bug",
"description": "Test Bug Description"
};

it('Create a new IssueCard', () => {
const card = issueCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
expect(res.body).toHaveProperty('title');
expect(res.body).toHaveProperty('description');
const { title, description } = res.body;
expect(title).toBe(card.title);
expect(description).toBe(card.description);
});
});

it('Get all IssueCards', () => {
return request(app.getHttpServer())
.get('/trello-manager/issue')
.expect(200)
.then((res) => {
expect(res.body).toBeInstanceOf(Array);
});
});

it('Get a IssueCard', () => {
const card = issueCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
const { id } = res.body;
return request(app.getHttpServer())
.get(`/trello-manager/issue/${id}`)
.expect(200)
.then((res) => {
expect(res.body).toHaveProperty('id');
expect(res.body).toHaveProperty('title');
expect(res.body).toHaveProperty('description');
const { title, description } = res.body;
expect(title).toBe(card.title);
expect(description).toBe(card.description);
});
});
});

it('Delete a IssueCard', () => {
const card = issueCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
const { id } = res.body;
return request(app.getHttpServer())
.delete(`/trello-manager/issue/${id}`)
.expect(200);
});
});

it('Create a new TaskCard', () => {
const card = taskCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
expect(res.body).toHaveProperty('title');
expect(res.body).toHaveProperty('category');
const { title, category } = res.body;
expect(title).toBe(card.title);
expect(category).toBe(card.category);
});
});

it('Get all TaskCards', () => {
return request(app.getHttpServer())
.get('/trello-manager/task')
.expect(200)
.then((res) => {
expect(res.body).toBeInstanceOf(Array);
});
});

it('Get a TaskCard', () => {
const card = taskCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
const { id } = res.body;
return request(app.getHttpServer())
.get(`/trello-manager/task/${id}`)
.expect(200)
.then((res) => {
expect(res.body).toHaveProperty('id');
expect(res.body).toHaveProperty('title');
expect(res.body).toHaveProperty('category');
const { title, category } = res.body;
expect(title).toBe(card.title);
expect(category).toBe(card.category);
});
});
});

it('Delete a TaskCard', () => {
const card = taskCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
const { id } = res.body;
return request(app.getHttpServer())
.delete(`/trello-manager/task/${id}`)
.expect(200);
});
});

it('Create a new BugCard', () => {
const card = bugCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
expect(res.body).toHaveProperty('title');
expect(res.body).toHaveProperty('description');
const { description } = res.body;
expect(description).toBe(card.description);
});
});

it('Get all BugCards', () => {
return request(app.getHttpServer())
.get('/trello-manager/bug')
.expect(200)
.then((res) => {
expect(res.body).toBeInstanceOf(Array);
});
});

it('Get a BugCard', () => {
const card = bugCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
const { id } = res.body;
return request(app.getHttpServer())
.get(`/trello-manager/bug/${id}`)
.expect(200)
.then((res) => {
expect(res.body).toHaveProperty('id');
expect(res.body).toHaveProperty('title');
expect(res.body).toHaveProperty('description');
const { description } = res.body;
expect(description).toBe(card.description);
});
});
});

it('Delete a BugCard', () => {
const card = bugCard;
return request(app.getHttpServer())
.post('/trello-manager')
.send(card)
.expect(201)
.then((res) => {
expect(res.body).toHaveProperty('id');
const { id } = res.body;
return request(app.getHttpServer())
.delete(`/trello-manager/bug/${id}`)
.expect(200);
});
});
});
Loading