From abde4f8de9b1e2ec99b8a4d056a12fe117c18bdf Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 14 Apr 2022 12:07:49 -0300 Subject: [PATCH] Bug 30536: Unit tests Content-Type: text/plain; charset=utf-8 This patch adds tests to make sure there's no behavior change regarding error conditions. When requests include wrong x-koha-embed values, a 400 error should be returned, both in our original implementation or relying on the Mojolicious::Plugin::OpenAPI features. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/query.t => SUCCESS: Tests pass 3. Apply the rest of the patches 4. Repeat 2 => SUCCESS: Tests still pass 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Marcel de Rooy --- t/db_dependent/api/v1/query.t | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/query.t b/t/db_dependent/api/v1/query.t index dd73f2095c..3b8be18f8a 100755 --- a/t/db_dependent/api/v1/query.t +++ b/t/db_dependent/api/v1/query.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Test::Mojo; use t::lib::TestBuilder; @@ -105,3 +105,38 @@ subtest 'q handling tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'x-koha-embed tests' => sub { + + plan tests => 5; + + $schema->storage->txn_begin; + + my $librarian = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 1 } # superlibrarian + } + ); + my $password = 'thePassword123'; + $librarian->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $librarian->userid; + + my $patron_id = $builder->build_object( { class => 'Koha::Patrons' } )->id; + + my $res = $t->get_ok( + "//$userid:$password@/api/v1/patrons?q={\"me.patron_id\":$patron_id}" + => { 'x-koha-embed' => 'extended_attributes' } )->status_is(200) + ->tx->res->json; + + is( scalar @{$res}, 1, 'One patron returned' ); + + $res = $t->get_ok( + "//$userid:$password@/api/v1/patrons?q={\"me.patron_id\":$patron_id}" => { + 'x-koha-embed' => + 'extended_attributes,custom_bad_embed,another_bad_embed' + } + )->status_is(400); + + $schema->storage->txn_rollback; +}; -- 2.20.1