blob: f30e049c5c3ce143289faddb74485a56fbe637d9 [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 => {
Akronb7876a82019-07-18 13:09:00 +020016 plugins => ['Auth'],
17 experimental_proxy => 1
Akron63d963b2019-07-05 15:35:51 +020018 }
19});
20
21# Mount fake backend
22# Get the fixture path
23my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server');
24my $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
Akron63d963b2019-07-05 15:35:51 +020036$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')
Akron56b3d0d2019-07-10 17:13:31 +020049 ->header_is('connection', 'close')
Akron63d963b2019-07-05 15:35:51 +020050 ;
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
72done_testing;
73__END__