Fix admin organisation management tests
This commit is contained in:
parent
0159ef91dc
commit
92afe1c531
3 changed files with 56 additions and 133 deletions
|
@ -1,38 +1,42 @@
|
|||
use Mojo::Base -strict;
|
||||
|
||||
use FindBin qw/ $Bin /;
|
||||
|
||||
use Test::More;
|
||||
use Mojo::JSON;
|
||||
use Test::Pear::LocalLoop;
|
||||
|
||||
my $framework = Test::Pear::LocalLoop->new;
|
||||
my $framework = Test::Pear::LocalLoop->new(
|
||||
etc_dir => "$Bin/../etc",
|
||||
);
|
||||
$framework->install_fixtures('users');
|
||||
my $t = $framework->framework;
|
||||
my $schema = $t->app->schema;
|
||||
|
||||
my $user = $schema->resultset('User')->create({
|
||||
email => 'admin@example.com',
|
||||
password => 'abc123',
|
||||
administrator => {},
|
||||
my $valid_entity = $schema->resultset('Entity')->create({
|
||||
organisation => {
|
||||
name => 'Shinra Electric Power Company',
|
||||
street_name => 'Sector 0, Midgar, Eastern Continent',
|
||||
town => 'Gaia',
|
||||
sector => 'A',
|
||||
postcode => 'WC1E 6AD',
|
||||
},
|
||||
type => "organisation",
|
||||
});
|
||||
|
||||
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
|
||||
|
||||
$schema->resultset('Organisation')->create({
|
||||
id => 1,
|
||||
name => 'Shinra Electric Power Company',
|
||||
street_name => 'Sector 0, Midgar, Eastern Continent',
|
||||
town => 'Gaia',
|
||||
sector => 'A',
|
||||
postcode => 'WC1E 6AD',
|
||||
my $pending_entity = $schema->resultset('Entity')->create({
|
||||
organisation => {
|
||||
name => '7th Heaven',
|
||||
street_name => 'Slums, Sector 7',
|
||||
town => 'Midgar',
|
||||
sector => 'A',
|
||||
postcode => 'WC1E 6AD',
|
||||
pending => \"1",
|
||||
},
|
||||
type => "organisation",
|
||||
});
|
||||
|
||||
$schema->resultset('PendingOrganisation')->create({
|
||||
id => 2,
|
||||
name => '7th Heaven',
|
||||
street_name => 'Slums, Sector 7',
|
||||
town => 'Midgar',
|
||||
postcode => 'WC1E 6AD',
|
||||
submitted_by_id => $user->id,
|
||||
});
|
||||
my $valid_id = $valid_entity->organisation->id;
|
||||
my $pending_id = $pending_entity->organisation->id;
|
||||
|
||||
#login to admin
|
||||
$t->ua->max_redirects(10);
|
||||
|
@ -42,15 +46,15 @@ $t->post_ok('/admin', form => {
|
|||
})->status_is(200);
|
||||
|
||||
#Read approved organisation
|
||||
$t->get_ok('/admin/organisations/valid/1/')
|
||||
->status_is(200);
|
||||
$t->get_ok("/admin/organisations/$valid_id")
|
||||
->status_is(200)->or($framework->dump_error);
|
||||
|
||||
#Read pending organisation
|
||||
$t->get_ok('/admin/organisations/pending/2/')
|
||||
->status_is(200);
|
||||
$t->get_ok("/admin/organisations/$pending_id")
|
||||
->status_is(200)->or($framework->dump_error);
|
||||
|
||||
#Valid approved organisation update
|
||||
$t->post_ok('/admin/organisations/valid/1/edit', form => {
|
||||
$t->post_ok("/admin/organisations/$valid_id", form => {
|
||||
name => 'Shinra Electric Power Company',
|
||||
street_name => 'Sector 0, Midgar, Eastern Continent',
|
||||
town => 'Gaia',
|
||||
|
@ -59,7 +63,7 @@ $t->post_ok('/admin/organisations/valid/1/edit', form => {
|
|||
})->status_is(200)->content_like(qr/Updated Organisation/);
|
||||
|
||||
#Failed validation on approved organisation
|
||||
$t->post_ok('/admin/organisations/valid/1/edit', form => {
|
||||
$t->post_ok("/admin/organisations/$valid_id", form => {
|
||||
name => 'Shinra Electric Power Company',
|
||||
street_name => 'Sector 0, Midgar, Eastern Continent',
|
||||
sector => 'A',
|
||||
|
@ -67,7 +71,7 @@ $t->post_ok('/admin/organisations/valid/1/edit', form => {
|
|||
})->content_like(qr/The validation has failed/);
|
||||
|
||||
#Valid pending organisation update
|
||||
$t->post_ok('/admin/organisations/pending/2/edit', form => {
|
||||
$t->post_ok("/admin/organisations/$pending_id", form => {
|
||||
name => '7th Heaven',
|
||||
street_name => 'Slums, Sector 7',
|
||||
town => 'Midgar',
|
||||
|
@ -75,14 +79,14 @@ $t->post_ok('/admin/organisations/pending/2/edit', form => {
|
|||
})->status_is(200)->content_like(qr/Updated Organisation/);
|
||||
|
||||
#Failed validation on pending organisation
|
||||
$t->post_ok('/admin/organisations/pending/2/edit', form => {
|
||||
$t->post_ok("/admin/organisations/$pending_id", form => {
|
||||
name => '7th Heaven',
|
||||
street_name => 'Slums, Sector 7',
|
||||
postcode => 'WC1E 6AD',
|
||||
})->content_like(qr/The validation has failed/);
|
||||
|
||||
#Valid adding organisation
|
||||
$t->post_ok('/admin/organisations/add/submit', form => {
|
||||
$t->post_ok('/admin/organisations/add', form => {
|
||||
name => 'Wall Market',
|
||||
street_name => 'Slums, Sector 6',
|
||||
town => 'Midgar',
|
||||
|
@ -91,7 +95,7 @@ $t->post_ok('/admin/organisations/add/submit', form => {
|
|||
})->status_is(200)->content_like(qr/Added Organisation/);
|
||||
|
||||
#Failed validation on adding organisation
|
||||
$t->post_ok('/admin/organisations/add/submit', form => {
|
||||
$t->post_ok('/admin/organisations/add', form => {
|
||||
name => 'Wall Market',
|
||||
street_name => 'Slums, Sector 6',
|
||||
postcode => 'TN35 5AQ',
|
||||
|
|
Reference in a new issue