2017-08-23 17:42:19 +00:00
|
|
|
use Mojo::Base -strict;
|
|
|
|
|
|
|
|
use Test::More;
|
|
|
|
use Mojo::JSON;
|
|
|
|
use Test::Pear::LocalLoop;
|
|
|
|
|
|
|
|
my $framework = Test::Pear::LocalLoop->new;
|
|
|
|
my $t = $framework->framework;
|
|
|
|
my $schema = $t->app->schema;
|
|
|
|
|
|
|
|
my $user = $schema->resultset('User')->create({
|
|
|
|
email => 'admin@example.com',
|
|
|
|
password => 'abc123',
|
|
|
|
administrator => {},
|
|
|
|
});
|
|
|
|
|
|
|
|
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
|
|
|
|
|
|
|
|
my $user1 = {
|
|
|
|
token => 'a',
|
|
|
|
full_name => 'Test User1',
|
|
|
|
display_name => 'Test User1',
|
|
|
|
email => 'test1@example.com',
|
|
|
|
postcode => 'LA1 1AA',
|
|
|
|
password => 'abc123',
|
|
|
|
year_of_birth => 2006,
|
|
|
|
};
|
|
|
|
|
|
|
|
my $org = {
|
|
|
|
token => 'e',
|
|
|
|
email => 'test50@example.com',
|
|
|
|
name => '7th Heaven',
|
|
|
|
street_name => 'Slums, Sector 7',
|
|
|
|
town => 'Midgar',
|
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
password => 'abc123',
|
|
|
|
};
|
|
|
|
|
|
|
|
$schema->resultset('AccountToken')->create({ name => $_->{token} })
|
|
|
|
for ( $user1, $org );
|
|
|
|
|
|
|
|
$framework->register_customer($user1);
|
|
|
|
|
|
|
|
$framework->register_organisation($org);
|
|
|
|
|
|
|
|
#login to admin
|
|
|
|
$t->ua->max_redirects(10);
|
|
|
|
$t->post_ok('/admin', form => {
|
|
|
|
email => 'admin@example.com',
|
|
|
|
password => 'abc123',
|
|
|
|
})->status_is(200);
|
|
|
|
|
|
|
|
#Read customer user
|
2017-08-24 11:48:32 +00:00
|
|
|
$t->get_ok('/admin/users/2/')
|
2017-08-23 17:42:19 +00:00
|
|
|
->status_is(200);
|
|
|
|
|
|
|
|
#Read organisation user
|
2017-08-24 11:48:32 +00:00
|
|
|
$t->get_ok('/admin/users/3/')
|
2017-08-23 17:42:19 +00:00
|
|
|
->status_is(200);
|
|
|
|
|
2017-08-24 11:48:32 +00:00
|
|
|
#Valid customer user update
|
|
|
|
$t->post_ok('/admin/users/2/edit', form => {
|
|
|
|
email => 'test12@example.com',
|
2017-08-23 17:42:19 +00:00
|
|
|
new_password => 'abc123',
|
2017-08-24 11:48:32 +00:00
|
|
|
full_name => 'Test User1',
|
|
|
|
display_name => 'Test User1',
|
2017-08-23 17:42:19 +00:00
|
|
|
town => 'Midgar',
|
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})->status_is(200)->content_like(qr/Updated User/);
|
|
|
|
|
2017-08-24 11:48:32 +00:00
|
|
|
#Failed validation on customer user from no postcode
|
|
|
|
$t->post_ok('/admin/users/2/edit', form => {
|
|
|
|
email => 'test12@example.com',
|
|
|
|
new_password => 'abc123',
|
|
|
|
full_name => 'Test User1',
|
|
|
|
display_name => 'Test User1',
|
|
|
|
town => 'Midgar',
|
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
#Failed validation on customer user from no display name
|
|
|
|
$t->post_ok('/admin/users/2/edit', form => {
|
|
|
|
email => 'test12@example.com',
|
|
|
|
new_password => 'abc123',
|
|
|
|
full_name => 'Test User1',
|
|
|
|
town => 'Midgar',
|
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
#Valid organisation user update
|
|
|
|
$t->post_ok('/admin/users/3/edit', form => {
|
|
|
|
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',
|
|
|
|
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-24 11:48:32 +00:00
|
|
|
$t->post_ok('/admin/users/3/edit', 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',
|
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
#Failed validation on organisation user from no street name
|
2017-08-24 11:48:32 +00:00
|
|
|
$t->post_ok('/admin/users/3/edit', form => {
|
2017-08-23 17:42:19 +00:00
|
|
|
email => 'test50@example.com',
|
|
|
|
new_password => 'abc123',
|
|
|
|
name => '7th Heaven',
|
|
|
|
town => 'Midgar',
|
|
|
|
postcode => 'WC1E 6AD',
|
|
|
|
})->content_like(qr/The validation has failed/);
|
|
|
|
|
|
|
|
done_testing();
|