blob: 4c79c536a339ab4dc98927070df8791cadb9c7dd [file] [log] [blame]
Akronb3923852016-02-01 16:07:59 +01001use Mojo::Base -strict;
2use Test::Mojo;
3use Test::More;
4use Mojolicious::Lite;
5use lib 'lib', '../lib';
6
7my $t = Test::Mojo->new;
8my $app = $t->app;
9
10# Add additional plugin path
11push(@{app->plugins->namespaces}, 'Kalamar::Plugin');
12
13plugin 'CHI' => {
14 user => {
15 driver => 'Memory',
16 global => 1
17 }
18};
19
20plugin 'KalamarUser' => {
21 api => 'http://10.0.10.51:7070/api/v0.1/'
22};
23
24post '/acct/login' => sub {
25 my $c = shift;
26 my $user = $c->param('user');
27 my $pwd = $c->param('pwd');
28 return $c->redirect_to('index') if $c->user->login($user, $pwd);
29 return $c->redirect_to;
30} => 'login';
31
32
33get '/' => sub {
34 my $c = shift;
35 my $details = $c->user->get('details');
36 return $c->redirect_to('login') unless $details;
37 $c->render(json => $details);
38} => 'index';
39
40
41get '/acct/settings' => sub {
42 my $c = shift;
43 my $settings = $c->user->get('settings');
44 return $c->redirect_to('login') unless $settings;
45 $c->render(json => $settings);
46};
47
48
49$t->get_ok('/')
50 ->status_is(302)
51 ->header_is('location', '/acct/login');
52
53# Tests
54$t->post_ok('/acct/login' => {} => form => {
55 user => 'kustvakt',
56 pwd => 'kustvakt2015'
57})
58 ->status_is(302)
59 ->header_is('location', '/');
60
61$t->get_ok('/')
62 ->status_is(200)
63 ->json_is('/country', 'Germany')
64 ->json_is('/firstName', 'Kustvakt')
65 ->json_is('/lastName', 'KorAP')
66 ->json_is('/email', 'kustvakt@ids-mannheim.de')
67 ;
68
69$t->get_ok('/acct/settings')
70 ->status_is(200)
71 ->json_is('/queryLanguage', 'COSMAS2')
72 ->json_is('/constFoundry', 'mate')
73 ->json_is('/relFoundry', 'mate')
74 ->json_is('/lemmaFoundry', 'tt')
75 ->json_is('/POSFoundry', 'tt')
76 ;
77
78done_testing;
79
80__END__
81
82# print Dumper $user->user_query;
83# print Dumper $user->get_collection_stat('242eea9442fcba4e4f51e4ff292eebe2aca4e7f3');
84# print Dumper $user->user_settings;
85print Dumper $user->collections;
86
87#print "\n";
88
89# my $x = 'ZGU0ZTllNTFkYzc3M2VhZmViYzdkYWE2ODI5NDc3NTk4NGQ1YThhOTMwOTNhOWYxNWMwN2M3Y2YyZmE3N2RlNQ==';
90# print b($x)->b64_decode,"\n";
91
92my $user = Kalamar::User->new->authorize_jwt('kustvakt', 'kustvakt2015');