This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/t/admin/organisation.t

105 lines
2.9 KiB
Perl
Raw Permalink Normal View History

use Mojo::Base -strict;
use FindBin qw/ $Bin /;
use Test::More;
use Test::Pear::LocalLoop;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/../etc",
);
$framework->install_fixtures('users');
my $t = $framework->framework;
my $schema = $t->app->schema;
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",
});
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,
},
type => "organisation",
});
my $valid_id = $valid_entity->organisation->id;
my $pending_id = $pending_entity->organisation->id;
#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
$t->get_ok("/admin/organisations/$valid_id")
->status_is(200)->or($framework->dump_error);
#Read pending organisation
$t->get_ok("/admin/organisations/$pending_id")
->status_is(200)->or($framework->dump_error);
#Valid approved organisation update
$t->post_ok("/admin/organisations/$valid_id", form => {
name => 'Shinra Electric Power Company',
street_name => 'Sector 0, Midgar, Eastern Continent',
town => 'Gaia',
2017-08-25 14:47:54 +00:00
sector => 'A',
postcode => 'WC1E 6AD',
})->status_is(200)->content_like(qr/Updated Organisation/);
#Failed validation on approved organisation
$t->post_ok("/admin/organisations/$valid_id", form => {
name => 'Shinra Electric Power Company',
street_name => 'Sector 0, Midgar, Eastern Continent',
2017-08-25 14:47:54 +00:00
sector => 'A',
postcode => 'WC1E 6AD',
})->content_like(qr/The validation has failed/);
#Valid pending organisation update
$t->post_ok("/admin/organisations/$pending_id", form => {
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
$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', form => {
name => 'Wall Market',
street_name => 'Slums, Sector 6',
town => 'Midgar',
2017-08-25 14:47:54 +00:00
sector => 'A',
postcode => 'TN35 5AQ',
})->status_is(200)->content_like(qr/Added Organisation/);
#Failed validation on adding organisation
$t->post_ok('/admin/organisations/add', form => {
name => 'Wall Market',
street_name => 'Slums, Sector 6',
postcode => 'TN35 5AQ',
})->content_like(qr/The validation has failed/);
done_testing();