Skip to content
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

feat(browseRequests): add browse endpoints with test and documentation in progress #297

Merged
merged 52 commits into from
Jun 19, 2020

Conversation

akhilesh26
Copy link
Contributor

Problem

Implementation of Browse endpoints.

Solution

Start writing tests for those endpoints

Areas of Impact

@coveralls
Copy link

coveralls commented Aug 4, 2019

Coverage Status

Coverage increased (+0.9%) to 61.422% when pulling f0808f4 on akhilesh26:phase2_api into 9b92daa on bookbrainz:master.

@akhilesh26
Copy link
Contributor Author

Hi @MonkeyDo,
Here the initial phase of tests for browse endpoints. My idea is to return the list of entity bbid instead of entity data. First, User will browse the entity bbid related to another entity, Then fetch the detail of an entity with BBID by using lookup requests if required. What is your plan to browse endpoints?
Suggest more endpoints for browse requests with the requirement explanation and check these test written in this PR. Thanks!

Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see you start with the tests!

Looking at your proposal document, there are linked entities in your tests that weren't originally planned. For example, /author?publisher=….
I think for now you should limit to the planned links, and maybe think about adding other ones after the GSOC project.
For reference, here is what was originally planned:

<ENTITY>                  <LINKED_ENTITY>
/work                     edition, author
/edition                  work, author, edition-group, publisher
/edition-group            edition, author
/author                   work, edition
/publisher                edition, work

test/src/api/routes/test-edition-group.js Outdated Show resolved Hide resolved
@akhilesh26
Copy link
Contributor Author

Hi @MonkeyDo
I refactored test cases according to option-4, Please look it once for more improvements, When you have time. Thanks!

test/src/api/helpers.js Outdated Show resolved Hide resolved
src/api/helpers/utils.js Outdated Show resolved Hide resolved
@akhilesh26
Copy link
Contributor Author

Hi @MonkeyDo,
Browse request is working for /author?work=<bbid> and /author?edition=<bbid>. Please help to get the required format response and validate the URL for the author's browser request as commented above. I will implement all browse endpoint on the basis of this.

@akhilesh26 akhilesh26 changed the title feat(tests): add tests for browse endpoints feat(tests): add browse endpoints with test and documentation in progress Aug 18, 2019
@akhilesh26 akhilesh26 changed the title feat(tests): add browse endpoints with test and documentation in progress feat(browseRequests): add browse endpoints with test and documentation in progress Aug 18, 2019
src/api/routes/edition.js Outdated Show resolved Hide resolved
@akhilesh26
Copy link
Contributor Author

@MonkeyDo Hi,
I updated filter validation according to the proposal, I think, all functionalities working now for browse request except edition & edition-group case. Please go through once and let me know if anything more on functionality. Then I will update documentation and tests also. Thanks!

Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad to see you making good progress!
We're just around the corner from the deadline, and at that pace I think you'll make it!

Let me know if you have any questions regarding the feedback below.

* sortName:
* type: string
* example: 'Heinlein, Robert A.'
* example: '<Sort name of enity>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enity -> entity

src/api/routes/author.js Outdated Show resolved Hide resolved
src/api/helpers/utils.js Outdated Show resolved Hide resolved
);
return res.status(200).send({
bbid: req.query.bbid,
relatedAuthors: authorRelationshipList
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering we are choosing to allow only one type of related entity at a time, would it be simpler for users to only have a related or relatedEntities property for all browse endpoints results, instead of a different one for each endpoint (relatedAuthors, relatedWorks, …) ?
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it gives the clarity on response.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point.
I would then suggest rolling back to what you originally had in the tests and proposal, and removing the related part to have the response structure be {bbid:…, authors:[…]}.

src/api/routes/edition.js Outdated Show resolved Hide resolved
src/api/routes/edition.js Outdated Show resolved Hide resolved
src/api/routes/publisher.js Outdated Show resolved Hide resolved
src/api/routes/work.js Outdated Show resolved Hide resolved
src/server/routes/search.js Outdated Show resolved Hide resolved
test/src/api/helpers.js Outdated Show resolved Hide resolved
@akhilesh26
Copy link
Contributor Author

@MonkeyDo Hi!
Thanks for the detailed review, I will try to resolve all these ASAP. The feeling was not well in the because of the headache in last days, so not able to complete these, but I will try to complete all ASAP. Thanks for such support.
I added all most all the tests for work browse request, I request you to look at those and if they are implemented correctly then I will extend for all entities.

Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test{Entity}BrowseRequest helpers don't currently allow you to test if the filters are working or not.
I would like to see less tests (I don't think there is any use in testing each filter-entity combination), but three tests specifically designed to ensure that each filter works, and that they work combined.
This will require a bit of rewrite. You'll need to set up the necessary works of different types and languages, and ensure that for each filter and for combined filters:
• you get 2 results if calling without the filter, and only one result with the filter
• without filter, there are different types/languages, and only one type if with the filter

That way we'll be sure that we don't break the filters mechanism in the future, rather that just testing that the query parameters are accepted.

This will ned to be done for each entity, as the filtering function is different for each.

@endurance21
Copy link
Contributor

@MonkeyDo
I see this work, unfinished
From where should I get started on this?..

@MonkeyDo
Copy link
Contributor

Hi @endurance21!
It would be quite useful if you wanted to pick this API project back up! I believe most of the coding part for this PR is completed, and only the tests require completion.

The API has lookup endpoints and browse endpoints.
The lookup endpoints you can test live (with its live documentation along with it) at https://api.test.bookbrainz.org/1/api-docs/
You can find a description of the entire project here (a GSOC project from last year): https://community.metabrainz.org/t/gsoc-2019-json-web-api-for-bookbrainz/421988

I think the best way to get started on it would be to do a PR review yourself, meaning reading through this PR code and pointing out anything that looks incorrect or could be improved upon
.
Then the next obvious step would be to fix the requested changes from my last review.

After that, we can take it from there and I will do another full review with a view to getting this PR merged :)

Don't hesitate if you have questions!

@endurance21
Copy link
Contributor

@MonkeyDo
Okay.

@MonkeyDo
Copy link
Contributor

I forgot some useful details you can find here: https://github.com/bookbrainz/bookbrainz-site#running-the-api

@prabalsingh24 prabalsingh24 force-pushed the phase2_api branch 3 times, most recently from 576fb17 to 41b3ee1 Compare April 24, 2020 13:18
@prabalsingh24
Copy link
Contributor

Screenshot_2020-04-24 Screenshot(1)

This is the response for http://localhost:9098/1/work?author=4e8f8704-7c34-4a00-8ce5-f02bf26ca7df

Do you think this should be having alias of the author?

@MonkeyDo
Copy link
Contributor

This is the response for http://localhost:9098/1/work?author=4e8f8704-7c34-4a00-8ce5-f02bf26ca7df

Do you think this should be having alias of the author?

No, we want people to fetch that —possibly beforehand— with /author/4e8f8704-7c34-4a00-8ce5-f02bf26ca7df

@prabalsingh24
Copy link
Contributor

@MonkeyDo Have a look at this when you're free :)

Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going really well, nice work !
It's really nice to see you're now quite comfortable with the testing framework, and thinking about what tests to write.

The route docs (inline swagger docs) still need a bit of love to match what's actually accepted for each browse endpoint (the accepted parameters and summaries don't match what's in the code).

On a more general note, I'm having serious second thought's about returning 406 errors when passed an invalid BBID. I think I was the one to decide that way back when last year, and it was probably a mistake.

406 Not Acceptable
This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content that conforms to the criteria given by the user agent.

That doesn't seem adapted at all :/
I think instead a 400 should be returned. Along with the existing error message ('BBID is not valid uuid') I think that's clear enough.
The error code will need changing in the makeEntityLoader helper, in the route documentation and route tests.

src/api/helpers/middleware.js Outdated Show resolved Hide resolved
src/api/helpers/middleware.js Outdated Show resolved Hide resolved
src/api/routes/edition-group.js Outdated Show resolved Hide resolved
src/api/routes/edition.js Outdated Show resolved Hide resolved
src/api/routes/publisher.js Show resolved Hide resolved
test/src/api/routes/test-edition-group.js Outdated Show resolved Hide resolved
test/src/api/routes/test-publisher.js Outdated Show resolved Hide resolved
test/src/api/routes/test-work.js Outdated Show resolved Hide resolved
@prabalsingh24
Copy link
Contributor

I think instead a 400 should be returned. Along with the existing error message ('BBID is not valid uuid') I think that's clear enough.

Aaah, This makes sense now. I was wondering why we did 400 error for this invalid-bbid-pr and 406 here.

Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good !

src/api/routes/author.js Outdated Show resolved Hide resolved
src/api/routes/author.js Show resolved Hide resolved
src/api/routes/author.js Outdated Show resolved Hide resolved
src/api/routes/edition-group.js Outdated Show resolved Hide resolved
src/api/routes/author.js Show resolved Hide resolved
src/api/routes/edition-group.js Show resolved Hide resolved
src/api/routes/edition.js Show resolved Hide resolved
src/api/routes/edition.js Outdated Show resolved Hide resolved
src/api/routes/publisher.js Show resolved Hide resolved
test/src/api/routes/test-author.js Show resolved Hide resolved
@MonkeyDo MonkeyDo merged commit 8cfe173 into metabrainz:master Jun 19, 2020
@MonkeyDo
Copy link
Contributor

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants