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