Added more tests to the admin-approval API and aesthetic changes to the test.

This commit is contained in:
Paul Dill 2017-03-05 19:07:32 +00:00
parent ac2563237a
commit cc0da394a7

View file

@ -81,7 +81,7 @@ $t->post_ok('/register' => json => $testJson)
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
print "test 3 - Making 'admin' an Admin\n"; print "test 4 - Making 'admin' an Admin\n";
my $rufusUserId = $t->app->db->selectrow_array("SELECT UserId FROM Users WHERE Email = ?", undef, ($emailAdmin)); my $rufusUserId = $t->app->db->selectrow_array("SELECT UserId FROM Users WHERE Email = ?", undef, ($emailAdmin));
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Administrators")}[0],0,"No admins"; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Administrators")}[0],0,"No admins";
$t->app->db->prepare("INSERT INTO Administrators (UserId) VALUES (?)")->execute($rufusUserId); $t->app->db->prepare("INSERT INTO Administrators (UserId) VALUES (?)")->execute($rufusUserId);
@ -92,7 +92,7 @@ is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Administrators")}[0],
#Login as non-admin Reno #Login as non-admin Reno
print "test 4 - Login - non-admin Reno (cookies, customer)\n"; print "test 5 - Login - non-admin Reno (cookies, customer)\n";
$testJson = { $testJson = {
'email' => $emailReno, 'email' => $emailReno,
'password' => $passwordReno, 'password' => $passwordReno,
@ -101,7 +101,7 @@ $t->post_ok('/login' => json => $testJson)
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
print "test 5 - add valid transaction (type 3: new organisation)\n"; print "test 6 - add valid transaction (type 3: new organisation)\n";
my ($test1) = $t->app->db->selectrow_array("SELECT COUNT(*) FROM PendingOrganisations", undef, ()); my ($test1) = $t->app->db->selectrow_array("SELECT COUNT(*) FROM PendingOrganisations", undef, ());
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],0,"No unverified organisations."; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],0,"No unverified organisations.";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],0,"No unverified transactions." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],0,"No unverified transactions." ;
@ -129,7 +129,7 @@ is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef,
my $newPendingTurtleOrgId = $t->tx->res->json->{unvalidatedOrganisationId};; my $newPendingTurtleOrgId = $t->tx->res->json->{unvalidatedOrganisationId};;
#print "Turtle Id: " . $newPendingTurtleOrgId . "\n"; #print "Turtle Id: " . $newPendingTurtleOrgId . "\n";
print "test 6 - Non-admin (customer) tries to approve their organisation and fails.\n"; print "test 7 - Non-admin (customer) tries to approve their organisation and fails.\n";
$json = { $json = {
unvalidatedOrganisationId => $newPendingTurtleOrgId, unvalidatedOrganisationId => $newPendingTurtleOrgId,
}; };
@ -139,7 +139,7 @@ $t->post_ok('/admin-approve' => json => $json)
->content_like(qr/You are not an admin/i); ->content_like(qr/You are not an admin/i);
print "test 7 - Logout Reno\n"; print "test 8 - Logout Reno\n";
$t->post_ok('/logout') $t->post_ok('/logout')
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
@ -150,7 +150,7 @@ $t->post_ok('/logout')
#Login as non-admin Choco Billy #Login as non-admin Choco Billy
print "test 8 - Login - non-admin Choco Billy (cookies, organisation)\n"; print "test 9 - Login - non-admin Choco Billy (cookies, organisation)\n";
$testJson = { $testJson = {
'email' => $emailBilly, 'email' => $emailBilly,
'password' => $passwordBilly, 'password' => $passwordBilly,
@ -160,7 +160,7 @@ $t->post_ok('/login' => json => $testJson)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
print "test 9 - add valid transaction (type 3: new organisation)\n"; print "test 10 - add valid transaction (type 3: new organisation)\n";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],1,"1 unverified organisations." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],1,"1 unverified organisations." ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],1,"1 unverified transactions." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],1,"1 unverified transactions." ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],1,"1 verified organisations (choco billy)" ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],1,"1 verified organisations (choco billy)" ;
@ -188,7 +188,7 @@ my $newPendingKalmOrgId = $t->tx->res->json->{unvalidatedOrganisationId};
#print "Kalm Id: " . $newPendingKalmOrgId . "\n"; #print "Kalm Id: " . $newPendingKalmOrgId . "\n";
print "test 10 - add valid transaction (type 2: unvalidated organisation)\n"; print "test 11 - add valid transaction (type 2: unvalidated organisation)\n";
$json = { $json = {
microCurrencyValue => 10, microCurrencyValue => 10,
transactionAdditionType => 2, transactionAdditionType => 2,
@ -204,7 +204,7 @@ is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions",
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],1,"1 verified organisations (choco billy)" ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],1,"1 verified organisations (choco billy)" ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],0,"No verified transactions." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],0,"No verified transactions." ;
print "test 11 - add valid transaction (type 3: new organisation)\n"; print "test 12 - add valid transaction (type 3: new organisation)\n";
my $nameToTestJunon = 'Store'; my $nameToTestJunon = 'Store';
$json = { $json = {
microCurrencyValue => 10, microCurrencyValue => 10,
@ -229,8 +229,7 @@ is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],0,"No verified transactions." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],0,"No verified transactions." ;
print "test 13 - add valid transaction (type 2: unvalidated organisation)\n";
print "test 12 - add valid transaction (type 2: unvalidated organisation)\n";
$json = { $json = {
microCurrencyValue => 20, microCurrencyValue => 20,
transactionAdditionType => 2, transactionAdditionType => 2,
@ -247,8 +246,7 @@ is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],0,"No verified transactions." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],0,"No verified transactions." ;
print "test 14 - add valid transaction (type 2: unvalidated organisation)\n";
print "test 13 - add valid transaction (type 2: unvalidated organisation)\n";
$json = { $json = {
microCurrencyValue => 30, microCurrencyValue => 30,
transactionAdditionType => 2, transactionAdditionType => 2,
@ -264,7 +262,7 @@ is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions",
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],1,"1 verified organisations (choco billy)" ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],1,"1 verified organisations (choco billy)" ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],0,"No verified transactions." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],0,"No verified transactions." ;
print "test 14 - Non-admin (organisation) tries to approve their organisation and fails.\n"; print "test 15 - Non-admin (organisation) tries to approve their organisation and fails.\n";
$json = { $json = {
unvalidatedOrganisationId => $newPendingKalmOrgId, unvalidatedOrganisationId => $newPendingKalmOrgId,
}; };
@ -273,7 +271,7 @@ $t->post_ok('/admin-approve' => json => $json)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/You are not an admin/i); ->content_like(qr/You are not an admin/i);
print "test 15 - Logout Choco Billy\n"; print "test 16 - Logout Choco Billy\n";
$t->post_ok('/logout') $t->post_ok('/logout')
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
@ -284,7 +282,7 @@ $t->post_ok('/logout')
#Login as Admin #Login as Admin
print "test 16 - Login - admin\n"; print "test 17 - Login - admin\n";
$testJson = { $testJson = {
'email' => $emailAdmin, 'email' => $emailAdmin,
'password' => $passwordAdmin, 'password' => $passwordAdmin,
@ -294,13 +292,13 @@ $t->post_ok('/login' => json => $testJson)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
print "test 17 - JSON is missing.\n"; print "test 18 - JSON is missing.\n";
$t->post_ok('/admin-approve' => json) $t->post_ok('/admin-approve' => json)
->status_is(400) ->status_is(400)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/JSON is missing/i); ->content_like(qr/JSON is missing/i);
print "test 18 - unvalidatedOrganisationId missing (non-modify).\n"; print "test 19 - unvalidatedOrganisationId missing (non-modify).\n";
$json = { $json = {
}; };
$t->post_ok('/admin-approve' => json => $json) $t->post_ok('/admin-approve' => json => $json)
@ -308,7 +306,7 @@ $t->post_ok('/admin-approve' => json => $json)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/unvalidatedOrganisationId is missing/i); ->content_like(qr/unvalidatedOrganisationId is missing/i);
print "test 19 - unvalidatedOrganisationId not number (non-modify).\n"; print "test 20 - unvalidatedOrganisationId not number (non-modify).\n";
$json = { $json = {
unvalidatedOrganisationId => 'Abc', unvalidatedOrganisationId => 'Abc',
}; };
@ -318,7 +316,7 @@ $t->post_ok('/admin-approve' => json => $json)
->content_like(qr/unvalidatedOrganisationId does not look like a number/i); ->content_like(qr/unvalidatedOrganisationId does not look like a number/i);
print "test 20 - unvalidatedOrganisationId does not exist (non-modify).\n"; print "test 21 - unvalidatedOrganisationId does not exist (non-modify).\n";
my ($maxPendingId) = $t->app->db->selectrow_array("SELECT MAX(PendingOrganisationId) FROM PendingOrganisations", undef,()); my ($maxPendingId) = $t->app->db->selectrow_array("SELECT MAX(PendingOrganisationId) FROM PendingOrganisations", undef,());
$json = { $json = {
unvalidatedOrganisationId => ($maxPendingId + 1), unvalidatedOrganisationId => ($maxPendingId + 1),
@ -330,7 +328,7 @@ $t->post_ok('/admin-approve' => json => $json)
#TODO add text to see the specific one has moved. #TODO add text to see the specific one has moved.
print "test 21 - valid approval (non-modify).\n"; print "test 22 - valid approval (non-modify).\n";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],3,"3 unverified organisations."; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],3,"3 unverified organisations.";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],6,"6 unverified transactions." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],6,"6 unverified transactions." ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],1,"1 verified organisations (choco billy)" ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],1,"1 verified organisations (choco billy)" ;
@ -348,9 +346,7 @@ is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef,
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations WHERE Name = ?", undef, ($nameToTestKalm))}[0],0,"Kalm does not exist in pending orgs."; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations WHERE Name = ?", undef, ($nameToTestKalm))}[0],0,"Kalm does not exist in pending orgs.";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations WHERE Name = ?", undef, ($nameToTestKalm))}[0],1,"Kalm exists in verified orgs."; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations WHERE Name = ?", undef, ($nameToTestKalm))}[0],1,"Kalm exists in verified orgs.";
#TODO check with values missing print "test 23 - valid approval (modify all).\n";
print "test 22 - valid approval (non-modify).\n";
#TODO if we implement constraints on the input data this will fail #TODO if we implement constraints on the input data this will fail
my $testName = "Change testing turtle name"; my $testName = "Change testing turtle name";
my $testFullAddress = "Change testing turtle address"; my $testFullAddress = "Change testing turtle address";
@ -369,11 +365,27 @@ is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions",
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],3,"3 verified organisations (choco billy, kalm inn and turtle)" ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],3,"3 verified organisations (choco billy, kalm inn and turtle)" ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],3,"3 verified transaction." ; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],3,"3 verified transaction." ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations WHERE Name = ?", undef, ($nameToTestTurtle))}[0],0,"Turtle does not exist in pending orgs."; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations WHERE Name = ?", undef, ($nameToTestTurtle))}[0],0,"Turtle does not exist in pending orgs.";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations WHERE Name = ?", undef, ($nameToTestTurtle))}[0],0,"Turtle does not exist in verified orgs, it been renamed."; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations WHERE Name = ?", undef, ($nameToTestTurtle))}[0],0,"Turtle does not exist in verified orgs, its been renamed.";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations WHERE Name = ? AND FullAddress = ? AND PostCode = ?", undef, ($testName, $testFullAddress, $testPostCode))}[0],1,"Turtle exists and has been renamed in verified orgs."; is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations WHERE Name = ? AND FullAddress = ? AND PostCode = ?", undef, ($testName, $testFullAddress, $testPostCode))}[0],1,"Turtle exists and has been renamed in verified orgs.";
print "test 24 - valid approval (modify some).\n";
#TODO if we implement constraints on the input data this will fail
my $testName = "Change testing junon name";
$json = {
unvalidatedOrganisationId => $newPendingJunonOrgId,
name => $testName,
};
$t->post_ok('/admin-approve' => json => $json)
->status_is(200)
->json_is('/success', Mojo::JSON->true);
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],0,"0 unverified organisation." ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],0,"0 unverified transaction." ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],4,"4 verified organisations (choco billy, kalm inn, turtle and junon)" ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions", undef, ())}[0],6,"6 verified transaction." ;
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations WHERE Name = ?", undef, ($nameToTestJunon))}[0],0,"Junon does not exist in pending orgs.";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations WHERE Name = ?", undef, ($nameToTestJunon))}[0],0,"Junon does not exist in verified orgs, its been renamed.";
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations WHERE Name = ?", undef, ($testName))}[0],1,"Junon exists and has been renamed in verified orgs.";
############################################## ##############################################
done_testing(); done_testing();