Refactor Organisation table to easier column names
This commit is contained in:
parent
e2cf58c895
commit
6596fd10aa
6 changed files with 93 additions and 142 deletions
|
@ -32,8 +32,11 @@ has error_messages => sub {
|
||||||
required => { message => 'No age sent.', status => 400 },
|
required => { message => 'No age sent.', status => 400 },
|
||||||
in_resultset => { message => 'Age range is invalid.', status => 400 },
|
in_resultset => { message => 'Age range is invalid.', status => 400 },
|
||||||
},
|
},
|
||||||
fulladdress => {
|
street_address => {
|
||||||
required => { message => 'No fulladdress sent.', status => 400 },
|
required => { message => 'No street_address sent.', status => 400 },
|
||||||
|
},
|
||||||
|
town => {
|
||||||
|
required => { message => 'No town sent.', status => 400 },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -80,8 +83,8 @@ sub post_register{
|
||||||
|
|
||||||
} elsif ( $usertype eq 'organisation' ) {
|
} elsif ( $usertype eq 'organisation' ) {
|
||||||
|
|
||||||
#TODO validation on the address. Or perhaps add the organisation to a "to be inspected" list then manually check them.
|
$validation->required('street_address');
|
||||||
$validation->required('fulladdress');
|
$validation->required('town');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,29 +102,23 @@ sub post_register{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $token = $validation->param('token');
|
|
||||||
my $username = $validation->param('username');
|
|
||||||
my $email = $validation->param('email');
|
|
||||||
my $postcode = $validation->param('postcode');
|
|
||||||
my $password = $validation->param('password');
|
|
||||||
|
|
||||||
if ($usertype eq 'customer'){
|
if ($usertype eq 'customer'){
|
||||||
# TODO replace with actually using the value on the post request
|
# TODO replace with actually using the value on the post request
|
||||||
my $ageForeignKey = $c->get_age_foreign_key( $validation->param('age') );
|
my $ageForeignKey = $c->get_age_foreign_key( $validation->param('age') );
|
||||||
|
|
||||||
$c->schema->txn_do( sub {
|
$c->schema->txn_do( sub {
|
||||||
$c->schema->resultset('AccountToken')->find({
|
$c->schema->resultset('AccountToken')->find({
|
||||||
accounttokenname => $token,
|
accounttokenname => $validation->param('token'),
|
||||||
used => 0,
|
used => 0,
|
||||||
})->update({ used => 1 });
|
})->update({ used => 1 });
|
||||||
$c->schema->resultset('User')->create({
|
$c->schema->resultset('User')->create({
|
||||||
customer => {
|
customer => {
|
||||||
username => $username,
|
username => $validation->param('username'),
|
||||||
agerange_fk => $ageForeignKey,
|
agerange_fk => $ageForeignKey,
|
||||||
postcode => $postcode,
|
postcode => $validation->param('postcode'),
|
||||||
},
|
},
|
||||||
email => $email,
|
email => $validation->param('email'),
|
||||||
hashedpassword => $password,
|
hashedpassword => $validation->param('password'),
|
||||||
joindate => DateTime->now,
|
joindate => DateTime->now,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -132,23 +129,27 @@ sub post_register{
|
||||||
|
|
||||||
$c->schema->txn_do( sub {
|
$c->schema->txn_do( sub {
|
||||||
$c->schema->resultset('AccountToken')->find({
|
$c->schema->resultset('AccountToken')->find({
|
||||||
accounttokenname => $token,
|
accounttokenname => $validation->param('token'),
|
||||||
used => 0,
|
used => 0,
|
||||||
})->update({ used => 1 });
|
})->update({ used => 1 });
|
||||||
$c->schema->resultset('User')->create({
|
$c->schema->resultset('User')->create({
|
||||||
organisation => {
|
organisation => {
|
||||||
name => $username,
|
name => $validation->param('username'),
|
||||||
fulladdress => $fullAddress,
|
street_address => $validation->param('street_address'),
|
||||||
postcode => $postcode,
|
town => $validation->param('town'),
|
||||||
|
postcode => $validation->param('postcode'),
|
||||||
},
|
},
|
||||||
email => $email,
|
email => $validation->param('email'),
|
||||||
hashedpassword => $password,
|
hashedpassword => $validation->param('password'),
|
||||||
joindate => DateTime->now,
|
joindate => DateTime->now,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $c->render( json => { success => Mojo::JSON->true } );
|
return $c->render( json => {
|
||||||
|
success => Mojo::JSON->true,
|
||||||
|
message => 'Registered Successfully',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -94,7 +94,7 @@ sub post_upload {
|
||||||
if ( $type == 1 ) {
|
if ( $type == 1 ) {
|
||||||
# Validated Organisation
|
# Validated Organisation
|
||||||
my $valid_org_rs = $c->schema->resultset('Organisation');
|
my $valid_org_rs = $c->schema->resultset('Organisation');
|
||||||
$validation->required('organisation_id')->number->in_resultset( 'organisationalid', $valid_org_rs );
|
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
|
||||||
} elsif ( $type == 2 ) {
|
} elsif ( $type == 2 ) {
|
||||||
# Unvalidated Organisation
|
# Unvalidated Organisation
|
||||||
my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ usersubmitted_fk => $user->id });
|
my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ usersubmitted_fk => $user->id });
|
||||||
|
|
|
@ -1,85 +1,42 @@
|
||||||
use utf8;
|
|
||||||
package Pear::LocalLoop::Schema::Result::Organisation;
|
package Pear::LocalLoop::Schema::Result::Organisation;
|
||||||
|
|
||||||
# Created by DBIx::Class::Schema::Loader
|
|
||||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
Pear::LocalLoop::Schema::Result::Organisation
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use base 'DBIx::Class::Core';
|
use base 'DBIx::Class::Core';
|
||||||
|
|
||||||
=head1 COMPONENTS LOADED
|
|
||||||
|
|
||||||
=over 4
|
|
||||||
|
|
||||||
=item * L<DBIx::Class::InflateColumn::DateTime>
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
__PACKAGE__->load_components("InflateColumn::DateTime");
|
__PACKAGE__->load_components("InflateColumn::DateTime");
|
||||||
|
|
||||||
=head1 TABLE: C<Organisations>
|
__PACKAGE__->table("organisations");
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
__PACKAGE__->table("Organisations");
|
|
||||||
|
|
||||||
=head1 ACCESSORS
|
|
||||||
|
|
||||||
=head2 organisationalid
|
|
||||||
|
|
||||||
data_type: 'integer'
|
|
||||||
is_auto_increment: 1
|
|
||||||
is_nullable: 0
|
|
||||||
|
|
||||||
=head2 name
|
|
||||||
|
|
||||||
data_type: 'text'
|
|
||||||
is_nullable: 0
|
|
||||||
|
|
||||||
=head2 fulladdress
|
|
||||||
|
|
||||||
data_type: 'text'
|
|
||||||
is_nullable: 0
|
|
||||||
|
|
||||||
=head2 postcode
|
|
||||||
|
|
||||||
data_type: 'text'
|
|
||||||
is_nullable: 0
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
"organisationalid",
|
id => {
|
||||||
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
|
data_type => 'integer',
|
||||||
"name",
|
is_auto_increment => 1,
|
||||||
{ data_type => "text", is_nullable => 0 },
|
is_nullable => 0,
|
||||||
"fulladdress",
|
},
|
||||||
{ data_type => "text", is_nullable => 0 },
|
name => {
|
||||||
"postcode",
|
data_type => 'varchar',
|
||||||
{ data_type => "text", is_nullable => 0 },
|
size => 255,
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
|
street_address => {
|
||||||
|
data_type => 'text',
|
||||||
|
is_nullable => 1,
|
||||||
|
},
|
||||||
|
town => {
|
||||||
|
data_type => 'varchar',
|
||||||
|
size => 255,
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
|
postcode => {
|
||||||
|
data_type => 'varchar',
|
||||||
|
size => 16,
|
||||||
|
is_nullable => 1,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
=head1 PRIMARY KEY
|
__PACKAGE__->set_primary_key('id');
|
||||||
|
|
||||||
=over 4
|
|
||||||
|
|
||||||
=item * L</organisationalid>
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("organisationalid");
|
|
||||||
|
|
||||||
=head1 RELATIONS
|
=head1 RELATIONS
|
||||||
|
|
||||||
|
@ -94,7 +51,7 @@ Related object: L<Pear::LocalLoop::Schema::Result::Transaction>
|
||||||
__PACKAGE__->has_many(
|
__PACKAGE__->has_many(
|
||||||
"transactions",
|
"transactions",
|
||||||
"Pear::LocalLoop::Schema::Result::Transaction",
|
"Pear::LocalLoop::Schema::Result::Transaction",
|
||||||
{ "foreign.sellerorganisationid_fk" => "self.organisationalid" },
|
{ "foreign.sellerorganisationid_fk" => 'self.id' },
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -109,14 +66,8 @@ Related object: L<Pear::LocalLoop::Schema::Result::User>
|
||||||
__PACKAGE__->might_have(
|
__PACKAGE__->might_have(
|
||||||
"user",
|
"user",
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
"Pear::LocalLoop::Schema::Result::User",
|
||||||
{ "foreign.organisationalid_fk" => "self.organisationalid" },
|
{ "foreign.organisationalid_fk" => 'self.id' },
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-24 17:32:21
|
|
||||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:p9FzM/H5YQbo2d0lN/DfCg
|
|
||||||
|
|
||||||
|
|
||||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -139,7 +139,7 @@ Related object: L<Pear::LocalLoop::Schema::Result::Organisation>
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"sellerorganisationid_fk",
|
"sellerorganisationid_fk",
|
||||||
"Pear::LocalLoop::Schema::Result::Organisation",
|
"Pear::LocalLoop::Schema::Result::Organisation",
|
||||||
{ organisationalid => "sellerorganisationid_fk" },
|
{ id => "sellerorganisationid_fk" },
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ Related object: L<Pear::LocalLoop::Schema::Result::Organisation>
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"organisation",
|
"organisation",
|
||||||
"Pear::LocalLoop::Schema::Result::Organisation",
|
"Pear::LocalLoop::Schema::Result::Organisation",
|
||||||
{ organisationalid => "organisationalid_fk" },
|
{ id => "organisationalid_fk" },
|
||||||
{
|
{
|
||||||
is_deferrable => 0,
|
is_deferrable => 0,
|
||||||
join_type => "LEFT",
|
join_type => "LEFT",
|
||||||
|
|
75
t/upload.t
75
t/upload.t
|
@ -7,40 +7,37 @@ use Test::Pear::LocalLoop;
|
||||||
my $framework = Test::Pear::LocalLoop->new;
|
my $framework = Test::Pear::LocalLoop->new;
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
|
my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text };
|
||||||
|
|
||||||
my @accountTokens = ('a', 'b', 'c');
|
my @account_tokens = ('a', 'b', 'c');
|
||||||
|
|
||||||
$schema->resultset('AccountToken')->populate([
|
$schema->resultset('AccountToken')->populate([
|
||||||
[ 'accounttokenname' ],
|
[ 'accounttokenname' ],
|
||||||
map { [ $_ ] } @accountTokens,
|
map { [ $_ ] } @account_tokens,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
#Add one company that we've apparently authenticated but does not have an account.
|
#Add one company that we've apparently authenticated but does not have an account.
|
||||||
my $companyIdNumShinra = 1;
|
my $org_id_shinra = 1;
|
||||||
my $name = "Shinra Electric Power Company";
|
|
||||||
my $fullAddress = "Sector 0, Midgar, Eastern Continent, Gaia";
|
|
||||||
my $postcode = "E1 M00";
|
|
||||||
|
|
||||||
my $org_rs = $schema->resultset('Organisation');
|
my $org_rs = $schema->resultset('Organisation');
|
||||||
|
|
||||||
is $org_rs->count, 0, "No organisations";
|
is $org_rs->count, 0, "No organisations";
|
||||||
$org_rs->create({
|
$org_rs->create({
|
||||||
organisationalid => $companyIdNumShinra,
|
id => $org_id_shinra,
|
||||||
name => $name,
|
name => 'Shinra Electric Power Company',
|
||||||
fulladdress => $fullAddress,
|
street_address => 'Sector 0, Midgar, Eastern Continent',
|
||||||
postcode => $postcode,
|
town => 'Gaia',
|
||||||
|
postcode => 'E1 M00',
|
||||||
});
|
});
|
||||||
is $org_rs->count, 1, "1 testing organisation";
|
is $org_rs->count, 1, "1 testing organisation";
|
||||||
|
|
||||||
#This depends on "register.t" and "login.t" working.
|
|
||||||
|
|
||||||
#Valid customer, this also tests that redirects are disabled for register.
|
#Valid customer, this also tests that redirects are disabled for register.
|
||||||
print "test 1 - Create customer user account (Rufus)\n";
|
print "test 1 - Create customer user account (Rufus)\n";
|
||||||
my $emailRufus = 'rufus@shinra.energy';
|
my $emailRufus = 'rufus@shinra.energy';
|
||||||
my $passwordRufus = 'MakoGold';
|
my $passwordRufus = 'MakoGold';
|
||||||
my $testJson = {
|
my $testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@accountTokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'RufusShinra',
|
'username' => 'RufusShinra',
|
||||||
'email' => $emailRufus,
|
'email' => $emailRufus,
|
||||||
'postcode' => 'E1 MP01',
|
'postcode' => 'E1 MP01',
|
||||||
|
@ -56,7 +53,7 @@ my $emailHojo = 'hojo@shinra.energy';
|
||||||
my $passwordHojo = 'Mako';
|
my $passwordHojo = 'Mako';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@accountTokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'ProfessorHojo',
|
'username' => 'ProfessorHojo',
|
||||||
'email' => $emailHojo,
|
'email' => $emailHojo,
|
||||||
'postcode' => 'E1 MP01',
|
'postcode' => 'E1 MP01',
|
||||||
|
@ -72,16 +69,18 @@ my $emailBilly = 'choco.billy@chocofarm.org';
|
||||||
my $passwordBilly = 'Choco';
|
my $passwordBilly = 'Choco';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'organisation',
|
'usertype' => 'organisation',
|
||||||
'token' => shift(@accountTokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'ChocoBillysGreens',
|
'username' => 'ChocoBillysGreens',
|
||||||
'email' => $emailBilly,
|
'email' => $emailBilly,
|
||||||
'postcode' => 'E4 C12',
|
'postcode' => 'E4 C12',
|
||||||
'password' => $passwordBilly,
|
'password' => $passwordBilly,
|
||||||
'fulladdress' => 'Chocobo Farm, Eastern Continent, Gaia'
|
'street_address' => 'Chocobo Farm, Eastern Continent',
|
||||||
|
'town' => 'Gaia',
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_like('/message', qr/Registered Successfully/);
|
||||||
|
|
||||||
######################################################
|
######################################################
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
print "test 6 - transaction_value missing\n";
|
print "test 6 - transaction_value missing\n";
|
||||||
my $json = {
|
my $json = {
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
organisation_id => $companyIdNumShinra,
|
organisation_id => $org_id_shinra,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
|
@ -122,7 +121,7 @@ print "test 7 - transaction_value non-numbers\n";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 'Abc',
|
transaction_value => 'Abc',
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
organisation_id => $companyIdNumShinra,
|
organisation_id => $org_id_shinra,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
|
@ -135,7 +134,7 @@ print "test 8 - transaction_value equal to zero\n";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 0,
|
transaction_value => 0,
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
organisation_id => $companyIdNumShinra,
|
organisation_id => $org_id_shinra,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
|
@ -148,7 +147,7 @@ print "test 9 - transaction_value less than zero\n";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => -1,
|
transaction_value => -1,
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
organisation_id => $companyIdNumShinra,
|
organisation_id => $org_id_shinra,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
|
@ -173,7 +172,7 @@ $json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 4,
|
transaction_type => 4,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
# organisation_id => $companyIdNumShinra
|
# organisation_id => $org_id_shinra
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/api/upload' => form => $upload )
|
$t->post_ok('/api/upload' => form => $upload )
|
||||||
|
@ -199,7 +198,7 @@ $json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
# organisation_id => $companyIdNumShinra
|
# organisation_id => $org_id_shinra
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
$t->post_ok('/api/upload' => form => $upload )
|
$t->post_ok('/api/upload' => form => $upload )
|
||||||
|
@ -211,7 +210,7 @@ print "test 14 - organisation_id for non-existent id. (type 1: already validated
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
organisation_id => ($companyIdNumShinra + 100),
|
organisation_id => ($org_id_shinra + 100),
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
|
@ -221,11 +220,11 @@ $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 @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions")}[0],0,"no transactions";
|
is $schema->resultset('Transaction')->count, 0, "no transactions";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
organisation_id => $companyIdNumShinra,
|
organisation_id => $org_id_shinra,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
|
@ -233,7 +232,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 @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions")}[0],1,"1 transaction";
|
is $schema->resultset('Transaction')->count, 1, "1 transaction";
|
||||||
|
|
||||||
# Add type 3 (new organisation) checking.
|
# Add type 3 (new organisation) checking.
|
||||||
|
|
||||||
|
@ -253,8 +252,8 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->content_like(qr/organisation_name is missing/i);
|
->content_like(qr/organisation_name is missing/i);
|
||||||
|
|
||||||
print "test 17 - add valid transaction (type 3: new organisation)\n";
|
print "test 17 - add valid transaction (type 3: new organisation)\n";
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations")}[0],0,"No pending organisations";
|
is $schema->resultset('PendingOrganisation')->count, 0, "No pending organisations";
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions")}[0],0,"No pending transactions";
|
is $schema->resultset('PendingTransaction')->count, 0, "No pending transactions";
|
||||||
|
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
|
@ -270,8 +269,8 @@ $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 @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingOrganisations")}[0],1,"1 pending organisation";
|
is $schema->resultset('PendingOrganisation')->count, 1, "1 pending organisations";
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions")}[0],1,"1 pending transaction";
|
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
||||||
|
|
||||||
# Add type 2 (unverified organisation) checking.
|
# Add type 2 (unverified organisation) checking.
|
||||||
|
|
||||||
|
@ -337,7 +336,7 @@ $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 23 - add valid transaction but for with account (type 2: existing organisation)\n";
|
||||||
my $org_result = $schema->resultset('PendingOrganisation')->find({ name => '7th Heaven' });
|
my $org_result = $schema->resultset('PendingOrganisation')->find({ name => '7th Heaven' });
|
||||||
my $unvalidatedOrganisationId = $org_result->pendingorganisationid;
|
my $unvalidatedOrganisationId = $org_result->pendingorganisationid;
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions")}[0],1,"1 pending transaction";
|
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 2,
|
transaction_type => 2,
|
||||||
|
@ -349,7 +348,7 @@ $t->post_ok('/api/upload' => form => $upload )
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
->json_is('/success', Mojo::JSON->false)
|
->json_is('/success', Mojo::JSON->false)
|
||||||
->content_like(qr/organisation_id does not exist in the database/i);
|
->content_like(qr/organisation_id does not exist in the database/i);
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions")}[0],1,"1 pending transaction";
|
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
||||||
|
|
||||||
print "test 24 - Logout Hojo\n";
|
print "test 24 - Logout Hojo\n";
|
||||||
$t->post_ok('/api/logout', json => { session_key => $session_key } )
|
$t->post_ok('/api/logout', json => { session_key => $session_key } )
|
||||||
|
@ -373,7 +372,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 26 - add valid transaction (type 2: existing organisation)\n";
|
print "test 26 - add valid transaction (type 2: existing organisation)\n";
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions")}[0],1,"1 pending transaction";
|
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 10,
|
transaction_value => 10,
|
||||||
transaction_type => 2,
|
transaction_type => 2,
|
||||||
|
@ -385,7 +384,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 @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM PendingTransactions")}[0],2,"2 pending transaction";
|
is $schema->resultset('PendingTransaction')->count, 2, "2 pending transactions";
|
||||||
|
|
||||||
|
|
||||||
print "test 27 - Logout Rufus\n";
|
print "test 27 - Logout Rufus\n";
|
||||||
|
@ -410,11 +409,11 @@ $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 29 - organisation buy from another organisation\n";
|
print "test 29 - organisation buy from another organisation\n";
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions")}[0],1,"1 transaction";
|
is $schema->resultset('Transaction')->count, 1, "1 transaction";
|
||||||
$json = {
|
$json = {
|
||||||
transaction_value => 100000,
|
transaction_value => 100000,
|
||||||
transaction_type => 1,
|
transaction_type => 1,
|
||||||
organisation_id => $companyIdNumShinra,
|
organisation_id => $org_id_shinra,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
|
||||||
|
@ -422,7 +421,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 @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Transactions")}[0],2,"2 transactions";
|
is $schema->resultset('Transaction')->count, 2, "2 transaction";
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
||||||
|
|
Reference in a new issue