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

(-)a/api/v1/swagger/paths/suggestions.yaml (+10 lines)
Lines 53-58 Link Here
53
        required: true
53
        required: true
54
        schema:
54
        schema:
55
          $ref: ../definitions.yaml#/suggestion
55
          $ref: ../definitions.yaml#/suggestion
56
      - name: x-koha-override
57
        in: header
58
        required: false
59
        description: |
60
          Overrides list sent as a request header
61
          Valid values:           
62
            * any
63
            * max_total
64
            * max_pending
65
        type: string
56
    produces:
66
    produces:
57
      - application/json
67
      - application/json
58
    responses:
68
    responses:
(-)a/t/db_dependent/api/v1/suggestions.t (-2 / +45 lines)
Lines 149-155 subtest 'get() tests' => sub { Link Here
149
149
150
subtest 'add() tests' => sub {
150
subtest 'add() tests' => sub {
151
151
152
    plan tests => 15;
152
    plan tests => 16;
153
153
154
    $schema->storage->txn_begin;
154
    $schema->storage->txn_begin;
155
155
Lines 237-242 subtest 'add() tests' => sub { Link Here
237
        ]
237
        ]
238
          );
238
          );
239
239
240
    subtest 'x-koha-override tests' => sub {
241
242
        plan tests => 14;
243
244
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
245
246
        t::lib::Mocks::mock_preference( 'MaxTotalSuggestions',    4 );
247
        t::lib::Mocks::mock_preference( 'MaxOpenSuggestions',     2 );
248
        t::lib::Mocks::mock_preference( 'NumberOfSuggestionDays', 2 );
249
250
        my $suggestion = $builder->build_object(
251
            {   class => 'Koha::Suggestions',
252
                value => { suggestedby => $patron->id, STATUS => 'ACCEPTED' }
253
            }
254
        );
255
256
        my $suggestion_data = $suggestion->to_api;
257
        delete $suggestion_data->{suggestion_id};
258
        delete $suggestion_data->{status};
259
260
        $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data )
261
          ->status_is( 201, 'First pending suggestion' );
262
263
        $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data )
264
          ->status_is( 201, 'Second pending suggestion' );
265
266
        $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data )
267
          ->status_is(400)
268
          ->json_is( '/error_code' => 'max_pending_reached' );
269
270
        $t->post_ok( "//$userid:$password@/api/v1/suggestions"
271
             => { 'x-koha-override' => 'max_pending' }
272
             => json => $suggestion_data )
273
          ->status_is( 201, 'max_pending override does the job' );
274
275
        $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data )
276
          ->status_is(400)
277
          ->json_is( '/error_code' => 'max_total_reached' );
278
279
        $t->post_ok(
280
            "//$userid:$password@/api/v1/suggestions" => { 'x-koha-override' => 'any' } => json => $suggestion_data )
281
          ->status_is( 201, 'any overrides anything' );
282
    };
283
240
    $schema->storage->txn_rollback;
284
    $schema->storage->txn_rollback;
241
};
285
};
242
286
243
- 

Return to bug 30663