baf7e23a3f6d8908e1fd73b0995afe529558971d
[srvgit] / t / lib / Koha / Plugin / BadAPIRoute.pm
1 package Koha::Plugin::BadAPIRoute;
2
3 use Modern::Perl;
4
5 use Mojo::JSON qw(decode_json);
6
7 use base qw(Koha::Plugins::Base);
8
9 our $VERSION = 0.01;
10 our $metadata = {
11     name            => 'Bad API Route Plugin',
12     author          => 'John Doe',
13     description     => 'Test plugin for bad API route',
14     date_authored   => '2018-',
15     date_updated    => '2013-01-14',
16     minimum_version => '17.11',
17     maximum_version => undef,
18     version         => $VERSION,
19     my_example_tag  => 'find_me',
20 };
21
22 sub new {
23     my ( $class, $args ) = @_;
24     $args->{'metadata'} = $metadata;
25     my $self = $class->SUPER::new($args);
26     return $self;
27 }
28
29 sub api_namespace {
30     return "badass";
31 }
32
33 sub api_routes {
34     my ( $self, $args ) = @_;
35
36     my $spec = qq{
37 {
38   "/patrons/{patron_id}/bother_wrong": {
39     "put": {
40       "x-mojo-to": "Koha::Plugin::BadAPIRoute#bother",
41       "operationId": "BotherPatron",
42       "tags": ["patrons"],
43       "parameters": [{
44         "name": "patron_id",
45         "in": "nowhere",
46         "description": "Internal patron identifier",
47         "required": true,
48         "type": "integer"
49       }],
50       "produces": [
51         "application/json"
52       ],
53       "responses": {
54         "200": {
55           "description": "A bothered patron",
56           "schema": {
57               "type": "object",
58                 "properties": {
59                   "bothered": {
60                     "description": "If the patron has been bothered",
61                     "type": "boolean"
62                   }
63                 }
64           }
65         },
66         "404": {
67           "description": "An error occurred",
68           "schema": {
69               "type": "object",
70                 "properties": {
71                   "error": {
72                     "description": "An explanation for the error",
73                     "type": "string"
74                   }
75                 }
76           }
77         }
78       },
79       "x-koha-authorization": {
80         "permissions": {
81           "borrowers": "1"
82         }
83       }
84     }
85   }
86 }
87     };
88
89     return decode_json($spec);
90 }
91
92 1;