2017-04-20 00:27:18 +00:00
|
|
|
use Mojo::Base -strict;
|
|
|
|
|
2017-02-19 00:36:41 +00:00
|
|
|
use Test::More;
|
|
|
|
use Mojo::JSON;
|
2017-04-20 00:27:18 +00:00
|
|
|
use Test::Pear::LocalLoop;
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 00:27:18 +00:00
|
|
|
my $framework = Test::Pear::LocalLoop->new;
|
|
|
|
my $t = $framework->framework;
|
|
|
|
my $schema = $t->app->schema;
|
2017-04-20 21:17:13 +00:00
|
|
|
my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text };
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 21:17:13 +00:00
|
|
|
my @account_tokens = ('a', 'b', 'c');
|
2017-04-20 00:27:18 +00:00
|
|
|
|
|
|
|
$schema->resultset('AccountToken')->populate([
|
2017-04-21 20:28:50 +00:00
|
|
|
[ 'name' ],
|
2017-04-20 21:17:13 +00:00
|
|
|
map { [ $_ ] } @account_tokens,
|
2017-04-20 00:27:18 +00:00
|
|
|
]);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
#Add a test purchase_time to use for receipt uploading.
|
|
|
|
my $test_purchase_time = "2017-08-14T11:29:07.965+01:00";
|
|
|
|
|
2017-02-19 00:36:41 +00:00
|
|
|
#Add one company that we've apparently authenticated but does not have an account.
|
|
|
|
|
2017-04-20 00:27:18 +00:00
|
|
|
my $org_rs = $schema->resultset('Organisation');
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 00:27:18 +00:00
|
|
|
is $org_rs->count, 0, "No organisations";
|
2017-08-31 18:03:49 +00:00
|
|
|
my $shinra_entity = $schema->resultset('Entity')->create_org({
|
2017-04-20 21:17:13 +00:00
|
|
|
name => 'Shinra Electric Power Company',
|
2017-04-21 13:16:48 +00:00
|
|
|
street_name => 'Sector 0, Midgar, Eastern Continent',
|
2017-04-20 21:17:13 +00:00
|
|
|
town => 'Gaia',
|
|
|
|
postcode => 'E1 M00',
|
2017-08-31 18:03:49 +00:00
|
|
|
submitted_by_id => 1,
|
2017-04-20 00:27:18 +00:00
|
|
|
});
|
|
|
|
is $org_rs->count, 1, "1 testing organisation";
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-08-31 18:03:49 +00:00
|
|
|
my $org_id_shinra = $shinra_entity->organisation->id;
|
|
|
|
|
2018-01-16 15:55:19 +00:00
|
|
|
$schema->resultset('Category')->create({
|
|
|
|
id => 1,
|
|
|
|
name => "Test Category",
|
|
|
|
});
|
|
|
|
|
2017-02-19 00:36:41 +00:00
|
|
|
#Valid customer, this also tests that redirects are disabled for register.
|
|
|
|
print "test 1 - Create customer user account (Rufus)\n";
|
2017-08-31 18:03:49 +00:00
|
|
|
my $emailRufus = 'test1@example.com';
|
|
|
|
my $passwordRufus = 'abc123';
|
2017-02-19 00:36:41 +00:00
|
|
|
my $testJson = {
|
2017-08-14 10:55:52 +00:00
|
|
|
'usertype' => 'customer',
|
|
|
|
'token' => shift(@account_tokens),
|
|
|
|
'full_name' => 'RufusShinra',
|
|
|
|
'display_name' => 'RufusShinra',
|
|
|
|
'email' => $emailRufus,
|
|
|
|
'postcode' => 'GU10 5SA',
|
|
|
|
'password' => $passwordRufus,
|
2017-06-13 20:05:27 +00:00
|
|
|
'year_of_birth' => 2006
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/register' => json => $testJson)
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
|
|
|
|
|
|
|
print "test 2 - Create customer user account (Hojo)\n";
|
|
|
|
my $emailHojo = 'hojo@shinra.energy';
|
|
|
|
my $passwordHojo = 'Mako';
|
2017-04-20 00:27:18 +00:00
|
|
|
$testJson = {
|
2017-08-14 10:55:52 +00:00
|
|
|
'usertype' => 'customer',
|
|
|
|
'token' => shift(@account_tokens),
|
|
|
|
'display_name' => 'ProfessorHojo',
|
|
|
|
'full_name' => 'ProfessorHojo',
|
|
|
|
'email' => $emailHojo,
|
|
|
|
'postcode' => 'DE15 9LT',
|
|
|
|
'password' => $passwordHojo,
|
2017-06-13 20:05:27 +00:00
|
|
|
'year_of_birth' => 2006
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/register' => json => $testJson)
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
|
|
|
|
|
|
|
print "test 3 - Create organisation user account (Choco Billy)\n";
|
|
|
|
my $emailBilly = 'choco.billy@chocofarm.org';
|
|
|
|
my $passwordBilly = 'Choco';
|
2017-04-20 00:27:18 +00:00
|
|
|
$testJson = {
|
2017-08-14 10:55:52 +00:00
|
|
|
'usertype' => 'organisation',
|
|
|
|
'token' => shift(@account_tokens),
|
|
|
|
'name' => 'ChocoBillysGreens',
|
|
|
|
'email' => $emailBilly,
|
|
|
|
'postcode' => 'SO50 7NJ',
|
|
|
|
'password' => $passwordBilly,
|
2017-04-21 13:16:48 +00:00
|
|
|
'street_name' => 'Chocobo Farm, Eastern Continent',
|
2017-04-20 21:17:13 +00:00
|
|
|
'town' => 'Gaia',
|
2017-08-25 14:47:54 +00:00
|
|
|
'sector' => 'A',
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/register' => json => $testJson)
|
2017-08-14 10:55:52 +00:00
|
|
|
->status_is(200)
|
2017-04-20 21:17:13 +00:00
|
|
|
->json_is('/success', Mojo::JSON->true)
|
|
|
|
->json_like('/message', qr/Registered Successfully/);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
######################################################
|
|
|
|
|
|
|
|
#Login as Hojo (customer)
|
|
|
|
|
|
|
|
#Test login, this also checks that redirects are disabled for login when logged out.
|
|
|
|
print "test 4 - Login - Rufus (cookies, customer)\n";
|
|
|
|
$testJson = {
|
|
|
|
'email' => $emailRufus,
|
|
|
|
'password' => $passwordRufus,
|
|
|
|
};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/login' => json => $testJson)
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
2017-04-18 22:43:49 +00:00
|
|
|
my $session_key = $t->tx->res->json('/session_key');
|
2017-02-19 00:36:41 +00:00
|
|
|
print "test 5 - JSON missing\n";
|
2017-04-20 11:33:56 +00:00
|
|
|
my $upload = {file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-04-20 00:27:18 +00:00
|
|
|
->status_is(400)
|
2017-02-19 00:36:41 +00:00
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-04-20 00:27:18 +00:00
|
|
|
->json_like('/message', qr/JSON is missing/);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
#TODO Check for malformed JSON.
|
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 6 - transaction_value missing\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
my $json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 21:17:13 +00:00
|
|
|
organisation_id => $org_id_shinra,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/transaction amount is missing/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 7 - transaction_value non-numbers\n";
|
2017-04-20 00:27:18 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 'Abc',
|
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 21:17:13 +00:00
|
|
|
organisation_id => $org_id_shinra,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/transaction amount does not look like a number/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 8 - transaction_value equal to zero\n";
|
2017-04-20 00:27:18 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 0,
|
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 21:17:13 +00:00
|
|
|
organisation_id => $org_id_shinra,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/transaction amount cannot be equal to or less than zero/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 9 - transaction_value less than zero\n";
|
2017-04-20 00:27:18 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => -1,
|
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 21:17:13 +00:00
|
|
|
organisation_id => $org_id_shinra,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/transaction amount cannot be equal to or less than zero/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 10 - transaction_type missing\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/transaction type is missing/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 11 - transaction_type invalid.\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 4,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-04-20 21:17:13 +00:00
|
|
|
# organisation_id => $org_id_shinra
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/transaction type is not a valid value/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
print "test 12 - file not uploaded.\n";
|
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 11:33:56 +00:00
|
|
|
organisation_id => 1,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-09-06 15:13:00 +00:00
|
|
|
$t->post_ok('/api/upload' => json => $json )
|
|
|
|
->status_is(200)
|
|
|
|
->or($framework->dump_error)
|
|
|
|
->json_is('/success', Mojo::JSON->true)
|
|
|
|
->json_like('/message', qr/Upload Successful/);
|
2017-08-31 10:41:38 +00:00
|
|
|
is $schema->resultset('Transaction')->count, 1, "1 transaction";
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 13 - organisation_id missing (type 1: already validated)\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-04-20 21:17:13 +00:00
|
|
|
# organisation_id => $org_id_shinra
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/organisation ID is missing/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 14 - organisation_id for non-existent id. (type 1: already validated)\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 21:17:13 +00:00
|
|
|
organisation_id => ($org_id_shinra + 100),
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/organisation ID does not exist in the database/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
print "test 15 - valid addition. (type 1: already validated)\n";
|
2017-08-31 10:41:38 +00:00
|
|
|
is $schema->resultset('Transaction')->count, 1, "1 transaction";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 21:17:13 +00:00
|
|
|
organisation_id => $org_id_shinra,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2018-01-16 15:55:19 +00:00
|
|
|
category => 1,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true)
|
2017-04-20 00:27:18 +00:00
|
|
|
->json_like('/message', qr/Upload Successful/);
|
2017-08-31 10:41:38 +00:00
|
|
|
is $schema->resultset('Transaction')->count, 2, "2 transaction";
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
# Add type 3 (new organisation) checking.
|
|
|
|
|
|
|
|
print "test 16 - organsation missing (type 3: new organisation)\n";
|
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 3,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 11:33:56 +00:00
|
|
|
street_name => "Slums, Sector 7",
|
2017-02-19 00:36:41 +00:00
|
|
|
town => "Midgar",
|
2017-04-20 00:27:18 +00:00
|
|
|
postcode => "E1 0AA",
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/organisation name is missing/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
print "test 17 - add valid transaction (type 3: new organisation)\n";
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->count, 0, "No pending organisations";
|
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 0, "No pending transactions";
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 3,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 11:33:56 +00:00
|
|
|
organisation_name => '7th Heaven',
|
|
|
|
street_name => "Slums, Sector 7",
|
2017-02-19 00:36:41 +00:00
|
|
|
town => "Midgar",
|
2017-04-20 00:27:18 +00:00
|
|
|
postcode => "E1 0AA",
|
2018-01-16 15:55:19 +00:00
|
|
|
category => 1,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true)
|
2017-04-20 00:27:18 +00:00
|
|
|
->json_like('/message', qr/Upload Successful/);
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->count, 1, "1 pending organisations";
|
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
# Add type 2 (unverified organisation) checking.
|
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 18 - organisation_id missing (type 2: existing organisation)\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 2,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
2017-08-31 18:03:49 +00:00
|
|
|
->or($framework->dump_error)
|
2017-02-19 00:36:41 +00:00
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/organisation ID is missing/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-04-20 11:33:56 +00:00
|
|
|
print "test 19 - organisation_id not a number (type 2: existing organisation)\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 2,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 11:33:56 +00:00
|
|
|
organisation_id => "Abc",
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/organisation ID is not a number/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
print "test 20 - id does not exist (type 2: existing organisation)\n";
|
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 2,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 11:33:56 +00:00
|
|
|
organisation_id => 1000, #Id that does not exist
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/organisation ID does not exist in the database/i);
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 21 - purchase_time is missing\n";
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
2017-08-14 10:55:52 +00:00
|
|
|
$json = {
|
|
|
|
transaction_value => 10,
|
2017-08-31 18:03:49 +00:00
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
organisation_id => $org_id_shinra,
|
|
|
|
session_key => $session_key,
|
|
|
|
};
|
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-08-14 15:21:06 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
2017-08-14 10:55:52 +00:00
|
|
|
|
|
|
|
print "test 22 - Logout Rufus (type 2: existing organisation)\n";
|
2017-04-20 00:27:18 +00:00
|
|
|
$t->post_ok('/api/logout', json => { session_key => $session_key } )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
|
|
|
|
|
|
|
#End of Rufus (customer)
|
|
|
|
|
|
|
|
######################################################
|
|
|
|
|
|
|
|
#Login as Hojo (customer)
|
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 23 - Login Hojo (cookies, customer)\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$testJson = {
|
|
|
|
'email' => $emailHojo,
|
|
|
|
'password' => $passwordHojo,
|
|
|
|
};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/login' => json => $testJson)
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
2017-04-18 22:43:49 +00:00
|
|
|
$session_key = $t->tx->res->json('/session_key');
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 24 - add valid transaction but for with account (type 2: existing organisation)\n";
|
2017-08-31 18:03:49 +00:00
|
|
|
my $org_result = $schema->resultset('Organisation')->find({ name => '7th Heaven' });
|
2017-04-21 13:16:48 +00:00
|
|
|
my $unvalidatedOrganisationId = $org_result->id;
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 2,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 11:33:56 +00:00
|
|
|
organisation_id => $unvalidatedOrganisationId,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2018-01-16 15:55:19 +00:00
|
|
|
category => 1,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-08-14 10:55:52 +00:00
|
|
|
->status_is(400)
|
2017-02-19 00:36:41 +00:00
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->content_like(qr/organisation ID does not exist in the database/i);
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 25 - Logout Hojo\n";
|
2017-04-20 00:27:18 +00:00
|
|
|
$t->post_ok('/api/logout', json => { session_key => $session_key } )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
|
|
|
|
|
|
|
#End of Hojo (customer)
|
|
|
|
|
|
|
|
######################################################
|
|
|
|
|
|
|
|
#Login as Rufus (customer)
|
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 26 - Login Rufus (cookies, customer)\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$testJson = {
|
|
|
|
'email' => $emailRufus,
|
|
|
|
'password' => $passwordRufus,
|
|
|
|
};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/login' => json => $testJson)
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
2017-04-18 22:43:49 +00:00
|
|
|
$session_key = $t->tx->res->json('/session_key');
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 27 - add valid transaction (type 2: existing organisation)\n";
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 10,
|
|
|
|
transaction_type => 2,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 11:33:56 +00:00
|
|
|
organisation_id => $unvalidatedOrganisationId,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true)
|
2017-04-20 00:27:18 +00:00
|
|
|
->json_like('/message', qr/Upload Successful/);
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 2, "2 pending transactions";
|
2017-02-19 00:36:41 +00:00
|
|
|
|
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 28 - Logout Rufus\n";
|
2017-04-20 00:27:18 +00:00
|
|
|
$t->post_ok('/api/logout' => json => { session_key => $session_key } )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
|
|
|
|
|
|
|
#End of Rufus (customer)
|
|
|
|
|
|
|
|
######################################################
|
|
|
|
|
|
|
|
#Login as Choco Billy (organisation)
|
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 29 - Login Choco Billy (cookies, organisation)\n";
|
2017-02-19 00:36:41 +00:00
|
|
|
$testJson = {
|
|
|
|
'email' => $emailBilly,
|
|
|
|
'password' => $passwordBilly,
|
|
|
|
};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/login' => json => $testJson)
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true);
|
2017-04-18 22:43:49 +00:00
|
|
|
$session_key = $t->tx->res->json('/session_key');
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-08-14 10:55:52 +00:00
|
|
|
print "test 30 - organisation buy from another organisation\n";
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Transaction')->count, 5, "5 transaction";
|
2017-02-19 00:36:41 +00:00
|
|
|
$json = {
|
2017-04-20 11:33:56 +00:00
|
|
|
transaction_value => 100000,
|
|
|
|
transaction_type => 1,
|
2017-08-14 10:55:52 +00:00
|
|
|
purchase_time => $test_purchase_time,
|
2017-04-20 21:17:13 +00:00
|
|
|
organisation_id => $org_id_shinra,
|
2017-04-18 22:43:49 +00:00
|
|
|
session_key => $session_key,
|
2017-02-19 00:36:41 +00:00
|
|
|
};
|
2017-04-20 11:33:56 +00:00
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
2017-04-06 21:43:27 +00:00
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
2017-02-19 00:36:41 +00:00
|
|
|
->status_is(200)
|
|
|
|
->json_is('/success', Mojo::JSON->true)
|
2017-04-20 00:27:18 +00:00
|
|
|
->json_like('/message', qr/Upload Successful/);
|
2017-08-31 18:03:49 +00:00
|
|
|
is $schema->resultset('Transaction')->count, 6, "6 transaction";
|
2017-02-19 00:36:41 +00:00
|
|
|
|
2017-09-05 11:03:49 +00:00
|
|
|
print "test 31 - organisation buy from same organisation\n";
|
|
|
|
$json = {
|
|
|
|
transaction_value => 100000,
|
|
|
|
transaction_type => 1,
|
|
|
|
purchase_time => $test_purchase_time,
|
|
|
|
organisation_id => 2,
|
|
|
|
session_key => $session_key,
|
|
|
|
};
|
|
|
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
|
|
|
$t->post_ok('/api/upload' => form => $upload )
|
|
|
|
->status_is(400)
|
|
|
|
->json_is('/success', Mojo::JSON->false)
|
2017-09-18 11:05:30 +00:00
|
|
|
->json_like('/message', qr/organisation ID does not exist in the database/);
|
2017-09-05 11:03:49 +00:00
|
|
|
is $schema->resultset('Transaction')->count, 6, "6 transaction";
|
|
|
|
|
2017-02-19 00:36:41 +00:00
|
|
|
done_testing();
|