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