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/user.t

102 lines
2.5 KiB
Perl
Raw Normal View History

use Mojo::Base -strict;
2017-08-31 15:38:03 +00:00
use FindBin qw/ $Bin /;
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');
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);
#Read customer user
2017-08-31 15:38:03 +00:00
$t->get_ok('/admin/users/1')
->status_is(200);
#Read organisation user
2017-08-31 15:38:03 +00:00
$t->get_ok('/admin/users/5')
->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-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',
new_password => 'abc123',
name => '7th Heaven',
street_name => 'Slums, Sector 7',
town => 'Midgar',
2017-08-25 14:32:39 +00:00
sector => 'A',
postcode => 'WC1E 6AD',
2017-08-24 11:48:32 +00:00
})->status_is(200)->content_like(qr/Updated User/);
#Failed validation on organisation user from no postcode
2017-08-31 15:38:03 +00:00
$t->post_ok('/admin/users/5', form => {
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',
})->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 => {
email => 'test50@example.com',
new_password => 'abc123',
name => '7th Heaven',
town => 'Midgar',
2017-08-25 14:32:39 +00:00
sector => 'A',
postcode => 'WC1E 6AD',
})->content_like(qr/The validation has failed/);
done_testing();