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