2017-08-18 15:46:49 +00:00
|
|
|
use Mojo::Base -strict;
|
|
|
|
|
2017-08-31 13:52:45 +00:00
|
|
|
use FindBin qw/ $Bin /;
|
|
|
|
|
2017-08-18 15:46:49 +00:00
|
|
|
use Test::More;
|
|
|
|
use Test::Pear::LocalLoop;
|
|
|
|
|
2017-08-31 13:52:45 +00:00
|
|
|
my $framework = Test::Pear::LocalLoop->new(
|
|
|
|
etc_dir => "$Bin/../etc",
|
|
|
|
);
|
|
|
|
$framework->install_fixtures('users');
|
2017-08-18 15:46:49 +00:00
|
|
|
my $t = $framework->framework;
|
|
|
|
my $schema = $t->app->schema;
|
|
|
|
|
2017-08-31 13:52:45 +00:00
|
|
|
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",
|
2017-08-18 15:46:49 +00:00
|
|
|
});
|
|
|
|
|
2017-08-31 13:52:45 +00:00
|
|
|
my $pending_entity = $schema->resultset('Entity')->create({
|
|
|
|
organisation => {
|
|
|
|
name => '7th Heaven',
|
|
|
|
street_name => 'Slums, Sector 7',
|
|
|
|
town => 'Midgar',
|
|
|
|
sector => 'A',
|
|
|
|
postcode => 'WC1E 6AD',
|
2017-09-13 14:23:01 +00:00
|
|
|
pending => 1,
|
2017-08-31 13:52:45 +00:00
|
|
|
},
|
|
|
|
type => "organisation",
|
2017-08-18 15:46:49 +00:00
|
|
|
});
|
|
|
|
|
2017-08-31 13:52:45 +00:00
|
|
|
my $valid_id = $valid_entity->organisation->id;
|
|
|
|
my $pending_id = $pending_entity->organisation->id;
|
2017-08-18 15:46:49 +00:00
|
|
|
|
|
|
|
#login to admin
|
|
|
|
$t->ua->max_redirects(10);
|
|
|
|
$t->post_ok('/admin', form => {
|
|
|
|
email => 'admin@example.com',
|
|
|
|
password => 'abc123',
|
|
|
|
})->status_is(200);
|
|
|
|
|
|
|
|
#Read approved organisation
|
2017-08-31 13:52:45 +00:00
|
|
|
$t->get_ok("/admin/organisations/$valid_id")
|
|
|
|
->status_is(200)->or($framework->dump_error);
|
2017-08-18 15:46:49 +00:00
|
|
|
|
|
|
|
#Read pending organisation
|
2017-08-31 13:52:45 +00:00
|
|
|
$t->get_ok("/admin/organisations/$pending_id")
|
|
|
|
->status_is(200)->or($framework->dump_error);
|
2017-08-18 15:46:49 +00:00
|
|
|
|
|
|
|
#Valid approved organisation update
|
2017-08-31 13:52:45 +00:00
|
|
|
$t->post_ok("/admin/organisations/$valid_id", form => {
|
2017-08-18 15:46:49 +00:00
|
|
|
name => 'Shinra Electric Power Company',
|
|
|
|
street_name => 'Sector 0, Midgar, Eastern Continent',
|
|
|
|
town => 'Gaia',
|
2017-08-25 14:47:54 +00:00
|
|
|
sector => 'A',
|
2017-08-18 15:46:49 +00:00
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})->status_is(200)->content_like(qr/Updated Organisation/);
|
|
|
|
|
|
|
|
#Failed validation on approved organisation
|
2017-08-31 13:52:45 +00:00
|
|
|
$t->post_ok("/admin/organisations/$valid_id", form => {
|
2017-08-18 15:46:49 +00:00
|
|
|
name => 'Shinra Electric Power Company',
|
|
|
|
street_name => 'Sector 0, Midgar, Eastern Continent',
|
2017-08-25 14:47:54 +00:00
|
|
|
sector => 'A',
|
2017-08-18 15:46:49 +00:00
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
#Valid pending organisation update
|
2017-08-31 13:52:45 +00:00
|
|
|
$t->post_ok("/admin/organisations/$pending_id", form => {
|
2017-08-18 15:46:49 +00:00
|
|
|
name => '7th Heaven',
|
|
|
|
street_name => 'Slums, Sector 7',
|
|
|
|
town => 'Midgar',
|
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})->status_is(200)->content_like(qr/Updated Organisation/);
|
|
|
|
|
|
|
|
#Failed validation on pending organisation
|
2017-08-31 13:52:45 +00:00
|
|
|
$t->post_ok("/admin/organisations/$pending_id", form => {
|
2017-08-18 15:46:49 +00:00
|
|
|
name => '7th Heaven',
|
|
|
|
street_name => 'Slums, Sector 7',
|
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
2017-08-21 14:18:34 +00:00
|
|
|
#Valid adding organisation
|
2017-08-31 13:52:45 +00:00
|
|
|
$t->post_ok('/admin/organisations/add', form => {
|
2017-08-21 14:18:34 +00:00
|
|
|
name => 'Wall Market',
|
|
|
|
street_name => 'Slums, Sector 6',
|
|
|
|
town => 'Midgar',
|
2017-08-25 14:47:54 +00:00
|
|
|
sector => 'A',
|
2017-08-21 14:18:34 +00:00
|
|
|
postcode => 'TN35 5AQ',
|
|
|
|
})->status_is(200)->content_like(qr/Added Organisation/);
|
|
|
|
|
|
|
|
#Failed validation on adding organisation
|
2017-08-31 13:52:45 +00:00
|
|
|
$t->post_ok('/admin/organisations/add', form => {
|
2017-08-21 14:18:34 +00:00
|
|
|
name => 'Wall Market',
|
|
|
|
street_name => 'Slums, Sector 6',
|
|
|
|
postcode => 'TN35 5AQ',
|
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
2017-08-18 15:46:49 +00:00
|
|
|
done_testing();
|