-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[O2B-505] Improve listTags API to accept filters (#537)
* Builds on `listTags` to accept filters such as: `ids, texts, emails, mattermosts` * Adds filter validation * Returns 204 status if no data is found * Adds corresponding tests * Makes GET API `/api/tags/` public
- Loading branch information
Showing
7 changed files
with
97 additions
and
30 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 |
---|---|---|
|
@@ -13,24 +13,12 @@ | |
|
||
module.exports = { | ||
up: (queryInterface, _Sequelize) => queryInterface.bulkInsert('tags', [ | ||
{ | ||
text: 'FOOD', | ||
}, | ||
{ | ||
text: 'RUN', | ||
}, | ||
{ | ||
text: 'MAINTENANCE', | ||
}, | ||
{ | ||
text: 'GLOBAL', | ||
}, | ||
{ | ||
text: 'TEST', | ||
}, | ||
{ | ||
text: 'OTHER', | ||
}, | ||
{ text: 'FOOD', email: '[email protected]', mattermost: 'food' }, | ||
{ text: 'RUN', email: '[email protected]', mattermost: 'marathon' }, | ||
{ text: 'MAINTENANCE' }, | ||
{ text: 'GLOBAL' }, | ||
{ text: 'TEST' }, | ||
{ text: 'OTHER', email: '[email protected]', mattermost: 'other' }, | ||
{ text: 'TEST-TAG-1' }, | ||
{ text: 'TEST-TAG-2' }, | ||
{ text: 'TEST-TAG-3' }, | ||
|
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
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
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 |
---|---|---|
|
@@ -1022,14 +1022,14 @@ module.exports = () => { | |
{ | ||
id: 1, | ||
text: 'FOOD', | ||
email: null, | ||
mattermost: null, | ||
email: '[email protected]', | ||
mattermost: 'food', | ||
}, | ||
{ | ||
id: 2, | ||
text: 'RUN', | ||
email: null, | ||
mattermost: null, | ||
email: '[email protected]', | ||
mattermost: 'marathon', | ||
}, | ||
]); | ||
expect(res.body.data.rootLogId).to.equal(1); | ||
|
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 |
---|---|---|
|
@@ -12,15 +12,69 @@ | |
*/ | ||
|
||
const { tag: { GetAllTagsUseCase } } = require('../../../lib/usecases'); | ||
const { dtos: { GetAllTagsDto } } = require('../../../lib/domain'); | ||
const chai = require('chai'); | ||
|
||
const { expect } = chai; | ||
|
||
module.exports = () => { | ||
it('should return an array', async () => { | ||
const { tags } = await new GetAllTagsUseCase() | ||
.execute(); | ||
let getAllTagsDto; | ||
|
||
beforeEach(async () => { | ||
getAllTagsDto = await GetAllTagsDto.validateAsync({}); | ||
}); | ||
it('should successfully return an array with tags', async () => { | ||
const { tags } = await new GetAllTagsUseCase().execute(); | ||
|
||
expect(tags).to.be.an('array'); | ||
}); | ||
it('should successfully return an array with tags with specified ids', async () => { | ||
getAllTagsDto.query = { filter: { ids: '1,2' } }; | ||
const { tags } = await new GetAllTagsUseCase().execute(getAllTagsDto); | ||
|
||
expect(tags).to.be.an('array'); | ||
expect(tags).to.have.lengthOf(2); | ||
expect(tags[0].id).to.equal(1); | ||
expect(tags[0].text).to.equal('FOOD'); | ||
expect(tags[1].id).to.equal(2); | ||
expect(tags[1].text).to.equal('RUN'); | ||
}); | ||
it('should successfully return 204 status if no tag was found with specified ids', async () => { | ||
getAllTagsDto.query = { filter: { ids: '5002' } }; | ||
const { tags } = await new GetAllTagsUseCase().execute(getAllTagsDto); | ||
|
||
expect(tags).to.be.an('array'); | ||
expect(tags).to.have.lengthOf(0); | ||
}); | ||
it('should successfully return an array with tags with specified texts', async () => { | ||
getAllTagsDto.query = { filter: { texts: 'FOOD,OTHER' } }; | ||
const { tags } = await new GetAllTagsUseCase().execute(getAllTagsDto); | ||
|
||
expect(tags).to.be.an('array'); | ||
expect(tags).to.have.lengthOf(2); | ||
expect(tags[0].id).to.equal(1); | ||
expect(tags[0].text).to.equal('FOOD'); | ||
expect(tags[1].id).to.equal(6); | ||
expect(tags[1].text).to.equal('OTHER'); | ||
}); | ||
it('should successfully return an array with tags with specified emails', async () => { | ||
getAllTagsDto.query = { filter: { emails: '[email protected]' } }; | ||
const { tags } = await new GetAllTagsUseCase().execute(getAllTagsDto); | ||
|
||
expect(tags).to.be.an('array'); | ||
expect(tags).to.have.lengthOf(1); | ||
expect(tags[0].id).to.equal(6); | ||
expect(tags[0].text).to.equal('OTHER'); | ||
}); | ||
it('should successfully return an array with tags with specified mattermosts', async () => { | ||
getAllTagsDto.query = { filter: { mattermosts: 'marathon,,food' } }; | ||
const { tags } = await new GetAllTagsUseCase().execute(getAllTagsDto); | ||
|
||
expect(tags).to.be.an('array'); | ||
expect(tags).to.have.lengthOf(2); | ||
expect(tags[0].id).to.equal(1); | ||
expect(tags[0].text).to.equal('FOOD'); | ||
expect(tags[1].id).to.equal(2); | ||
expect(tags[1].text).to.equal('RUN'); | ||
}); | ||
}; |