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