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

(-)a/t/Koha/REST/Plugin/Query.t (-11 / +68 lines)
Lines 209-225 get '/build_query' => sub { Link Here
209
get '/stash_embed' => sub {
209
get '/stash_embed' => sub {
210
    my $c = shift;
210
    my $c = shift;
211
211
212
    $c->stash_embed();
212
    try {
213
    my $embed   = $c->stash('koha.embed');
213
        $c->stash_embed(
214
    my $strings = $c->stash('koha.strings');
214
            {
215
                spec => {
216
                    'parameters' => [
217
                        {
218
                            'in'    => 'header',
219
                            'name'  => 'x-koha-embed',
220
                            'items' => {
221
                                'enum' => [
222
                                    'checkouts', 'checkouts.item',
223
                                    'library',   'holds+count'
224
                                ]
225
                            }
226
                        }
227
                    ]
228
                }
229
            }
230
        );
215
231
216
    $c->render(
232
        my $embed   = $c->stash('koha.embed');
217
        status => 200,
233
        my $strings = $c->stash('koha.strings');
218
        json   => {
234
219
            strings => $strings,
235
        $c->render(
220
            embed   => $embed,
236
            status => 200,
221
        }
237
            json   => {
222
    );
238
                strings => $strings,
239
                embed   => $embed
240
            }
241
        );
242
    }
243
    catch {
244
        $c->render(
245
            status => 400,
246
            json   => { error => "$_" }
247
        );
248
    };
249
};
250
251
get '/stash_embed_no_spec' => sub {
252
    my $c = shift;
253
254
    try {
255
        $c->stash_embed( { spec => {} } );
256
257
        my $embed   = $c->stash('koha.embed');
258
        my $strings = $c->stash('koha.strings');
259
260
        $c->render(
261
            status => 200,
262
            json   => {
263
                strings => $strings,
264
                embed   => $embed
265
            }
266
        );
267
    }
268
    catch {
269
        $c->render(
270
            status => 400,
271
            json   => { error => "$_" }
272
        );
273
    };
223
};
274
};
224
275
225
get '/stash_overrides' => sub {
276
get '/stash_overrides' => sub {
Lines 433-439 subtest '_build_query_params_from_api' => sub { Link Here
433
484
434
subtest 'stash_embed() tests' => sub {
485
subtest 'stash_embed() tests' => sub {
435
486
436
    plan tests => 14;
487
    plan tests => 17;
437
488
438
    my $t = Test::Mojo->new;
489
    my $t = Test::Mojo->new;
439
490
Lines 465-470 subtest 'stash_embed() tests' => sub { Link Here
465
            patron    => { }
516
            patron    => { }
466
        })
517
        })
467
      ->json_is( '/strings' => 1 );
518
      ->json_is( '/strings' => 1 );
519
520
    $t->get_ok( '/stash_embed_no_spec' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } )
521
      ->status_is(400)
522
      ->json_is( '/error' =>
523
          qq{Exception 'Koha::Exceptions::BadParameter' thrown 'Embedding objects is not allowed on this endpoint.'\n}
524
      );
468
};
525
};
469
526
470
subtest 'stash_overrides() tests' => sub {
527
subtest 'stash_overrides() tests' => sub {
(-)a/t/db_dependent/api/v1/query.t (-2 / +9 lines)
Lines 108-114 subtest 'q handling tests' => sub { Link Here
108
108
109
subtest 'x-koha-embed tests' => sub {
109
subtest 'x-koha-embed tests' => sub {
110
110
111
    plan tests => 5;
111
    plan tests => 8;
112
112
113
    $schema->storage->txn_begin;
113
    $schema->storage->txn_begin;
114
114
Lines 138-142 subtest 'x-koha-embed tests' => sub { Link Here
138
        }
138
        }
139
    )->status_is(400);
139
    )->status_is(400);
140
140
141
    $res = $t->get_ok(
142
        "//$userid:$password@/api/v1/cities" => {
143
            'x-koha-embed' => 'any_embed'
144
        }
145
    )->status_is(400)->tx->res->json;
146
147
    is($res, 'Embedding objects is not allowed on this endpoint.', 'Correct error message is returned');
148
141
    $schema->storage->txn_rollback;
149
    $schema->storage->txn_rollback;
142
};
150
};
143
- 

Return to bug 32713