Skip to content

Commit

Permalink
feat(task): implement task functionality
Browse files Browse the repository at this point in the history
-implement crud operations on task
-implement crud operations on label
-implement crud operations on board
-implement crud operations on category

[Delivers #3]
  • Loading branch information
jkarenzi committed Jun 21, 2024
1 parent 2f0d641 commit d237a6d
Show file tree
Hide file tree
Showing 34 changed files with 1,726 additions and 23 deletions.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PORT =
DB_NAME =
APP_URL =
JWT_SECRET =
EMAIL =
EMAIL_PASS =
MONGO_INITDB_ROOT_USERNAME =
MONGO_INITDB_ROOT_PASSWORD =
MONGO_URL =
12 changes: 6 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
**what does this PR do?**
### What does this PR do?

**Description of the task to be completed**
### Description of the task to be completed

**How can this be manually tested?**
### How can this be manually tested?

**Swagger documentation screenshot**
### Swagger documentation screenshot

**Test screenshot**
### Test screenshot

**What are the relevant pivotal trackers/story id?**
### What are the relevant pivotal trackers/story id?
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ To get started with the TaskMaster API, follow these simple steps:
npm run dev
```


## Testing

- Run tests
Expand All @@ -47,6 +48,24 @@ To get started with the TaskMaster API, follow these simple steps:
npm run test:ci
```

## Docker

- Run in docker container
```bash
docker-compose -f docker-compose.yml up
```

- Stop the container
```bash
docker-compose -f docker-compose.yml down
```

- Run tests in docker container

```bash
docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from test
```

## Usage

Once the development server is running, you can interact with the API using HTTP requests.
Expand Down
121 changes: 121 additions & 0 deletions __tests__/boardController.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
export {};
const request = require('supertest');
const app = require('../src/app');
require('dotenv').config()
const sendEmail = require('../src/utils/sendEmail')


const {connectDB, disconnectDB, getToken} = require('./testSetup')

beforeAll(connectDB)
afterAll(disconnectDB)

jest.mock('../src/utils/sendEmail')

describe('Board Controller tests', () => {
let boardId:string;
let token:string;

const createBoardFormData = {
name:'WEEK 1 BOARD',
description:'my week 1 tasks'
}

const updateBoardFormData = {
name:'WEEK 2 BOARD',
description:'my week 1 tasks'
}

const failedValidationFormData = {
theContent: 5
}

const signUpFormData = {
fullName:'test test test',
email:'[email protected]',
password:'testing123456'
}

const loginFormData = {
email:'[email protected]',
password:'testing123456'
}

beforeAll(async() => {
token = await getToken()
})

sendEmail.mockImplementationOnce(() => Promise.resolve({response:'ok'}))

it('should create a new board successfully', async() => {
const response = await request(app).post('/api/boards').send(createBoardFormData).set('Authorization', `Bearer ${token}`)
boardId = response.body.data._id
expect(response.status).toBe(201);
expect(response.body.message).toBe('Board created successfully');
})

it('should return a 409 for duplicate board name upon creation', async() => {
const response = await request(app).post('/api/boards').send(createBoardFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(409);
expect(response.body.message).toBe('Board already exists');
})

it('should return a 400 for failed validation upon creating new board', async() => {
const response = await request(app).post('/api/boards').send(failedValidationFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(400);
expect(response.body.message).toBeDefined()
})

it('should get all boards successfully', async() => {
const response = await request(app).get('/api/boards').set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(200);
expect(response.body.data).toBeDefined();
})

it('should update existing board successfully', async() => {
const response = await request(app).patch(`/api/boards/${boardId}`).send(updateBoardFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(200);
expect(response.body.data).toBeDefined()
})

it('should return a 409 for duplicate board name upon updation', async() => {
const createBoardData = {
name:'WEEK 3 BOARD',
description:'my week 1 tasks'
}

const createResponse = await request(app).post('/api/boards').send(createBoardData).set('Authorization', `Bearer ${token}`)

const response = await request(app).patch(`/api/boards/${createResponse.body.data._id}`).send(updateBoardFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(409);
expect(response.body.message).toBe('Board already exists');
})

it('should return a 400 for failed validation upon updation', async() => {
const response = await request(app).patch(`/api/boards/${boardId}`).send(failedValidationFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(400);
expect(response.body.message).toBeDefined()
})

it('should return a 409 if board is not found or does not belong to currently logged in user upon updation', async () => {
await request(app).post('/api/auth/signup').send(signUpFormData);
const loginResponse = await request(app).post('/api/auth/login').send(loginFormData);
const createResponse = await request(app).post('/api/boards').send(createBoardFormData).set('Authorization', `Bearer ${loginResponse.body.token}`)
const response = await request(app).patch(`/api/boards/${createResponse.body.data._id}`).send(updateBoardFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(409);
expect(response.body.message).toBe('Board not found or does not belong to currently logged in user');
})

it('should delete board successfully', async () => {
const response = await request(app).delete(`/api/boards/${boardId}`).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(204);
})

it('should return a 409 if board is not found or does not belong to currently logged in user upon deletion', async () => {
const loginResponse = await request(app).post('/api/auth/login').send(loginFormData);
const createResponse = await request(app).post('/api/boards').send({name:'my board'}).set('Authorization', `Bearer ${loginResponse.body.token}`)
const response = await request(app).delete(`/api/boards/${createResponse.body.data._id}`).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(409);
expect(response.body.message).toBe('Board not found or does not belong to currently logged in user');
})
})
144 changes: 144 additions & 0 deletions __tests__/categoryController.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
export {};
const request = require('supertest');
const app = require('../src/app');
require('dotenv').config()
const sendEmail = require('../src/utils/sendEmail')

const {connectDB, disconnectDB, getToken} = require('./testSetup')

beforeAll(connectDB)
afterAll(disconnectDB)

jest.mock('../src/utils/sendEmail')

describe('Category Controller tests', () => {
let boardId:string;
let categoryId:string;
let token:string;

const createBoardFormData = {
name:'WEEK 1 BOARD',
description:'my week 1 tasks'
}

const updateCategoryFormData = {
name:'Doing'
}

const failedValidationFormData = {
theContent: 5
}

const signUpFormData = {
fullName:'test test test',
email:'[email protected]',
password:'testing123456'
}

const loginFormData = {
email:'[email protected]',
password:'testing123456'
}

beforeAll(async() => {
token = await getToken()
})

sendEmail.mockImplementationOnce(() => Promise.resolve({response:'ok'}))

it('should create a new category successfully', async() => {
const boardResponse = await request(app).post('/api/boards').send(createBoardFormData).set('Authorization', `Bearer ${token}`)
boardId = boardResponse.body.data._id

const createCategoryFormData = {
name:'To do',
boardId
}

const response = await request(app).post('/api/categories').send(createCategoryFormData).set('Authorization', `Bearer ${token}`)
categoryId = response.body.data._id
expect(response.status).toBe(201);
expect(response.body.message).toBe('Category created successfully');
})

it('should return a 409 for duplicate category name', async() => {
const createCategoryFormData = {
name:'To do',
boardId
}

const response = await request(app).post('/api/categories').send(createCategoryFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(409);
expect(response.body.message).toBe('Category already exists');
})

it('should return a 400 for failed validation upon creating new category', async() => {
const response = await request(app).post('/api/categories').send(failedValidationFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(400);
expect(response.body.message).toBeDefined()
})

it('should get all categories successfully', async() => {
const response = await request(app).get(`/api/categories/${boardId}`).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(200);
expect(response.body.data).toBeDefined();
})

it('should update existing category successfully', async() => {
const response = await request(app).patch(`/api/categories/${categoryId}`).send(updateCategoryFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(200);
expect(response.body.data).toBeDefined()
})

it('should return a 409 for duplicate category name upon updation', async() => {
const createCategoryFormData = {
name:'TEST',
boardId
}

const categoryResponse = await request(app).post('/api/categories').send(createCategoryFormData).set('Authorization', `Bearer ${token}`)
const response = await request(app).patch(`/api/categories/${categoryResponse.body.data._id}`).send(updateCategoryFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(409);
expect(response.body.message).toBe('Category already exists');
})

it('should return a 400 for failed validation upon updation', async() => {
const response = await request(app).patch(`/api/categories/${categoryId}`).send(failedValidationFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(400);
expect(response.body.message).toBeDefined()
})

it('should return a 409 if category is not found or does not belong to currently logged in user upon updation', async () => {
await request(app).post('/api/auth/signup').send(signUpFormData);
const loginResponse = await request(app).post('/api/auth/login').send(loginFormData);
const boardResponse = await request(app).post('/api/boards').send(createBoardFormData).set('Authorization', `Bearer ${loginResponse.body.token}`)
const createCategoryFormData = {
name:'To do',
boardId: boardResponse.body.data._id
}

const createResponse = await request(app).post('/api/categories').send(createCategoryFormData).set('Authorization', `Bearer ${loginResponse.body.token}`)
const response = await request(app).patch(`/api/categories/${createResponse.body.data._id}`).send(updateCategoryFormData).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(409);
expect(response.body.message).toBe('Category not found or does not belong to currently logged in user');
})

it('should delete category successfully', async () => {
const response = await request(app).delete(`/api/categories/${categoryId}`).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(204);
})

it('should return a 409 if category is not found or does not belong to currently logged in user upon deletion', async () => {
const loginResponse = await request(app).post('/api/auth/login').send(loginFormData);
const boardResponse = await request(app).post('/api/boards').send({name:'my board'}).set('Authorization', `Bearer ${token}`)
const createCategoryFormData = {
name:'To do list',
boardId: boardResponse.body.data._id
}

const createResponse = await request(app).post('/api/categories').send(createCategoryFormData).set('Authorization', `Bearer ${loginResponse.body.token}`)
const response = await request(app).delete(`/api/categories/${createResponse.body.data._id}`).set('Authorization', `Bearer ${token}`)
expect(response.status).toBe(409);
expect(response.body.message).toBe('Category not found or does not belong to currently logged in user');
})
})
Loading

0 comments on commit d237a6d

Please sign in to comment.