Test suite starts covering HTTP interface.

+ Added some files missing in previous commits.
This commit is contained in:
Florian "flowdy" Heß 2017-02-06 08:10:05 +01:00
parent 8b1a68f07b
commit bb05b06cf3
7 changed files with 110 additions and 12 deletions

19
TrsrDB/Category.pm Normal file
View File

@ -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;

34
t/02_http+scripts.t Normal file
View File

@ -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*<FQDN>(.*?)\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();

View File

@ -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

View File

@ -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

View File

@ -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),

View File

@ -0,0 +1,27 @@
% stash links => [ '#filter-view' => 'Filter view' ];
<form action="<%= url_for %>" method="get">
<div id="filter-view" class="targettable" style="float: left;">
<input type="text" value="<%= param 'purpose' %>" name="purpose" title="purpose" placeholder="Purpose">
% my $categories = app->db->resultset("Category")->search({}, { order_by => "ID" });
% my $category = param 'category';
<select id="category" name="category" title="category">
<option value="">Purpose</option>
% while ( my $c = $categories->next ) {
<option value="<%= $c->ID %>" <%== $category == $c->ID ? 'selected="selected"' : '' %>>
<%= $c->label %>
</option>
% }
</select>
<input style="width:5em;" type="text" placeholder="from/YYYY[-MM]" value="<%= param 'from' %>" name="from" title="from/YYYY[-MM]">
<input style="width:5em;" type="text" placeholder="until YYYY-MM-DD" value="<%= param 'until' %>" name="until" title="until YYYY-MM-DD">
</div>
<input type="number" style="width:3em;" name="page" value="<%= (param('page') // 1) + 1 %>" min="1" title="page">
<button type="submit">Go</button>
</form>