blob: d8a04504a5be0b08f6e0cbf9908d367853c87f7e [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
Akron1b0c2652017-04-27 15:28:49 +020076# Login mit falschem Nutzernamen:
77# 400 und:
78{"errors":[[2022,"LDAP Authentication failed due to unknown user or password!"]]}
79
Akron741b2b12017-04-13 22:15:59 +020080
81
Akrone8235be2016-06-27 11:02:18 +020082ok(!$c->user->get('details'), 'User not logged in');
83
84# Login with user credentials
85ok($c->user->login('kustvakt', 'kustvakt2015'), 'Login with demo user');
86is($c->stash('user'), 'kustvakt', 'Kustvakt is logged in');
87like($c->stash('auth'), qr/^api_token /, 'Kustvakt is logged in');
88
89my $details = $c->user->get('details');
90is($details->{email}, 'kustvakt@ids-mannheim.de', 'Email');
91is($details->{firstName}, 'Kustvakt', 'Firstname');
92is($details->{lastName}, 'KorAP', 'Lastname');
93is($details->{country}, 'Germany', 'Country');
94is($details->{address}, 'Mannheim', 'Address');
95is($details->{username}, 'kustvakt', 'Username');
96is($details->{institution}, 'IDS Mannheim', 'Institution');
97
98my $settings = $c->user->get('settings');
99is($settings->{username}, 'kustvakt', 'Username');
100
101# ok($c->user->set(details => { firstName => 'Me' }), 'Set first name');
102#ok($c->user->set(details => {
103# firstName => 'Akron',
104# lastName => 'Fuxfell'
105#}), 'Set first name');
106
107# diag Dumper $c->user->get('info');
108
109ok(1,'Fine');
110
111done_testing;
112__END__