From 5cc5d0708b830b9ee70afb437183ce06ea88eb58 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 8 Apr 2019 15:38:22 -0300 Subject: [PATCH] Bug 18205: (follow-up) Tests for V1 setting the right interface Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/REST/V1.t | 49 ++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/REST/V1.t b/t/db_dependent/Koha/REST/V1.t index faddea9da3..3fc6ce035d 100644 --- a/t/db_dependent/Koha/REST/V1.t +++ b/t/db_dependent/Koha/REST/V1.t @@ -17,12 +17,25 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Test::Mojo; use Test::Warn; +use t::lib::Mocks; +use t::lib::TestBuilder; + +use Koha::ActionLogs; +use Koha::Database; + use JSON::Validator::OpenAPI::Mojolicious; +my $builder = t::lib::TestBuilder->new; +my $schema = Koha::Database->new->schema; + +t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); + +my $t = Test::Mojo->new('Koha::REST::V1'); + subtest 'Type definition tests' => sub { plan tests => 4; @@ -42,3 +55,37 @@ subtest 'Type definition tests' => sub { is( $types->type('mij'), 'application/marc-in-json', 'application/marc-in-json is defined' ); is( $types->type('marc'), 'application/marc', 'application/marc is defined' ); }; + +subtest 'logging with the right interface' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $user = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); + my $userid = $user->userid; + my $password = 'thisIsaPassword!234'; + $user->set_password( { password => $password, skip_validation => 1 } ); + + # create a known patron + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + # Make changes to the patron through the API + $t->put_ok( + "//$userid:$password@/api/v1/patrons/" + . $patron->borrowernumber => json => { + surname => 'This is a new firstname', + address => 'An address', + city => $patron->city, + library_id => $patron->branchcode, + category_id => $patron->categorycode + } + )->status_is(200); + + my $log = Koha::ActionLogs->search( + { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } )->next; + is( $log->interface, 'api', 'Interface correctly logged' ); + is( $log->user, $user->borrowernumber, 'User correctly logged' ); + + $schema->storage->txn_rollback; +}; -- 2.21.0