Add return JSON value to upload API when adding a new organisation, fix admin-approve test and fix admin-approve bug.
This commit is contained in:
parent
5ddf707367
commit
ac2563237a
4 changed files with 40 additions and 24 deletions
|
@ -77,9 +77,10 @@ sub post_admin_approve {
|
||||||
my $statementInsOrg = $self->db->prepare("INSERT INTO Organisations (Name, FullAddress, PostCode) VALUES (?, ?, ?)");
|
my $statementInsOrg = $self->db->prepare("INSERT INTO Organisations (Name, FullAddress, PostCode) VALUES (?, ?, ?)");
|
||||||
$statementInsOrg->execute($name, $fullAddress, $postcode);
|
$statementInsOrg->execute($name, $fullAddress, $postcode);
|
||||||
my $organisationalId = $self->db->last_insert_id(undef,undef, "Organisations", "OrganisationalId") . "\n";
|
my $organisationalId = $self->db->last_insert_id(undef,undef, "Organisations", "OrganisationalId") . "\n";
|
||||||
|
#print "OrgId: " . $organisationalId . "\n";
|
||||||
|
|
||||||
my $statementSelectPendingTrans = $self->db->prepare("SELECT BuyerUserId_FK, ValueMicroCurrency, ProofImage, TimeDateSubmitted FROM PendingTransactions WHERE PendingSellerOrganisationId_FK = ?");
|
my $statementSelectPendingTrans = $self->db->prepare("SELECT BuyerUserId_FK, ValueMicroCurrency, ProofImage, TimeDateSubmitted FROM PendingTransactions WHERE PendingSellerOrganisationId_FK = ?");
|
||||||
$statementSelectPendingTrans->execute($organisationalId);
|
$statementSelectPendingTrans->execute($unvalidatedOrganisationId);
|
||||||
|
|
||||||
my $statementInsTrans = $self->db->prepare("INSERT INTO Transactions (BuyerUserId_FK, SellerOrganisationId_FK, ValueMicroCurrency, ProofImage, TimeDateSubmitted) VALUES (?, ?, ?, ?, ?)");
|
my $statementInsTrans = $self->db->prepare("INSERT INTO Transactions (BuyerUserId_FK, SellerOrganisationId_FK, ValueMicroCurrency, ProofImage, TimeDateSubmitted) VALUES (?, ?, ?, ?, ?)");
|
||||||
|
|
||||||
|
@ -103,5 +104,7 @@ sub post_admin_approve {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
|
@ -234,10 +234,17 @@ sub post_upload {
|
||||||
if ($rowsAdded2 != 0) {
|
if ($rowsAdded2 != 0) {
|
||||||
$file->move_to('images/' . $filename);
|
$file->move_to('images/' . $filename);
|
||||||
$self->app->log->debug('Path Success: file:' . __FILE__ . ', line: ' . __LINE__);
|
$self->app->log->debug('Path Success: file:' . __FILE__ . ', line: ' . __LINE__);
|
||||||
return $self->render( json => {
|
|
||||||
|
my $returnedJson = {
|
||||||
success => Mojo::JSON->true,
|
success => Mojo::JSON->true,
|
||||||
message => 'Added transaction for unvalidated organisation.',
|
message => 'Added transaction for unvalidated organisation.',
|
||||||
},
|
};
|
||||||
|
|
||||||
|
if ($transactionAdditionType == 3){
|
||||||
|
$returnedJson->{unvalidatedOrganisationId} = $unvalidatedOrganisationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $self->render( json => $returnedJson,
|
||||||
status => 200,);
|
status => 200,);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use Test::More skip_all => "Test is currently broken";
|
use Test::More;
|
||||||
use Test::Mojo;
|
use Test::Mojo;
|
||||||
use Mojo::JSON;
|
use Mojo::JSON;
|
||||||
|
|
||||||
|
@ -119,14 +119,15 @@ $json = {
|
||||||
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/upload' => form => $upload )
|
$t->post_ok('/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_has('/unvalidatedOrganisationId');
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],1,"1 unverified organisation." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],1,"1 unverified organisation." ;
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],1,"1 unverified transaction." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],1,"1 unverified transaction." ;
|
||||||
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." ;
|
||||||
|
|
||||||
my $newPendingTurtleOrgId = $t->app->db->last_insert_id(undef,undef, "PendingOrganisations", "PendingOrganisationId");
|
my $newPendingTurtleOrgId = $t->tx->res->json->{unvalidatedOrganisationId};;
|
||||||
print "Turtle Id: " . $newPendingTurtleOrgId;
|
#print "Turtle Id: " . $newPendingTurtleOrgId . "\n";
|
||||||
|
|
||||||
print "test 6 - Non-admin (customer) tries to approve their organisation and fails.\n";
|
print "test 6 - Non-admin (customer) tries to approve their organisation and fails.\n";
|
||||||
$json = {
|
$json = {
|
||||||
|
@ -176,14 +177,15 @@ $json = {
|
||||||
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/upload' => form => $upload )
|
$t->post_ok('/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_has('/unvalidatedOrganisationId');
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],2,"2 unverified organisations." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],2,"2 unverified organisations." ;
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],2,"2 unverified transactions." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],2,"2 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)" ;
|
||||||
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." ;
|
||||||
|
|
||||||
my $newPendingKalmOrgId = $t->app->db->last_insert_id(undef,undef, "PendingOrganisations", "PendingOrganisationId");
|
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 10 - add valid transaction (type 2: unvalidated organisation)\n";
|
||||||
|
@ -195,15 +197,14 @@ $json = {
|
||||||
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/upload' => form => $upload )
|
$t->post_ok('/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_hasnt('/unvalidatedOrganisationId');
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],2,"2 unverified organisations." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],2,"2 unverified organisations." ;
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],3,"3 unverified transactions." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],3,"3 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)" ;
|
||||||
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 11 - add valid transaction (type 3: new organisation)\n";
|
||||||
|
|
||||||
my $nameToTestJunon = 'Store';
|
my $nameToTestJunon = 'Store';
|
||||||
$json = {
|
$json = {
|
||||||
microCurrencyValue => 10,
|
microCurrencyValue => 10,
|
||||||
|
@ -216,10 +217,11 @@ $json = {
|
||||||
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/upload' => form => $upload)
|
$t->post_ok('/upload' => form => $upload)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_has('/unvalidatedOrganisationId');
|
||||||
|
|
||||||
my $newPendingJunonOrgId = $t->app->db->last_insert_id(undef,undef, "PendingOrganisations", "PendingOrganisationId");
|
my $newPendingJunonOrgId = $t->tx->res->json->{unvalidatedOrganisationId};
|
||||||
print "Junon Id: " . $newPendingJunonOrgId . "\n";
|
#print "Junon Id: " . $newPendingJunonOrgId . "\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],4,"4 unverified transactions." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],4,"4 unverified transactions." ;
|
||||||
|
@ -237,14 +239,14 @@ $json = {
|
||||||
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/upload' => form => $upload )
|
$t->post_ok('/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_hasnt('/unvalidatedOrganisationId');
|
||||||
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],5,"5 unverified transactions." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],5,"5 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)" ;
|
||||||
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." ;
|
||||||
|
|
||||||
#done_testing();
|
|
||||||
#exit;
|
|
||||||
|
|
||||||
print "test 13 - add valid transaction (type 2: unvalidated organisation)\n";
|
print "test 13 - add valid transaction (type 2: unvalidated organisation)\n";
|
||||||
$json = {
|
$json = {
|
||||||
|
@ -255,7 +257,8 @@ $json = {
|
||||||
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/upload' => form => $upload )
|
$t->post_ok('/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_hasnt('/unvalidatedOrganisationId');
|
||||||
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)" ;
|
||||||
|
@ -361,10 +364,10 @@ $json = {
|
||||||
$t->post_ok('/admin-approve' => json => $json)
|
$t->post_ok('/admin-approve' => json => $json)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true);
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],2,"2 unverified organisation." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations", undef, ())}[0],1,"1 unverified organisation." ;
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],4,"4 unverified transaction." ;
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions", undef, ())}[0],3,"3 unverified transaction." ;
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Organisations", undef, ())}[0],2,"2 verified organisations (choco billy and kalm inn)" ;
|
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],2,"2 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, it 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.";
|
||||||
|
|
|
@ -266,7 +266,10 @@ my $upload = {json => Mojo::JSON::encode_json($json), file2 => {file => './t/tes
|
||||||
$t->post_ok('/upload' => form => $upload )
|
$t->post_ok('/upload' => form => $upload )
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_has('/unvalidatedOrganisationId')
|
||||||
->content_like(qr/Added transaction for unvalidated organisation/i);
|
->content_like(qr/Added transaction for unvalidated organisation/i);
|
||||||
|
my $unvalidatedOrganisationId = $t->tx->res->json->{unvalidatedOrganisationId};
|
||||||
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations WHERE PendingOrganisationId = ?", undef, ($unvalidatedOrganisationId))}[0],1,"unvalidatedOrganisationId exists";
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations")}[0],1,"1 pending organisation";
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations")}[0],1,"1 pending organisation";
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions")}[0],1,"1 pending transaction";
|
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions")}[0],1,"1 pending transaction";
|
||||||
|
|
||||||
|
|
Reference in a new issue