|
Description
Julian Maurice
2021-12-09 07:26:06 UTC
Created attachment 128371 [details] [review] Bug 29668: Add API route to add a basket Example usage: POST /api/v1/acquisitions/baskets { "vendor_id": 1, "name": "Basket #1", } Test plan: 1. Try requesting this endpoint with your favorite API tool (I recommend https://github.com/frigus02/RESTer) 2. Run `prove t/db_dependent/api/v1/acquisitions_baskets/post.t` This isn't compatible with the current master branch because of some changes in the api directory structure, but I think you already know. Some merge conflicts have to be resolved. There is the new route acquisitions/baskets/managers which probably wasn't there yet when this patch was written. Created attachment 183072 [details] [review] Bug 29668: Add API route to add a basket Example usage: POST /api/v1/acquisitions/baskets { "vendor_id": 1, "name": "Basket #1", } Test plan: 1. Try requesting this endpoint with your favorite API tool (I recommend https://github.com/frigus02/RESTer) 2. Run `prove t/db_dependent/api/v1/acquisitions_baskets/post.t` Edit (tcohen): Re-did the commit with some fixes in the spec Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Created attachment 183073 [details] [review] Bug 29668: Move tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Created attachment 183074 [details] [review] Bug 29668: Adapt to current guidelines The added patches make some changes: * $c->req->json is used to access the request body, as explained by the Mojolicious OpenAPI plugin author it should be done. * Instead of calling `$basket->to_api` we use the `$c->objects->to_api` helper which deals with calling context (embeds, etc). Otherwise it would require doing it manually if embeds are added. * Tests are grouped together the same way the rest of them are. To test: 1. Apply this patches 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/acquisitions_baskets.t => SUCCESS: Tests pass! Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Created attachment 189122 [details] [review] Bug 29668: Add API route to add a basket Example usage: POST /api/v1/acquisitions/baskets { "vendor_id": 1, "name": "Basket #1", } Test plan: 1. Try requesting this endpoint with your favorite API tool (I recommend https://github.com/frigus02/RESTer) 2. Run `prove t/db_dependent/api/v1/acquisitions_baskets/post.t` Edit (tcohen): Re-did the commit with some fixes in the spec Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Created attachment 189123 [details] [review] Bug 29668: Move tests Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Created attachment 189124 [details] [review] Bug 29668: Adapt to current guidelines The added patches make some changes: * $c->req->json is used to access the request body, as explained by the Mojolicious OpenAPI plugin author it should be done. * Instead of calling `$basket->to_api` we use the `$c->objects->to_api` helper which deals with calling context (embeds, etc). Otherwise it would require doing it manually if embeds are added. * Tests are grouped together the same way the rest of them are. To test: 1. Apply this patches 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/acquisitions_baskets.t => SUCCESS: Tests pass! Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Tests failed for me :(
kohadev-koha@kohadevbox:koha(main)$ prove t/db_dependent/api/v1/acquisitions_baskets.t
t/db_dependent/api/v1/acquisitions_baskets.t .. 1/4
# Failed test '403 Forbidden'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 124.
# got: '404'
# expected: '403'
# Failed test '400 Bad Request'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 134.
# got: '404'
# expected: '400'
# Failed test '201 Created'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 136.
# got: '404'
# expected: '201'
# Failed test 'has value for JSON Pointer "/basket_id"'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 136.
# Failed test 'exact match for JSON Pointer "/vendor_id"'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 136.
# got: undef
# expected: '5'
# Failed test '201 Created'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 146.
# got: '404'
# expected: '201'
# Failed test 'has value for JSON Pointer "/basket_id"'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 146.
# Failed test 'exact match for JSON Pointer "/vendor_id"'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 146.
# got: undef
# expected: '5'
# Failed test 'exact match for JSON Pointer "/name"'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 146.
# got: undef
# expected: 'Basket #1'
# Failed test 'exact match for JSON Pointer "/vendor_note"'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 146.
# got: undef
# expected: 'Vendor note'
# Looks like you failed 10 tests of 14.
# Failed test 'add() tests'
# at t/db_dependent/api/v1/acquisitions_baskets.t line 149.
# Looks like you failed 1 test of 4.
t/db_dependent/api/v1/acquisitions_baskets.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/4 subtests
Test Summary Report
-------------------
t/db_dependent/api/v1/acquisitions_baskets.t (Wstat: 256 (exited 1) Tests: 4 Failed: 1)
Failed test: 3
Non-zero exit status: 1
Files=1, Tests=4, 3 wallclock secs ( 0.01 usr 0.00 sys + 2.92 cusr 0.17 csys = 3.10 CPU)
Result: FAIL
(In reply to Laura Escamilla from comment #10) > Tests failed for me :( > > # got: '404' > # expected: '403' Did you run `yarn api:bundle` before the tests? No I didn't.... I will test this again! Created attachment 189227 [details] [review] Bug 29668: Add API route to add a basket Example usage: POST /api/v1/acquisitions/baskets { "vendor_id": 1, "name": "Basket #1", } Test plan: 1. Try requesting this endpoint with your favorite API tool (I recommend https://github.com/frigus02/RESTer) 2. Run `prove t/db_dependent/api/v1/acquisitions_baskets/post.t` Edit (tcohen): Re-did the commit with some fixes in the spec Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com> Created attachment 189228 [details] [review] Bug 29668: Move tests Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com> Created attachment 189229 [details] [review] Bug 29668: Adapt to current guidelines The added patches make some changes: * $c->req->json is used to access the request body, as explained by the Mojolicious OpenAPI plugin author it should be done. * Instead of calling `$basket->to_api` we use the `$c->objects->to_api` helper which deals with calling context (embeds, etc). Otherwise it would require doing it manually if embeds are added. * Tests are grouped together the same way the rest of them are. To test: 1. Apply this patches 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/acquisitions_baskets.t => SUCCESS: Tests pass! Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com> Thank you, Tomas and Julian! This worked great so I'm passing QA. |