From bb05b06cf3dcdcfcdc801ef42fe175605396bdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20=22flowdy=22=20He=C3=9F?= Date: Mon, 6 Feb 2017 08:10:05 +0100 Subject: [PATCH] Test suite starts covering HTTP interface. + Added some files missing in previous commits. --- TrsrDB/Category.pm | 19 ++++++++++++++++++ t/{schema.t => 01_schema.t} | 0 t/02_http+scripts.t | 34 +++++++++++++++++++++++++++++++++ t/schema.out | 6 +++--- t/schema.sh | 30 +++++++++++++++++++++-------- t/schema.sql | 6 +++++- templates/filter-widget.html.ep | 27 ++++++++++++++++++++++++++ 7 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 TrsrDB/Category.pm rename t/{schema.t => 01_schema.t} (100%) create mode 100644 t/02_http+scripts.t create mode 100644 templates/filter-widget.html.ep diff --git a/TrsrDB/Category.pm b/TrsrDB/Category.pm new file mode 100644 index 0000000..11e6bd2 --- /dev/null +++ b/TrsrDB/Category.pm @@ -0,0 +1,19 @@ +use strict; + +package TrsrDB::Category; +use base qw/DBIx::Class::Core/; + +__PACKAGE__->table('category'); +__PACKAGE__->add_columns(qw/ID label/); +__PACKAGE__->set_primary_key('ID'); + +__PACKAGE__->has_many( + debits => 'TrsrDB::Debit', + { 'foreign.category' => 'self.ID' } +); +__PACKAGE__->has_many( + credits => 'TrsrDB::Credit', + { 'foreign.category' => 'self.ID' } +); + +1; diff --git a/t/schema.t b/t/01_schema.t similarity index 100% rename from t/schema.t rename to t/01_schema.t diff --git a/t/02_http+scripts.t b/t/02_http+scripts.t new file mode 100644 index 0000000..21c3f47 --- /dev/null +++ b/t/02_http+scripts.t @@ -0,0 +1,34 @@ +use strict; + +use Test::More; +use Test::Mojo; + +my $t = Test::Mojo->new("TrsrDB::HTTP"); + +my ($url) = qx{perl httpuser -a test -g 2} =~ m{^\s*(.*?)\s}xms; + +ok length($url), "User created"; + +$t->get_ok($url); + +$t->content_like(qr/name="samepassword"/, "Page asks for password repetition"); + +$t->post_ok($url => form => { user => "test", password => "pw", samepassword => "pw" }) + ->status_is(302)->header_is( Location => "/" ); + +$t->get_ok("/logout"); + +$t->get_ok("/")->status_is(302)->header_is( Location => "/login" ); + +$t->post_ok("/login" => form => { user => "test", password => "pw" }) + ->status_is(302)->header_is( Location => "/" ); + +$t->post_ok("/account" => form => $_ )->header_is( Location => "/" ) + for { ID => "Club", type => q{}, altId => 1, IBAN => "*", name => "Main account" }, + { ID => "john", name => "John Tester", type => "Member", altId => 44 }, + { ID => "alex", name => "Alex Webber", type => "Member", altId => 6, IBAN => "DE12345678901234567890" }, + { ID => "rose", name => "Delia Rosenthal", altId => 45, type => 'Member' }, + { ID => "flow", name => "Florian Hess", type => 'Member' }, + ; + +done_testing(); diff --git a/t/schema.out b/t/schema.out index a20aa92..019a247 100644 --- a/t/schema.out +++ b/t/schema.out @@ -9,9 +9,9 @@ john: 0 +0 0 Club: 0 +0 -16250 alex: 7200 +16250 0 # Some updates and deletes that could, unless denied, destroy consistency ... -Error: near line 42: paid is set and adjusted automatically according to added Transfer records -Error: near line 43: Debt is involved in transfers to revoke at first -Error: near line 44: FOREIGN KEY constraint failed +Error: near line 46: paid is set and adjusted automatically according to added Transfer records +Error: near line 47: Debt is involved in transfers to revoke at first +Error: near line 48: FOREIGN KEY constraint failed # After revoking transactions, you are free to change or delete debts and credits ... Club: 7200 +0 0 alex: 0 +0 0 diff --git a/t/schema.sh b/t/schema.sh index dbc1ab4..6d6ab4c 100644 --- a/t/schema.sh +++ b/t/schema.sh @@ -1,11 +1,25 @@ +#!/bin/bash +set -e +db=${1-`mktemp -t trsr-XXXXXXXXX.db`} + setup_database() { - cat schema/{tables.sql,*/*} | sqlite3 $1 + cat schema/{tables.sql,*/*} | sqlite3 $db } -echo "My database file: $1" -if setup_database $1; then - diff t/schema.out <(sqlite3 $1 < t/schema.sql 2>&1) \ - && rm $1 && setup_database $1 \ - && TRSRDB_SQLITE_FILE=$1 perl t/schema.t \ - && rm -i $1 -fi +cleanup () { local rc=$?; rm -i $db; exit $rc; } +trap cleanup EXIT + +echo "My database file: $db" + +setup_database $db + +echo -e "Test level #1: Plain SQL commands\n\t(Create accounts, debits, credits, transfers and revocation)"; +diff t/schema.out <(sqlite3 $db < t/schema.sql 2>&1) + +echo "Test level #2: Access via DBIx::Class API" +export TRSRDB_SQLITE_FILE=$db +: > $db; setup_database $db && perl t/01_schema.t + +echo "Test level #3: Access via perl scripts and HTTP server" +: > $db; setup_database $db && perl t/02_http+scripts.t + diff --git a/t/schema.sql b/t/schema.sql index 225d893..eae71d4 100644 --- a/t/schema.sql +++ b/t/schema.sql @@ -3,7 +3,11 @@ PRAGMA recursive_triggers = ON; -- To understand the sql below, see the schema.sql file. -INSERT INTO Account VALUES ("Club", "eV", 1, NULL), ("john", "Member", 44, NULL), ("alex", "Member", 6, "DE1234567890123456"); +INSERT INTO Account VALUES + ("Club", "Main account", "eV", 1, NULL), + ("john", "John Tester", "Member", 44, NULL), + ("alex", "Alex Webber", "Member", 6, "DE1234567890123456"); + INSERT INTO Category ("label") VALUES ("Membership fees"), ("Service"); INSERT INTO Credit VALUES (1, "Club", "2016-01-01", "Membership fees May 2016 until incl. April 2017", 1, 0, 0), diff --git a/templates/filter-widget.html.ep b/templates/filter-widget.html.ep new file mode 100644 index 0000000..b3816dc --- /dev/null +++ b/templates/filter-widget.html.ep @@ -0,0 +1,27 @@ +% stash links => [ '#filter-view' => 'Filter view' ]; +
+
+ + + +% my $categories = app->db->resultset("Category")->search({}, { order_by => "ID" }); +% my $category = param 'category'; + + + + + + +
+ + + + +