Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use Test::More; |
| 3 | use Test::Mojo; |
| 4 | use Mojo::File qw/path/; |
| 5 | use Data::Dumper; |
| 6 | |
| 7 | |
| 8 | ##################### |
| 9 | # Start Fake server # |
| 10 | ##################### |
| 11 | my $mount_point = '/realapi/'; |
| 12 | $ENV{KALAMAR_API} = $mount_point; |
| 13 | |
| 14 | my $t = Test::Mojo->new('Kalamar' => { |
| 15 | Kalamar => { |
Akron | b7876a8 | 2019-07-18 13:09:00 +0200 | [diff] [blame] | 16 | plugins => ['Auth'], |
| 17 | experimental_proxy => 1 |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 18 | } |
| 19 | }); |
| 20 | |
| 21 | # Mount fake backend |
| 22 | # Get the fixture path |
| 23 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server'); |
| 24 | my $fake_backend = $t->app->plugin( |
| 25 | Mount => { |
| 26 | $mount_point => |
| 27 | $fixtures_path->child('mock.pl') |
| 28 | } |
| 29 | ); |
| 30 | # Configure fake backend |
| 31 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 32 | |
| 33 | # Globally set server |
| 34 | $t->app->ua->server->app($t->app); |
| 35 | |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 36 | $t->get_ok('/realapi/v1.0') |
| 37 | ->status_is(200) |
| 38 | ->content_is('Fake server available') |
| 39 | ; |
| 40 | |
| 41 | $t->get_ok('/api/v1.0/') |
| 42 | ->status_is(200) |
| 43 | ->content_is('Fake server available') |
| 44 | ; |
| 45 | |
| 46 | $t->get_ok('/api/v1.0/search?ql=cosmas3') |
| 47 | ->status_is(400) |
| 48 | ->json_is('/errors/0/0','307') |
Akron | 56b3d0d | 2019-07-10 17:13:31 +0200 | [diff] [blame] | 49 | ->header_is('connection', 'close') |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 50 | ; |
| 51 | |
| 52 | $t->post_ok('/api/v1.0/oauth2/token' => {} => form => { |
| 53 | username => 'test', |
| 54 | password => 'pass' |
| 55 | }) |
| 56 | ->status_is(400) |
| 57 | ->json_is('/errors/0/1','Grant Type unknown') |
| 58 | ; |
| 59 | |
| 60 | $t->post_ok('/api/v1.0/oauth2/token' => {} => form => { |
| 61 | grant_type => 'password', |
| 62 | client_id => 2, |
| 63 | client_secret => 'k414m4r-s3cr3t', |
| 64 | username => 'test', |
| 65 | password => 'pass' |
| 66 | }) |
| 67 | ->status_is(200) |
| 68 | ->json_is('/token_type', 'Bearer') |
| 69 | ; |
| 70 | |
| 71 | |
| 72 | done_testing; |
| 73 | __END__ |