View | Details | Raw Unified | Return to bug 20996
Collapse All | Expand All

(-)a/t/db_dependent/Illrequests.t (-70 / +5 lines)
Lines 28-34 use Test::MockObject; Link Here
28
use Test::MockModule;
28
use Test::MockModule;
29
use Test::Exception;
29
use Test::Exception;
30
30
31
use Test::More tests => 11;
31
use Test::More tests => 10;
32
32
33
my $schema = Koha::Database->new->schema;
33
my $schema = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
Lines 523-529 subtest 'Backend core methods' => sub { Link Here
523
523
524
subtest 'Helpers' => sub {
524
subtest 'Helpers' => sub {
525
525
526
    plan tests => 9;
526
    plan tests => 7;
527
527
528
    $schema->storage->txn_begin;
528
    $schema->storage->txn_begin;
529
529
Lines 551-585 subtest 'Helpers' => sub { Link Here
551
    $config->set_series('getPrefixes',
551
    $config->set_series('getPrefixes',
552
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
552
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
553
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
553
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
554
    is($illrq_obj->getPrefix({ brw_cat => "C", branch => "CPL" }), "CBAR",
555
       "getPrefix: brw_cat");
556
    $config->set_series('getPrefixes',
557
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
558
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
559
    is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST",
554
    is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST",
560
       "getPrefix: branch");
555
       "getPrefix: branch");
561
    $config->set_series('getPrefixes',
556
    $config->set_series('getPrefixes',
562
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
557
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
563
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
558
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
564
    is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "DEFAULT",
559
    is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "",
565
       "getPrefix: default");
560
       "getPrefix: default");
566
    $config->set_always('getPrefixes', {});
561
    $config->set_always('getPrefixes', {});
567
    is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "",
562
    is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "",
568
       "getPrefix: the empty prefix");
563
       "getPrefix: the empty prefix");
569
564
570
    # id_prefix
565
    # id_prefix
571
    $config->set_series('getPrefixes',
566
    $config->set_series('getPrefixes',
572
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
567
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
573
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
574
    is($illrq_obj->id_prefix, "ATEST-", "id_prefix: brw_cat");
575
    $config->set_series('getPrefixes',
576
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
577
                        { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
568
                        { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
578
    is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch");
569
    is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch");
579
    $config->set_series('getPrefixes',
570
    $config->set_series('getPrefixes',
580
                        { CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" },
571
                        { CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" },
581
                        { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
572
                        { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
582
    is($illrq_obj->id_prefix, "DEFAULT-", "id_prefix: default");
573
    is($illrq_obj->id_prefix, "", "id_prefix: default");
583
574
584
    # requires_moderation
575
    # requires_moderation
585
    $illrq_obj->status('NEW')->store;
576
    $illrq_obj->status('NEW')->store;
Lines 791-849 subtest 'Checking Limits' => sub { Link Here
791
782
792
    $schema->storage->txn_rollback;
783
    $schema->storage->txn_rollback;
793
};
784
};
794
795
subtest 'TO_JSON() tests' => sub {
796
797
    plan tests => 10;
798
799
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
800
801
    # Mock ->capabilities
802
    $illreqmodule->mock( 'capabilities', sub { return 'capable'; } );
803
804
    # Mock ->metadata
805
    $illreqmodule->mock( 'metadata', sub { return 'metawhat?'; } );
806
807
    $schema->storage->txn_begin;
808
809
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
810
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
811
    my $illreq  = $builder->build_object(
812
        {
813
            class => 'Koha::Illrequests',
814
            value => {
815
                branchcode     => $library->branchcode,
816
                borrowernumber => $patron->borrowernumber
817
            }
818
        }
819
    );
820
    my $illreq_json = $illreq->TO_JSON;
821
    is( $illreq_json->{patron},
822
        undef, '%embed not passed, no \'patron\' attribute' );
823
    is( $illreq_json->{metadata},
824
        undef, '%embed not passed, no \'metadata\' attribute' );
825
    is( $illreq_json->{capabilities},
826
        undef, '%embed not passed, no \'capabilities\' attribute' );
827
    is( $illreq_json->{library},
828
        undef, '%embed not passed, no \'library\' attribute' );
829
830
    $illreq_json = $illreq->TO_JSON(
831
        { patron => 1, metadata => 1, capabilities => 1, library => 1 } );
832
    is( $illreq_json->{patron}->{firstname},
833
        $patron->firstname,
834
        '%embed passed, \'patron\' attribute correct (firstname)' );
835
    is( $illreq_json->{patron}->{surname},
836
        $patron->surname,
837
        '%embed passed, \'patron\' attribute correct (surname)' );
838
    is( $illreq_json->{patron}->{cardnumber},
839
        $patron->cardnumber,
840
        '%embed passed, \'patron\' attribute correct (cardnumber)' );
841
    is( $illreq_json->{metadata},
842
        'metawhat?', '%embed passed, \'metadata\' attribute correct' );
843
    is( $illreq_json->{capabilities},
844
        'capable', '%embed passed, \'capabilities\' attribute correct' );
845
    is( $illreq_json->{library}->{branchcode},
846
        $library->branchcode, '%embed not passed, no \'library\' attribute' );
847
848
    $schema->storage->txn_rollback;
849
};
(-)a/t/db_dependent/api/v1/illrequests.t (-11 / +9 lines)
Lines 38-44 my $t = Test::Mojo->new('Koha::REST::V1'); Link Here
38
38
39
subtest 'list() tests' => sub {
39
subtest 'list() tests' => sub {
40
40
41
    plan tests => 15;
41
    plan tests => 18;
42
42
43
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
43
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
44
    # Mock ->capabilities
44
    # Mock ->capabilities
Lines 67-72 subtest 'list() tests' => sub { Link Here
67
        {
67
        {
68
            class => 'Koha::Illrequests',
68
            class => 'Koha::Illrequests',
69
            value => {
69
            value => {
70
                backend        => 'FreeForm',
70
                branchcode     => $library->branchcode,
71
                branchcode     => $library->branchcode,
71
                borrowernumber => $patron->borrowernumber
72
                borrowernumber => $patron->borrowernumber
72
            }
73
            }
Lines 77-96 subtest 'list() tests' => sub { Link Here
77
    $tx = $t->ua->build_tx( GET => '/api/v1/illrequests' );
78
    $tx = $t->ua->build_tx( GET => '/api/v1/illrequests' );
78
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
79
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
79
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
80
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
80
    $t->request_ok($tx)->status_is(200)->json_is( [ $illrequest->TO_JSON ] );
81
    $t->request_ok($tx)->status_is(200)->json_is( [ $illrequest->unblessed ] );
81
82
82
    # One illrequest created, returned with augmented data
83
    # One illrequest created, returned with augmented data
83
    $tx = $t->ua->build_tx( GET =>
84
    $tx = $t->ua->build_tx( GET =>
84
          '/api/v1/illrequests?embed=patron,library,capabilities,metadata' );
85
          '/api/v1/illrequests?embed=patron,library,capabilities,metadata' );
85
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
86
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
86
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
87
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
87
    $t->request_ok($tx)->status_is(200)->json_is(
88
    $t->request_ok($tx)->status_is(200)
88
        [
89
        ->json_has( '/0/patron', $patron->unblessed )
89
            $illrequest->TO_JSON(
90
        ->json_has( '/0/capabilities', 'capable' )
90
                { patron => 1, library => 1, capabilities => 1, metadata => 1 }
91
        ->json_has( '/0/library', $library->unblessed  )
91
            )
92
        ->json_has( '/0/metadata', 'metawhat?'  );
92
        ]
93
    );
94
93
95
    # Create another ILL request
94
    # Create another ILL request
96
    my $illrequest2 = $builder->build_object(
95
    my $illrequest2 = $builder->build_object(
Lines 108-114 subtest 'list() tests' => sub { Link Here
108
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
107
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
109
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
108
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
110
    $t->request_ok($tx)->status_is(200)
109
    $t->request_ok($tx)->status_is(200)
111
      ->json_is( [ $illrequest->TO_JSON, $illrequest2->TO_JSON ] );
110
      ->json_is( [ $illrequest->unblessed, $illrequest2->unblessed ] );
112
111
113
    # Warn on unsupported query parameter
112
    # Warn on unsupported query parameter
114
    $tx = $t->ua->build_tx( GET => '/api/v1/illrequests?request_blah=blah' );
113
    $tx = $t->ua->build_tx( GET => '/api/v1/illrequests?request_blah=blah' );
115
- 

Return to bug 20996