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

(-)a/api/v1/swagger/paths/suggestions.yaml (-1 / +17 lines)
Lines 57-62 Link Here
57
        required: true
57
        required: true
58
        schema:
58
        schema:
59
          $ref: "../swagger.yaml#/definitions/suggestion"
59
          $ref: "../swagger.yaml#/definitions/suggestion"
60
      - name: x-koha-override
61
        in: header
62
        required: false
63
        description: Overrides list sent as a request header
64
        type: array
65
        items:
66
          type: string
67
          enum:
68
            - any
69
            - max_total
70
            - max_pending
71
        collectionFormat: csv
60
    produces:
72
    produces:
61
      - application/json
73
      - application/json
62
    responses:
74
    responses:
Lines 65-71 Link Here
65
        schema:
77
        schema:
66
          $ref: "../swagger.yaml#/definitions/suggestion"
78
          $ref: "../swagger.yaml#/definitions/suggestion"
67
      "400":
79
      "400":
68
        description: Bad request
80
        description: |
81
          Bad request. Possible `error_code` attribute values:
82
83
          * `max_total_reached`
84
          * `max_pending_reached`
69
        schema:
85
        schema:
70
          $ref: "../swagger.yaml#/definitions/error"
86
          $ref: "../swagger.yaml#/definitions/error"
71
      "403":
87
      "403":
(-)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