Skip to content

Commit a24b132

Browse files
authored
Merge pull request #394 from Real-Dev-Squad/develop
develop to main sync
2 parents 4c555b3 + c63b90b commit a24b132

File tree

6 files changed

+41
-24
lines changed

6 files changed

+41
-24
lines changed

CONTRIBUTING.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Contributing to Real Dev Squad API
32

43
- [Getting Started](#getting-started)
@@ -25,19 +24,22 @@ The script associated with `npm run test` will run all tests that ensures that y
2524
repository. This will run the lint, integration and unit tests.
2625

2726
##### `npm run lint`
27+
2828
Runs the lint checks in the project.
2929

3030
##### `npm run generate-api-schema`
31+
3132
Generates the API schema in the file `public/apiSchema.json`.
3233

3334
##### `npm run validate-setup`
34-
Runs the test for checking local development setup is working properly or not.
3535

36+
Runs the test for checking local development setup is working properly or not.
3637

3738
## Project Structure
39+
3840
The following project structure should be followed:
3941

40-
``` shell script
42+
```shell script
4143
|-- website-backend
4244
|-- config
4345
| |-- custom-environment-variables.js
@@ -89,6 +91,7 @@ The following project structure should be followed:
8991
```
9092
9193
## Generating Authentication Token
94+
9295
- Run the project locally, make sure the server is listening to requests
9396
- Navigate to `https://github.com/login/oauth/authorize?client_id=<GITHUB_CLIENT_ID>`
9497
- Authorize the application
@@ -97,8 +100,8 @@ The following project structure should be followed:
97100
- For non-production environments, authentication is also supported with the `Authorization` header.
98101
- Authorization header: `Authorization: Bearer <token>`
99102
100-
101103
## Testing Guidelines
104+
102105
- Libraries used in testing in the project:
103106
- [mocha](https://mochajs.org/): Test framework
104107
- [chai](https://www.chaijs.com/): Assertion library
@@ -110,6 +113,7 @@ The following project structure should be followed:
110113
- Java version 1.8 or higher.
111114
112115
## Using Firebase Emulator Locally
116+
113117
- [Firebase Local Emulator Suite](https://firebase.google.com/docs/emulator-suite) can be used locally as the DB for the project
114118
- Pre-requisites:
115119
- Node.js version 8.0 or higher.
@@ -119,15 +123,18 @@ The following project structure should be followed:
119123
- [Future] You can view the emulator UI at: `http://localhost:4000`
120124
121125
## Running test scripts on Windows
126+
122127
- Git Bash is recommended for running test scripts on Windows.
123128
- Run `npm run test-integration` for running integration tests.
124129
- Run `npm run test-unit` for running unit tests.
125-
- Make sure to close the emulator window after running the tests in order to avoid the blocking of the port for the next tests to run.
130+
- Make sure the server is not running.
131+
- Make sure to close the emulator window after running the tests in order to avoid the blocking of the port for the next tests to run.
126132
- For e.g - After running the integration tests, close the emulator window and then run the command for unit tests.
127133
128134
## Pull request guidelines
135+
129136
- Ensure that the tests pass locally before raising a PR.
130137
- All pull requests should have base as the develop branch.
131138
- Every pull request should have associated issue(s) on our [issue tracker](https://github.com/Real-Dev-Squad/website-backend/issues).
132139
- For any non-trivial fixes and features, unit and integration tests must be added. The PR reviewer should not approve/merge PR(s) that lack these.
133-
- The PR(s) should be merged only after the CI passes.
140+
- The PR(s) should be merged only after the CI passes.

constants/tasks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const TASK_STATUS = {
88
ACTIVE: 'active',
99
ASSIGNED: 'assigned',
1010
BLOCKED: 'blocked',
11-
COMPLETED: 'completed'
11+
COMPLETED: 'completed',
12+
UNASSIGNED: 'unAssigned'
1213
}
1314

1415
module.exports = { TASK_TYPE, TASK_STATUS }

controllers/tasks.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const tasks = require('../models/tasks')
2+
const { TASK_STATUS } = require('../constants/tasks')
23
/**
34
* Creates new task
45
*
@@ -52,8 +53,15 @@ const fetchTasks = async (req, res) => {
5253
*/
5354
const getUserTasks = async (req, res) => {
5455
try {
56+
const { status } = req.query
5557
const { username } = req.params
56-
const allTasks = await tasks.fetchUserTasks(username)
58+
let allTasks = []
59+
60+
if (!Object.values(TASK_STATUS).includes(status)) {
61+
return res.boom.notFound('Status not found!')
62+
}
63+
64+
allTasks = await tasks.fetchUserTasks(username, status ? [status] : [])
5765

5866
if (allTasks.userNotFound) {
5967
return res.boom.notFound('User doesn\'t exist')

package-lock.json

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/tasks.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('Tasks', function () {
173173
title: 'Assigned task',
174174
purpose: 'To Test mocha',
175175
featureUrl: '<testUrl>',
176-
type: 'Dev | Group',
176+
type: 'group',
177177
links: [
178178
'test1'
179179
],
@@ -185,11 +185,10 @@ describe('Tasks', function () {
185185
'd12',
186186
'd23'
187187
],
188-
participants: [appOwner.username],
188+
participants: ['user1'],
189189
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
190190
lossRate: { [DINERO]: 1 },
191-
isNoteworthy: true,
192-
assignee: 'user1'
191+
isNoteworthy: true
193192
}
194193
const { taskId } = await tasks.updateTask(assignedTask)
195194
const res = await chai
@@ -261,7 +260,7 @@ describe('Tasks', function () {
261260
it('Should return 200 when username is valid', function (done) {
262261
chai
263262
.request(app)
264-
.get(`/tasks/${appOwner.username}`)
263+
.get(`/tasks/${appOwner.username}?status=active`)
265264
.end((err, res) => {
266265
if (err) { return done(err) }
267266
expect(res).to.have.status(200)
@@ -284,7 +283,7 @@ describe('Tasks', function () {
284283
it('Should return 404 when username is invalid', function (done) {
285284
chai
286285
.request(app)
287-
.get('/tasks/dummyUser')
286+
.get('/tasks/dummyUser?status=active')
288287
.end((err, res) => {
289288
if (err) { return done(err) }
290289
expect(res).to.have.status(404)

utils/tasks.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11

22
const { getUsername, getUserId, getParticipantUsernames, getParticipantUserIds } = require('./users')
3+
const { TASK_TYPE } = require('../constants/tasks')
34

45
const fromFirestoreData = async (task) => {
56
if (!task) {
67
return task
78
}
8-
let { createdBy, assignee, participants } = task
9+
10+
let { createdBy, assignee, participants, type } = task
11+
912
if (createdBy) {
1013
createdBy = await getUsername(createdBy)
1114
}
15+
1216
if (assignee) {
1317
assignee = await getUsername(assignee)
1418
}
1519

16-
if (Array.isArray(participants)) {
20+
if (type === TASK_TYPE.GROUP) {
1721
participants = await getParticipantUsernames(participants)
1822
}
1923

0 commit comments

Comments
 (0)