blob: d904fb75484322838c9b21a0ee78a86489a74bfd [file] [log] [blame]
Akrone8235be2016-06-27 11:02:18 +02001use Mojo::Base -strict;
2use lib '../lib', 'lib';
Akronbe9d5b32017-04-05 20:48:24 +02003use Test::More;
Akrone8235be2016-06-27 11:02:18 +02004use Test::Mojo;
5use Data::Dumper;
6
Akron741b2b12017-04-13 22:15:59 +02007$ENV{MOJO_MODE} = 'test';
Akrone8235be2016-06-27 11:02:18 +02008
9my $t = Test::Mojo->new('Kalamar');
10
Akronbe9d5b32017-04-05 20:48:24 +020011$t->get_ok('/')
12 ->element_exists('form[action=/user/login] input[name=handle_or_email]');
13
Akron741b2b12017-04-13 22:15:59 +020014$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')
Akron2e3d3772017-04-14 16:20:40 +020021 ->element_exists('input[name=handle_or_email][value=test]')
Akron741b2b12017-04-13 22:15:59 +020022 ;
Akronbe9d5b32017-04-05 20:48:24 +020023
Akrone5ef4e02017-04-19 17:07:52 +020024$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
Akron2e3d3772017-04-14 16:20:40 +020035
Akronbe9d5b32017-04-05 20:48:24 +020036done_testing;
37__END__
Akrone8235be2016-06-27 11:02:18 +020038
39
Akron741b2b12017-04-13 22:15:59 +020040
41
42
Akrone8235be2016-06-27 11:02:18 +020043ok(!$c->user->get('details'), 'User not logged in');
44
45# Login with user credentials
46ok($c->user->login('kustvakt', 'kustvakt2015'), 'Login with demo user');
47is($c->stash('user'), 'kustvakt', 'Kustvakt is logged in');
48like($c->stash('auth'), qr/^api_token /, 'Kustvakt is logged in');
49
50my $details = $c->user->get('details');
51is($details->{email}, 'kustvakt@ids-mannheim.de', 'Email');
52is($details->{firstName}, 'Kustvakt', 'Firstname');
53is($details->{lastName}, 'KorAP', 'Lastname');
54is($details->{country}, 'Germany', 'Country');
55is($details->{address}, 'Mannheim', 'Address');
56is($details->{username}, 'kustvakt', 'Username');
57is($details->{institution}, 'IDS Mannheim', 'Institution');
58
59my $settings = $c->user->get('settings');
60is($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
70ok(1,'Fine');
71
72done_testing;
73__END__