-
Notifications
You must be signed in to change notification settings - Fork 8
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
#169817560 add search functionality #52
Conversation
* tags: | ||
* - Search | ||
* name: Search the requests | ||
* parameters: |
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.
aa759ee
to
29127a2
Compare
src/controllers/search.controller.js
Outdated
|
||
const pagination = { | ||
limit, | ||
offset: Number.isNaN(offset) ? undefined : offset |
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.
Offset should be zero by default. Also, line 22 cannot return a NaN value so the check here is unnecessary.
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.
@adesege Because pagination in this search is optional, I was thinking if the user searches without providing the page value or limit value, he should get the data without pagination. In that situation, line 22 would return NaN and that's why I was checking first. If you say that offset should be zero by default, there would be no pagination. Can you give me your suggestions? because for me without setting the default values for page and limit which would be pagination, I'm not finding any other option except checking.
src/controllers/search.controller.js
Outdated
limit, | ||
offset: Number.isNaN(offset) ? undefined : offset | ||
}; | ||
const results = await SearchService.searchAll(userData, term, pagination); |
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.
Always pass an object as a single param to a function as opposed to setting multiple params
src/services/search.service.js
Outdated
* @returns {response} @memberof SearchService | ||
*/ | ||
static getStatusQuery(term) { | ||
if (term === 'approved' || term === 'rejected' || term === 'pending') { |
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.
Use the .includes()
instead
09dfc7c
to
3e6b3ed
Compare
src/controllers/search.controller.js
Outdated
offset | ||
}; | ||
let results; | ||
if (location) { |
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.
What happens when the user searches by both location and name, for instance?
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.
@adesege It returns results for both of them, see below image, it returns results for both location and status and they are different requests as you see
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.
I don't think so. Run a search for approved
status and location
. Show the location
property in the return object. Also, remove the pagination queries in the request url
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.
Yh I get it. let me fix it
src/controllers/search.controller.js
Outdated
* | ||
* @class searchController | ||
*/ | ||
class searchController { |
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.
Class names must be in pascal case
src/tests/fixtures/trip.fixture.js
Outdated
const newTripComment = { | ||
id: faker.random.number({ min: 20, max: 50 }), | ||
userId: loggedInUser.id, | ||
tripId: faker.random.number(), | ||
tripType: 'one-way', | ||
departure: faker.address.city(), | ||
destination: faker.address.city(), | ||
travelDate: faker.date.future(), | ||
originId: faker.random.number({ min: 1, max: 2 }), | ||
destinationId: faker.random.number({ min: 1, max: 2 }), | ||
departureDate: faker.date.future(), | ||
travelReasons: faker.lorem.sentence(), | ||
accommodation: faker.lorem.sentence(), | ||
accommodationId: faker.random.number() | ||
}; | ||
|
||
const tripComment = { | ||
userId: loggedInUser.id, | ||
tripType: 'one-way', | ||
departure: faker.address.city(), | ||
destination: faker.address.city(), | ||
travelDate: faker.date.future(), | ||
originId: faker.random.number({ min: 1, max: 2 }), | ||
destinationId: faker.random.number({ min: 1, max: 2 }), | ||
departureDate: faker.date.future(), | ||
travelReasons: faker.lorem.sentence(), | ||
accommodation: faker.lorem.sentence(), | ||
accommodationId: faker.random.number() | ||
}; |
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.
Use spread operator to copy common object properties
src/tests/search/search.test.js
Outdated
chai.use(chaiHttp); | ||
|
||
describe('Test searching requests:', () => { | ||
let departuredate; |
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.
A variable with multiple words should be in camel case
src/tests/search/search.test.js
Outdated
done(); | ||
}); | ||
}); | ||
it('Should return status code of 201 on successful trip creation', (done) => { |
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 are you creating a trip here?
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.
I was creating a trip that later needs to be searched for. But maybe I can use the fixture instead
src/tests/search/search.test.js
Outdated
const fakerDate = new Date(departuredate); | ||
const month = (`0${fakerDate.getMonth() + 1}`).slice(-2); | ||
const date = (`0${fakerDate.getDate()}`).slice(-2); | ||
const formattedDate = `${fakerDate.getFullYear()}-${month}-${date}`; |
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.
Move this to a function
src/tests/search/search.test.js
Outdated
}); | ||
it('Should return status code of 200 on with search results when search by status and with pagination', (done) => { | ||
chai.request(app) | ||
.get(`/api/search?status=pending&page=${faker.random.number({ min: 1, max: 1 })}&limit=${faker.random.number()}`) |
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.
There's no point using faker to generate the page and limit values.
- Add search controller - Add search service - Add search tests - Add search api documentation [stars #169817560]
1ea764d
to
fc647d5
Compare
fc647d5
to
3351620
Compare
What does this PR do?
Add search functionality feature
Description of Task to be completed?
How should this be manually tested?
then
$ npm run test
or you can use Postman to send a get request to /api/search?term={query} and replace the query with your search choice
What are the relevant pivotal tracker stories?
#169817560
Screenshots