-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(task): implement task functionality
-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
Showing
34 changed files
with
1,726 additions
and
23 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,9 @@ | ||
PORT = | ||
DB_NAME = | ||
APP_URL = | ||
JWT_SECRET = | ||
EMAIL = | ||
EMAIL_PASS = | ||
MONGO_INITDB_ROOT_USERNAME = | ||
MONGO_INITDB_ROOT_PASSWORD = | ||
MONGO_URL = |
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,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? |
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,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'); | ||
}) | ||
}) |
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,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'); | ||
}) | ||
}) |
Oops, something went wrong.