Add a basic test for static content

This commit is contained in:
Daniel Friesel 2019-04-18 12:22:17 -04:00
parent 065c844fde
commit 015b51ba84
2 changed files with 54 additions and 0 deletions

View file

@ -144,3 +144,20 @@ If you use the checkout link again, travelynx will perform a force checkout: it
will log that you have left the train at the specified station, but omit
arrival time, delay, and other real-time data. At the moment, this data cannot
be specified manually.
Testing
---
The test scripts assume that travelynx.conf contains a valid database
connection. However, they will override db.user to `travelynx_temp`. This
must be an account which has the same password as the one specified in
travelynx.conf, but uses a temporary schema. This way, tests will always
start from a clean slate and will not leave any trace in the database.
Create this account as follows:
* `createuser -P travelynx_temp` (enter the password you are using for the
regular development user)
* from inside a psql admin shell: `alter role travelynx_temp set search_path = pg_temp;`
Run the tests by executing `prove`.

37
t/01-static.t Normal file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env perl
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 => {db => {user => 'travelynx_temp'}});
$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('/register')->status_is(200);
$t->element_exists('input[name="csrf_token"]');
$t->element_exists('a[href="/impressum"]');
$t->text_like('button' => qr{Registrieren});
$t->get_ok('/login')->status_is(200);
$t->element_exists('input[name="csrf_token"]');
$t->text_like('button' => qr{Anmelden});
$t->get_ok('/about')->status_is(200);
# Protected sites should redirect to login form
for my $protected (qw(/account /change_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();