Started refactoring pending orgs table
This commit is contained in:
parent
718d5f002e
commit
99ef319c3b
4 changed files with 61 additions and 126 deletions
|
@ -1,100 +1,52 @@
|
||||||
use utf8;
|
use utf8;
|
||||||
package Pear::LocalLoop::Schema::Result::PendingOrganisation;
|
package Pear::LocalLoop::Schema::Result::PendingOrganisation;
|
||||||
|
|
||||||
# Created by DBIx::Class::Schema::Loader
|
|
||||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
Pear::LocalLoop::Schema::Result::PendingOrganisation
|
|
||||||
|
|
||||||
=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<PendingOrganisations>
|
__PACKAGE__->table("pending_organisations");
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
__PACKAGE__->table("PendingOrganisations");
|
|
||||||
|
|
||||||
=head1 ACCESSORS
|
|
||||||
|
|
||||||
=head2 pendingorganisationid
|
|
||||||
|
|
||||||
data_type: 'integer'
|
|
||||||
is_auto_increment: 1
|
|
||||||
is_nullable: 0
|
|
||||||
|
|
||||||
=head2 usersubmitted_fk
|
|
||||||
|
|
||||||
data_type: 'integer'
|
|
||||||
is_foreign_key: 1
|
|
||||||
is_nullable: 0
|
|
||||||
|
|
||||||
=head2 timedatesubmitted
|
|
||||||
|
|
||||||
data_type: 'integer'
|
|
||||||
is_nullable: 0
|
|
||||||
|
|
||||||
=head2 name
|
|
||||||
|
|
||||||
data_type: 'text'
|
|
||||||
is_nullable: 0
|
|
||||||
|
|
||||||
=head2 fulladdress
|
|
||||||
|
|
||||||
data_type: 'text'
|
|
||||||
is_nullable: 1
|
|
||||||
|
|
||||||
=head2 postcode
|
|
||||||
|
|
||||||
data_type: 'text'
|
|
||||||
is_nullable: 1
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
"pendingorganisationid",
|
id => {
|
||||||
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
|
data_type => 'integer',
|
||||||
"usersubmitted_fk",
|
is_auto_increment => 1,
|
||||||
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
|
is_nullable => 0,
|
||||||
"timedatesubmitted",
|
},
|
||||||
{ data_type => "datetime", is_nullable => 0 },
|
name => {
|
||||||
"name",
|
data_type => 'varchar',
|
||||||
{ data_type => "text", is_nullable => 0 },
|
size => 255,
|
||||||
"fulladdress",
|
is_nullable => 0,
|
||||||
{ data_type => "text", is_nullable => 1 },
|
},
|
||||||
"postcode",
|
street_address => {
|
||||||
{ data_type => "text", is_nullable => 1 },
|
data_type => 'text',
|
||||||
|
is_nullable => 1,
|
||||||
|
},
|
||||||
|
town => {
|
||||||
|
data_type => 'varchar',
|
||||||
|
size => 255,
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
|
postcode => {
|
||||||
|
data_type => 'varchar',
|
||||||
|
size => 16,
|
||||||
|
is_nullable => 1,
|
||||||
|
},
|
||||||
|
submitted_by_id => {
|
||||||
|
data_type => "integer",
|
||||||
|
is_foreign_key => 1,
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
|
submitted_at => {
|
||||||
|
data_type => "datetime",
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
=head1 PRIMARY KEY
|
__PACKAGE__->set_primary_key('id');
|
||||||
|
|
||||||
=over 4
|
|
||||||
|
|
||||||
=item * L</pendingorganisationid>
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("pendingorganisationid");
|
|
||||||
|
|
||||||
=head1 RELATIONS
|
=head1 RELATIONS
|
||||||
|
|
||||||
|
@ -110,7 +62,7 @@ __PACKAGE__->has_many(
|
||||||
"pending_transactions",
|
"pending_transactions",
|
||||||
"Pear::LocalLoop::Schema::Result::PendingTransaction",
|
"Pear::LocalLoop::Schema::Result::PendingTransaction",
|
||||||
{
|
{
|
||||||
"foreign.pendingsellerorganisationid_fk" => "self.pendingorganisationid",
|
"foreign.pendingsellerorganisationid_fk" => "self.id",
|
||||||
},
|
},
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
);
|
);
|
||||||
|
@ -124,9 +76,9 @@ Related object: L<Pear::LocalLoop::Schema::Result::User>
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"usersubmitted_fk",
|
"submitted_by",
|
||||||
"Pear::LocalLoop::Schema::Result::User",
|
"Pear::LocalLoop::Schema::Result::User",
|
||||||
{ userid => "usersubmitted_fk" },
|
{ userid => "submitted_by_id" },
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ Related object: L<Pear::LocalLoop::Schema::Result::PendingOrganisation>
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"pendingsellerorganisationid_fk",
|
"pendingsellerorganisationid_fk",
|
||||||
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
|
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
|
||||||
{ pendingorganisationid => "pendingsellerorganisationid_fk" },
|
{ id => "pendingsellerorganisationid_fk" },
|
||||||
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ Related object: L<Pear::LocalLoop::Schema::Result::PendingOrganisation>
|
||||||
__PACKAGE__->has_many(
|
__PACKAGE__->has_many(
|
||||||
"pending_organisations",
|
"pending_organisations",
|
||||||
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
|
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
|
||||||
{ "foreign.usersubmitted_fk" => "self.userid" },
|
{ "foreign.submitted_by_id" => "self.userid" },
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,20 @@
|
||||||
use Mojo::Base -strict;
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Test::Mojo;
|
|
||||||
use Mojo::JSON;
|
use Mojo::JSON;
|
||||||
|
use Test::Pear::LocalLoop;
|
||||||
|
|
||||||
use FindBin;
|
my $framework = Test::Pear::LocalLoop->new;
|
||||||
|
my $t = $framework->framework;
|
||||||
|
my $schema = $t->app->schema;
|
||||||
|
my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text };
|
||||||
|
|
||||||
BEGIN {
|
my @account_tokens = ('a', 'b', 'c');
|
||||||
$ENV{MOJO_MODE} = 'testing';
|
|
||||||
$ENV{MOJO_LOG_LEVEL} = 'debug';
|
|
||||||
}
|
|
||||||
|
|
||||||
my $t = Test::Mojo->new("Pear::LocalLoop");
|
|
||||||
|
|
||||||
my $dbh = $t->app->db;
|
|
||||||
|
|
||||||
#Dump all pf the test tables and start again.
|
|
||||||
my $sqlDeployment = Mojo::File->new("$FindBin::Bin/../dropschema.sql")->slurp;
|
|
||||||
for (split ';', $sqlDeployment){
|
|
||||||
$dbh->do($_) or die $dbh->errstr;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sqlDeployment = Mojo::File->new("$FindBin::Bin/../schema.sql")->slurp;
|
|
||||||
for (split ';', $sqlDeployment){
|
|
||||||
$dbh->do($_) or die $dbh->errstr;
|
|
||||||
}
|
|
||||||
|
|
||||||
my @accountTokens = ('a', 'b', 'c');
|
|
||||||
my $tokenStatement = $dbh->prepare('INSERT INTO AccountTokens (AccountTokenName) VALUES (?)');
|
|
||||||
foreach (@accountTokens){
|
|
||||||
my $rowsAdded = $tokenStatement->execute($_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$schema->resultset('AccountToken')->populate([
|
||||||
|
[ 'accounttokenname' ],
|
||||||
|
map { [ $_ ] } @account_tokens,
|
||||||
|
]);
|
||||||
|
|
||||||
#This depends on "register.t", "login.t" and "upload.t" working.
|
#This depends on "register.t", "login.t" and "upload.t" working.
|
||||||
|
|
||||||
|
@ -40,7 +24,7 @@ my $emailReno = 'reno@shinra.energy';
|
||||||
my $passwordReno = 'turks';
|
my $passwordReno = 'turks';
|
||||||
my $testJson = {
|
my $testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@accountTokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'Reno',
|
'username' => 'Reno',
|
||||||
'email' => $emailReno,
|
'email' => $emailReno,
|
||||||
'postcode' => 'E1 MP01',
|
'postcode' => 'E1 MP01',
|
||||||
|
@ -56,24 +40,24 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
print "test 3 - Create admin account\n";
|
print "test 3 - Create admin account\n";
|
||||||
my $emailAdmin = 'admin@foodloop.net';
|
my $emailAdmin = 'admin@foodloop.net';
|
||||||
my $passwordAdmin = 'ethics';
|
my $passwordAdmin = 'ethics';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@accountTokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'admin',
|
'username' => 'admin',
|
||||||
'email' => $emailAdmin,
|
'email' => $emailAdmin,
|
||||||
'postcode' => 'NW1 W01',
|
'postcode' => 'NW1 W01',
|
||||||
|
@ -85,11 +69,10 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true);
|
||||||
|
|
||||||
print "test 4 - 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 $rufus_user = $schema->resultset('User')->find({ email => $emailAdmin });
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Administrators")}[0],0,"No admins";
|
is $schema->resultset('Administrator')->count, 0, "No admins";
|
||||||
$t->app->db->prepare("INSERT INTO Administrators (UserId) VALUES (?)")->execute($rufusUserId);
|
$rufus_user->find_or_create_related('administrator', {});
|
||||||
is @{$t->app->db->selectrow_arrayref("SELECT COUNT(*) FROM Administrators")}[0],1,"1 admin";
|
is $schema->resultset('Administrator')->count, 1, "1 admin";
|
||||||
|
|
||||||
|
|
||||||
######################################################
|
######################################################
|
||||||
|
|
||||||
|
@ -350,7 +333,7 @@ $json = {
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/admin-approve' => json => $json)
|
$t->post_ok('/api/admin-approve' => json => $json)
|
||||||
->status_is(200)
|
->status_is(200)->or($dump_error)
|
||||||
->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],2,"2 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],4,"4 unverified transaction." ;
|
||||||
|
|
Reference in a new issue