blob: a484d1d7c8ba0b3960f852de9579f44aeb772065 [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
Akronbc213c02017-04-20 16:45:55 +020011$t->get_ok('/?q=Baum')
12 ->status_is(200)
13 ->text_like('h1 span', qr/KorAP: Find .Baum./i)
14 ->text_like('#total-results', qr/\d+$/)
15 ->content_like(qr/\"authorized\"\:null/)
16 ;
17
Akronbe9d5b32017-04-05 20:48:24 +020018$t->get_ok('/')
19 ->element_exists('form[action=/user/login] input[name=handle_or_email]');
20
Akron741b2b12017-04-13 22:15:59 +020021$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
22 ->status_is(302)
23 ->header_is('Location' => '/');
24
25$t->get_ok('/')
26 ->status_is(200)
27 ->element_exists('div.notify-error')
Akron2e3d3772017-04-14 16:20:40 +020028 ->element_exists('input[name=handle_or_email][value=test]')
Akron741b2b12017-04-13 22:15:59 +020029 ;
Akronbe9d5b32017-04-05 20:48:24 +020030
Akrone5ef4e02017-04-19 17:07:52 +020031$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'pass' })
32 ->status_is(302)
33 ->header_is('Location' => '/');
34
35$t->get_ok('/')
36 ->status_is(200)
37 ->element_exists_not('div.notify-error')
38 ->element_exists('div.notify-success')
Akronbc213c02017-04-20 16:45:55 +020039 ->text_is('div.notify-success', 'Login successful')
40 ;
41
42# Now the user is logged in and should be able to
43# search with authorization
44$t->get_ok('/?q=Baum')
45 ->status_is(200)
46 ->text_like('h1 span', qr/KorAP: Find .Baum./i)
47 ->text_like('#total-results', qr/\d+$/)
48 ->element_exists_not('div.notify-error')
49 ->content_like(qr/\"authorized\"\:\"test\"/)
Akrone5ef4e02017-04-19 17:07:52 +020050 ;
51
Akron2e3d3772017-04-14 16:20:40 +020052
Akronbc213c02017-04-20 16:45:55 +020053# Logout
54$t->get_ok('/user/logout')
55 ->status_is(302)
56 ->header_is('Location' => '/');
57
58$t->get_ok('/')
59 ->status_is(200)
60 ->element_exists_not('div.notify-error')
61 ->element_exists('div.notify-success')
62 ->text_is('div.notify-success', 'Logout successful')
63 ;
64
65$t->get_ok('/?q=Baum')
66 ->status_is(200)
67 ->text_like('h1 span', qr/KorAP: Find .Baum./i)
68 ->text_like('#total-results', qr/\d+$/)
69 ->content_like(qr/\"authorized\"\:null/)
70 ;
71
Akronbe9d5b32017-04-05 20:48:24 +020072done_testing;
73__END__
Akrone8235be2016-06-27 11:02:18 +020074
75
Akron741b2b12017-04-13 22:15:59 +020076
77
Akrone8235be2016-06-27 11:02:18 +020078ok(!$c->user->get('details'), 'User not logged in');
79
80# Login with user credentials
81ok($c->user->login('kustvakt', 'kustvakt2015'), 'Login with demo user');
82is($c->stash('user'), 'kustvakt', 'Kustvakt is logged in');
83like($c->stash('auth'), qr/^api_token /, 'Kustvakt is logged in');
84
85my $details = $c->user->get('details');
86is($details->{email}, 'kustvakt@ids-mannheim.de', 'Email');
87is($details->{firstName}, 'Kustvakt', 'Firstname');
88is($details->{lastName}, 'KorAP', 'Lastname');
89is($details->{country}, 'Germany', 'Country');
90is($details->{address}, 'Mannheim', 'Address');
91is($details->{username}, 'kustvakt', 'Username');
92is($details->{institution}, 'IDS Mannheim', 'Institution');
93
94my $settings = $c->user->get('settings');
95is($settings->{username}, 'kustvakt', 'Username');
96
97# ok($c->user->set(details => { firstName => 'Me' }), 'Set first name');
98#ok($c->user->set(details => {
99# firstName => 'Akron',
100# lastName => 'Fuxfell'
101#}), 'Set first name');
102
103# diag Dumper $c->user->get('info');
104
105ok(1,'Fine');
106
107done_testing;
108__END__