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 536-542 subtest 'Backend core methods' => sub { Link Here
536
536
537
subtest 'Helpers' => sub {
537
subtest 'Helpers' => sub {
538
538
539
    plan tests => 9;
539
    plan tests => 7;
540
540
541
    $schema->storage->txn_begin;
541
    $schema->storage->txn_begin;
542
542
Lines 564-598 subtest 'Helpers' => sub { Link Here
564
    $config->set_series('getPrefixes',
564
    $config->set_series('getPrefixes',
565
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
565
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
566
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
566
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
567
    is($illrq_obj->getPrefix({ brw_cat => "C", branch => "CPL" }), "CBAR",
568
       "getPrefix: brw_cat");
569
    $config->set_series('getPrefixes',
570
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
571
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
572
    is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST",
567
    is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST",
573
       "getPrefix: branch");
568
       "getPrefix: branch");
574
    $config->set_series('getPrefixes',
569
    $config->set_series('getPrefixes',
575
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
570
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
576
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
571
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
577
    is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "DEFAULT",
572
    is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "",
578
       "getPrefix: default");
573
       "getPrefix: default");
579
    $config->set_always('getPrefixes', {});
574
    $config->set_always('getPrefixes', {});
580
    is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "",
575
    is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "",
581
       "getPrefix: the empty prefix");
576
       "getPrefix: the empty prefix");
582
577
583
    # id_prefix
578
    # id_prefix
584
    $config->set_series('getPrefixes',
579
    $config->set_series('getPrefixes',
585
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
580
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
586
                        { A => "ATEST", C => "CBAR", default => "DEFAULT" });
587
    is($illrq_obj->id_prefix, "ATEST-", "id_prefix: brw_cat");
588
    $config->set_series('getPrefixes',
589
                        { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
590
                        { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
581
                        { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
591
    is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch");
582
    is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch");
592
    $config->set_series('getPrefixes',
583
    $config->set_series('getPrefixes',
593
                        { CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" },
584
                        { CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" },
594
                        { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
585
                        { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
595
    is($illrq_obj->id_prefix, "DEFAULT-", "id_prefix: default");
586
    is($illrq_obj->id_prefix, "", "id_prefix: default");
596
587
597
    # requires_moderation
588
    # requires_moderation
598
    $illrq_obj->status('NEW')->store;
589
    $illrq_obj->status('NEW')->store;
Lines 804-862 subtest 'Checking Limits' => sub { Link Here
804
795
805
    $schema->storage->txn_rollback;
796
    $schema->storage->txn_rollback;
806
};
797
};
807
808
subtest 'TO_JSON() tests' => sub {
809
810
    plan tests => 10;
811
812
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
813
814
    # Mock ->capabilities
815
    $illreqmodule->mock( 'capabilities', sub { return 'capable'; } );
816
817
    # Mock ->metadata
818
    $illreqmodule->mock( 'metadata', sub { return 'metawhat?'; } );
819
820
    $schema->storage->txn_begin;
821
822
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
823
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
824
    my $illreq  = $builder->build_object(
825
        {
826
            class => 'Koha::Illrequests',
827
            value => {
828
                branchcode     => $library->branchcode,
829
                borrowernumber => $patron->borrowernumber
830
            }
831
        }
832
    );
833
    my $illreq_json = $illreq->TO_JSON;
834
    is( $illreq_json->{patron},
835
        undef, '%embed not passed, no \'patron\' attribute' );
836
    is( $illreq_json->{metadata},
837
        undef, '%embed not passed, no \'metadata\' attribute' );
838
    is( $illreq_json->{capabilities},
839
        undef, '%embed not passed, no \'capabilities\' attribute' );
840
    is( $illreq_json->{library},
841
        undef, '%embed not passed, no \'library\' attribute' );
842
843
    $illreq_json = $illreq->TO_JSON(
844
        { patron => 1, metadata => 1, capabilities => 1, library => 1 } );
845
    is( $illreq_json->{patron}->{firstname},
846
        $patron->firstname,
847
        '%embed passed, \'patron\' attribute correct (firstname)' );
848
    is( $illreq_json->{patron}->{surname},
849
        $patron->surname,
850
        '%embed passed, \'patron\' attribute correct (surname)' );
851
    is( $illreq_json->{patron}->{cardnumber},
852
        $patron->cardnumber,
853
        '%embed passed, \'patron\' attribute correct (cardnumber)' );
854
    is( $illreq_json->{metadata},
855
        'metawhat?', '%embed passed, \'metadata\' attribute correct' );
856
    is( $illreq_json->{capabilities},
857
        'capable', '%embed passed, \'capabilities\' attribute correct' );
858
    is( $illreq_json->{library}->{branchcode},
859
        $library->branchcode, '%embed not passed, no \'library\' attribute' );
860
861
    $schema->storage->txn_rollback;
862
};
(-)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