Skip to content

Commit

Permalink
Merge pull request #10 from ezequielramos/main
Browse files Browse the repository at this point in the history
fix create watchlist status code returned
  • Loading branch information
ezequielramos authored Jul 8, 2024
2 parents c3864bd + 0fbb924 commit 342b1da
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/controllers/watch-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ function getWatchLists() {
return watchLists;
}

function createWatchList(name: string) {
function createWatchList(name: string, active: boolean) {
watchListId++;
const watchList: WatchList = {
"id": watchListId,
"created_date": new Date().toISOString(),
"modified_date": new Date().toISOString(),
"active": true,
"active": active,
"name": name,
"comment": "",
"color": "123456",
Expand Down
4 changes: 2 additions & 2 deletions src/routes/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ function loadCardRoutes(app: Express) {
watchLists = [req.body.watch_lists];
}

const watchListsIds = getWatchLists().filter(wl => wl.id != -1).map(wl => wl.id);

if (watchLists.includes(-1)) {
return res.status(400).json({
"traceback": "",
Expand All @@ -50,6 +48,8 @@ function loadCardRoutes(app: Express) {
});
}

const watchListsIds = getWatchLists().filter(wl => wl.id != -1).map(wl => wl.id);

for (const watchList of watchLists) {

if (!watchListsIds.includes(watchList)) {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/watch-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ function loadWatchListsRoutes(app: Express) {
});
}

const watchList = createWatchList(req.body.name);
const watchList = createWatchList(req.body.name, req.body.active === true);

return res.status(200).json(watchList);
return res.status(201).json(watchList);
});

}
Expand Down
5 changes: 3 additions & 2 deletions tests/watch-lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ describe('Watch Lists Route Testing', async () => {
res = await request.post(`/watch-lists/`)
.set('Authorization', 'Token ' + token)
.send({
name: 'Company 1'
name: 'Company 1',
active: true
})
.type('application/json');
expect(res.statusCode).to.be.equal(200);
expect(res.statusCode).to.be.equal(201);

res = await request.get(`/watch-lists/`).set('Authorization', 'Token ' + token);
expect(res.statusCode).to.be.equal(200);
Expand Down

0 comments on commit 342b1da

Please sign in to comment.