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 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 7 | $ENV{MOJO_MODE} = 'test'; |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 8 | |
| 9 | my $t = Test::Mojo->new('Kalamar'); |
| 10 | |
Akron | bc213c0 | 2017-04-20 16:45:55 +0200 | [diff] [blame^] | 11 | $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 | |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 18 | $t->get_ok('/') |
| 19 | ->element_exists('form[action=/user/login] input[name=handle_or_email]'); |
| 20 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 21 | $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') |
Akron | 2e3d377 | 2017-04-14 16:20:40 +0200 | [diff] [blame] | 28 | ->element_exists('input[name=handle_or_email][value=test]') |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 29 | ; |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 30 | |
Akron | e5ef4e0 | 2017-04-19 17:07:52 +0200 | [diff] [blame] | 31 | $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') |
Akron | bc213c0 | 2017-04-20 16:45:55 +0200 | [diff] [blame^] | 39 | ->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\"/) |
Akron | e5ef4e0 | 2017-04-19 17:07:52 +0200 | [diff] [blame] | 50 | ; |
| 51 | |
Akron | 2e3d377 | 2017-04-14 16:20:40 +0200 | [diff] [blame] | 52 | |
Akron | bc213c0 | 2017-04-20 16:45:55 +0200 | [diff] [blame^] | 53 | # 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 | |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 72 | done_testing; |
| 73 | __END__ |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 74 | |
| 75 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 76 | |
| 77 | |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 78 | ok(!$c->user->get('details'), 'User not logged in'); |
| 79 | |
| 80 | # Login with user credentials |
| 81 | ok($c->user->login('kustvakt', 'kustvakt2015'), 'Login with demo user'); |
| 82 | is($c->stash('user'), 'kustvakt', 'Kustvakt is logged in'); |
| 83 | like($c->stash('auth'), qr/^api_token /, 'Kustvakt is logged in'); |
| 84 | |
| 85 | my $details = $c->user->get('details'); |
| 86 | is($details->{email}, 'kustvakt@ids-mannheim.de', 'Email'); |
| 87 | is($details->{firstName}, 'Kustvakt', 'Firstname'); |
| 88 | is($details->{lastName}, 'KorAP', 'Lastname'); |
| 89 | is($details->{country}, 'Germany', 'Country'); |
| 90 | is($details->{address}, 'Mannheim', 'Address'); |
| 91 | is($details->{username}, 'kustvakt', 'Username'); |
| 92 | is($details->{institution}, 'IDS Mannheim', 'Institution'); |
| 93 | |
| 94 | my $settings = $c->user->get('settings'); |
| 95 | is($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 | |
| 105 | ok(1,'Fine'); |
| 106 | |
| 107 | done_testing; |
| 108 | __END__ |