Updated tests to include receipt datetime submission
This commit is contained in:
parent
85c80980c3
commit
f9703b6561
2 changed files with 85 additions and 48 deletions
|
@ -106,6 +106,7 @@ my $json = {
|
|||
street_name => "2 James St",
|
||||
town => "Lancaster",
|
||||
postcode => "LA1 1UP",
|
||||
purchase_time => "2017-08-14T11:29:07.965+01:00",
|
||||
session_key => $session_key,
|
||||
};
|
||||
my $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||
|
@ -133,6 +134,7 @@ $json = {
|
|||
street_name => "The Crescent",
|
||||
town => "Morecambe",
|
||||
postcode => "LA4 5BZ",
|
||||
purchase_time => "2017-08-14T11:29:07.965+01:00",
|
||||
session_key => $session_key,
|
||||
};
|
||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||
|
@ -148,6 +150,7 @@ $json = {
|
|||
street_name => "63-65 Church Street",
|
||||
town => "Lancaster",
|
||||
postcode => "LA1 1ET",
|
||||
purchase_time => "2017-08-14T11:29:07.965+01:00",
|
||||
session_key => $session_key,
|
||||
};
|
||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||
|
|
|
@ -16,6 +16,9 @@ $schema->resultset('AccountToken')->populate([
|
|||
map { [ $_ ] } @account_tokens,
|
||||
]);
|
||||
|
||||
#Add a test purchase_time to use for receipt uploading.
|
||||
my $test_purchase_time = "2017-08-14T11:29:07.965+01:00";
|
||||
|
||||
#Add one company that we've apparently authenticated but does not have an account.
|
||||
my $org_id_shinra = 1;
|
||||
|
||||
|
@ -110,6 +113,7 @@ $t->post_ok('/api/upload' => form => $upload )
|
|||
print "test 6 - transaction_value missing\n";
|
||||
my $json = {
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => $org_id_shinra,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -123,6 +127,7 @@ print "test 7 - transaction_value non-numbers\n";
|
|||
$json = {
|
||||
transaction_value => 'Abc',
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => $org_id_shinra,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -136,6 +141,7 @@ print "test 8 - transaction_value equal to zero\n";
|
|||
$json = {
|
||||
transaction_value => 0,
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => $org_id_shinra,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -149,6 +155,7 @@ print "test 9 - transaction_value less than zero\n";
|
|||
$json = {
|
||||
transaction_value => -1,
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => $org_id_shinra,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -161,6 +168,7 @@ $t->post_ok('/api/upload' => form => $upload )
|
|||
print "test 10 - transaction_type missing\n";
|
||||
$json = {
|
||||
transaction_value => 10,
|
||||
purchase_time => $test_purchase_time,
|
||||
session_key => $session_key,
|
||||
};
|
||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||
|
@ -173,6 +181,7 @@ print "test 11 - transaction_type invalid.\n";
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 4,
|
||||
purchase_time => $test_purchase_time,
|
||||
session_key => $session_key,
|
||||
# organisation_id => $org_id_shinra
|
||||
};
|
||||
|
@ -186,6 +195,7 @@ print "test 12 - file not uploaded.\n";
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => 1,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -199,6 +209,7 @@ print "test 13 - organisation_id missing (type 1: already validated)\n";
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
session_key => $session_key,
|
||||
# organisation_id => $org_id_shinra
|
||||
};
|
||||
|
@ -212,6 +223,7 @@ print "test 14 - organisation_id for non-existent id. (type 1: already validated
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => ($org_id_shinra + 100),
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -226,6 +238,7 @@ is $schema->resultset('Transaction')->count, 0, "no transactions";
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => $org_id_shinra,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -242,6 +255,7 @@ print "test 16 - organsation missing (type 3: new organisation)\n";
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 3,
|
||||
purchase_time => $test_purchase_time,
|
||||
street_name => "Slums, Sector 7",
|
||||
town => "Midgar",
|
||||
postcode => "E1 0AA",
|
||||
|
@ -260,6 +274,7 @@ is $schema->resultset('PendingTransaction')->count, 0, "No pending transactions"
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 3,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_name => '7th Heaven',
|
||||
street_name => "Slums, Sector 7",
|
||||
town => "Midgar",
|
||||
|
@ -280,6 +295,7 @@ print "test 18 - organisation_id missing (type 2: existing organisation)\n";
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 2,
|
||||
purchase_time => $test_purchase_time,
|
||||
session_key => $session_key,
|
||||
};
|
||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||
|
@ -292,6 +308,7 @@ print "test 19 - organisation_id not a number (type 2: existing organisation)\n"
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 2,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => "Abc",
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -305,6 +322,7 @@ print "test 20 - id does not exist (type 2: existing organisation)\n";
|
|||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 2,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => 1000, #Id that does not exist
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -314,7 +332,21 @@ $t->post_ok('/api/upload' => form => $upload )
|
|||
->json_is('/success', Mojo::JSON->false)
|
||||
->content_like(qr/organisation_id does not exist in the database/i);
|
||||
|
||||
print "test 21 - Logout Rufus (type 2: existing organisation)\n";
|
||||
print "test 21 - purchase_time is missing\n";
|
||||
is $schema->resultset('Transaction')->count, 0, "no transactions";
|
||||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 1,
|
||||
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 )
|
||||
->status_is(400)
|
||||
->json_is('/success', Mojo::JSON->false)
|
||||
->content_like(qr/purchase_time is missing/i);
|
||||
|
||||
print "test 22 - Logout Rufus (type 2: existing organisation)\n";
|
||||
$t->post_ok('/api/logout', json => { session_key => $session_key } )
|
||||
->status_is(200)
|
||||
->json_is('/success', Mojo::JSON->true);
|
||||
|
@ -325,7 +357,7 @@ $t->post_ok('/api/logout', json => { session_key => $session_key } )
|
|||
|
||||
#Login as Hojo (customer)
|
||||
|
||||
print "test 22 - Login Hojo (cookies, customer)\n";
|
||||
print "test 23 - Login Hojo (cookies, customer)\n";
|
||||
$testJson = {
|
||||
'email' => $emailHojo,
|
||||
'password' => $passwordHojo,
|
||||
|
@ -335,13 +367,14 @@ $t->post_ok('/api/login' => json => $testJson)
|
|||
->json_is('/success', Mojo::JSON->true);
|
||||
$session_key = $t->tx->res->json('/session_key');
|
||||
|
||||
print "test 23 - add valid transaction but for with account (type 2: existing organisation)\n";
|
||||
print "test 24 - add valid transaction but for with account (type 2: existing organisation)\n";
|
||||
my $org_result = $schema->resultset('PendingOrganisation')->find({ name => '7th Heaven' });
|
||||
my $unvalidatedOrganisationId = $org_result->id;
|
||||
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
||||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 2,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => $unvalidatedOrganisationId,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -352,7 +385,7 @@ $t->post_ok('/api/upload' => form => $upload )
|
|||
->content_like(qr/organisation_id does not exist in the database/i);
|
||||
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
||||
|
||||
print "test 24 - Logout Hojo\n";
|
||||
print "test 25 - Logout Hojo\n";
|
||||
$t->post_ok('/api/logout', json => { session_key => $session_key } )
|
||||
->status_is(200)
|
||||
->json_is('/success', Mojo::JSON->true);
|
||||
|
@ -363,7 +396,7 @@ $t->post_ok('/api/logout', json => { session_key => $session_key } )
|
|||
|
||||
#Login as Rufus (customer)
|
||||
|
||||
print "test 25 - Login Rufus (cookies, customer)\n";
|
||||
print "test 26 - Login Rufus (cookies, customer)\n";
|
||||
$testJson = {
|
||||
'email' => $emailRufus,
|
||||
'password' => $passwordRufus,
|
||||
|
@ -373,11 +406,12 @@ $t->post_ok('/api/login' => json => $testJson)
|
|||
->json_is('/success', Mojo::JSON->true);
|
||||
$session_key = $t->tx->res->json('/session_key');
|
||||
|
||||
print "test 26 - add valid transaction (type 2: existing organisation)\n";
|
||||
print "test 27 - add valid transaction (type 2: existing organisation)\n";
|
||||
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
||||
$json = {
|
||||
transaction_value => 10,
|
||||
transaction_type => 2,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => $unvalidatedOrganisationId,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -389,7 +423,7 @@ $t->post_ok('/api/upload' => form => $upload )
|
|||
is $schema->resultset('PendingTransaction')->count, 2, "2 pending transactions";
|
||||
|
||||
|
||||
print "test 27 - Logout Rufus\n";
|
||||
print "test 28 - Logout Rufus\n";
|
||||
$t->post_ok('/api/logout' => json => { session_key => $session_key } )
|
||||
->status_is(200)
|
||||
->json_is('/success', Mojo::JSON->true);
|
||||
|
@ -400,7 +434,7 @@ $t->post_ok('/api/logout' => json => { session_key => $session_key } )
|
|||
|
||||
#Login as Choco Billy (organisation)
|
||||
|
||||
print "test 28 - Login Choco Billy (cookies, organisation)\n";
|
||||
print "test 29 - Login Choco Billy (cookies, organisation)\n";
|
||||
$testJson = {
|
||||
'email' => $emailBilly,
|
||||
'password' => $passwordBilly,
|
||||
|
@ -410,11 +444,12 @@ $t->post_ok('/api/login' => json => $testJson)
|
|||
->json_is('/success', Mojo::JSON->true);
|
||||
$session_key = $t->tx->res->json('/session_key');
|
||||
|
||||
print "test 29 - organisation buy from another organisation\n";
|
||||
print "test 30 - organisation buy from another organisation\n";
|
||||
is $schema->resultset('Transaction')->count, 1, "1 transaction";
|
||||
$json = {
|
||||
transaction_value => 100000,
|
||||
transaction_type => 1,
|
||||
purchase_time => $test_purchase_time,
|
||||
organisation_id => $org_id_shinra,
|
||||
session_key => $session_key,
|
||||
};
|
||||
|
@ -426,4 +461,3 @@ $t->post_ok('/api/upload' => form => $upload )
|
|||
is $schema->resultset('Transaction')->count, 2, "2 transaction";
|
||||
|
||||
done_testing();
|
||||
|
||||
|
|
Reference in a new issue