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

(-)a/t/db_dependent/api/v1/patrons.t (-2 / +52 lines)
Lines 43-49 my $t = Test::Mojo->new('Koha::REST::V1'); Link Here
43
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
43
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
44
44
45
subtest 'list() tests' => sub {
45
subtest 'list() tests' => sub {
46
    plan tests => 2;
46
47
    plan tests => 3;
47
48
48
    $schema->storage->txn_begin;
49
    $schema->storage->txn_begin;
49
    unauthorized_access_tests('GET', undef, undef);
50
    unauthorized_access_tests('GET', undef, undef);
Lines 140-145 subtest 'list() tests' => sub { Link Here
140
141
141
        $schema->storage->txn_rollback;
142
        $schema->storage->txn_rollback;
142
    };
143
    };
144
145
    subtest 'search_limited() tests' => sub {
146
147
        plan tests => 9;
148
149
        $schema->storage->txn_begin;
150
151
        my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
152
        my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
153
154
        my $patron_1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_1->id } });
155
        my $patron_2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_1->id } });
156
        my $patron_3 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_2->id } });
157
158
        my @libraries_where_can_see_patrons = ($library_1->id, $library_2->id);
159
160
        my $mocked_patron = Test::MockModule->new('Koha::Patron');
161
        $mocked_patron->mock( 'libraries_where_can_see_patrons', sub
162
            {
163
                return @libraries_where_can_see_patrons;
164
            }
165
        );
166
167
        my $librarian = $builder->build_object(
168
            {
169
                class => 'Koha::Patrons',
170
                value => { flags => 2**4 }    # borrowers flag = 4
171
            }
172
        );
173
        my $password = 'thePassword123';
174
        $librarian->set_password( { password => $password, skip_validation => 1 } );
175
        my $userid = $librarian->userid;
176
177
        $t->get_ok("//$userid:$password@/api/v1/patrons?_order_by=patron_id&q=" . encode_json({ library_id => [ $library_1->id, $library_2->id ] }))
178
          ->status_is(200)
179
          ->json_is( '/0/patron_id' => $patron_1->id )
180
          ->json_is( '/1/patron_id' => $patron_2->id )
181
          ->json_is( '/2/patron_id' => $patron_3->id );
182
183
        @libraries_where_can_see_patrons = ($library_2->id);
184
185
        my $res = $t->get_ok("//$userid:$password@/api/v1/patrons?_order_by=patron_id&q=" . encode_json({ library_id => [ $library_1->id, $library_2->id ] }))
186
          ->status_is(200)
187
          ->json_is( '/0/patron_id' => $patron_3->id, 'Returns the only allowed patron' )
188
          ->tx->res->json;
189
190
        is( scalar @{$res}, 1, 'Only one patron returned' );
191
192
        $schema->storage->txn_rollback;
193
    };
143
};
194
};
144
195
145
subtest 'get() tests' => sub {
196
subtest 'get() tests' => sub {
146
- 

Return to bug 29503