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