2017-08-23 17:42:19 +00:00
|
|
|
use Mojo::Base -strict;
|
|
|
|
|
2017-08-31 15:38:03 +00:00
|
|
|
use FindBin qw/ $Bin /;
|
|
|
|
|
2017-08-23 17:42:19 +00:00
|
|
|
use Test::More;
|
|
|
|
use Test::Pear::LocalLoop;
|
|
|
|
|
2017-08-31 15:38:03 +00:00
|
|
|
my $framework = Test::Pear::LocalLoop->new(
|
|
|
|
etc_dir => "$Bin/../etc",
|
|
|
|
);
|
|
|
|
$framework->install_fixtures('users');
|
2017-08-23 17:42:19 +00:00
|
|
|
my $t = $framework->framework;
|
|
|
|
my $schema = $t->app->schema;
|
|
|
|
|
|
|
|
#login to admin
|
|
|
|
$t->ua->max_redirects(10);
|
|
|
|
$t->post_ok('/admin', form => {
|
|
|
|
email => 'admin@example.com',
|
|
|
|
password => 'abc123',
|
|
|
|
})->status_is(200);
|
|
|
|
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->get_ok('/admin/users')
|
|
|
|
->status_is(200)
|
|
|
|
->or($framework->dump_error);
|
|
|
|
|
2017-08-23 17:42:19 +00:00
|
|
|
#Read customer user
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->get_ok('/admin/users/1')
|
2017-08-23 17:42:19 +00:00
|
|
|
->status_is(200);
|
|
|
|
|
|
|
|
#Read organisation user
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->get_ok('/admin/users/5')
|
2017-08-23 17:42:19 +00:00
|
|
|
->status_is(200);
|
|
|
|
|
2017-08-24 11:48:32 +00:00
|
|
|
#Valid customer user update
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->post_ok(
|
|
|
|
'/admin/users/1',
|
|
|
|
form => {
|
|
|
|
email => 'test12@example.com',
|
|
|
|
new_password => 'abc123',
|
|
|
|
full_name => 'Test User1',
|
|
|
|
display_name => 'Test User1',
|
|
|
|
town => 'Midgar',
|
|
|
|
sector => 'A',
|
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})
|
|
|
|
->status_is(200)
|
|
|
|
->or($framework->dump_error)
|
|
|
|
->content_like(qr/Updated User/);
|
2017-08-23 17:42:19 +00:00
|
|
|
|
2017-08-24 11:48:32 +00:00
|
|
|
#Failed validation on customer user from no postcode
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->post_ok('/admin/users/2', form => {
|
2017-08-24 11:48:32 +00:00
|
|
|
email => 'test12@example.com',
|
|
|
|
new_password => 'abc123',
|
|
|
|
full_name => 'Test User1',
|
|
|
|
display_name => 'Test User1',
|
|
|
|
town => 'Midgar',
|
2017-08-25 14:32:39 +00:00
|
|
|
sector => 'A',
|
2017-08-24 11:48:32 +00:00
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
#Failed validation on customer user from no display name
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->post_ok('/admin/users/2', form => {
|
2017-08-24 11:48:32 +00:00
|
|
|
email => 'test12@example.com',
|
|
|
|
new_password => 'abc123',
|
|
|
|
full_name => 'Test User1',
|
|
|
|
town => 'Midgar',
|
|
|
|
postcode => 'WC1E 6AD',
|
2017-08-25 14:32:39 +00:00
|
|
|
sector => 'A',
|
2017-08-24 11:48:32 +00:00
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
#Valid organisation user update
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->post_ok('/admin/users/5', form => {
|
2017-08-24 11:48:32 +00:00
|
|
|
email => 'test51@example.com',
|
2017-08-23 17:42:19 +00:00
|
|
|
new_password => 'abc123',
|
|
|
|
name => '7th Heaven',
|
|
|
|
street_name => 'Slums, Sector 7',
|
|
|
|
town => 'Midgar',
|
2017-08-25 14:32:39 +00:00
|
|
|
sector => 'A',
|
2017-08-23 17:42:19 +00:00
|
|
|
postcode => 'WC1E 6AD',
|
2017-08-24 11:48:32 +00:00
|
|
|
})->status_is(200)->content_like(qr/Updated User/);
|
2017-08-23 17:42:19 +00:00
|
|
|
|
|
|
|
#Failed validation on organisation user from no postcode
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->post_ok('/admin/users/5', form => {
|
2017-08-23 17:42:19 +00:00
|
|
|
email => 'test50@example.com',
|
|
|
|
new_password => 'abc123',
|
|
|
|
name => '7th Heaven',
|
|
|
|
street_name => 'Slums, Sector 7',
|
|
|
|
town => 'Midgar',
|
2017-08-25 14:32:39 +00:00
|
|
|
sector => 'A',
|
2017-08-23 17:42:19 +00:00
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
#Failed validation on organisation user from no street name
|
2017-08-31 15:38:03 +00:00
|
|
|
$t->post_ok('/admin/users/5', form => {
|
2017-08-23 17:42:19 +00:00
|
|
|
email => 'test50@example.com',
|
|
|
|
new_password => 'abc123',
|
|
|
|
name => '7th Heaven',
|
|
|
|
town => 'Midgar',
|
2017-08-25 14:32:39 +00:00
|
|
|
sector => 'A',
|
2017-08-23 17:42:19 +00:00
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
done_testing();
|