From 3d3e7f472fdce5b3d884a889633e5c30fd87f262 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Wed, 4 Jul 2018 13:13:33 +0100 Subject: [PATCH] Bug 20996: Fix unit tests - Remove unit tests relating to TO_JSON - Add tests for new explicit embedding - Modify tests relating to now deprecated brw_cat Signed-off-by: Magnus Enger Signed-off-by: Josef Moravec --- t/db_dependent/Illrequests.t | 75 +++---------------------------------- t/db_dependent/api/v1/illrequests.t | 19 +++++----- 2 files changed, 14 insertions(+), 80 deletions(-) diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t index 1411eac..a9f933a 100644 --- a/t/db_dependent/Illrequests.t +++ b/t/db_dependent/Illrequests.t @@ -28,7 +28,7 @@ use Test::MockObject; use Test::MockModule; use Test::Exception; -use Test::More tests => 11; +use Test::More tests => 10; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; @@ -536,7 +536,7 @@ subtest 'Backend core methods' => sub { subtest 'Helpers' => sub { - plan tests => 9; + plan tests => 7; $schema->storage->txn_begin; @@ -564,35 +564,26 @@ subtest 'Helpers' => sub { $config->set_series('getPrefixes', { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, { A => "ATEST", C => "CBAR", default => "DEFAULT" }); - is($illrq_obj->getPrefix({ brw_cat => "C", branch => "CPL" }), "CBAR", - "getPrefix: brw_cat"); - $config->set_series('getPrefixes', - { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, - { A => "ATEST", C => "CBAR", default => "DEFAULT" }); is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", "getPrefix: branch"); $config->set_series('getPrefixes', { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, { A => "ATEST", C => "CBAR", default => "DEFAULT" }); - is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "DEFAULT", + is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", "getPrefix: default"); $config->set_always('getPrefixes', {}); - is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "", + is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", "getPrefix: the empty prefix"); # id_prefix $config->set_series('getPrefixes', { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, - { A => "ATEST", C => "CBAR", default => "DEFAULT" }); - is($illrq_obj->id_prefix, "ATEST-", "id_prefix: brw_cat"); - $config->set_series('getPrefixes', - { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, { AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); $config->set_series('getPrefixes', { CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, { AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); - is($illrq_obj->id_prefix, "DEFAULT-", "id_prefix: default"); + is($illrq_obj->id_prefix, "", "id_prefix: default"); # requires_moderation $illrq_obj->status('NEW')->store; @@ -804,59 +795,3 @@ subtest 'Checking Limits' => sub { $schema->storage->txn_rollback; }; - -subtest 'TO_JSON() tests' => sub { - - plan tests => 10; - - my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); - - # Mock ->capabilities - $illreqmodule->mock( 'capabilities', sub { return 'capable'; } ); - - # Mock ->metadata - $illreqmodule->mock( 'metadata', sub { return 'metawhat?'; } ); - - $schema->storage->txn_begin; - - my $library = $builder->build_object( { class => 'Koha::Libraries' } ); - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); - my $illreq = $builder->build_object( - { - class => 'Koha::Illrequests', - value => { - branchcode => $library->branchcode, - borrowernumber => $patron->borrowernumber - } - } - ); - my $illreq_json = $illreq->TO_JSON; - is( $illreq_json->{patron}, - undef, '%embed not passed, no \'patron\' attribute' ); - is( $illreq_json->{metadata}, - undef, '%embed not passed, no \'metadata\' attribute' ); - is( $illreq_json->{capabilities}, - undef, '%embed not passed, no \'capabilities\' attribute' ); - is( $illreq_json->{library}, - undef, '%embed not passed, no \'library\' attribute' ); - - $illreq_json = $illreq->TO_JSON( - { patron => 1, metadata => 1, capabilities => 1, library => 1 } ); - is( $illreq_json->{patron}->{firstname}, - $patron->firstname, - '%embed passed, \'patron\' attribute correct (firstname)' ); - is( $illreq_json->{patron}->{surname}, - $patron->surname, - '%embed passed, \'patron\' attribute correct (surname)' ); - is( $illreq_json->{patron}->{cardnumber}, - $patron->cardnumber, - '%embed passed, \'patron\' attribute correct (cardnumber)' ); - is( $illreq_json->{metadata}, - 'metawhat?', '%embed passed, \'metadata\' attribute correct' ); - is( $illreq_json->{capabilities}, - 'capable', '%embed passed, \'capabilities\' attribute correct' ); - is( $illreq_json->{library}->{branchcode}, - $library->branchcode, '%embed not passed, no \'library\' attribute' ); - - $schema->storage->txn_rollback; -}; diff --git a/t/db_dependent/api/v1/illrequests.t b/t/db_dependent/api/v1/illrequests.t index b0850e9..b58d529 100644 --- a/t/db_dependent/api/v1/illrequests.t +++ b/t/db_dependent/api/v1/illrequests.t @@ -38,7 +38,7 @@ my $t = Test::Mojo->new('Koha::REST::V1'); subtest 'list() tests' => sub { - plan tests => 15; + plan tests => 18; my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); # Mock ->capabilities @@ -67,6 +67,7 @@ subtest 'list() tests' => sub { { class => 'Koha::Illrequests', value => { + backend => 'FreeForm', branchcode => $library->branchcode, borrowernumber => $patron->borrowernumber } @@ -77,20 +78,18 @@ subtest 'list() tests' => sub { $tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); $tx->req->env( { REMOTE_ADDR => $remote_address } ); - $t->request_ok($tx)->status_is(200)->json_is( [ $illrequest->TO_JSON ] ); + $t->request_ok($tx)->status_is(200)->json_is( [ $illrequest->unblessed ] ); # One illrequest created, returned with augmented data $tx = $t->ua->build_tx( GET => '/api/v1/illrequests?embed=patron,library,capabilities,metadata' ); $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); $tx->req->env( { REMOTE_ADDR => $remote_address } ); - $t->request_ok($tx)->status_is(200)->json_is( - [ - $illrequest->TO_JSON( - { patron => 1, library => 1, capabilities => 1, metadata => 1 } - ) - ] - ); + $t->request_ok($tx)->status_is(200) + ->json_has( '/0/patron', $patron->unblessed ) + ->json_has( '/0/capabilities', 'capable' ) + ->json_has( '/0/library', $library->unblessed ) + ->json_has( '/0/metadata', 'metawhat?' ); # Create another ILL request my $illrequest2 = $builder->build_object( @@ -108,7 +107,7 @@ subtest 'list() tests' => sub { $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); $tx->req->env( { REMOTE_ADDR => $remote_address } ); $t->request_ok($tx)->status_is(200) - ->json_is( [ $illrequest->TO_JSON, $illrequest2->TO_JSON ] ); + ->json_is( [ $illrequest->unblessed, $illrequest2->unblessed ] ); # Warn on unsupported query parameter $tx = $t->ua->build_tx( GET => '/api/v1/illrequests?request_blah=blah' ); -- 2.1.4