diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index c8d154b..a04a9bc 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -172,9 +172,9 @@ sub startup { $admin_routes->get('/organisations')->to('admin-organisations#list'); $admin_routes->get('/organisations/valid/:id')->to('admin-organisations#valid_read'); - $admin_routes->get('/organisations/valid/:id/edit')->to('admin-organisations#valid_edit'); + $admin_routes->post('/organisations/valid/:id/edit')->to('admin-organisations#valid_edit'); $admin_routes->get('/organisations/pending/:id')->to('admin-organisations#pending_read'); - $admin_routes->get('/organisations/pending/:id/edit')->to('admin-organisations#pending_edit'); + $admin_routes->post('/organisations/pending/:id/edit')->to('admin-organisations#pending_edit'); $admin_routes->get('/organisations/pending/:id/approve')->to('admin-organisations#pending_approve'); $admin_routes->get('/feedback')->to('admin-feedback#index'); diff --git a/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm b/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm index 84eef3f..0b3e4c5 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm @@ -117,7 +117,7 @@ sub pending_edit { $c->flash( success => 'Updated Organisation' ); } }; - $c->redirect_to( '/admin/organisations/valid/' . $pending_org->id ); + $c->redirect_to( '/admin/organisations/pending/' . $pending_org->id ); } sub pending_approve { diff --git a/t/admin/update.t b/t/admin/update.t new file mode 100644 index 0000000..84fc3e6 --- /dev/null +++ b/t/admin/update.t @@ -0,0 +1,81 @@ +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'; + +$schema->resultset('Organisation')->create({ + id => 1, + name => 'Shinra Electric Power Company', + street_name => 'Sector 0, Midgar, Eastern Continent', + town => 'Gaia', + postcode => 'WC1E 6AD', +}); + +$schema->resultset('PendingOrganisation')->create({ + id => 2, + name => '7th Heaven', + street_name => 'Slums, Sector 7', + town => 'Midgar', + postcode => 'WC1E 6AD', + submitted_by_id => $user->id, +}); + +#login to admin +$t->ua->max_redirects(10); +$t->post_ok('/admin', form => { + email => 'admin@example.com', + password => 'abc123', +})->status_is(200); + +#Read approved organisation +$t->get_ok('/admin/organisations/valid/1/') + ->status_is(200); + +#Read pending organisation +$t->get_ok('/admin/organisations/pending/2/') + ->status_is(200); + +#Valid approved organisation update +$t->post_ok('/admin/organisations/valid/1/edit', form => { + name => 'Shinra Electric Power Company', + street_name => 'Sector 0, Midgar, Eastern Continent', + town => 'Gaia', + postcode => 'WC1E 6AD', +})->status_is(200)->content_like(qr/Updated Organisation/); + +#Failed validation on approved organisation +$t->post_ok('/admin/organisations/valid/1/edit', form => { + name => 'Shinra Electric Power Company', + street_name => 'Sector 0, Midgar, Eastern Continent', + postcode => 'WC1E 6AD', +})->content_like(qr/The validation has failed/); + +#Valid pending organisation update +$t->post_ok('/admin/organisations/pending/2/edit', form => { + name => '7th Heaven', + street_name => 'Slums, Sector 7', + town => 'Midgar', + postcode => 'WC1E 6AD', +})->status_is(200)->content_like(qr/Updated Organisation/); + +#Failed validation on pending organisation +$t->post_ok('/admin/organisations/pending/2/edit', form => { + name => '7th Heaven', + street_name => 'Slums, Sector 7', + postcode => 'WC1E 6AD', +})->content_like(qr/The validation has failed/); + +done_testing(); diff --git a/templates/admin/organisations/pending_read.html.ep b/templates/admin/organisations/pending_read.html.ep index aa0bec9..bbf99e0 100644 --- a/templates/admin/organisations/pending_read.html.ep +++ b/templates/admin/organisations/pending_read.html.ep @@ -16,8 +16,8 @@ %= $pending_org->name