From 04f4de4f14f57cd52ee0d61e6fc2b30c781cd204 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 27 Jul 2025 10:34:16 +0200 Subject: tests: Remove (not really helpful) number prefix --- t/01-static.t | 50 --- t/02-static-en.t | 50 --- t/03-static-fr.t | 50 --- t/10-registration.t | 228 ------------ t/11-journey-stats.t | 205 ----------- t/12-journey-edit.t | 240 ------------- t/21-relations.t | 857 ---------------------------------------------- t/22-transit-visibility.t | 530 ---------------------------- t/23-journey-visibility.t | 480 -------------------------- t/24-past-visibility.t | 569 ------------------------------ t/journey-edit.t | 240 +++++++++++++ t/journey-stats.t | 205 +++++++++++ t/journey-visibility.t | 480 ++++++++++++++++++++++++++ t/past-visibility.t | 569 ++++++++++++++++++++++++++++++ t/registration.t | 228 ++++++++++++ t/relations.t | 857 ++++++++++++++++++++++++++++++++++++++++++++++ t/static-de.t | 50 +++ t/static-en.t | 50 +++ t/static-fr.t | 50 +++ t/transit-visibility.t | 530 ++++++++++++++++++++++++++++ 20 files changed, 3259 insertions(+), 3259 deletions(-) delete mode 100644 t/01-static.t delete mode 100644 t/02-static-en.t delete mode 100644 t/03-static-fr.t delete mode 100644 t/10-registration.t delete mode 100644 t/11-journey-stats.t delete mode 100644 t/12-journey-edit.t delete mode 100644 t/21-relations.t delete mode 100644 t/22-transit-visibility.t delete mode 100644 t/23-journey-visibility.t delete mode 100644 t/24-past-visibility.t create mode 100644 t/journey-edit.t create mode 100644 t/journey-stats.t create mode 100644 t/journey-visibility.t create mode 100644 t/past-visibility.t create mode 100644 t/registration.t create mode 100644 t/relations.t create mode 100644 t/static-de.t create mode 100644 t/static-en.t create mode 100644 t/static-fr.t create mode 100644 t/transit-visibility.t diff --git a/t/01-static.t b/t/01-static.t deleted file mode 100644 index 21d0350..0000000 --- a/t/01-static.t +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2020 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -use Test::More; -use Test::Mojo; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); - -$t->get_ok('/')->status_is(200); -$t->text_like( 'a[href="/register"]' => qr{Registrieren} ); -$t->text_like( 'a[href="/login"]' => qr{Anmelden} ); - -$t->get_ok('/about')->status_is(200); -$t->get_ok('/api')->status_is(200); -$t->get_ok('/changelog')->status_is(200); -$t->get_ok('/legend')->status_is(200); -$t->get_ok('/offline.html')->status_is(200); - -$t->get_ok('/login')->status_is(200); -$t->element_exists('input[name="csrf_token"]'); -$t->text_like( 'button' => qr{Anmelden} ); - -$t->get_ok('/recover')->status_is(200); - -$t->get_ok('/register')->status_is(200); -$t->element_exists('input[name="csrf_token"]'); -$t->element_exists('a[href="/impressum"]'); -$t->text_like( 'button' => qr{Registrieren} ); - -# Protected sites should redirect to login form - -for my $protected (qw(/account /account/password /history /s/EE)) { - $t->get_ok($protected)->text_like( 'button' => qr{Anmelden} ); -} - -# Otherwise, we expect a 404 -$t->get_ok('/definitelydoesnotexist')->status_is(404); - -done_testing(); diff --git a/t/02-static-en.t b/t/02-static-en.t deleted file mode 100644 index 26641cb..0000000 --- a/t/02-static-en.t +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2020 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -use Test::More; -use Test::Mojo; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('en-GB') } ); - -$t->get_ok('/')->status_is(200); -$t->text_like( 'a[href="/register"]' => qr{Register} ); -$t->text_like( 'a[href="/login"]' => qr{Login} ); - -$t->get_ok('/about')->status_is(200); -$t->get_ok('/api')->status_is(200); -$t->get_ok('/changelog')->status_is(200); -$t->get_ok('/legend')->status_is(200); -$t->get_ok('/offline.html')->status_is(200); - -$t->get_ok('/login')->status_is(200); -$t->element_exists('input[name="csrf_token"]'); -$t->text_like( 'button' => qr{Login} ); - -$t->get_ok('/recover')->status_is(200); - -$t->get_ok('/register')->status_is(200); -$t->element_exists('input[name="csrf_token"]'); -$t->element_exists('a[href="/impressum"]'); -$t->text_like( 'button' => qr{Register} ); - -# Protected sites should redirect to login form - -for my $protected (qw(/account /account/password /history /s/EE)) { - $t->get_ok($protected)->text_like( 'button' => qr{Login} ); -} - -# Otherwise, we expect a 404 -$t->get_ok('/definitelydoesnotexist')->status_is(404); - -done_testing(); diff --git a/t/03-static-fr.t b/t/03-static-fr.t deleted file mode 100644 index dc4c278..0000000 --- a/t/03-static-fr.t +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2020 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -use Test::More; -use Test::Mojo; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('fr-FR') } ); - -$t->get_ok('/')->status_is(200); -$t->text_like( 'a[href="/register"]' => qr{Inscription} ); -$t->text_like( 'a[href="/login"]' => qr{Connexion} ); - -$t->get_ok('/about')->status_is(200); -$t->get_ok('/api')->status_is(200); -$t->get_ok('/changelog')->status_is(200); -$t->get_ok('/legend')->status_is(200); -$t->get_ok('/offline.html')->status_is(200); - -$t->get_ok('/login')->status_is(200); -$t->element_exists('input[name="csrf_token"]'); -$t->text_like( 'button' => qr{Connexion} ); - -$t->get_ok('/recover')->status_is(200); - -$t->get_ok('/register')->status_is(200); -$t->element_exists('input[name="csrf_token"]'); -$t->element_exists('a[href="/impressum"]'); -$t->text_like( 'button' => qr{Inscription} ); - -# Protected sites should redirect to login form - -for my $protected (qw(/account /account/password /history /s/EE)) { - $t->get_ok($protected)->text_like( 'button' => qr{Connexion} ); -} - -# Otherwise, we expect a 404 -$t->get_ok('/definitelydoesnotexist')->status_is(404); - -done_testing(); diff --git a/t/10-registration.t b/t/10-registration.t deleted file mode 100644 index ec09eaf..0000000 --- a/t/10-registration.t +++ /dev/null @@ -1,228 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2020 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -# Tests the standard registration -> verification -> successful login flow - -use Test::More; -use Test::Mojo; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); - -if ( not $t->app->config->{db} ) { - plan( skip_all => 'No database configured' ); -} - -$t->app->pg->db->query('drop schema if exists travelynx_test_02 cascade'); -$t->app->pg->db->query('create schema travelynx_test_02'); -$t->app->pg->db->query('set search_path to travelynx_test_02'); -$t->app->pg->on( - connection => sub { - my ( $pg, $dbh ) = @_; - $dbh->do('set search_path to travelynx_test_02'); - } -); - -$t->app->config->{mail}->{disabled} = 1; - -$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 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, - dt => 1, - user => 'someone', - email => 'foo@example.org', - password => 'foofoofoo', - password2 => 'foofoofoo', - } -); -$t->status_is(200)->content_like(qr{Verifizierungslink}); - -# Failed registration (CSRF) -$t->post_ok( - '/register' => form => { - csrf_token => $csrf_token, - user => 'noone', - email => 'foo2@example.org', - password => 'foofoofoo', - password2 => 'foofoofoo', - } -); -$t->status_is(400)->content_like(qr{CSRF}); - -# Failed registration (user name not available) -$t->post_ok( - '/register' => form => { - csrf_token => $csrf_token, - dt => 1, - user => 'someone', - email => 'foo@example.org', - password => 'foofoofoo', - password2 => 'foofoofoo', - } -); -$t->status_is(200)->content_like(qr{Name bereits vergeben}); - -$csrf_token = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - -# Failed login (not verified yet) -$t->post_ok( - '/login' => form => { - csrf_token => $csrf_token, - user => 'someone', - password => 'foofoofoo', - } -); -$t->status_is(400)->content_like(qr{nicht freigeschaltet}); - -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}); - -# Failed login (wrong password) -$t->post_ok( - '/login' => form => { - csrf_token => $csrf_token, - user => 'someone', - password => 'definitely invalid', - } -); -$t->status_is(400)->content_like(qr{falsches Passwort}); - -# Successful login -$t->post_ok( - '/login' => form => { - csrf_token => $csrf_token, - user => 'someone', - password => 'foofoofoo', - } -); -$t->status_is(302)->header_is( location => '/' ); - -# Request deletion - -$csrf_token = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - -$t->post_ok( - '/delete' => form => { - action => 'delete', - csrf_token => $csrf_token, - password => 'foofoofoo', - } -); -$t->status_is(302)->header_is( location => '/account' ); -$t->get_ok('/account'); -$t->status_is(200)->content_like(qr{wird gelöscht}); - -$t->post_ok( - '/delete' => form => { - action => 'undelete', - csrf_token => $csrf_token, - } -); -$t->status_is(302)->header_is( location => '/account' ); -$t->get_ok('/account'); -$t->status_is(200)->content_unlike(qr{wird gelöscht}); - -$csrf_token - = $t->ua->get('/account/password')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - -$t->post_ok( - '/account/password' => form => { - csrf_token => $csrf_token, - oldpw => 'foofoofoo', - newpw => 'barbarbar', - newpw2 => 'barbarbar', - } -); -$t->status_is(302)->header_is( location => '/account' ); - -$csrf_token = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') - ->attr('value'); -$t->post_ok( - '/logout' => form => { - csrf_token => $csrf_token, - } -); -$t->status_is(302)->header_is( location => '/login' ); - -$csrf_token = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') - ->attr('value'); -$t->post_ok( - '/login' => form => { - csrf_token => $csrf_token, - user => 'someone', - password => 'barbarbar', - } -); -$t->status_is(302)->header_is( location => '/' ); - -$csrf_token = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') - ->attr('value'); -$t->post_ok( - '/logout' => form => { - csrf_token => $csrf_token, - } -); -$t->status_is(302)->header_is( location => '/login' ); - -$csrf_token = $t->ua->get('/recover')->res->dom->at('input[name=csrf_token]') - ->attr('value'); -$t->post_ok( - '/recover' => form => { - csrf_token => $csrf_token, - action => 'initiate', - user => 'someone', - email => 'foo@example.org', - } -); -$t->status_is(200)->content_like(qr{wird durchgeführt}); - -$res = $t->app->pg->db->select( 'pending_passwords', ['token'], - { user_id => $uid } ); -$token = $res->hash->{token}; - -$t->get_ok("/recover/${uid}/${token}") - ->status_is(200) - ->content_like(qr{Neues Passwort eintragen}); - -$t->post_ok( - '/recover' => form => { - csrf_token => $csrf_token, - action => 'set_password', - id => $uid, - token => $token, - newpw => 'foofoofoo2', - newpw2 => 'foofoofoo2', - } -); -$t->status_is(302)->header_is( location => '/account' ); - -$t->app->pg->db->query('drop schema travelynx_test_02 cascade'); -done_testing(); diff --git a/t/11-journey-stats.t b/t/11-journey-stats.t deleted file mode 100644 index 205bf96..0000000 --- a/t/11-journey-stats.t +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2020 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -# Tests journey entry and statistics - -use Test::More; -use Test::Mojo; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); - -if ( not $t->app->config->{db} ) { - plan( skip_all => 'No database configured' ); -} - -$t->app->pg->db->query('drop schema if exists travelynx_test_11 cascade'); -$t->app->pg->db->query('create schema travelynx_test_11'); -$t->app->pg->db->query('set search_path to travelynx_test_11'); -$t->app->pg->on( - connection => sub { - my ( $pg, $dbh ) = @_; - $dbh->do('set search_path to travelynx_test_11'); - } -); - -$t->app->config->{mail}->{disabled} = 1; - -$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 0; -$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, - dt => 1, - 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 => '/' ); - -$csrf_token - = $t->ua->get('/journey/add')->res->dom->at('input[name=csrf_token]') - ->attr('value'); -$t->post_ok( - '/journey/add' => form => { - csrf_token => $csrf_token, - action => 'save', - train => 'RE 42 11238', - dep_station => 'EMSTP', - sched_departure => '2018-10-16T17:36', - rt_departure => '2018-10-16T17:36', - arr_station => 'EG', - sched_arrival => '2018-10-16T18:34', - rt_arrival => '2018-10-16T18:34', - comment => 'Passierschein A38', - } -); -$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{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}) - ->content_like(qr{Bei Abfahrt: 00:00 Stunden}) - ->content_like(qr{Bei Ankunft: 00:00 Stunden}); - -$t->get_ok('/history/2018') - ->status_is(200) - ->content_like(qr{62 km}) - ->content_like(qr{00:58 Stunden}) - ->content_like(qr{00:00 Stunden}) - ->content_like(qr{Bei Abfahrt: 00:00 Stunden}) - ->content_like(qr{Bei Ankunft: 00:00 Stunden}); - -$t->get_ok('/history/map') - ->status_is(200) - ->content_like(qr{\[\[51.956[^,]*,7.635[^]]*\],'M.nster\(Westf\)Hbf'\],}) - ->content_like(qr{\[\[51.504[^,]*,7.102[^]]*\],'Gelsenkirchen Hbf'\]}); - -$csrf_token - = $t->ua->get('/journey/add')->res->dom->at('input[name=csrf_token]') - ->attr('value'); -$t->post_ok( - '/journey/add' => form => { - csrf_token => $csrf_token, - action => 'save', - train => 'RE 42 11238', - dep_station => 'EMSTP', - sched_departure => '2018-11-16T17:36', - rt_departure => '2018-11-16T17:45', - arr_station => 'EG', - sched_arrival => '2018-11-16T18:34', - rt_arrival => '2018-11-16T19:00', - } -); -$t->status_is(302)->header_is( location => '/journey/2' ); - -$t->get_ok('/history/2018/11') - ->status_is(200) - ->content_like(qr{62 km}) - ->content_like(qr{01:15 Stunden}) - ->content_like(qr{nach Fahrplan: 00:58}) - ->content_like(qr{00:00 Stunden}) - ->content_like(qr{Bei Abfahrt: 00:09 Stunden}) - ->content_like(qr{Bei Ankunft: 00:26 Stunden}); - -$t->get_ok('/history/2018') - ->status_is(200) - ->content_like(qr{124 km}) - ->content_like(qr{02:13 Stunden}) - ->content_like(qr{nach Fahrplan: 01:56}) - ->content_like(qr{00:00 Stunden}) - ->content_like(qr{Bei Abfahrt: 00:09 Stunden}) - ->content_like(qr{Bei Ankunft: 00:26 Stunden}); - -$csrf_token - = $t->ua->get('/journey/add')->res->dom->at('input[name=csrf_token]') - ->attr('value'); -$t->post_ok( - '/journey/add' => form => { - csrf_token => $csrf_token, - action => 'save', - train => 'ICE 1', - dep_station => 'EE', - sched_departure => '2018-11-17T15:42', - rt_departure => '', - arr_station => 'BL', - sched_arrival => '2018-11-17T19:42', - rt_arrival => '', - } -); -$t->status_is(302)->header_is( location => '/journey/3' ); - -$t->get_ok('/history/2018/11') - ->status_is(200) - ->content_like(qr{513 km}) - ->content_like(qr{05:15 Stunden}) - ->content_like(qr{nach Fahrplan: 04:58}) - ->content_like(qr{00:00 Stunden}) - ->content_like(qr{Bei Abfahrt: 00:09 Stunden}) - ->content_like(qr{Bei Ankunft: 00:26 Stunden}); - -$t->get_ok('/history/2018') - ->status_is(200) - ->content_like(qr{576 km}) - ->content_like(qr{06:13 Stunden}) - ->content_like(qr{nach Fahrplan: 05:56}) - ->content_like(qr{00:00 Stunden}) - ->content_like(qr{Bei Abfahrt: 00:09 Stunden}) - ->content_like(qr{Bei Ankunft: 00:26 Stunden}); - -$t->app->pg->db->query('drop schema travelynx_test_11 cascade'); -done_testing(); diff --git a/t/12-journey-edit.t b/t/12-journey-edit.t deleted file mode 100644 index f0b2f36..0000000 --- a/t/12-journey-edit.t +++ /dev/null @@ -1,240 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2020 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -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; -use utf8; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); - -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; - -$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 0; -$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, - dt => 1, - 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 => '/' ); - -my ( $success, $error ) = $t->app->journeys->add( - db => $t->app->pg->db, - uid => $uid, - backend_id => 1, - dep_station => 'Münster(Westf)Hbf', - arr_station => 'Gelsenkirchen Hbf', - 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' -); - -ok( $success, "journeys->add" ); -is( $error, undef, "journeys->add" ); - -$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*\n*\s* \(\+6, \s*Plan: \s*\n*\s* ..:36\)}mx) - ->content_like(qr{..:33 \s*\n*\s* \( -1, \s*Plan: \s*\n*\s* ..:34\)}mx) - ->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(); diff --git a/t/21-relations.t b/t/21-relations.t deleted file mode 100644 index c5fbe32..0000000 --- a/t/21-relations.t +++ /dev/null @@ -1,857 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2023 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -# Tests journey entry and statistics - -use Test::More; -use Test::Mojo; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); - -if ( not $t->app->config->{db} ) { - plan( skip_all => 'No database configured' ); -} - -$t->app->pg->db->query('drop schema if exists travelynx_test_21 cascade'); -$t->app->pg->db->query('create schema travelynx_test_21'); -$t->app->pg->db->query('set search_path to travelynx_test_21'); -$t->app->pg->on( - connection => sub { - my ( $pg, $dbh ) = @_; - $dbh->do('set search_path to travelynx_test_21'); - } -); - -$t->app->config->{mail}->{disabled} = 1; - -$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 1; -$t->app->start( 'database', 'migrate' ); - -my $u = $t->app->users; - -my $uid1 = $u->add( - name => 'test1', - email => 'test1@example.org', - token => 'abcd', - password => q{}, -); - -my $uid2 = $u->add( - name => 'test2', - email => 'test2@example.org', - token => 'efgh', - password => q{}, -); - -$u->verify_registration_token( - uid => $uid1, - token => 'abcd' -); -$u->verify_registration_token( - uid => $uid2, - token => 'efgh' -); - -$u->set_social( - uid => $uid1, - accept_follow_requests => 1 -); -$u->set_social( - uid => $uid2, - accept_follow_requests => 1 -); - -is( - $u->get_relation( - uid => $uid1, - target => $uid2 - ), - undef -); -is( - $u->get_relation( - uid => $uid2, - target => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); - -$u->request_follow( - uid => $uid1, - target => $uid2 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - 'requests_follow' -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 1 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 1 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 1 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 1 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 1 ); -is_deeply( - [ $u->get_follow_requests( uid => $uid2 ) ], - [ { id => $uid1, name => 'test1' } ] -); -is_deeply( - [ $u->get_follow_requests( uid => $uid1, sent => 1 ) ], - [ { id => $uid2, name => 'test2' } ] -); - -$u->reject_follow_request( - uid => $uid2, - applicant => $uid1 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - undef -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); - -$u->request_follow( - uid => $uid1, - target => $uid2 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - 'requests_follow' -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 1 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 1 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 1 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 1 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 1 ); -is_deeply( - [ $u->get_follow_requests( uid => $uid2 ) ], - [ { id => $uid1, name => 'test1' } ] -); -is_deeply( - [ $u->get_follow_requests( uid => $uid1, sent => 1 ) ], - [ { id => $uid2, name => 'test2' } ] -); - -$u->accept_follow_request( - uid => $uid2, - applicant => $uid1 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - 'follows' -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 1 ); -is( scalar $u->get_followees( uid => $uid1 ), 1 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); -is_deeply( - [ $u->get_followers( uid => $uid2 ) ], - [ - { - id => $uid1, - name => 'test1', - following_back => 0, - followback_requested => 0, - can_follow_back => 0, - can_request_follow_back => 1 - } - ] -); -is_deeply( - [ $u->get_followees( uid => $uid1 ) ], - [ { id => $uid2, name => 'test2', following_back => 0 } ] -); - -$u->remove_follower( - uid => $uid2, - follower => $uid1 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - undef -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); - -$u->request_follow( - uid => $uid1, - target => $uid2 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - 'requests_follow' -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); - -$u->block( - uid => $uid2, - target => $uid1 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - 'is_blocked_by' -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 1 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); -is_deeply( - [ $u->get_blocked_users( uid => $uid2 ) ], - [ { id => $uid1, name => 'test1' } ] -); - -$u->unblock( - uid => $uid2, - target => $uid1 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - undef -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); - -$u->block( - uid => $uid2, - target => $uid1 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - 'is_blocked_by' -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 1 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); -is_deeply( - [ $u->get_blocked_users( uid => $uid2 ) ], - [ { id => $uid1, name => 'test1' } ] -); - -$u->unblock( - uid => $uid2, - target => $uid1 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - undef -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); - -$u->request_follow( - uid => $uid1, - target => $uid2 -); -$u->accept_follow_request( - uid => $uid2, - applicant => $uid1 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - 'follows' -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 1 ); -is( scalar $u->get_followees( uid => $uid1 ), 1 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); -is_deeply( - [ $u->get_followers( uid => $uid2 ) ], - [ - { - id => $uid1, - name => 'test1', - following_back => 0, - followback_requested => 0, - can_follow_back => 0, - can_request_follow_back => 1 - } - ] -); -is_deeply( - [ $u->get_followees( uid => $uid1 ) ], - [ { id => $uid2, name => 'test2', following_back => 0 } ] -); - -$u->unfollow( - uid => $uid1, - target => $uid2 -); - -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - undef -); -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - undef -); -is( scalar $u->get_followers( uid => $uid1 ), 0 ); -is( scalar $u->get_followers( uid => $uid2 ), 0 ); -is( scalar $u->get_followees( uid => $uid1 ), 0 ); -is( scalar $u->get_followees( uid => $uid2 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); -is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); -is( - scalar $u->get_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - scalar $u->get_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); -is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); -is( $u->has_follow_requests( uid => $uid1 ), 0 ); -is( $u->has_follow_requests( uid => $uid2 ), 0 ); -is( - $u->has_follow_requests( - uid => $uid1, - sent => 1 - ), - 0 -); -is( - $u->has_follow_requests( - uid => $uid2, - sent => 1 - ), - 0 -); -is( $u->get( uid => $uid1 )->{notifications}, 0 ); -is( $u->get( uid => $uid2 )->{notifications}, 0 ); - -$t->app->pg->db->query('drop schema travelynx_test_21 cascade'); -done_testing(); diff --git a/t/22-transit-visibility.t b/t/22-transit-visibility.t deleted file mode 100644 index 6aa48ed..0000000 --- a/t/22-transit-visibility.t +++ /dev/null @@ -1,530 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2023 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -# Tests journey entry and statistics - -use Test::More; -use Test::Mojo; - -use DateTime; -use Travel::Status::DE::IRIS::Result; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); - -if ( not $t->app->config->{db} ) { - plan( skip_all => 'No database configured' ); -} - -$t->app->pg->db->query('drop schema if exists travelynx_test_22 cascade'); -$t->app->pg->db->query('create schema travelynx_test_22'); -$t->app->pg->db->query('set search_path to travelynx_test_22'); -$t->app->pg->on( - connection => sub { - my ( $pg, $dbh ) = @_; - $dbh->do('set search_path to travelynx_test_22'); - } -); - -$t->app->config->{mail}->{disabled} = 1; - -$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 1; -$t->app->start( 'database', 'migrate' ); - -my $u = $t->app->users; - -sub login { - my %opt = @_; - my $csrf_token - = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - $t->post_ok( - '/login' => form => { - csrf_token => $csrf_token, - user => $opt{user}, - password => $opt{password}, - } - ); - $t->status_is(302)->header_is( location => '/' ); -} - -sub logout { - my $csrf_token - = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - $t->post_ok( - '/logout' => form => { - csrf_token => $csrf_token, - } - ); - $t->status_is(302)->header_is( location => '/login' ); -} - -sub test_intransit_visibility { - my %opt = @_; - - if ( $opt{set_default_visibility} ) { - my %p = %{ $u->get_privacy_by( uid => $opt{uid} ) }; - $p{default_visibility} = $opt{set_default_visibility}; - $u->set_privacy( - uid => $opt{uid}, - %p - ); - } - - if ( $opt{set_visibility} ) { - $t->app->in_transit->update_visibility( - uid => $opt{uid}, - visibility => $opt{set_visibility} - ); - } - - my $status = $t->app->get_user_status( $opt{uid} ); - my $token - = $status->{sched_departure}->epoch - . q{?token=} - . $status->{dep_eva} . q{-} - . $status->{timestamp}->epoch % 337; - my $j_token - = $status->{dep_eva} . q{-} - . $status->{timestamp}->epoch % 337 . q{-} - . $status->{sched_departure}->epoch; - - my $desc - = "in_transit vis=$opt{effective_visibility_str} (from $opt{visibility_str})"; - - is( $status->{visibility}, $opt{visibility}, $desc ); - is( $status->{visibility_str}, $opt{visibility_str}, $desc ); - is( $status->{effective_visibility}, $opt{effective_visibility}, $desc ); - is( $status->{effective_visibility_str}, - $opt{effective_visibility_str}, $desc ); - - if ( $opt{public} ) { - $t->get_ok('/status/test1') - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok('/ajax/status/test1.html') - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok('/p/test1')->status_is(200)->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok('/status/test1') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok('/ajax/status/test1.html') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok('/p/test1') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - } - - if ( $opt{with_token} ) { - $t->get_ok("/status/test1/$token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok("/ajax/status/test1.html?token=$j_token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/status/test1/$token") - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok("/ajax/status/test1.html?token=$j_token") - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - } - - login( - user => 'test1', - password => 'password1' - ); - - # users can see their own status if visibility is >= followrs - if ( $opt{effective_visibility} >= 60 ) { - $t->get_ok('/status/test1') - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok('/ajax/status/test1.html') - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok('/p/test1')->status_is(200)->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok('/status/test1') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok('/ajax/status/test1.html') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok('/p/test1') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - } - - # users can see their own status with token if visibility is >= unlisted - if ( $opt{effective_visibility} >= 30 ) { - $t->get_ok("/status/test1/$token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok("/ajax/status/test1.html?token=$j_token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/status/test1/$token") - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok("/ajax/status/test1.html?token=$j_token") - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - } - - logout(); - login( - user => 'test2', - password => 'password2' - ); - - # uid2 can see uid1 if visibility is >= followers - if ( $opt{effective_visibility} >= 60 ) { - $t->get_ok('/status/test1') - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok('/ajax/status/test1.html') - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok('/p/test1')->status_is(200)->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok('/status/test1') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok('/ajax/status/test1.html') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok('/p/test1') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - } - - # uid2 can see uid1 with token if visibility is >= unlisted - if ( $opt{effective_visibility} >= 30 ) { - $t->get_ok("/status/test1/$token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok("/ajax/status/test1.html?token=$j_token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/status/test1/$token") - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok("/ajax/status/test1.html?token=$j_token") - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - } - - logout(); - login( - user => 'test3', - password => 'password3' - ); - - # uid3 can see uid1 if visibility is >= travelynx - if ( $opt{effective_visibility} >= 80 ) { - $t->get_ok('/status/test1') - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok('/ajax/status/test1.html') - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok('/p/test1')->status_is(200)->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok('/status/test1') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok('/ajax/status/test1.html') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok('/p/test1') - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - } - - # uid3 can see uid1 with token if visibility is >= unlisted - if ( $opt{effective_visibility} >= 30 ) { - $t->get_ok("/status/test1/$token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - $t->get_ok("/ajax/status/test1.html?token=$j_token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/status/test1/$token") - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - $t->get_ok("/ajax/status/test1.html?token=$j_token") - ->status_is(200) - ->content_like(qr{nicht eingecheckt}); - } - - logout(); -} - -my $uid1 = $u->add( - name => 'test1', - email => 'test1@example.org', - token => 'abcd', - password => 'password1', -); - -my $uid2 = $u->add( - name => 'test2', - email => 'test2@example.org', - token => 'efgh', - password => 'password2', -); - -my $uid3 = $u->add( - name => 'test3', - email => 'test3@example.org', - token => 'ijkl', - password => 'password3', -); - -$u->verify_registration_token( - uid => $uid1, - token => 'abcd' -); -$u->verify_registration_token( - uid => $uid2, - token => 'efgh' -); -$u->verify_registration_token( - uid => $uid3, - token => 'ijkl' -); - -$u->set_social( - uid => $uid1, - accept_follows => 1 -); -$u->set_social( - uid => $uid2, - accept_follows => 1 -); -$u->set_social( - uid => $uid3, - accept_follows => 1 -); - -$u->follow( - uid => $uid2, - target => $uid1 -); - -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - 'follows' -); -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - undef -); - -my $dep = DateTime->now; -my $arr = $dep->clone->add( hours => 1 ); -my $train_dep = Travel::Status::DE::IRIS::Result->new( - classes => 'N', - type => 'DPN', - train_no => '667', - raw_id => '1234-2306251312-1', - departure_ts => '2306251312', - platform => 8, - station => 'Aachen Hbf', - station_uic => 8000001, - route_post => 'Mainz Hbf|Aalen Hbf', -); -my $train_arr = Travel::Status::DE::IRIS::Result->new( - classes => 'N', - type => 'DPN', - train_no => '667', - raw_id => '1234-2306251312-3', - arrival_ts => '2306252000', - platform => 1, - station => 'Aalen Hbf', - station_uic => 8000002, - route_pre => 'Aachen Hbf|Mainz Hbf', -); -$t->app->in_transit->add( - uid => $uid1, - departure_eva => 8000001, - train => $train_dep, - route => [], - backend_id => $t->app->stations->get_backend_id( iris => 1 ), -); -$t->app->in_transit->set_arrival_eva( - uid => $uid1, - arrival_eva => 8000002, -); - -test_intransit_visibility( - uid => $uid1, - visibility => undef, - visibility_str => 'default', - effective_visibility => 30, - effective_visibility_str => 'unlisted', - public => 0, - with_token => 1, -); - -test_intransit_visibility( - uid => $uid1, - set_default_visibility => 10, - visibility => undef, - visibility_str => 'default', - effective_visibility => 10, - effective_visibility_str => 'private', - public => 0, - with_token => 0, -); - -test_intransit_visibility( - uid => $uid1, - set_default_visibility => 30, - visibility => undef, - visibility_str => 'default', - effective_visibility => 30, - effective_visibility_str => 'unlisted', - public => 0, - with_token => 1, -); - -test_intransit_visibility( - uid => $uid1, - set_default_visibility => 60, - visibility => undef, - visibility_str => 'default', - effective_visibility => 60, - effective_visibility_str => 'followers', - public => 0, - with_token => 1, -); - -test_intransit_visibility( - uid => $uid1, - set_default_visibility => 80, - visibility => undef, - visibility_str => 'default', - effective_visibility => 80, - effective_visibility_str => 'travelynx', - public => 0, - with_token => 1, -); - -test_intransit_visibility( - uid => $uid1, - set_default_visibility => 100, - visibility => undef, - visibility_str => 'default', - effective_visibility => 100, - effective_visibility_str => 'public', - public => 1, - with_token => 1, -); - -test_intransit_visibility( - uid => $uid1, - set_visibility => 'private', - visibility => 10, - visibility_str => 'private', - effective_visibility => 10, - effective_visibility_str => 'private', - public => 0, - with_token => 0, -); - -test_intransit_visibility( - uid => $uid1, - set_visibility => 'unlisted', - visibility => 30, - visibility_str => 'unlisted', - effective_visibility => 30, - effective_visibility_str => 'unlisted', - public => 0, - with_token => 1, -); - -test_intransit_visibility( - uid => $uid1, - set_visibility => 'followers', - visibility => 60, - visibility_str => 'followers', - effective_visibility => 60, - effective_visibility_str => 'followers', - public => 0, - with_token => 1, -); - -test_intransit_visibility( - uid => $uid1, - set_visibility => 'travelynx', - visibility => 80, - visibility_str => 'travelynx', - effective_visibility => 80, - effective_visibility_str => 'travelynx', - public => 0, - with_token => 1, -); - -test_intransit_visibility( - uid => $uid1, - set_visibility => 'public', - visibility => 100, - visibility_str => 'public', - effective_visibility => 100, - effective_visibility_str => 'public', - public => 1, - with_token => 1, -); - -$t->app->in_transit->update_visibility( - uid => $uid1, - visibility => undef, -); - -test_intransit_visibility( - uid => $uid1, - set_default_visibility => 10, - visibility => undef, - visibility_str => 'default', - effective_visibility => 10, - effective_visibility_str => 'private', - public => 0, - with_token => 0, -); - -$t->app->pg->db->query('drop schema travelynx_test_22 cascade'); -done_testing(); diff --git a/t/23-journey-visibility.t b/t/23-journey-visibility.t deleted file mode 100644 index c2294b3..0000000 --- a/t/23-journey-visibility.t +++ /dev/null @@ -1,480 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2023 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -# Tests journey entry and statistics - -use Test::More; -use Test::Mojo; - -use DateTime; -use Travel::Status::DE::IRIS::Result; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); - -if ( not $t->app->config->{db} ) { - plan( skip_all => 'No database configured' ); -} - -$t->app->pg->db->query('drop schema if exists travelynx_test_23 cascade'); -$t->app->pg->db->query('create schema travelynx_test_23'); -$t->app->pg->db->query('set search_path to travelynx_test_23'); -$t->app->pg->on( - connection => sub { - my ( $pg, $dbh ) = @_; - $dbh->do('set search_path to travelynx_test_23'); - } -); - -$t->app->config->{mail}->{disabled} = 1; - -$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 1; -$t->app->start( 'database', 'migrate' ); - -my $u = $t->app->users; - -sub login { - my %opt = @_; - my $csrf_token - = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - $t->post_ok( - '/login' => form => { - csrf_token => $csrf_token, - user => $opt{user}, - password => $opt{password}, - } - ); - $t->status_is(302)->header_is( location => '/' ); -} - -sub logout { - my $csrf_token - = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - $t->post_ok( - '/logout' => form => { - csrf_token => $csrf_token, - } - ); - $t->status_is(302)->header_is( location => '/login' ); -} - -sub test_journey_visibility { - my %opt = @_; - my $jid = $opt{journey_id}; - - if ( $opt{set_default_visibility} ) { - my %p = %{ $u->get_privacy_by( uid => $opt{uid} ) }; - $p{default_visibility} = $opt{set_default_visibility}; - $u->set_privacy( - uid => $opt{uid}, - %p - ); - } - - if ( $opt{set_visibility} ) { - $t->app->journeys->update_visibility( - uid => $opt{uid}, - id => $jid, - visibility => $opt{set_visibility} - ); - } - - my $status = $t->app->get_user_status( $opt{uid} ); - my $journey = $t->app->journeys->get_single( - uid => $opt{uid}, - journey_id => $jid - ); - my $token - = q{?token=} - . $status->{dep_eva} . q{-} - . $journey->{checkin_ts} % 337 . q{-} - . $status->{sched_departure}->epoch; - - my $desc - = "journey=$jid vis=$opt{effective_visibility_str} (from $opt{visibility_str})"; - - is( $status->{visibility}, $opt{visibility}, $desc ); - is( $status->{visibility_str}, $opt{visibility_str}, $desc ); - is( $status->{effective_visibility}, $opt{effective_visibility}, $desc ); - is( $status->{effective_visibility_str}, - $opt{effective_visibility_str}, $desc ); - - if ( $opt{public} ) { - $t->get_ok("/p/test1/j/$jid") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/p/test1/j/$jid") - ->status_is(404) - ->content_like(qr{Fahrt nicht gefunden.}); - } - - if ( $opt{with_token} ) { - $t->get_ok("/p/test1/j/$jid$token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/p/test1/j/$jid$token") - ->status_is(404) - ->content_like(qr{Fahrt nicht gefunden.}); - } - - login( - user => 'test1', - password => 'password1' - ); - - # users can see their own status if visibility is >= followrs - if ( $opt{effective_visibility} >= 60 ) { - $t->get_ok("/p/test1/j/$jid") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/p/test1/j/$jid") - ->status_is(404) - ->content_like(qr{Fahrt nicht gefunden.}); - } - - # users can see their own status with token if visibility is >= unlisted - if ( $opt{effective_visibility} >= 30 ) { - $t->get_ok("/p/test1/j/$jid$token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/p/test1/j/$jid$token") - ->status_is(404) - ->content_like(qr{Fahrt nicht gefunden.}); - } - - logout(); - login( - user => 'test2', - password => 'password2' - ); - - # uid2 can see uid1 if visibility is >= followers - if ( $opt{effective_visibility} >= 60 ) { - $t->get_ok("/p/test1/j/$jid") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/p/test1/j/$jid") - ->status_is(404) - ->content_like(qr{Fahrt nicht gefunden.}); - } - - # uid2 can see uid1 with token if visibility is >= unlisted - if ( $opt{effective_visibility} >= 30 ) { - $t->get_ok("/p/test1/j/$jid$token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/p/test1/j/$jid$token") - ->status_is(404) - ->content_like(qr{Fahrt nicht gefunden.}); - } - - logout(); - login( - user => 'test3', - password => 'password3' - ); - - # uid3 can see uid1 if visibility is >= travelynx - if ( $opt{effective_visibility} >= 80 ) { - $t->get_ok("/p/test1/j/$jid") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/p/test1/j/$jid") - ->status_is(404) - ->content_like(qr{Fahrt nicht gefunden.}); - } - - # uid3 can see uid1 with token if visibility is >= unlisted - if ( $opt{effective_visibility} >= 30 ) { - $t->get_ok("/p/test1/j/$jid$token") - ->status_is(200) - ->content_like(qr{DPN\s*667}); - } - else { - $t->get_ok("/p/test1/j/$jid$token") - ->status_is(404) - ->content_like(qr{Fahrt nicht gefunden.}); - } - - logout(); -} - -my $uid1 = $u->add( - name => 'test1', - email => 'test1@example.org', - token => 'abcd', - password => 'password1', -); - -my $uid2 = $u->add( - name => 'test2', - email => 'test2@example.org', - token => 'efgh', - password => 'password2', -); - -my $uid3 = $u->add( - name => 'test3', - email => 'test3@example.org', - token => 'ijkl', - password => 'password3', -); - -$u->verify_registration_token( - uid => $uid1, - token => 'abcd' -); -$u->verify_registration_token( - uid => $uid2, - token => 'efgh' -); -$u->verify_registration_token( - uid => $uid3, - token => 'ijkl' -); - -$u->set_social( - uid => $uid1, - accept_follows => 1 -); -$u->set_social( - uid => $uid2, - accept_follows => 1 -); -$u->set_social( - uid => $uid3, - accept_follows => 1 -); - -$u->follow( - uid => $uid2, - target => $uid1 -); - -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - 'follows' -); -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - undef -); - -my $dep = DateTime->now->subtract( hours => 2 ); -my $arr = DateTime->now->subtract( hours => 1 ); -my $train_dep = Travel::Status::DE::IRIS::Result->new( - classes => 'N', - type => 'DPN', - train_no => '667', - raw_id => '1234-2306251312-1', - departure_ts => $dep->strftime('%y%m%d%H%M'), - platform => 8, - station => 'Aachen Hbf', - station_uic => 8000001, - route_post => 'Mainz Hbf|Aalen Hbf', -); -my $train_arr = Travel::Status::DE::IRIS::Result->new( - classes => 'N', - type => 'DPN', - train_no => '667', - raw_id => '1234-2306251312-3', - arrival_ts => $arr->strftime('%y%m%d%H%M'), - platform => 1, - station => 'Aalen Hbf', - station_uic => 8000002, - route_pre => 'Aachen Hbf|Mainz Hbf', -); -$t->app->in_transit->add( - uid => $uid1, - departure_eva => 8000001, - train => $train_dep, - route => [], - backend_id => $t->app->stations->get_backend_id( iris => 1 ), -); -$t->app->in_transit->set_arrival_eva( - uid => $uid1, - arrival_eva => 8000002, -); - -my $db = $t->app->pg->db; -my $tx = $db->begin; - -my $journey = $t->app->in_transit->get( - uid => $uid1, - db => $db, -); -my $jid = $t->app->journeys->add_from_in_transit( - journey => $journey, - db => $db -); -$t->app->in_transit->delete( - uid => $uid1, - db => $db -); -$tx->commit; - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - visibility => undef, - visibility_str => 'default', - effective_visibility => 30, - effective_visibility_str => 'unlisted', - public => 0, - with_token => 1, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_default_visibility => 10, - visibility => undef, - visibility_str => 'default', - effective_visibility => 10, - effective_visibility_str => 'private', - public => 0, - with_token => 0, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_default_visibility => 30, - visibility => undef, - visibility_str => 'default', - effective_visibility => 30, - effective_visibility_str => 'unlisted', - public => 0, - with_token => 1, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_default_visibility => 60, - visibility => undef, - visibility_str => 'default', - effective_visibility => 60, - effective_visibility_str => 'followers', - public => 0, - with_token => 1, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_default_visibility => 80, - visibility => undef, - visibility_str => 'default', - effective_visibility => 80, - effective_visibility_str => 'travelynx', - public => 0, - with_token => 1, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_default_visibility => 100, - visibility => undef, - visibility_str => 'default', - effective_visibility => 100, - effective_visibility_str => 'public', - public => 1, - with_token => 1, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'private', - visibility => 10, - visibility_str => 'private', - effective_visibility => 10, - effective_visibility_str => 'private', - public => 0, - with_token => 0, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'unlisted', - visibility => 30, - visibility_str => 'unlisted', - effective_visibility => 30, - effective_visibility_str => 'unlisted', - public => 0, - with_token => 1, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'followers', - visibility => 60, - visibility_str => 'followers', - effective_visibility => 60, - effective_visibility_str => 'followers', - public => 0, - with_token => 1, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'travelynx', - visibility => 80, - visibility_str => 'travelynx', - effective_visibility => 80, - effective_visibility_str => 'travelynx', - public => 0, - with_token => 1, -); - -test_journey_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'public', - visibility => 100, - visibility_str => 'public', - effective_visibility => 100, - effective_visibility_str => 'public', - public => 1, - with_token => 1, -); - -$t->app->pg->db->query('drop schema travelynx_test_23 cascade'); -done_testing(); diff --git a/t/24-past-visibility.t b/t/24-past-visibility.t deleted file mode 100644 index 5c084b2..0000000 --- a/t/24-past-visibility.t +++ /dev/null @@ -1,569 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2023 Birte Kristina Friesel -# -# SPDX-License-Identifier: MIT - -use Mojo::Base -strict; - -# Tests journey entry and statistics - -use Test::More; -use Test::Mojo; - -use DateTime; -use Travel::Status::DE::IRIS::Result; - -# Include application -use FindBin; -require "$FindBin::Bin/../index.pl"; - -my $t = Test::Mojo->new('Travelynx'); - -$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); - -if ( not $t->app->config->{db} ) { - plan( skip_all => 'No database configured' ); -} - -$t->app->pg->db->query('drop schema if exists travelynx_test_24 cascade'); -$t->app->pg->db->query('create schema travelynx_test_24'); -$t->app->pg->db->query('set search_path to travelynx_test_24'); -$t->app->pg->on( - connection => sub { - my ( $pg, $dbh ) = @_; - $dbh->do('set search_path to travelynx_test_24'); - } -); - -$t->app->config->{mail}->{disabled} = 1; - -$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 1; -$t->app->start( 'database', 'migrate' ); - -my $u = $t->app->users; - -sub login { - my %opt = @_; - my $csrf_token - = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - $t->post_ok( - '/login' => form => { - csrf_token => $csrf_token, - user => $opt{user}, - password => $opt{password}, - } - ); - $t->status_is(302)->header_is( location => '/' ); -} - -sub logout { - my $csrf_token - = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') - ->attr('value'); - $t->post_ok( - '/logout' => form => { - csrf_token => $csrf_token, - } - ); - $t->status_is(302)->header_is( location => '/login' ); -} - -sub test_history_visibility { - my %opt = @_; - my $jid = $opt{journey_id}; - - if ( $opt{set_default_visibility} ) { - my %p = %{ $u->get_privacy_by( uid => $opt{uid} ) }; - $p{default_visibility} = $opt{set_default_visibility}; - $u->set_privacy( - uid => $opt{uid}, - %p - ); - } - - if ( $opt{set_past_visibility} ) { - my %p = %{ $u->get_privacy_by( uid => $opt{uid} ) }; - $p{past_visibility} = $opt{set_past_visibility}; - $u->set_privacy( - uid => $opt{uid}, - %p - ); - } - - if ( $opt{set_visibility} ) { - $t->app->journeys->update_visibility( - uid => $opt{uid}, - id => $jid, - visibility => $opt{set_visibility} - ); - } - - my $status = $t->app->get_user_status( $opt{uid} ); - my $journey = $t->app->journeys->get_single( - uid => $opt{uid}, - journey_id => $jid, - with_visibility => 1, - ); - my $token - = q{?token=} - . $status->{dep_eva} . q{-} - . $journey->{checkin_ts} % 337 . q{-} - . $status->{sched_departure}->epoch; - - $opt{set_past_visibility} //= q{}; - my $desc - = "history vis=$opt{set_past_visibility} journey=$jid vis=$journey->{effective_visibility_str}"; - - if ( $opt{public} ) { - $t->get_ok('/p/test1') - ->status_is(200) - ->content_like( qr{DPN\s*667}, "public $desc" ); - } - else { - $t->get_ok('/p/test1') - ->status_is(200) - ->content_unlike( qr{DPN\s*667}, "public $desc" ); - } - - login( - user => 'test1', - password => 'password1' - ); - - if ( $opt{self} ) { - $t->get_ok('/p/test1') - ->status_is(200) - ->content_like( qr{DPN\s*667}, "self $desc" ); - } - else { - $t->get_ok('/p/test1') - ->status_is(200) - ->content_unlike( qr{DPN\s*667}, "self $desc" ); - } - - logout(); - login( - user => 'test2', - password => 'password2' - ); - - if ( $opt{followers} ) { - $t->get_ok('/p/test1') - ->status_is(200) - ->content_like( qr{DPN\s*667}, "follower $desc" ); - } - else { - $t->get_ok('/p/test1') - ->status_is(200) - ->content_unlike( qr{DPN\s*667}, "follower $desc" ); - } - - logout(); - login( - user => 'test3', - password => 'password3' - ); - - if ( $opt{travelynx} ) { - $t->get_ok('/p/test1') - ->status_is(200) - ->content_like( qr{DPN\s*667}, "travelynx $desc" ); - } - else { - $t->get_ok('/p/test1') - ->status_is(200) - ->content_unlike( qr{DPN\s*667}, "travelynx $desc" ); - } - - logout(); -} - -my $uid1 = $u->add( - name => 'test1', - email => 'test1@example.org', - token => 'abcd', - password => 'password1', -); - -my $uid2 = $u->add( - name => 'test2', - email => 'test2@example.org', - token => 'efgh', - password => 'password2', -); - -my $uid3 = $u->add( - name => 'test3', - email => 'test3@example.org', - token => 'ijkl', - password => 'password3', -); - -$u->verify_registration_token( - uid => $uid1, - token => 'abcd' -); -$u->verify_registration_token( - uid => $uid2, - token => 'efgh' -); -$u->verify_registration_token( - uid => $uid3, - token => 'ijkl' -); - -$u->set_social( - uid => $uid1, - accept_follows => 1 -); -$u->set_social( - uid => $uid2, - accept_follows => 1 -); -$u->set_social( - uid => $uid3, - accept_follows => 1 -); - -$u->follow( - uid => $uid2, - target => $uid1 -); - -is( - $u->get_relation( - subject => $uid2, - object => $uid1 - ), - 'follows' -); -is( - $u->get_relation( - subject => $uid1, - object => $uid2 - ), - undef -); - -my $dep = DateTime->now->subtract( hours => 2 ); -my $arr = DateTime->now->subtract( hours => 1 ); -my $train_dep = Travel::Status::DE::IRIS::Result->new( - classes => 'N', - type => 'DPN', - train_no => '667', - raw_id => '1234-2306251312-1', - departure_ts => $dep->strftime('%y%m%d%H%M'), - platform => 8, - station => 'Aachen Hbf', - station_uic => 8000001, - route_post => 'Mainz Hbf|Aalen Hbf', -); -my $train_arr = Travel::Status::DE::IRIS::Result->new( - classes => 'N', - type => 'DPN', - train_no => '667', - raw_id => '1234-2306251312-3', - arrival_ts => $arr->strftime('%y%m%d%H%M'), - platform => 1, - station => 'Aalen Hbf', - station_uic => 8000002, - route_pre => 'Aachen Hbf|Mainz Hbf', -); -$t->app->in_transit->add( - uid => $uid1, - departure_eva => 8000001, - train => $train_dep, - route => [], - backend_id => $t->app->stations->get_backend_id( iris => 1 ), -); -$t->app->in_transit->set_arrival_eva( - uid => $uid1, - arrival_eva => 8000002, -); - -$t->app->in_transit->update_visibility( - uid => $uid1, - visibility => 'public', -); - -my $db = $t->app->pg->db; -my $tx = $db->begin; - -my $journey = $t->app->in_transit->get( - uid => $uid1, - db => $db, -); -my $jid = $t->app->journeys->add_from_in_transit( - journey => $journey, - db => $db -); -$t->app->in_transit->delete( - uid => $uid1, - db => $db -); -$tx->commit; - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_past_visibility => 10, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_past_visibility => 60, - self => 1, - followers => 1, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_past_visibility => 80, - self => 1, - followers => 1, - travelynx => 1, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_past_visibility => 100, - self => 1, - followers => 1, - travelynx => 1, - public => 1, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'private', - set_past_visibility => 10, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'private', - set_past_visibility => 60, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'private', - set_past_visibility => 80, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'private', - set_past_visibility => 100, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'unlisted', - set_past_visibility => 10, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'unlisted', - set_past_visibility => 60, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'unlisted', - set_past_visibility => 80, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'unlisted', - set_past_visibility => 100, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'followers', - set_past_visibility => 10, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'followers', - set_past_visibility => 60, - self => 1, - followers => 1, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'followers', - set_past_visibility => 80, - self => 1, - followers => 1, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'followers', - set_past_visibility => 100, - self => 1, - followers => 1, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'travelynx', - set_past_visibility => 10, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'travelynx', - set_past_visibility => 60, - self => 1, - followers => 1, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'travelynx', - set_past_visibility => 80, - self => 1, - followers => 1, - travelynx => 1, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'travelynx', - set_past_visibility => 100, - self => 1, - followers => 1, - travelynx => 1, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'public', - set_past_visibility => 10, - self => 0, - followers => 0, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'public', - set_past_visibility => 60, - self => 1, - followers => 1, - travelynx => 0, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'public', - set_past_visibility => 80, - self => 1, - followers => 1, - travelynx => 1, - public => 0, -); - -test_history_visibility( - uid => $uid1, - journey_id => $jid, - set_visibility => 'public', - set_past_visibility => 100, - self => 1, - followers => 1, - travelynx => 1, - public => 1, -); - -$t->app->pg->db->query('drop schema travelynx_test_24 cascade'); -done_testing(); diff --git a/t/journey-edit.t b/t/journey-edit.t new file mode 100644 index 0000000..f0b2f36 --- /dev/null +++ b/t/journey-edit.t @@ -0,0 +1,240 @@ +#!/usr/bin/env perl + +# Copyright (C) 2020 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +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; +use utf8; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); + +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; + +$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 0; +$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, + dt => 1, + 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 => '/' ); + +my ( $success, $error ) = $t->app->journeys->add( + db => $t->app->pg->db, + uid => $uid, + backend_id => 1, + dep_station => 'Münster(Westf)Hbf', + arr_station => 'Gelsenkirchen Hbf', + 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' +); + +ok( $success, "journeys->add" ); +is( $error, undef, "journeys->add" ); + +$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*\n*\s* \(\+6, \s*Plan: \s*\n*\s* ..:36\)}mx) + ->content_like(qr{..:33 \s*\n*\s* \( -1, \s*Plan: \s*\n*\s* ..:34\)}mx) + ->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(); diff --git a/t/journey-stats.t b/t/journey-stats.t new file mode 100644 index 0000000..205bf96 --- /dev/null +++ b/t/journey-stats.t @@ -0,0 +1,205 @@ +#!/usr/bin/env perl + +# Copyright (C) 2020 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +# Tests journey entry and statistics + +use Test::More; +use Test::Mojo; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); + +if ( not $t->app->config->{db} ) { + plan( skip_all => 'No database configured' ); +} + +$t->app->pg->db->query('drop schema if exists travelynx_test_11 cascade'); +$t->app->pg->db->query('create schema travelynx_test_11'); +$t->app->pg->db->query('set search_path to travelynx_test_11'); +$t->app->pg->on( + connection => sub { + my ( $pg, $dbh ) = @_; + $dbh->do('set search_path to travelynx_test_11'); + } +); + +$t->app->config->{mail}->{disabled} = 1; + +$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 0; +$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, + dt => 1, + 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 => '/' ); + +$csrf_token + = $t->ua->get('/journey/add')->res->dom->at('input[name=csrf_token]') + ->attr('value'); +$t->post_ok( + '/journey/add' => form => { + csrf_token => $csrf_token, + action => 'save', + train => 'RE 42 11238', + dep_station => 'EMSTP', + sched_departure => '2018-10-16T17:36', + rt_departure => '2018-10-16T17:36', + arr_station => 'EG', + sched_arrival => '2018-10-16T18:34', + rt_arrival => '2018-10-16T18:34', + comment => 'Passierschein A38', + } +); +$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{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}) + ->content_like(qr{Bei Abfahrt: 00:00 Stunden}) + ->content_like(qr{Bei Ankunft: 00:00 Stunden}); + +$t->get_ok('/history/2018') + ->status_is(200) + ->content_like(qr{62 km}) + ->content_like(qr{00:58 Stunden}) + ->content_like(qr{00:00 Stunden}) + ->content_like(qr{Bei Abfahrt: 00:00 Stunden}) + ->content_like(qr{Bei Ankunft: 00:00 Stunden}); + +$t->get_ok('/history/map') + ->status_is(200) + ->content_like(qr{\[\[51.956[^,]*,7.635[^]]*\],'M.nster\(Westf\)Hbf'\],}) + ->content_like(qr{\[\[51.504[^,]*,7.102[^]]*\],'Gelsenkirchen Hbf'\]}); + +$csrf_token + = $t->ua->get('/journey/add')->res->dom->at('input[name=csrf_token]') + ->attr('value'); +$t->post_ok( + '/journey/add' => form => { + csrf_token => $csrf_token, + action => 'save', + train => 'RE 42 11238', + dep_station => 'EMSTP', + sched_departure => '2018-11-16T17:36', + rt_departure => '2018-11-16T17:45', + arr_station => 'EG', + sched_arrival => '2018-11-16T18:34', + rt_arrival => '2018-11-16T19:00', + } +); +$t->status_is(302)->header_is( location => '/journey/2' ); + +$t->get_ok('/history/2018/11') + ->status_is(200) + ->content_like(qr{62 km}) + ->content_like(qr{01:15 Stunden}) + ->content_like(qr{nach Fahrplan: 00:58}) + ->content_like(qr{00:00 Stunden}) + ->content_like(qr{Bei Abfahrt: 00:09 Stunden}) + ->content_like(qr{Bei Ankunft: 00:26 Stunden}); + +$t->get_ok('/history/2018') + ->status_is(200) + ->content_like(qr{124 km}) + ->content_like(qr{02:13 Stunden}) + ->content_like(qr{nach Fahrplan: 01:56}) + ->content_like(qr{00:00 Stunden}) + ->content_like(qr{Bei Abfahrt: 00:09 Stunden}) + ->content_like(qr{Bei Ankunft: 00:26 Stunden}); + +$csrf_token + = $t->ua->get('/journey/add')->res->dom->at('input[name=csrf_token]') + ->attr('value'); +$t->post_ok( + '/journey/add' => form => { + csrf_token => $csrf_token, + action => 'save', + train => 'ICE 1', + dep_station => 'EE', + sched_departure => '2018-11-17T15:42', + rt_departure => '', + arr_station => 'BL', + sched_arrival => '2018-11-17T19:42', + rt_arrival => '', + } +); +$t->status_is(302)->header_is( location => '/journey/3' ); + +$t->get_ok('/history/2018/11') + ->status_is(200) + ->content_like(qr{513 km}) + ->content_like(qr{05:15 Stunden}) + ->content_like(qr{nach Fahrplan: 04:58}) + ->content_like(qr{00:00 Stunden}) + ->content_like(qr{Bei Abfahrt: 00:09 Stunden}) + ->content_like(qr{Bei Ankunft: 00:26 Stunden}); + +$t->get_ok('/history/2018') + ->status_is(200) + ->content_like(qr{576 km}) + ->content_like(qr{06:13 Stunden}) + ->content_like(qr{nach Fahrplan: 05:56}) + ->content_like(qr{00:00 Stunden}) + ->content_like(qr{Bei Abfahrt: 00:09 Stunden}) + ->content_like(qr{Bei Ankunft: 00:26 Stunden}); + +$t->app->pg->db->query('drop schema travelynx_test_11 cascade'); +done_testing(); diff --git a/t/journey-visibility.t b/t/journey-visibility.t new file mode 100644 index 0000000..c2294b3 --- /dev/null +++ b/t/journey-visibility.t @@ -0,0 +1,480 @@ +#!/usr/bin/env perl + +# Copyright (C) 2023 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +# Tests journey entry and statistics + +use Test::More; +use Test::Mojo; + +use DateTime; +use Travel::Status::DE::IRIS::Result; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); + +if ( not $t->app->config->{db} ) { + plan( skip_all => 'No database configured' ); +} + +$t->app->pg->db->query('drop schema if exists travelynx_test_23 cascade'); +$t->app->pg->db->query('create schema travelynx_test_23'); +$t->app->pg->db->query('set search_path to travelynx_test_23'); +$t->app->pg->on( + connection => sub { + my ( $pg, $dbh ) = @_; + $dbh->do('set search_path to travelynx_test_23'); + } +); + +$t->app->config->{mail}->{disabled} = 1; + +$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 1; +$t->app->start( 'database', 'migrate' ); + +my $u = $t->app->users; + +sub login { + my %opt = @_; + my $csrf_token + = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + $t->post_ok( + '/login' => form => { + csrf_token => $csrf_token, + user => $opt{user}, + password => $opt{password}, + } + ); + $t->status_is(302)->header_is( location => '/' ); +} + +sub logout { + my $csrf_token + = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + $t->post_ok( + '/logout' => form => { + csrf_token => $csrf_token, + } + ); + $t->status_is(302)->header_is( location => '/login' ); +} + +sub test_journey_visibility { + my %opt = @_; + my $jid = $opt{journey_id}; + + if ( $opt{set_default_visibility} ) { + my %p = %{ $u->get_privacy_by( uid => $opt{uid} ) }; + $p{default_visibility} = $opt{set_default_visibility}; + $u->set_privacy( + uid => $opt{uid}, + %p + ); + } + + if ( $opt{set_visibility} ) { + $t->app->journeys->update_visibility( + uid => $opt{uid}, + id => $jid, + visibility => $opt{set_visibility} + ); + } + + my $status = $t->app->get_user_status( $opt{uid} ); + my $journey = $t->app->journeys->get_single( + uid => $opt{uid}, + journey_id => $jid + ); + my $token + = q{?token=} + . $status->{dep_eva} . q{-} + . $journey->{checkin_ts} % 337 . q{-} + . $status->{sched_departure}->epoch; + + my $desc + = "journey=$jid vis=$opt{effective_visibility_str} (from $opt{visibility_str})"; + + is( $status->{visibility}, $opt{visibility}, $desc ); + is( $status->{visibility_str}, $opt{visibility_str}, $desc ); + is( $status->{effective_visibility}, $opt{effective_visibility}, $desc ); + is( $status->{effective_visibility_str}, + $opt{effective_visibility_str}, $desc ); + + if ( $opt{public} ) { + $t->get_ok("/p/test1/j/$jid") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/p/test1/j/$jid") + ->status_is(404) + ->content_like(qr{Fahrt nicht gefunden.}); + } + + if ( $opt{with_token} ) { + $t->get_ok("/p/test1/j/$jid$token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/p/test1/j/$jid$token") + ->status_is(404) + ->content_like(qr{Fahrt nicht gefunden.}); + } + + login( + user => 'test1', + password => 'password1' + ); + + # users can see their own status if visibility is >= followrs + if ( $opt{effective_visibility} >= 60 ) { + $t->get_ok("/p/test1/j/$jid") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/p/test1/j/$jid") + ->status_is(404) + ->content_like(qr{Fahrt nicht gefunden.}); + } + + # users can see their own status with token if visibility is >= unlisted + if ( $opt{effective_visibility} >= 30 ) { + $t->get_ok("/p/test1/j/$jid$token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/p/test1/j/$jid$token") + ->status_is(404) + ->content_like(qr{Fahrt nicht gefunden.}); + } + + logout(); + login( + user => 'test2', + password => 'password2' + ); + + # uid2 can see uid1 if visibility is >= followers + if ( $opt{effective_visibility} >= 60 ) { + $t->get_ok("/p/test1/j/$jid") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/p/test1/j/$jid") + ->status_is(404) + ->content_like(qr{Fahrt nicht gefunden.}); + } + + # uid2 can see uid1 with token if visibility is >= unlisted + if ( $opt{effective_visibility} >= 30 ) { + $t->get_ok("/p/test1/j/$jid$token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/p/test1/j/$jid$token") + ->status_is(404) + ->content_like(qr{Fahrt nicht gefunden.}); + } + + logout(); + login( + user => 'test3', + password => 'password3' + ); + + # uid3 can see uid1 if visibility is >= travelynx + if ( $opt{effective_visibility} >= 80 ) { + $t->get_ok("/p/test1/j/$jid") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/p/test1/j/$jid") + ->status_is(404) + ->content_like(qr{Fahrt nicht gefunden.}); + } + + # uid3 can see uid1 with token if visibility is >= unlisted + if ( $opt{effective_visibility} >= 30 ) { + $t->get_ok("/p/test1/j/$jid$token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/p/test1/j/$jid$token") + ->status_is(404) + ->content_like(qr{Fahrt nicht gefunden.}); + } + + logout(); +} + +my $uid1 = $u->add( + name => 'test1', + email => 'test1@example.org', + token => 'abcd', + password => 'password1', +); + +my $uid2 = $u->add( + name => 'test2', + email => 'test2@example.org', + token => 'efgh', + password => 'password2', +); + +my $uid3 = $u->add( + name => 'test3', + email => 'test3@example.org', + token => 'ijkl', + password => 'password3', +); + +$u->verify_registration_token( + uid => $uid1, + token => 'abcd' +); +$u->verify_registration_token( + uid => $uid2, + token => 'efgh' +); +$u->verify_registration_token( + uid => $uid3, + token => 'ijkl' +); + +$u->set_social( + uid => $uid1, + accept_follows => 1 +); +$u->set_social( + uid => $uid2, + accept_follows => 1 +); +$u->set_social( + uid => $uid3, + accept_follows => 1 +); + +$u->follow( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + 'follows' +); +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + undef +); + +my $dep = DateTime->now->subtract( hours => 2 ); +my $arr = DateTime->now->subtract( hours => 1 ); +my $train_dep = Travel::Status::DE::IRIS::Result->new( + classes => 'N', + type => 'DPN', + train_no => '667', + raw_id => '1234-2306251312-1', + departure_ts => $dep->strftime('%y%m%d%H%M'), + platform => 8, + station => 'Aachen Hbf', + station_uic => 8000001, + route_post => 'Mainz Hbf|Aalen Hbf', +); +my $train_arr = Travel::Status::DE::IRIS::Result->new( + classes => 'N', + type => 'DPN', + train_no => '667', + raw_id => '1234-2306251312-3', + arrival_ts => $arr->strftime('%y%m%d%H%M'), + platform => 1, + station => 'Aalen Hbf', + station_uic => 8000002, + route_pre => 'Aachen Hbf|Mainz Hbf', +); +$t->app->in_transit->add( + uid => $uid1, + departure_eva => 8000001, + train => $train_dep, + route => [], + backend_id => $t->app->stations->get_backend_id( iris => 1 ), +); +$t->app->in_transit->set_arrival_eva( + uid => $uid1, + arrival_eva => 8000002, +); + +my $db = $t->app->pg->db; +my $tx = $db->begin; + +my $journey = $t->app->in_transit->get( + uid => $uid1, + db => $db, +); +my $jid = $t->app->journeys->add_from_in_transit( + journey => $journey, + db => $db +); +$t->app->in_transit->delete( + uid => $uid1, + db => $db +); +$tx->commit; + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + visibility => undef, + visibility_str => 'default', + effective_visibility => 30, + effective_visibility_str => 'unlisted', + public => 0, + with_token => 1, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_default_visibility => 10, + visibility => undef, + visibility_str => 'default', + effective_visibility => 10, + effective_visibility_str => 'private', + public => 0, + with_token => 0, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_default_visibility => 30, + visibility => undef, + visibility_str => 'default', + effective_visibility => 30, + effective_visibility_str => 'unlisted', + public => 0, + with_token => 1, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_default_visibility => 60, + visibility => undef, + visibility_str => 'default', + effective_visibility => 60, + effective_visibility_str => 'followers', + public => 0, + with_token => 1, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_default_visibility => 80, + visibility => undef, + visibility_str => 'default', + effective_visibility => 80, + effective_visibility_str => 'travelynx', + public => 0, + with_token => 1, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_default_visibility => 100, + visibility => undef, + visibility_str => 'default', + effective_visibility => 100, + effective_visibility_str => 'public', + public => 1, + with_token => 1, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'private', + visibility => 10, + visibility_str => 'private', + effective_visibility => 10, + effective_visibility_str => 'private', + public => 0, + with_token => 0, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'unlisted', + visibility => 30, + visibility_str => 'unlisted', + effective_visibility => 30, + effective_visibility_str => 'unlisted', + public => 0, + with_token => 1, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'followers', + visibility => 60, + visibility_str => 'followers', + effective_visibility => 60, + effective_visibility_str => 'followers', + public => 0, + with_token => 1, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'travelynx', + visibility => 80, + visibility_str => 'travelynx', + effective_visibility => 80, + effective_visibility_str => 'travelynx', + public => 0, + with_token => 1, +); + +test_journey_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'public', + visibility => 100, + visibility_str => 'public', + effective_visibility => 100, + effective_visibility_str => 'public', + public => 1, + with_token => 1, +); + +$t->app->pg->db->query('drop schema travelynx_test_23 cascade'); +done_testing(); diff --git a/t/past-visibility.t b/t/past-visibility.t new file mode 100644 index 0000000..5c084b2 --- /dev/null +++ b/t/past-visibility.t @@ -0,0 +1,569 @@ +#!/usr/bin/env perl + +# Copyright (C) 2023 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +# Tests journey entry and statistics + +use Test::More; +use Test::Mojo; + +use DateTime; +use Travel::Status::DE::IRIS::Result; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); + +if ( not $t->app->config->{db} ) { + plan( skip_all => 'No database configured' ); +} + +$t->app->pg->db->query('drop schema if exists travelynx_test_24 cascade'); +$t->app->pg->db->query('create schema travelynx_test_24'); +$t->app->pg->db->query('set search_path to travelynx_test_24'); +$t->app->pg->on( + connection => sub { + my ( $pg, $dbh ) = @_; + $dbh->do('set search_path to travelynx_test_24'); + } +); + +$t->app->config->{mail}->{disabled} = 1; + +$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 1; +$t->app->start( 'database', 'migrate' ); + +my $u = $t->app->users; + +sub login { + my %opt = @_; + my $csrf_token + = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + $t->post_ok( + '/login' => form => { + csrf_token => $csrf_token, + user => $opt{user}, + password => $opt{password}, + } + ); + $t->status_is(302)->header_is( location => '/' ); +} + +sub logout { + my $csrf_token + = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + $t->post_ok( + '/logout' => form => { + csrf_token => $csrf_token, + } + ); + $t->status_is(302)->header_is( location => '/login' ); +} + +sub test_history_visibility { + my %opt = @_; + my $jid = $opt{journey_id}; + + if ( $opt{set_default_visibility} ) { + my %p = %{ $u->get_privacy_by( uid => $opt{uid} ) }; + $p{default_visibility} = $opt{set_default_visibility}; + $u->set_privacy( + uid => $opt{uid}, + %p + ); + } + + if ( $opt{set_past_visibility} ) { + my %p = %{ $u->get_privacy_by( uid => $opt{uid} ) }; + $p{past_visibility} = $opt{set_past_visibility}; + $u->set_privacy( + uid => $opt{uid}, + %p + ); + } + + if ( $opt{set_visibility} ) { + $t->app->journeys->update_visibility( + uid => $opt{uid}, + id => $jid, + visibility => $opt{set_visibility} + ); + } + + my $status = $t->app->get_user_status( $opt{uid} ); + my $journey = $t->app->journeys->get_single( + uid => $opt{uid}, + journey_id => $jid, + with_visibility => 1, + ); + my $token + = q{?token=} + . $status->{dep_eva} . q{-} + . $journey->{checkin_ts} % 337 . q{-} + . $status->{sched_departure}->epoch; + + $opt{set_past_visibility} //= q{}; + my $desc + = "history vis=$opt{set_past_visibility} journey=$jid vis=$journey->{effective_visibility_str}"; + + if ( $opt{public} ) { + $t->get_ok('/p/test1') + ->status_is(200) + ->content_like( qr{DPN\s*667}, "public $desc" ); + } + else { + $t->get_ok('/p/test1') + ->status_is(200) + ->content_unlike( qr{DPN\s*667}, "public $desc" ); + } + + login( + user => 'test1', + password => 'password1' + ); + + if ( $opt{self} ) { + $t->get_ok('/p/test1') + ->status_is(200) + ->content_like( qr{DPN\s*667}, "self $desc" ); + } + else { + $t->get_ok('/p/test1') + ->status_is(200) + ->content_unlike( qr{DPN\s*667}, "self $desc" ); + } + + logout(); + login( + user => 'test2', + password => 'password2' + ); + + if ( $opt{followers} ) { + $t->get_ok('/p/test1') + ->status_is(200) + ->content_like( qr{DPN\s*667}, "follower $desc" ); + } + else { + $t->get_ok('/p/test1') + ->status_is(200) + ->content_unlike( qr{DPN\s*667}, "follower $desc" ); + } + + logout(); + login( + user => 'test3', + password => 'password3' + ); + + if ( $opt{travelynx} ) { + $t->get_ok('/p/test1') + ->status_is(200) + ->content_like( qr{DPN\s*667}, "travelynx $desc" ); + } + else { + $t->get_ok('/p/test1') + ->status_is(200) + ->content_unlike( qr{DPN\s*667}, "travelynx $desc" ); + } + + logout(); +} + +my $uid1 = $u->add( + name => 'test1', + email => 'test1@example.org', + token => 'abcd', + password => 'password1', +); + +my $uid2 = $u->add( + name => 'test2', + email => 'test2@example.org', + token => 'efgh', + password => 'password2', +); + +my $uid3 = $u->add( + name => 'test3', + email => 'test3@example.org', + token => 'ijkl', + password => 'password3', +); + +$u->verify_registration_token( + uid => $uid1, + token => 'abcd' +); +$u->verify_registration_token( + uid => $uid2, + token => 'efgh' +); +$u->verify_registration_token( + uid => $uid3, + token => 'ijkl' +); + +$u->set_social( + uid => $uid1, + accept_follows => 1 +); +$u->set_social( + uid => $uid2, + accept_follows => 1 +); +$u->set_social( + uid => $uid3, + accept_follows => 1 +); + +$u->follow( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + 'follows' +); +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + undef +); + +my $dep = DateTime->now->subtract( hours => 2 ); +my $arr = DateTime->now->subtract( hours => 1 ); +my $train_dep = Travel::Status::DE::IRIS::Result->new( + classes => 'N', + type => 'DPN', + train_no => '667', + raw_id => '1234-2306251312-1', + departure_ts => $dep->strftime('%y%m%d%H%M'), + platform => 8, + station => 'Aachen Hbf', + station_uic => 8000001, + route_post => 'Mainz Hbf|Aalen Hbf', +); +my $train_arr = Travel::Status::DE::IRIS::Result->new( + classes => 'N', + type => 'DPN', + train_no => '667', + raw_id => '1234-2306251312-3', + arrival_ts => $arr->strftime('%y%m%d%H%M'), + platform => 1, + station => 'Aalen Hbf', + station_uic => 8000002, + route_pre => 'Aachen Hbf|Mainz Hbf', +); +$t->app->in_transit->add( + uid => $uid1, + departure_eva => 8000001, + train => $train_dep, + route => [], + backend_id => $t->app->stations->get_backend_id( iris => 1 ), +); +$t->app->in_transit->set_arrival_eva( + uid => $uid1, + arrival_eva => 8000002, +); + +$t->app->in_transit->update_visibility( + uid => $uid1, + visibility => 'public', +); + +my $db = $t->app->pg->db; +my $tx = $db->begin; + +my $journey = $t->app->in_transit->get( + uid => $uid1, + db => $db, +); +my $jid = $t->app->journeys->add_from_in_transit( + journey => $journey, + db => $db +); +$t->app->in_transit->delete( + uid => $uid1, + db => $db +); +$tx->commit; + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_past_visibility => 10, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_past_visibility => 60, + self => 1, + followers => 1, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_past_visibility => 80, + self => 1, + followers => 1, + travelynx => 1, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_past_visibility => 100, + self => 1, + followers => 1, + travelynx => 1, + public => 1, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'private', + set_past_visibility => 10, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'private', + set_past_visibility => 60, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'private', + set_past_visibility => 80, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'private', + set_past_visibility => 100, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'unlisted', + set_past_visibility => 10, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'unlisted', + set_past_visibility => 60, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'unlisted', + set_past_visibility => 80, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'unlisted', + set_past_visibility => 100, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'followers', + set_past_visibility => 10, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'followers', + set_past_visibility => 60, + self => 1, + followers => 1, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'followers', + set_past_visibility => 80, + self => 1, + followers => 1, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'followers', + set_past_visibility => 100, + self => 1, + followers => 1, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'travelynx', + set_past_visibility => 10, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'travelynx', + set_past_visibility => 60, + self => 1, + followers => 1, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'travelynx', + set_past_visibility => 80, + self => 1, + followers => 1, + travelynx => 1, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'travelynx', + set_past_visibility => 100, + self => 1, + followers => 1, + travelynx => 1, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'public', + set_past_visibility => 10, + self => 0, + followers => 0, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'public', + set_past_visibility => 60, + self => 1, + followers => 1, + travelynx => 0, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'public', + set_past_visibility => 80, + self => 1, + followers => 1, + travelynx => 1, + public => 0, +); + +test_history_visibility( + uid => $uid1, + journey_id => $jid, + set_visibility => 'public', + set_past_visibility => 100, + self => 1, + followers => 1, + travelynx => 1, + public => 1, +); + +$t->app->pg->db->query('drop schema travelynx_test_24 cascade'); +done_testing(); diff --git a/t/registration.t b/t/registration.t new file mode 100644 index 0000000..ec09eaf --- /dev/null +++ b/t/registration.t @@ -0,0 +1,228 @@ +#!/usr/bin/env perl + +# Copyright (C) 2020 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +# Tests the standard registration -> verification -> successful login flow + +use Test::More; +use Test::Mojo; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); + +if ( not $t->app->config->{db} ) { + plan( skip_all => 'No database configured' ); +} + +$t->app->pg->db->query('drop schema if exists travelynx_test_02 cascade'); +$t->app->pg->db->query('create schema travelynx_test_02'); +$t->app->pg->db->query('set search_path to travelynx_test_02'); +$t->app->pg->on( + connection => sub { + my ( $pg, $dbh ) = @_; + $dbh->do('set search_path to travelynx_test_02'); + } +); + +$t->app->config->{mail}->{disabled} = 1; + +$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 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, + dt => 1, + user => 'someone', + email => 'foo@example.org', + password => 'foofoofoo', + password2 => 'foofoofoo', + } +); +$t->status_is(200)->content_like(qr{Verifizierungslink}); + +# Failed registration (CSRF) +$t->post_ok( + '/register' => form => { + csrf_token => $csrf_token, + user => 'noone', + email => 'foo2@example.org', + password => 'foofoofoo', + password2 => 'foofoofoo', + } +); +$t->status_is(400)->content_like(qr{CSRF}); + +# Failed registration (user name not available) +$t->post_ok( + '/register' => form => { + csrf_token => $csrf_token, + dt => 1, + user => 'someone', + email => 'foo@example.org', + password => 'foofoofoo', + password2 => 'foofoofoo', + } +); +$t->status_is(200)->content_like(qr{Name bereits vergeben}); + +$csrf_token = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + +# Failed login (not verified yet) +$t->post_ok( + '/login' => form => { + csrf_token => $csrf_token, + user => 'someone', + password => 'foofoofoo', + } +); +$t->status_is(400)->content_like(qr{nicht freigeschaltet}); + +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}); + +# Failed login (wrong password) +$t->post_ok( + '/login' => form => { + csrf_token => $csrf_token, + user => 'someone', + password => 'definitely invalid', + } +); +$t->status_is(400)->content_like(qr{falsches Passwort}); + +# Successful login +$t->post_ok( + '/login' => form => { + csrf_token => $csrf_token, + user => 'someone', + password => 'foofoofoo', + } +); +$t->status_is(302)->header_is( location => '/' ); + +# Request deletion + +$csrf_token = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + +$t->post_ok( + '/delete' => form => { + action => 'delete', + csrf_token => $csrf_token, + password => 'foofoofoo', + } +); +$t->status_is(302)->header_is( location => '/account' ); +$t->get_ok('/account'); +$t->status_is(200)->content_like(qr{wird gelöscht}); + +$t->post_ok( + '/delete' => form => { + action => 'undelete', + csrf_token => $csrf_token, + } +); +$t->status_is(302)->header_is( location => '/account' ); +$t->get_ok('/account'); +$t->status_is(200)->content_unlike(qr{wird gelöscht}); + +$csrf_token + = $t->ua->get('/account/password')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + +$t->post_ok( + '/account/password' => form => { + csrf_token => $csrf_token, + oldpw => 'foofoofoo', + newpw => 'barbarbar', + newpw2 => 'barbarbar', + } +); +$t->status_is(302)->header_is( location => '/account' ); + +$csrf_token = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') + ->attr('value'); +$t->post_ok( + '/logout' => form => { + csrf_token => $csrf_token, + } +); +$t->status_is(302)->header_is( location => '/login' ); + +$csrf_token = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') + ->attr('value'); +$t->post_ok( + '/login' => form => { + csrf_token => $csrf_token, + user => 'someone', + password => 'barbarbar', + } +); +$t->status_is(302)->header_is( location => '/' ); + +$csrf_token = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') + ->attr('value'); +$t->post_ok( + '/logout' => form => { + csrf_token => $csrf_token, + } +); +$t->status_is(302)->header_is( location => '/login' ); + +$csrf_token = $t->ua->get('/recover')->res->dom->at('input[name=csrf_token]') + ->attr('value'); +$t->post_ok( + '/recover' => form => { + csrf_token => $csrf_token, + action => 'initiate', + user => 'someone', + email => 'foo@example.org', + } +); +$t->status_is(200)->content_like(qr{wird durchgeführt}); + +$res = $t->app->pg->db->select( 'pending_passwords', ['token'], + { user_id => $uid } ); +$token = $res->hash->{token}; + +$t->get_ok("/recover/${uid}/${token}") + ->status_is(200) + ->content_like(qr{Neues Passwort eintragen}); + +$t->post_ok( + '/recover' => form => { + csrf_token => $csrf_token, + action => 'set_password', + id => $uid, + token => $token, + newpw => 'foofoofoo2', + newpw2 => 'foofoofoo2', + } +); +$t->status_is(302)->header_is( location => '/account' ); + +$t->app->pg->db->query('drop schema travelynx_test_02 cascade'); +done_testing(); diff --git a/t/relations.t b/t/relations.t new file mode 100644 index 0000000..c5fbe32 --- /dev/null +++ b/t/relations.t @@ -0,0 +1,857 @@ +#!/usr/bin/env perl + +# Copyright (C) 2023 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +# Tests journey entry and statistics + +use Test::More; +use Test::Mojo; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); + +if ( not $t->app->config->{db} ) { + plan( skip_all => 'No database configured' ); +} + +$t->app->pg->db->query('drop schema if exists travelynx_test_21 cascade'); +$t->app->pg->db->query('create schema travelynx_test_21'); +$t->app->pg->db->query('set search_path to travelynx_test_21'); +$t->app->pg->on( + connection => sub { + my ( $pg, $dbh ) = @_; + $dbh->do('set search_path to travelynx_test_21'); + } +); + +$t->app->config->{mail}->{disabled} = 1; + +$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 1; +$t->app->start( 'database', 'migrate' ); + +my $u = $t->app->users; + +my $uid1 = $u->add( + name => 'test1', + email => 'test1@example.org', + token => 'abcd', + password => q{}, +); + +my $uid2 = $u->add( + name => 'test2', + email => 'test2@example.org', + token => 'efgh', + password => q{}, +); + +$u->verify_registration_token( + uid => $uid1, + token => 'abcd' +); +$u->verify_registration_token( + uid => $uid2, + token => 'efgh' +); + +$u->set_social( + uid => $uid1, + accept_follow_requests => 1 +); +$u->set_social( + uid => $uid2, + accept_follow_requests => 1 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + undef +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); + +$u->request_follow( + uid => $uid1, + target => $uid2 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + 'requests_follow' +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 1 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 1 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 1 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 1 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 1 ); +is_deeply( + [ $u->get_follow_requests( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); +is_deeply( + [ $u->get_follow_requests( uid => $uid1, sent => 1 ) ], + [ { id => $uid2, name => 'test2' } ] +); + +$u->reject_follow_request( + uid => $uid2, + applicant => $uid1 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + undef +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); + +$u->request_follow( + uid => $uid1, + target => $uid2 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + 'requests_follow' +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 1 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 1 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 1 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 1 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 1 ); +is_deeply( + [ $u->get_follow_requests( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); +is_deeply( + [ $u->get_follow_requests( uid => $uid1, sent => 1 ) ], + [ { id => $uid2, name => 'test2' } ] +); + +$u->accept_follow_request( + uid => $uid2, + applicant => $uid1 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + 'follows' +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 1 ); +is( scalar $u->get_followees( uid => $uid1 ), 1 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); +is_deeply( + [ $u->get_followers( uid => $uid2 ) ], + [ + { + id => $uid1, + name => 'test1', + following_back => 0, + followback_requested => 0, + can_follow_back => 0, + can_request_follow_back => 1 + } + ] +); +is_deeply( + [ $u->get_followees( uid => $uid1 ) ], + [ { id => $uid2, name => 'test2', following_back => 0 } ] +); + +$u->remove_follower( + uid => $uid2, + follower => $uid1 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + undef +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); + +$u->request_follow( + uid => $uid1, + target => $uid2 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + 'requests_follow' +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); + +$u->block( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + 'is_blocked_by' +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 1 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); +is_deeply( + [ $u->get_blocked_users( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); + +$u->unblock( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + undef +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); + +$u->block( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + 'is_blocked_by' +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 1 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); +is_deeply( + [ $u->get_blocked_users( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); + +$u->unblock( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + undef +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); + +$u->request_follow( + uid => $uid1, + target => $uid2 +); +$u->accept_follow_request( + uid => $uid2, + applicant => $uid1 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + 'follows' +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 1 ); +is( scalar $u->get_followees( uid => $uid1 ), 1 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); +is_deeply( + [ $u->get_followers( uid => $uid2 ) ], + [ + { + id => $uid1, + name => 'test1', + following_back => 0, + followback_requested => 0, + can_follow_back => 0, + can_request_follow_back => 1 + } + ] +); +is_deeply( + [ $u->get_followees( uid => $uid1 ) ], + [ { id => $uid2, name => 'test2', following_back => 0 } ] +); + +$u->unfollow( + uid => $uid1, + target => $uid2 +); + +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + undef +); +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( + scalar $u->get_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + scalar $u->get_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is( $u->has_follow_requests( uid => $uid1 ), 0 ); +is( $u->has_follow_requests( uid => $uid2 ), 0 ); +is( + $u->has_follow_requests( + uid => $uid1, + sent => 1 + ), + 0 +); +is( + $u->has_follow_requests( + uid => $uid2, + sent => 1 + ), + 0 +); +is( $u->get( uid => $uid1 )->{notifications}, 0 ); +is( $u->get( uid => $uid2 )->{notifications}, 0 ); + +$t->app->pg->db->query('drop schema travelynx_test_21 cascade'); +done_testing(); diff --git a/t/static-de.t b/t/static-de.t new file mode 100644 index 0000000..21d0350 --- /dev/null +++ b/t/static-de.t @@ -0,0 +1,50 @@ +#!/usr/bin/env perl + +# Copyright (C) 2020 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +use Test::More; +use Test::Mojo; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); + +$t->get_ok('/')->status_is(200); +$t->text_like( 'a[href="/register"]' => qr{Registrieren} ); +$t->text_like( 'a[href="/login"]' => qr{Anmelden} ); + +$t->get_ok('/about')->status_is(200); +$t->get_ok('/api')->status_is(200); +$t->get_ok('/changelog')->status_is(200); +$t->get_ok('/legend')->status_is(200); +$t->get_ok('/offline.html')->status_is(200); + +$t->get_ok('/login')->status_is(200); +$t->element_exists('input[name="csrf_token"]'); +$t->text_like( 'button' => qr{Anmelden} ); + +$t->get_ok('/recover')->status_is(200); + +$t->get_ok('/register')->status_is(200); +$t->element_exists('input[name="csrf_token"]'); +$t->element_exists('a[href="/impressum"]'); +$t->text_like( 'button' => qr{Registrieren} ); + +# Protected sites should redirect to login form + +for my $protected (qw(/account /account/password /history /s/EE)) { + $t->get_ok($protected)->text_like( 'button' => qr{Anmelden} ); +} + +# Otherwise, we expect a 404 +$t->get_ok('/definitelydoesnotexist')->status_is(404); + +done_testing(); diff --git a/t/static-en.t b/t/static-en.t new file mode 100644 index 0000000..26641cb --- /dev/null +++ b/t/static-en.t @@ -0,0 +1,50 @@ +#!/usr/bin/env perl + +# Copyright (C) 2020 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +use Test::More; +use Test::Mojo; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('en-GB') } ); + +$t->get_ok('/')->status_is(200); +$t->text_like( 'a[href="/register"]' => qr{Register} ); +$t->text_like( 'a[href="/login"]' => qr{Login} ); + +$t->get_ok('/about')->status_is(200); +$t->get_ok('/api')->status_is(200); +$t->get_ok('/changelog')->status_is(200); +$t->get_ok('/legend')->status_is(200); +$t->get_ok('/offline.html')->status_is(200); + +$t->get_ok('/login')->status_is(200); +$t->element_exists('input[name="csrf_token"]'); +$t->text_like( 'button' => qr{Login} ); + +$t->get_ok('/recover')->status_is(200); + +$t->get_ok('/register')->status_is(200); +$t->element_exists('input[name="csrf_token"]'); +$t->element_exists('a[href="/impressum"]'); +$t->text_like( 'button' => qr{Register} ); + +# Protected sites should redirect to login form + +for my $protected (qw(/account /account/password /history /s/EE)) { + $t->get_ok($protected)->text_like( 'button' => qr{Login} ); +} + +# Otherwise, we expect a 404 +$t->get_ok('/definitelydoesnotexist')->status_is(404); + +done_testing(); diff --git a/t/static-fr.t b/t/static-fr.t new file mode 100644 index 0000000..dc4c278 --- /dev/null +++ b/t/static-fr.t @@ -0,0 +1,50 @@ +#!/usr/bin/env perl + +# Copyright (C) 2020 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +use Test::More; +use Test::Mojo; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('fr-FR') } ); + +$t->get_ok('/')->status_is(200); +$t->text_like( 'a[href="/register"]' => qr{Inscription} ); +$t->text_like( 'a[href="/login"]' => qr{Connexion} ); + +$t->get_ok('/about')->status_is(200); +$t->get_ok('/api')->status_is(200); +$t->get_ok('/changelog')->status_is(200); +$t->get_ok('/legend')->status_is(200); +$t->get_ok('/offline.html')->status_is(200); + +$t->get_ok('/login')->status_is(200); +$t->element_exists('input[name="csrf_token"]'); +$t->text_like( 'button' => qr{Connexion} ); + +$t->get_ok('/recover')->status_is(200); + +$t->get_ok('/register')->status_is(200); +$t->element_exists('input[name="csrf_token"]'); +$t->element_exists('a[href="/impressum"]'); +$t->text_like( 'button' => qr{Inscription} ); + +# Protected sites should redirect to login form + +for my $protected (qw(/account /account/password /history /s/EE)) { + $t->get_ok($protected)->text_like( 'button' => qr{Connexion} ); +} + +# Otherwise, we expect a 404 +$t->get_ok('/definitelydoesnotexist')->status_is(404); + +done_testing(); diff --git a/t/transit-visibility.t b/t/transit-visibility.t new file mode 100644 index 0000000..6aa48ed --- /dev/null +++ b/t/transit-visibility.t @@ -0,0 +1,530 @@ +#!/usr/bin/env perl + +# Copyright (C) 2023 Birte Kristina Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +# Tests journey entry and statistics + +use Test::More; +use Test::Mojo; + +use DateTime; +use Travel::Status::DE::IRIS::Result; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +$t->ua->on( start => sub { $_[1]->req->headers->accept_language('de-DE') } ); + +if ( not $t->app->config->{db} ) { + plan( skip_all => 'No database configured' ); +} + +$t->app->pg->db->query('drop schema if exists travelynx_test_22 cascade'); +$t->app->pg->db->query('create schema travelynx_test_22'); +$t->app->pg->db->query('set search_path to travelynx_test_22'); +$t->app->pg->on( + connection => sub { + my ( $pg, $dbh ) = @_; + $dbh->do('set search_path to travelynx_test_22'); + } +); + +$t->app->config->{mail}->{disabled} = 1; + +$ENV{__TRAVELYNX_TEST_MINI_IRIS} = 1; +$t->app->start( 'database', 'migrate' ); + +my $u = $t->app->users; + +sub login { + my %opt = @_; + my $csrf_token + = $t->ua->get('/login')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + $t->post_ok( + '/login' => form => { + csrf_token => $csrf_token, + user => $opt{user}, + password => $opt{password}, + } + ); + $t->status_is(302)->header_is( location => '/' ); +} + +sub logout { + my $csrf_token + = $t->ua->get('/account')->res->dom->at('input[name=csrf_token]') + ->attr('value'); + $t->post_ok( + '/logout' => form => { + csrf_token => $csrf_token, + } + ); + $t->status_is(302)->header_is( location => '/login' ); +} + +sub test_intransit_visibility { + my %opt = @_; + + if ( $opt{set_default_visibility} ) { + my %p = %{ $u->get_privacy_by( uid => $opt{uid} ) }; + $p{default_visibility} = $opt{set_default_visibility}; + $u->set_privacy( + uid => $opt{uid}, + %p + ); + } + + if ( $opt{set_visibility} ) { + $t->app->in_transit->update_visibility( + uid => $opt{uid}, + visibility => $opt{set_visibility} + ); + } + + my $status = $t->app->get_user_status( $opt{uid} ); + my $token + = $status->{sched_departure}->epoch + . q{?token=} + . $status->{dep_eva} . q{-} + . $status->{timestamp}->epoch % 337; + my $j_token + = $status->{dep_eva} . q{-} + . $status->{timestamp}->epoch % 337 . q{-} + . $status->{sched_departure}->epoch; + + my $desc + = "in_transit vis=$opt{effective_visibility_str} (from $opt{visibility_str})"; + + is( $status->{visibility}, $opt{visibility}, $desc ); + is( $status->{visibility_str}, $opt{visibility_str}, $desc ); + is( $status->{effective_visibility}, $opt{effective_visibility}, $desc ); + is( $status->{effective_visibility_str}, + $opt{effective_visibility_str}, $desc ); + + if ( $opt{public} ) { + $t->get_ok('/status/test1') + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok('/ajax/status/test1.html') + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok('/p/test1')->status_is(200)->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok('/status/test1') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok('/ajax/status/test1.html') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok('/p/test1') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + } + + if ( $opt{with_token} ) { + $t->get_ok("/status/test1/$token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok("/ajax/status/test1.html?token=$j_token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/status/test1/$token") + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok("/ajax/status/test1.html?token=$j_token") + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + } + + login( + user => 'test1', + password => 'password1' + ); + + # users can see their own status if visibility is >= followrs + if ( $opt{effective_visibility} >= 60 ) { + $t->get_ok('/status/test1') + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok('/ajax/status/test1.html') + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok('/p/test1')->status_is(200)->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok('/status/test1') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok('/ajax/status/test1.html') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok('/p/test1') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + } + + # users can see their own status with token if visibility is >= unlisted + if ( $opt{effective_visibility} >= 30 ) { + $t->get_ok("/status/test1/$token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok("/ajax/status/test1.html?token=$j_token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/status/test1/$token") + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok("/ajax/status/test1.html?token=$j_token") + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + } + + logout(); + login( + user => 'test2', + password => 'password2' + ); + + # uid2 can see uid1 if visibility is >= followers + if ( $opt{effective_visibility} >= 60 ) { + $t->get_ok('/status/test1') + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok('/ajax/status/test1.html') + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok('/p/test1')->status_is(200)->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok('/status/test1') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok('/ajax/status/test1.html') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok('/p/test1') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + } + + # uid2 can see uid1 with token if visibility is >= unlisted + if ( $opt{effective_visibility} >= 30 ) { + $t->get_ok("/status/test1/$token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok("/ajax/status/test1.html?token=$j_token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/status/test1/$token") + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok("/ajax/status/test1.html?token=$j_token") + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + } + + logout(); + login( + user => 'test3', + password => 'password3' + ); + + # uid3 can see uid1 if visibility is >= travelynx + if ( $opt{effective_visibility} >= 80 ) { + $t->get_ok('/status/test1') + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok('/ajax/status/test1.html') + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok('/p/test1')->status_is(200)->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok('/status/test1') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok('/ajax/status/test1.html') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok('/p/test1') + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + } + + # uid3 can see uid1 with token if visibility is >= unlisted + if ( $opt{effective_visibility} >= 30 ) { + $t->get_ok("/status/test1/$token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + $t->get_ok("/ajax/status/test1.html?token=$j_token") + ->status_is(200) + ->content_like(qr{DPN\s*667}); + } + else { + $t->get_ok("/status/test1/$token") + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + $t->get_ok("/ajax/status/test1.html?token=$j_token") + ->status_is(200) + ->content_like(qr{nicht eingecheckt}); + } + + logout(); +} + +my $uid1 = $u->add( + name => 'test1', + email => 'test1@example.org', + token => 'abcd', + password => 'password1', +); + +my $uid2 = $u->add( + name => 'test2', + email => 'test2@example.org', + token => 'efgh', + password => 'password2', +); + +my $uid3 = $u->add( + name => 'test3', + email => 'test3@example.org', + token => 'ijkl', + password => 'password3', +); + +$u->verify_registration_token( + uid => $uid1, + token => 'abcd' +); +$u->verify_registration_token( + uid => $uid2, + token => 'efgh' +); +$u->verify_registration_token( + uid => $uid3, + token => 'ijkl' +); + +$u->set_social( + uid => $uid1, + accept_follows => 1 +); +$u->set_social( + uid => $uid2, + accept_follows => 1 +); +$u->set_social( + uid => $uid3, + accept_follows => 1 +); + +$u->follow( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + subject => $uid2, + object => $uid1 + ), + 'follows' +); +is( + $u->get_relation( + subject => $uid1, + object => $uid2 + ), + undef +); + +my $dep = DateTime->now; +my $arr = $dep->clone->add( hours => 1 ); +my $train_dep = Travel::Status::DE::IRIS::Result->new( + classes => 'N', + type => 'DPN', + train_no => '667', + raw_id => '1234-2306251312-1', + departure_ts => '2306251312', + platform => 8, + station => 'Aachen Hbf', + station_uic => 8000001, + route_post => 'Mainz Hbf|Aalen Hbf', +); +my $train_arr = Travel::Status::DE::IRIS::Result->new( + classes => 'N', + type => 'DPN', + train_no => '667', + raw_id => '1234-2306251312-3', + arrival_ts => '2306252000', + platform => 1, + station => 'Aalen Hbf', + station_uic => 8000002, + route_pre => 'Aachen Hbf|Mainz Hbf', +); +$t->app->in_transit->add( + uid => $uid1, + departure_eva => 8000001, + train => $train_dep, + route => [], + backend_id => $t->app->stations->get_backend_id( iris => 1 ), +); +$t->app->in_transit->set_arrival_eva( + uid => $uid1, + arrival_eva => 8000002, +); + +test_intransit_visibility( + uid => $uid1, + visibility => undef, + visibility_str => 'default', + effective_visibility => 30, + effective_visibility_str => 'unlisted', + public => 0, + with_token => 1, +); + +test_intransit_visibility( + uid => $uid1, + set_default_visibility => 10, + visibility => undef, + visibility_str => 'default', + effective_visibility => 10, + effective_visibility_str => 'private', + public => 0, + with_token => 0, +); + +test_intransit_visibility( + uid => $uid1, + set_default_visibility => 30, + visibility => undef, + visibility_str => 'default', + effective_visibility => 30, + effective_visibility_str => 'unlisted', + public => 0, + with_token => 1, +); + +test_intransit_visibility( + uid => $uid1, + set_default_visibility => 60, + visibility => undef, + visibility_str => 'default', + effective_visibility => 60, + effective_visibility_str => 'followers', + public => 0, + with_token => 1, +); + +test_intransit_visibility( + uid => $uid1, + set_default_visibility => 80, + visibility => undef, + visibility_str => 'default', + effective_visibility => 80, + effective_visibility_str => 'travelynx', + public => 0, + with_token => 1, +); + +test_intransit_visibility( + uid => $uid1, + set_default_visibility => 100, + visibility => undef, + visibility_str => 'default', + effective_visibility => 100, + effective_visibility_str => 'public', + public => 1, + with_token => 1, +); + +test_intransit_visibility( + uid => $uid1, + set_visibility => 'private', + visibility => 10, + visibility_str => 'private', + effective_visibility => 10, + effective_visibility_str => 'private', + public => 0, + with_token => 0, +); + +test_intransit_visibility( + uid => $uid1, + set_visibility => 'unlisted', + visibility => 30, + visibility_str => 'unlisted', + effective_visibility => 30, + effective_visibility_str => 'unlisted', + public => 0, + with_token => 1, +); + +test_intransit_visibility( + uid => $uid1, + set_visibility => 'followers', + visibility => 60, + visibility_str => 'followers', + effective_visibility => 60, + effective_visibility_str => 'followers', + public => 0, + with_token => 1, +); + +test_intransit_visibility( + uid => $uid1, + set_visibility => 'travelynx', + visibility => 80, + visibility_str => 'travelynx', + effective_visibility => 80, + effective_visibility_str => 'travelynx', + public => 0, + with_token => 1, +); + +test_intransit_visibility( + uid => $uid1, + set_visibility => 'public', + visibility => 100, + visibility_str => 'public', + effective_visibility => 100, + effective_visibility_str => 'public', + public => 1, + with_token => 1, +); + +$t->app->in_transit->update_visibility( + uid => $uid1, + visibility => undef, +); + +test_intransit_visibility( + uid => $uid1, + set_default_visibility => 10, + visibility => undef, + visibility_str => 'default', + effective_visibility => 10, + effective_visibility_str => 'private', + public => 0, + with_token => 0, +); + +$t->app->pg->db->query('drop schema travelynx_test_22 cascade'); +done_testing(); -- cgit v1.2.3