Fixed validation removing redundant code

This commit is contained in:
Finn 2017-08-23 16:47:29 +01:00
parent 49beb3037d
commit 6f01bf2661
3 changed files with 87 additions and 90 deletions

View file

@ -102,7 +102,6 @@ sub post_register{
} }
elsif ($usertype eq 'organisation') { elsif ($usertype eq 'organisation') {
my $fullAddress = $validation->param('fulladdress');
$c->schema->txn_do( sub { $c->schema->txn_do( sub {
$c->schema->resultset('AccountToken')->find({ $c->schema->resultset('AccountToken')->find({

View file

@ -148,7 +148,6 @@ sub post_account_update {
} }
elsif ( defined $user->organisation_id ) { elsif ( defined $user->organisation_id ) {
my $fullAddress = $validation->param('fulladdress');
$c->schema->txn_do( sub { $c->schema->txn_do( sub {
$user->organisation->update({ $user->organisation->update({

View file

@ -92,12 +92,12 @@ $t->post_ok('/api/register' => json => $testJson)
#Blank name #Blank name
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'a', 'token' => 'a',
'display_name' => 'test name', 'display_name' => 'test name',
'full_name' => '', 'full_name' => '',
'email' => 'a@b.com', 'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 2005 'year_of_birth' => 2005
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
@ -108,12 +108,12 @@ $t->post_ok('/api/register' => json => $testJson)
#Blank name #Blank name
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'a', 'token' => 'a',
'display_name' => '', 'display_name' => '',
'full_name' => 'test name', 'full_name' => 'test name',
'email' => 'a@b.com', 'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 2005 'year_of_birth' => 2005
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
@ -125,13 +125,13 @@ $t->post_ok('/api/register' => json => $testJson)
#Valid customer #Valid customer
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'a', 'token' => 'a',
'full_name' => 'test name', 'full_name' => 'test name',
'display_name' => 'test name', 'display_name' => 'test name',
'email' => 'a@b.com', 'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 2005 'year_of_birth' => 2005
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
@ -140,35 +140,35 @@ $t->post_ok('/api/register' => json => $testJson)
#Valid customer2 #Valid customer2
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'b', 'token' => 'b',
'full_name' => 'test name', 'full_name' => 'test name',
'display_name' => 'test name', 'display_name' => 'test name',
'email' => 'b@c.com', 'email' => 'b@c.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 2005 'year_of_birth' => 2005
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->or($dump_error) ->or($dump_error)
->status_is(200) ->status_is(200)
->or($dump_error) ->or($dump_error)
->json_is('/success', Mojo::JSON->true) ->json_is('/success', Mojo::JSON->true)
->or($dump_error); ->or($dump_error);
#Valid customer3 #Valid customer3
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'c', 'token' => 'c',
'full_name' => 'test name', 'full_name' => 'test name',
'display_name' => 'test name', 'display_name' => 'test name',
'email' => 'c@d.com', 'email' => 'c@d.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 2005 'year_of_birth' => 2005
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
#email missing JSON #email missing JSON
@ -186,53 +186,53 @@ $t->post_ok('/api/register' => json => $testJson)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/no email sent/i); ->content_like(qr/no email sent/i);
#invalid email 1 #invalid email 1
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'd', 'token' => 'd',
'full_name' => 'test name', 'full_name' => 'test name',
'display_name' => 'test name', 'display_name' => 'test name',
'email' => 'dfsd@.com', 'email' => 'dfsd@.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 2006 'year_of_birth' => 2006
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->status_is(400) ->status_is(400)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/email/i) ->content_like(qr/email/i)
->content_like(qr/invalid/i); ->content_like(qr/invalid/i);
#invalid email 2 #invalid email 2
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'd', 'token' => 'd',
'full_name' => 'test name', 'full_name' => 'test name',
'display_name' => 'test name', 'display_name' => 'test name',
'email' => 'dfsd@com', 'email' => 'dfsd@com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 2006 'year_of_birth' => 2006
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->status_is(400) ->status_is(400)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/email/i) ->content_like(qr/email/i)
->content_like(qr/invalid/i); ->content_like(qr/invalid/i);
#Email exists #Email exists
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'd', 'token' => 'd',
'full_name' => 'test name', 'full_name' => 'test name',
'display_name' => 'test name', 'display_name' => 'test name',
'email' => 'a@b.com', 'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 2006 'year_of_birth' => 2006
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->status_is(403) ->status_is(403)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/email/i) ->content_like(qr/email/i)
->content_like(qr/exists/i); ->content_like(qr/exists/i);
@ -288,16 +288,15 @@ $t->post_ok('/api/register' => json => $testJson)
#Invalid user type #Invalid user type
$testJson = { $testJson = {
'usertype' => 'organisation1', 'usertype' => 'organisation1',
'token' => 'f', 'token' => 'f',
'name' => 'test name', 'name' => 'test name',
'email' => 'org@org.com', 'email' => 'org@org.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'fulladdress' => 'mary lane testing....'
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->status_is(400) ->status_is(400)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/usertype/i) ->content_like(qr/usertype/i)
->content_like(qr/invalid/i); ->content_like(qr/invalid/i);
@ -320,29 +319,29 @@ $t->post_ok('/api/register' => json => $testJson)
#Age is invalid #Age is invalid
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => 'f', 'token' => 'f',
'full_name' => 'test name', 'full_name' => 'test name',
'display_name' => 'test name', 'display_name' => 'test name',
'email' => 'test@example.com', 'email' => 'test@example.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'year_of_birth' => 'invalid' 'year_of_birth' => 'invalid'
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->status_is(400) ->status_is(400)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/year_of_birth/i) ->content_like(qr/year_of_birth/i)
->content_like(qr/invalid/i); ->content_like(qr/invalid/i);
#full address missing JSON #full address missing JSON
$testJson = { $testJson = {
'usertype' => 'organisation', 'usertype' => 'organisation',
'token' => 'f', 'token' => 'f',
'name' => 'test org', 'name' => 'test org',
'email' => 'org@org.com', 'email' => 'org@org.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->status_is(400) ->status_is(400)
@ -353,17 +352,17 @@ $t->post_ok('/api/register' => json => $testJson)
#Organisation valid #Organisation valid
$testJson = { $testJson = {
'usertype' => 'organisation', 'usertype' => 'organisation',
'token' => 'f', 'token' => 'f',
'name' => 'org name', 'name' => 'org name',
'email' => 'org@org.com', 'email' => 'org@org.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'street_name' => 'mary lane testing....', 'street_name' => 'mary lane testing....',
'town' => 'Lancaster', 'town' => 'Lancaster',
}; };
$t->post_ok('/api/register' => json => $testJson) $t->post_ok('/api/register' => json => $testJson)
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
is $t->app->schema->resultset('User')->count, 4, 'Correct user count'; is $t->app->schema->resultset('User')->count, 4, 'Correct user count';