Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use lib '../lib', 'lib'; |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 3 | use Test::More; |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 4 | use Test::Mojo; |
| 5 | use Data::Dumper; |
| 6 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 7 | $ENV{MOJO_MODE} = 'test'; |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 8 | |
| 9 | my $t = Test::Mojo->new('Kalamar'); |
| 10 | |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 11 | $t->get_ok('/') |
| 12 | ->element_exists('form[action=/user/login] input[name=handle_or_email]'); |
| 13 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 14 | #$t->post_ok('/user/login' => form => { handle_or_email => 'test' }) |
| 15 | # ->status_is(302); |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 16 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 17 | $t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' }) |
| 18 | ->status_is(302) |
| 19 | ->header_is('Location' => '/'); |
| 20 | |
| 21 | $t->get_ok('/') |
| 22 | ->status_is(200) |
| 23 | ->element_exists('div.notify-error') |
Akron | 2e3d377 | 2017-04-14 16:20:40 +0200 | [diff] [blame] | 24 | ->element_exists('input[name=handle_or_email][value=test]') |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 25 | ; |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 26 | |
Akron | 2e3d377 | 2017-04-14 16:20:40 +0200 | [diff] [blame] | 27 | |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 28 | done_testing; |
| 29 | __END__ |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 30 | |
| 31 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 32 | |
| 33 | |
| 34 | |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 35 | ok(!$c->user->get('details'), 'User not logged in'); |
| 36 | |
| 37 | # Login with user credentials |
| 38 | ok($c->user->login('kustvakt', 'kustvakt2015'), 'Login with demo user'); |
| 39 | is($c->stash('user'), 'kustvakt', 'Kustvakt is logged in'); |
| 40 | like($c->stash('auth'), qr/^api_token /, 'Kustvakt is logged in'); |
| 41 | |
| 42 | my $details = $c->user->get('details'); |
| 43 | is($details->{email}, 'kustvakt@ids-mannheim.de', 'Email'); |
| 44 | is($details->{firstName}, 'Kustvakt', 'Firstname'); |
| 45 | is($details->{lastName}, 'KorAP', 'Lastname'); |
| 46 | is($details->{country}, 'Germany', 'Country'); |
| 47 | is($details->{address}, 'Mannheim', 'Address'); |
| 48 | is($details->{username}, 'kustvakt', 'Username'); |
| 49 | is($details->{institution}, 'IDS Mannheim', 'Institution'); |
| 50 | |
| 51 | my $settings = $c->user->get('settings'); |
| 52 | is($settings->{username}, 'kustvakt', 'Username'); |
| 53 | |
| 54 | # ok($c->user->set(details => { firstName => 'Me' }), 'Set first name'); |
| 55 | #ok($c->user->set(details => { |
| 56 | # firstName => 'Akron', |
| 57 | # lastName => 'Fuxfell' |
| 58 | #}), 'Set first name'); |
| 59 | |
| 60 | # diag Dumper $c->user->get('info'); |
| 61 | |
| 62 | ok(1,'Fine'); |
| 63 | |
| 64 | done_testing; |
| 65 | __END__ |