summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-08-28 20:33:02 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-08-28 20:33:02 +0200
commitea0fe3ea3e72eb690dd5a92eb4831523be740d08 (patch)
tree5bdb9c62e14b6b9f065e3985f251ef1663098725 /t
parent51af59647ef06fa39bec75cd1a9e57cb795d1419 (diff)
add journey edit test
Diffstat (limited to 't')
-rw-r--r--t/11-journey-stats.t3
-rw-r--r--t/12-journey-edit.t199
2 files changed, 201 insertions, 1 deletions
diff --git a/t/11-journey-stats.t b/t/11-journey-stats.t
index 23fba56..3a28794 100644
--- a/t/11-journey-stats.t
+++ b/t/11-journey-stats.t
@@ -90,7 +90,8 @@ $t->get_ok('/journey/1')->status_is(200)->content_like(qr{M.nster\(Westf\)Hbf})
->content_like(qr{Linie 42})->content_like(qr{..:36})
->content_like(qr{..:34})->content_like(qr{ca[.] 62 km})
->content_like(qr{Luftlinie: 62 km})->content_like(qr{64 km/h})
- ->content_like(qr{Passierschein A38});
+ ->content_like(qr{Passierschein A38})
+ ->content_like(qr{Daten wurden manuell eingetragen});
$t->get_ok('/history/2018/10')->status_is(200)->content_like(qr{62 km})
->content_like(qr{00:58 Stunden})->content_like(qr{00:00 Stunden})
diff --git a/t/12-journey-edit.t b/t/12-journey-edit.t
new file mode 100644
index 0000000..b1cf6af
--- /dev/null
+++ b/t/12-journey-edit.t
@@ -0,0 +1,199 @@
+#!/usr/bin/env perl
+use Mojo::Base -strict;
+
+# Tests journey entry and statistics
+
+use Test::More;
+use Test::Mojo;
+
+# Include application
+use FindBin;
+require "$FindBin::Bin/../index.pl";
+
+use DateTime;
+
+my $t = Test::Mojo->new('Travelynx');
+
+if ( not $t->app->config->{db} ) {
+ plan( skip_all => 'No database configured' );
+}
+
+$t->app->pg->db->query('drop schema if exists travelynx_test_12 cascade');
+$t->app->pg->db->query('create schema travelynx_test_12');
+$t->app->pg->db->query('set search_path to travelynx_test_12');
+$t->app->pg->on(
+ connection => sub {
+ my ( $pg, $dbh ) = @_;
+ $dbh->do('set search_path to travelynx_test_12');
+ }
+);
+
+$t->app->config->{mail}->{disabled} = 1;
+
+$t->app->start( 'database', 'migrate' );
+
+my $csrf_token
+ = $t->ua->get('/register')->res->dom->at('input[name=csrf_token]')
+ ->attr('value');
+
+# Successful registration
+$t->post_ok(
+ '/register' => form => {
+ csrf_token => $csrf_token,
+ user => 'someone',
+ email => 'foo@example.org',
+ password => 'foofoofoo',
+ password2 => 'foofoofoo',
+ }
+);
+$t->status_is(200)->content_like(qr{Verifizierungslink});
+
+my $res = $t->app->pg->db->select( 'users', ['id'], { name => 'someone' } );
+my $uid = $res->hash->{id};
+$res = $t->app->pg->db->select( 'pending_registrations', ['token'],
+ { user_id => $uid } );
+my $token = $res->hash->{token};
+
+# Successful verification
+$t->get_ok("/reg/${uid}/${token}");
+$t->status_is(200)->content_like(qr{freigeschaltet});
+
+# Successful login
+$t->post_ok(
+ '/login' => form => {
+ csrf_token => $csrf_token,
+ user => 'someone',
+ password => 'foofoofoo',
+ }
+);
+$t->status_is(302)->header_is( location => '/' );
+
+$t->app->journeys->add(
+ db => $t->app->pg->db,
+ uid => $uid,
+ dep_station => 'EMST',
+ arr_station => 'EG',
+ sched_departure => DateTime->new(
+ year => 2018,
+ month => 10,
+ day => 16,
+ hour => 17,
+ minute => 36,
+ time_zone => 'Europe/Berlin'
+ ),
+ rt_departure => DateTime->new(
+ year => 2018,
+ month => 10,
+ day => 16,
+ hour => 17,
+ minute => 36,
+ time_zone => 'Europe/Berlin'
+ ),
+ sched_arrival => DateTime->new(
+ year => 2018,
+ month => 10,
+ day => 16,
+ hour => 18,
+ minute => 34,
+ time_zone => 'Europe/Berlin'
+ ),
+ rt_arrival => DateTime->new(
+ year => 2018,
+ month => 10,
+ day => 16,
+ hour => 18,
+ minute => 34,
+ time_zone => 'Europe/Berlin'
+ ),
+ cancelled => 0,
+ train_type => 'RE',
+ train_line => '42',
+ train_no => '11238',
+ comment => 'Huhu'
+);
+
+$t->get_ok('/journey/1')->status_is(200)->content_like(qr{M.nster\(Westf\)Hbf})
+ ->content_like(qr{Gelsenkirchen Hbf})->content_like(qr{RE 11238})
+ ->content_like(qr{Linie 42})->content_like(qr{..:36})
+ ->content_like(qr{..:34})->content_like(qr{ca[.] 62 km})
+ ->content_like(qr{Luftlinie: 62 km})->content_like(qr{64 km/h})
+ ->content_like(qr{Huhu})->content_like(qr{Daten wurden manuell eingetragen});
+
+$t->post_ok(
+ '/journey/edit' => form => {
+ action => 'edit',
+ journey_id => 1,
+ }
+);
+
+$t->status_is(200)->content_like(qr{M.nster\(Westf\)Hbf})
+ ->content_like(qr{Gelsenkirchen Hbf})->content_like(qr{RE 11238})
+ ->content_like(qr{Linie 42})->content_like(qr{16.10.2018 ..:36})
+ ->content_like(qr{16.10.2018 ..:34})->content_like(qr{Huhu});
+
+$csrf_token = $t->tx->res->dom->at('input[name=csrf_token]')->attr('value');
+
+$t->post_ok(
+ '/journey/edit' => form => {
+ action => 'save',
+ journey_id => 1,
+ csrf_token => $csrf_token,
+ from_name => 'Münster(Westf)Hbf',
+ to_name => 'Gelsenkirchen Hbf',
+ sched_departure => '16.10.2018 17:36',
+ rt_departure => '16.10.2018 17:36',
+ sched_arrival => '16.10.2018 18:34',
+ rt_arrival => '16.10.2018 18:34',
+ }
+);
+
+$t->status_is(302)->header_is( location => '/journey/1' );
+
+$t->get_ok('/journey/1')->status_is(200)->content_like(qr{M.nster\(Westf\)Hbf})
+ ->content_like(qr{Gelsenkirchen Hbf})->content_like(qr{RE 11238})
+ ->content_like(qr{Linie 42})->content_like(qr{..:36})
+ ->content_like(qr{..:34})->content_like(qr{ca[.] 62 km})
+ ->content_like(qr{Luftlinie: 62 km})->content_like(qr{64 km/h})
+ ->content_like(qr{Huhu})->content_like(qr{Daten wurden manuell eingetragen});
+
+$t->post_ok(
+ '/journey/edit' => form => {
+ action => 'edit',
+ journey_id => 1,
+ }
+);
+
+$t->status_is(200)->content_like(qr{M.nster\(Westf\)Hbf})
+ ->content_like(qr{Gelsenkirchen Hbf})->content_like(qr{RE 11238})
+ ->content_like(qr{Linie 42})->content_like(qr{16.10.2018 ..:36})
+ ->content_like(qr{16.10.2018 ..:34})->content_like(qr{Huhu});
+
+$csrf_token = $t->tx->res->dom->at('input[name=csrf_token]')->attr('value');
+
+$t->post_ok(
+ '/journey/edit' => form => {
+ action => 'save',
+ journey_id => 1,
+ csrf_token => $csrf_token,
+ from_name => 'Münster(Westf)Hbf',
+ to_name => 'Gelsenkirchen Hbf',
+ sched_departure => '16.10.2018 17:36',
+ rt_departure => '16.10.2018 17:42',
+ sched_arrival => '16.10.2018 18:34',
+ rt_arrival => '16.10.2018 18:33',
+ }
+);
+
+$t->status_is(302)->header_is( location => '/journey/1' );
+
+$t->get_ok('/journey/1')->status_is(200)->content_like(qr{M.nster\(Westf\)Hbf})
+ ->content_like(qr{Gelsenkirchen Hbf})->content_like(qr{RE 11238})
+ ->content_like(qr{Linie 42})
+ ->content_like(qr{..:42\s*\(\+6,\s*Plan: ..:36\)})
+ ->content_like(qr{..:33\s*\(-1,\s*Plan: ..:34\)})
+ ->content_like(qr{ca[.] 62 km})->content_like(qr{Luftlinie: 62 km})
+ ->content_like(qr{73 km/h})->content_like(qr{Huhu})
+ ->content_like(qr{Daten wurden manuell eingetragen});
+
+$t->app->pg->db->query('drop schema travelynx_test_12 cascade');
+done_testing();