Description
Tomás Cohen Arazi (tcohen)
2021-03-22 19:52:21 UTC
+1 Created attachment 128915 [details] [review] Bug 28020: Unit tests The unhandled_exception() Mojo helper didn't have proper tests. As this bug is adding a slight behavior change, I tried to add some. As it relies on the OpenAPI plugin, it cannot be done the usual way using Mojo::Lite. So I picked a route and forced an exception through mocking to be able to write tests. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Created attachment 128916 [details] [review] Bug 28020: Add error_code to error responses This patch adds the *error_code* attribute to the error response definition. This way it can be added when returning an error. I also made a sample usage of it on the generic unhandled_exception helper, which the unit tests on this patchset expect. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Created attachment 128917 [details] [review] Bug 28020: (follow-up) Add docs about error_code on the API This patch intends to be a guide for inserting Markdown documentation for error codes. The idea is that it can be copied and pasted as-is in new routes. And adapted to new error codes. To test: 1. Apply this patch 2. Run: $ npx redoc-cli@0.10.4 bundle --cdn --output index.html \ api/v1/swagger/swagger.yaml => SUCCESS: It builds correctly 3. Open index.tml on your browser 4. Pick a route, and see the 500 status description includes information about the possible `error_code` values. 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Created attachment 128918 [details] [review] Bug 28020: Unit tests The unhandled_exception() Mojo helper didn't have proper tests. As this bug is adding a slight behavior change, I tried to add some. As it relies on the OpenAPI plugin, it cannot be done the usual way using Mojo::Lite. So I picked a route and forced an exception through mocking to be able to write tests. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Created attachment 128919 [details] [review] Bug 28020: Add error_code to error responses This patch adds the *error_code* attribute to the error response definition. This way it can be added when returning an error. I also made a sample usage of it on the generic unhandled_exception helper, which the unit tests on this patchset expect. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Created attachment 128920 [details] [review] Bug 28020: (follow-up) Add docs about error_code on the API This patch intends to be a guide for inserting Markdown documentation for error codes. The idea is that it can be copied and pasted as-is in new routes. And adapted to new error codes. To test: 1. Apply this patch 2. Run: $ npx redoc-cli@0.10.4 bundle --cdn --output index.html \ api/v1/swagger/swagger.yaml => SUCCESS: It builds correctly 3. Open index.tml on your browser 4. Pick a route, and see the 500 status description includes information about the possible `error_code` values. 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Rebasing on top of bug 29018 as that one needs to be backportable. Created attachment 128921 [details] [review] Bug 28020: Unit tests The unhandled_exception() Mojo helper didn't have proper tests. As this bug is adding a slight behavior change, I tried to add some. As it relies on the OpenAPI plugin, it cannot be done the usual way using Mojo::Lite. So I picked a route and forced an exception through mocking to be able to write tests. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Created attachment 128922 [details] [review] Bug 28020: Add error_code to error responses This patch adds the *error_code* attribute to the error response definition. This way it can be added when returning an error. I also made a sample usage of it on the generic unhandled_exception helper, which the unit tests on this patchset expect. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Created attachment 128923 [details] [review] Bug 28020: (follow-up) Add docs about error_code on the API This patch intends to be a guide for inserting Markdown documentation for error codes. The idea is that it can be copied and pasted as-is in new routes. And adapted to new error codes. To test: 1. Apply this patch 2. Run: $ npx redoc-cli@0.10.4 bundle --cdn --output index.html \ api/v1/swagger/swagger.yaml => SUCCESS: It builds correctly 3. Open index.tml on your browser 4. Pick a route, and see the 500 status description includes information about the possible `error_code` values. 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Created attachment 128961 [details] [review] Bug 28020: Unit tests The unhandled_exception() Mojo helper didn't have proper tests. As this bug is adding a slight behavior change, I tried to add some. As it relies on the OpenAPI plugin, it cannot be done the usual way using Mojo::Lite. So I picked a route and forced an exception through mocking to be able to write tests. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Created attachment 128962 [details] [review] Bug 28020: Add error_code to error responses This patch adds the *error_code* attribute to the error response definition. This way it can be added when returning an error. I also made a sample usage of it on the generic unhandled_exception helper, which the unit tests on this patchset expect. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Created attachment 128963 [details] [review] Bug 28020: (follow-up) Add docs about error_code on the API This patch intends to be a guide for inserting Markdown documentation for error codes. The idea is that it can be copied and pasted as-is in new routes. And adapted to new error codes. To test: 1. Apply this patch 2. Run: $ npx redoc-cli@0.10.4 bundle --cdn --output index.html \ api/v1/swagger/swagger.yaml => SUCCESS: It builds correctly 3. Open index.tml on your browser 4. Pick a route, and see the 500 status description includes information about the possible `error_code` values. 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Pushed to master for 22.05, thanks to everybody involved [U+1F984] |