Fix admin user test for entity upgrade
This commit is contained in:
parent
815056b771
commit
4cc8aad367
4 changed files with 41 additions and 71 deletions
|
@ -175,7 +175,6 @@ sub startup {
|
|||
$admin_routes->get('/users/:id')->to('admin-users#read');
|
||||
$admin_routes->post('/users/:id')->to('admin-users#update');
|
||||
$admin_routes->post('/users/:id/delete')->to('admin-users#delete');
|
||||
$admin_routes->post('/users/:id/edit')->to('admin-users#edit');
|
||||
|
||||
$admin_routes->get('/organisations')->to('admin-organisations#list');
|
||||
$admin_routes->get('/organisations/add')->to('admin-organisations#add_org');
|
||||
|
|
|
@ -40,7 +40,7 @@ sub read {
|
|||
}
|
||||
}
|
||||
|
||||
sub edit {
|
||||
sub update {
|
||||
my $c = shift;
|
||||
|
||||
my $id = $c->param('id');
|
||||
|
@ -61,10 +61,10 @@ sub edit {
|
|||
$validation->required('postcode')->postcode;
|
||||
$validation->optional('new_password');
|
||||
|
||||
if ( defined $user->customer_id ) {
|
||||
if ( $user->type eq 'customer' ) {
|
||||
$validation->required('display_name');
|
||||
$validation->required('full_name');
|
||||
} elsif ( defined $user->organisation_id ) {
|
||||
} elsif ( $user->type eq 'organisation' ) {
|
||||
$validation->required('name');
|
||||
$validation->required('street_name');
|
||||
$validation->required('town');
|
||||
|
@ -73,15 +73,14 @@ sub edit {
|
|||
|
||||
if ( $validation->has_error ) {
|
||||
$c->flash( error => 'The validation has failed' );
|
||||
$c->app->log->warn(Dumper $validation);
|
||||
return $c->redirect_to( '/admin/users/' . $id );
|
||||
}
|
||||
|
||||
if ( defined $user->customer_id ){
|
||||
if ( $user->type eq 'customer' ){
|
||||
|
||||
try {
|
||||
$c->schema->txn_do( sub {
|
||||
$user->customer->update({
|
||||
$user->entity->customer->update({
|
||||
full_name => $validation->param('full_name'),
|
||||
display_name => $validation->param('display_name'),
|
||||
postcode => $validation->param('postcode'),
|
||||
|
@ -100,11 +99,11 @@ sub edit {
|
|||
};
|
||||
}
|
||||
}
|
||||
elsif ( defined $user->organisation_id ) {
|
||||
elsif ( $user->type eq 'organisation' ) {
|
||||
|
||||
try {
|
||||
$c->schema->txn_do( sub {
|
||||
$user->organisation->update({
|
||||
$user->entity->organisation->update({
|
||||
name => $validation->param('name'),
|
||||
street_name => $validation->param('street_name'),
|
||||
town => $validation->param('town'),
|
||||
|
@ -129,9 +128,4 @@ sub edit {
|
|||
$c->redirect_to( '/admin/users/' . $id );
|
||||
}
|
||||
|
||||
sub update {
|
||||
my $c = shift;
|
||||
$c->redirect_to( '/admin/users' );
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -1,49 +1,17 @@
|
|||
use Mojo::Base -strict;
|
||||
|
||||
use FindBin qw/ $Bin /;
|
||||
|
||||
use Test::More;
|
||||
use Mojo::JSON;
|
||||
use Test::Pear::LocalLoop;
|
||||
|
||||
my $framework = Test::Pear::LocalLoop->new;
|
||||
my $framework = Test::Pear::LocalLoop->new(
|
||||
etc_dir => "$Bin/../etc",
|
||||
);
|
||||
$framework->install_fixtures('users');
|
||||
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',
|
||||
sector => 'A',
|
||||
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 => {
|
||||
|
@ -51,27 +19,36 @@ $t->post_ok('/admin', form => {
|
|||
password => 'abc123',
|
||||
})->status_is(200);
|
||||
|
||||
$t->get_ok('/admin/users')
|
||||
->status_is(200)
|
||||
->or($framework->dump_error);
|
||||
|
||||
#Read customer user
|
||||
$t->get_ok('/admin/users/2/')
|
||||
$t->get_ok('/admin/users/1')
|
||||
->status_is(200);
|
||||
|
||||
#Read organisation user
|
||||
$t->get_ok('/admin/users/3/')
|
||||
$t->get_ok('/admin/users/5')
|
||||
->status_is(200);
|
||||
|
||||
#Valid customer user update
|
||||
$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',
|
||||
sector => 'A',
|
||||
postcode => 'WC1E 6AD',
|
||||
})->status_is(200)->content_like(qr/Updated User/);
|
||||
$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/);
|
||||
|
||||
#Failed validation on customer user from no postcode
|
||||
$t->post_ok('/admin/users/2/edit', form => {
|
||||
$t->post_ok('/admin/users/2', form => {
|
||||
email => 'test12@example.com',
|
||||
new_password => 'abc123',
|
||||
full_name => 'Test User1',
|
||||
|
@ -81,7 +58,7 @@ $t->post_ok('/admin/users/2/edit', form => {
|
|||
})->content_like(qr/The validation has failed/);
|
||||
|
||||
#Failed validation on customer user from no display name
|
||||
$t->post_ok('/admin/users/2/edit', form => {
|
||||
$t->post_ok('/admin/users/2', form => {
|
||||
email => 'test12@example.com',
|
||||
new_password => 'abc123',
|
||||
full_name => 'Test User1',
|
||||
|
@ -91,7 +68,7 @@ $t->post_ok('/admin/users/2/edit', form => {
|
|||
})->content_like(qr/The validation has failed/);
|
||||
|
||||
#Valid organisation user update
|
||||
$t->post_ok('/admin/users/3/edit', form => {
|
||||
$t->post_ok('/admin/users/5', form => {
|
||||
email => 'test51@example.com',
|
||||
new_password => 'abc123',
|
||||
name => '7th Heaven',
|
||||
|
@ -102,7 +79,7 @@ $t->post_ok('/admin/users/3/edit', form => {
|
|||
})->status_is(200)->content_like(qr/Updated User/);
|
||||
|
||||
#Failed validation on organisation user from no postcode
|
||||
$t->post_ok('/admin/users/3/edit', form => {
|
||||
$t->post_ok('/admin/users/5', form => {
|
||||
email => 'test50@example.com',
|
||||
new_password => 'abc123',
|
||||
name => '7th Heaven',
|
||||
|
@ -112,7 +89,7 @@ $t->post_ok('/admin/users/3/edit', form => {
|
|||
})->content_like(qr/The validation has failed/);
|
||||
|
||||
#Failed validation on organisation user from no street name
|
||||
$t->post_ok('/admin/users/3/edit', form => {
|
||||
$t->post_ok('/admin/users/5', form => {
|
||||
email => 'test50@example.com',
|
||||
new_password => 'abc123',
|
||||
name => '7th Heaven',
|
||||
|
|
|
@ -25,14 +25,14 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label for="type">Account Type</label>
|
||||
<input id="type" type="text" class="form-control" value="<%= defined $user->customer_id ? 'Customer' : 'Organisation' %>" disabled>
|
||||
<input id="type" type="text" class="form-control" value="<%= $user->type eq 'customer' ? 'Customer' : 'Organisation' %>" disabled>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="new_password">New Password</label>
|
||||
<input id="new_password" type="password" autocomplete="off" class="form-control" placeholder="New Password" name="new_password">
|
||||
<p class="help-block">Leave blank unless you want to change their password</p>
|
||||
</div>
|
||||
% if ( my $customer_rs = $user->customer ) {
|
||||
% if ( my $customer_rs = $user->entity->customer ) {
|
||||
<h3 class="card-header">
|
||||
Customer Details
|
||||
</h3>
|
||||
|
@ -52,7 +52,7 @@
|
|||
<label for="year_of_birth">Year of Birth</label>
|
||||
<input id="year_of_birth" type="number" class="form-control" placeholder="Year of Birth" name="year_of_birth" value="<%= $customer_rs->year_of_birth %>" disabled>
|
||||
</div>
|
||||
% } elsif ( my $org_rs = $user->organisation ) {
|
||||
% } elsif ( my $org_rs = $user->entity->organisation ) {
|
||||
<h3 class="card-header">
|
||||
Organisation Details
|
||||
</h3>
|
||||
|
|
Reference in a new issue