Merge branch 'development' into TBSliver/Schema-Changes

This commit is contained in:
Tom Bloor 2017-08-31 13:07:23 +01:00
commit bd8b1f91a4
4 changed files with 14 additions and 10 deletions

View file

@ -65,6 +65,7 @@ sub valid_read {
undef, { undef, {
page => $c->param('page') || 1, page => $c->param('page') || 1,
rows => 10, rows => 10,
order_by => { -desc => 'submitted_at' },
}, },
); );
$c->stash( $c->stash(

View file

@ -93,7 +93,7 @@ sub post_upload {
my $validation = $c->validation; my $validation = $c->validation;
# Test for file before loading the JSON in to the validator # Test for file before loading the JSON in to the validator
$validation->required('file')->upload->filetype('image/jpeg'); $validation->optional('file')->upload->filetype('image/jpeg');
$validation->input( $c->stash->{api_json} ); $validation->input( $c->stash->{api_json} );
@ -162,14 +162,14 @@ sub post_upload {
my $upload = $validation->param('file'); my $upload = $validation->param('file');
my $purchase_time = $c->parse_iso_datetime($validation->param('purchase_time') || ''); my $purchase_time = $c->parse_iso_datetime($validation->param('purchase_time') || '');
$purchase_time ||= DateTime->now(); $purchase_time ||= DateTime->now();
my $file = $c->store_file_from_upload( $upload ); my $file = defined $upload ? $c->store_file_from_upload( $upload ) : undef;
my $new_transaction = $organisation->create_related( my $new_transaction = $organisation->create_related(
'transactions', 'transactions',
{ {
buyer => $user, buyer => $user,
value => $transaction_value, value => $transaction_value,
proof_image => $file, ( defined $file ? ( proof_image => $file ) : ( proof_image => 'a' ) ),
purchase_time => $c->format_db_datetime($purchase_time), purchase_time => $c->format_db_datetime($purchase_time),
} }
); );

View file

@ -202,9 +202,10 @@ $json = {
}; };
$upload = {json => Mojo::JSON::encode_json($json)}; $upload = {json => Mojo::JSON::encode_json($json)};
$t->post_ok('/api/upload' => form => $upload ) $t->post_ok('/api/upload' => form => $upload )
->status_is(400) ->status_is(200)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->true)
->content_like(qr/no file uploaded/i); ->json_like('/message', qr/Upload Successful/);
is $schema->resultset('Transaction')->count, 1, "1 transaction";
print "test 13 - organisation_id missing (type 1: already validated)\n"; print "test 13 - organisation_id missing (type 1: already validated)\n";
$json = { $json = {
@ -235,7 +236,7 @@ $t->post_ok('/api/upload' => form => $upload )
->content_like(qr/organisation_id does not exist in the database/i); ->content_like(qr/organisation_id does not exist in the database/i);
print "test 15 - valid addition. (type 1: already validated)\n"; print "test 15 - valid addition. (type 1: already validated)\n";
is $schema->resultset('Transaction')->count, 0, "no transactions"; is $schema->resultset('Transaction')->count, 1, "1 transaction";
$json = { $json = {
transaction_value => 10, transaction_value => 10,
transaction_type => 1, transaction_type => 1,
@ -248,7 +249,7 @@ $t->post_ok('/api/upload' => form => $upload )
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true) ->json_is('/success', Mojo::JSON->true)
->json_like('/message', qr/Upload Successful/); ->json_like('/message', qr/Upload Successful/);
is $schema->resultset('Transaction')->count, 1, "1 transaction"; is $schema->resultset('Transaction')->count, 2, "2 transaction";
# Add type 3 (new organisation) checking. # Add type 3 (new organisation) checking.
@ -445,7 +446,7 @@ $t->post_ok('/api/login' => json => $testJson)
$session_key = $t->tx->res->json('/session_key'); $session_key = $t->tx->res->json('/session_key');
print "test 30 - organisation buy from another organisation\n"; print "test 30 - organisation buy from another organisation\n";
is $schema->resultset('Transaction')->count, 1, "1 transaction"; is $schema->resultset('Transaction')->count, 2, "2 transaction";
$json = { $json = {
transaction_value => 100000, transaction_value => 100000,
transaction_type => 1, transaction_type => 1,
@ -458,6 +459,6 @@ $t->post_ok('/api/upload' => form => $upload )
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true) ->json_is('/success', Mojo::JSON->true)
->json_like('/message', qr/Upload Successful/); ->json_like('/message', qr/Upload Successful/);
is $schema->resultset('Transaction')->count, 2, "2 transaction"; is $schema->resultset('Transaction')->count, 3, "3 transaction";
done_testing(); done_testing();

View file

@ -42,6 +42,8 @@
<div class="col">From: <%= $transaction->buyer->name %></div> <div class="col">From: <%= $transaction->buyer->name %></div>
<div class="col">To: <%= $transaction->seller->name %></div> <div class="col">To: <%= $transaction->seller->name %></div>
<div class="col">Value: <%= $transaction->value %></div> <div class="col">Value: <%= $transaction->value %></div>
<div class="col">Submitted At: <%= $transaction->submitted_at %></div>
<div class="col">Purchase Time: <%= $transaction->purchase_time %></div>
</div> </div>
</div> </div>
</li> </li>