Akron | b392385 | 2016-02-01 16:07:59 +0100 | [diff] [blame^] | 1 | use Mojo::Base -strict; |
| 2 | use Test::Mojo; |
| 3 | use Test::More; |
| 4 | use Mojolicious::Lite; |
| 5 | use lib 'lib', '../lib'; |
| 6 | |
| 7 | my $t = Test::Mojo->new; |
| 8 | my $app = $t->app; |
| 9 | |
| 10 | # Add additional plugin path |
| 11 | push(@{app->plugins->namespaces}, 'Kalamar::Plugin'); |
| 12 | |
| 13 | plugin 'CHI' => { |
| 14 | user => { |
| 15 | driver => 'Memory', |
| 16 | global => 1 |
| 17 | } |
| 18 | }; |
| 19 | |
| 20 | plugin 'KalamarUser' => { |
| 21 | api => 'http://10.0.10.51:7070/api/v0.1/' |
| 22 | }; |
| 23 | |
| 24 | post '/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 | |
| 33 | get '/' => 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 | |
| 41 | get '/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 | |
| 78 | done_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; |
| 85 | print Dumper $user->collections; |
| 86 | |
| 87 | #print "\n"; |
| 88 | |
| 89 | # my $x = 'ZGU0ZTllNTFkYzc3M2VhZmViYzdkYWE2ODI5NDc3NTk4NGQ1YThhOTMwOTNhOWYxNWMwN2M3Y2YyZmE3N2RlNQ=='; |
| 90 | # print b($x)->b64_decode,"\n"; |
| 91 | |
| 92 | my $user = Kalamar::User->new->authorize_jwt('kustvakt', 'kustvakt2015'); |