-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#Refocus get /subjects filtering by tag working #68
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,104 @@ | ||
/** | ||
* Copyright (c) 2016, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/** | ||
* tests/subjectTagFilter/subjectTagFilter.js | ||
*/ | ||
'use strict'; | ||
const supertest = require('supertest'); | ||
|
||
const api = supertest(require('../../index').app); | ||
const constants = require('../../api/v1/constants'); | ||
const tu = require('../testUtils'); | ||
const u = require('./utils'); | ||
const Subject = tu.db.Subject; | ||
const path = '/v1/subjects'; | ||
const expect = require('chai').expect; | ||
|
||
describe(`api: GET ${path}`, () => { | ||
let token; | ||
|
||
const na = { | ||
name: `${tu.namePrefix}NorthAmerica`, | ||
description: 'continent', | ||
}; | ||
const us = { | ||
name: `${tu.namePrefix}UnitedStates`, | ||
description: 'country', | ||
tags: ['US'], | ||
}; | ||
const vt = { | ||
name: `${tu.namePrefix}Vermont`, | ||
description: 'state', | ||
tags: ['US', 'NE'], | ||
}; | ||
|
||
before((done) => { | ||
tu.createToken() | ||
.then((returnedToken) => { | ||
token = returnedToken; | ||
done(); | ||
}) | ||
.catch((err) => done(err)); | ||
}); | ||
|
||
before((done) => { | ||
Subject.create(na) | ||
.then((createdNa) => { | ||
na.id = createdNa.id; | ||
us.parentId = na.id; | ||
return Subject.create(us); | ||
}) | ||
.then((createdUs) => { | ||
us.id = createdUs.id; | ||
vt.parentId = us.id; | ||
return Subject.create(vt); | ||
}) | ||
.then((createdVt) => { | ||
vt.id = createdVt.id; | ||
done(); | ||
}) | ||
.catch((err) => done(err)); | ||
}); | ||
|
||
after(u.forceDelete); | ||
after(tu.forceDeleteUser); | ||
|
||
it('GET with tag filter :: one tag', (done) => { | ||
api.get(`${path}?tags=US`) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res.body.length).to.equal(2); | ||
expect(res.body[0].tags).to.eql(['US']); | ||
expect(res.body[1].tags).to.eql(['US', 'NE']); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('GET with tag filter :: multiple tags', (done) => { | ||
api.get(`${path}?tags=NE,US`) | ||
.set('Authorization', token) | ||
.expect(constants.httpStatus.OK) | ||
.end((err, res) => { | ||
if (err) { | ||
return done(err); | ||
} | ||
|
||
expect(res.body.length).to.equal(1); | ||
expect(res.body[0].tags).to.eql(['US', 'NE']); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 60 here? (Might need to allow for longer since you could build up a list of includes or excludes.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each tag length is max 60 char long, as restricted by model.
Also, the changes in this PR only handles includes at sql level like
v1/subjects?tags=mytag
.Do we need excludes here as well? I assumed the story was about includes only to get trust data working. I can create another PR if we need excludes as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok we can get this through as is, but i think we want to follow up with story to allow
v1/subjects?tags=tag1,tag2,tag3
orv1/subjects?tags=-tag10,tag11
for parity with the analogous functionality on the /hierarchy endpointThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, let me create a story then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the /hierarchy endpoint filters are case insensitive too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shriramshankar Just checked, we can add different case tags to a subject, like I can have
Is this expected behavior?
Also, if we need to filter case insensitive, there are 2 ways:
I can add this feature to the new story to filter by excludes as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you can have mixed cases for tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if we can have mixed tags, then option 2 won't work and we will have to do filtering on API layer? What is the use case of having mixed tags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since filtering for the hierarchy end point was done in the API layer, it made sense to store the tags the way it was created by the user.