Change registration to be the same as the api docs
This commit is contained in:
parent
7e5211b7b7
commit
1d1b4aa1cf
8 changed files with 91 additions and 154 deletions
|
@ -8,10 +8,8 @@ has error_messages => sub {
|
||||||
required => { message => 'No token sent.', status => 400 },
|
required => { message => 'No token sent.', status => 400 },
|
||||||
in_resultset => { message => 'Token invalid or has been used.', status => 401 },
|
in_resultset => { message => 'Token invalid or has been used.', status => 401 },
|
||||||
},
|
},
|
||||||
username => {
|
name => {
|
||||||
required => { message => 'No username sent or was blank.', status => 400 },
|
required => { message => 'No name sent or was blank.', status => 400 },
|
||||||
like => { message => 'Username can only be A-Z, a-z and 0-9 characters.', status => 400 },
|
|
||||||
not_in_resultset => { message => 'Username exists.', status => 403 },
|
|
||||||
},
|
},
|
||||||
email => {
|
email => {
|
||||||
required => { message => 'No email sent.', status => 400 },
|
required => { message => 'No email sent.', status => 400 },
|
||||||
|
@ -20,6 +18,7 @@ has error_messages => sub {
|
||||||
},
|
},
|
||||||
postcode => {
|
postcode => {
|
||||||
required => { message => 'No postcode sent.', status => 400 },
|
required => { message => 'No postcode sent.', status => 400 },
|
||||||
|
postcode => { message => 'Postcode is invalid', status => 400 },
|
||||||
},
|
},
|
||||||
password => {
|
password => {
|
||||||
required => { message => 'No password sent.', status => 400 },
|
required => { message => 'No password sent.', status => 400 },
|
||||||
|
@ -28,10 +27,10 @@ has error_messages => sub {
|
||||||
required => { message => 'No usertype sent.', status => 400 },
|
required => { message => 'No usertype sent.', status => 400 },
|
||||||
in => { message => '"usertype" is invalid.', status => 400 },
|
in => { message => '"usertype" is invalid.', status => 400 },
|
||||||
},
|
},
|
||||||
age => {
|
age_range => {
|
||||||
required => { message => 'No age sent.', status => 400 },
|
required => { message => 'No age_range sent.', status => 400 },
|
||||||
number => { message => 'Age range is invalid', status => 400 },
|
number => { message => 'age_range is invalid', status => 400 },
|
||||||
in_resultset => { message => 'Age range is invalid.', status => 400 },
|
in_resultset => { message => 'age_range is invalid.', status => 400 },
|
||||||
},
|
},
|
||||||
street_name => {
|
street_name => {
|
||||||
required => { message => 'No street_name sent.', status => 400 },
|
required => { message => 'No street_name sent.', status => 400 },
|
||||||
|
@ -46,62 +45,30 @@ sub post_register{
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
my $validation = $c->validation;
|
my $validation = $c->validation;
|
||||||
|
$validation->input( $c->stash->{api_json} );
|
||||||
my $json = $c->req->json;
|
|
||||||
|
|
||||||
if ( ! defined $json ){
|
|
||||||
return $c->render( json => {
|
|
||||||
success => Mojo::JSON->false,
|
|
||||||
message => 'No json sent.',
|
|
||||||
},
|
|
||||||
status => 400,); #Malformed request
|
|
||||||
}
|
|
||||||
$validation->input( $json );
|
|
||||||
|
|
||||||
my $token_rs = $c->schema->resultset('AccountToken')->search_rs({used => 0});
|
my $token_rs = $c->schema->resultset('AccountToken')->search_rs({used => 0});
|
||||||
$validation->required('token')->in_resultset('name', $token_rs);
|
$validation->required('token')->in_resultset('name', $token_rs);
|
||||||
|
|
||||||
my $customer_rs = $c->schema->resultset('Customer');
|
|
||||||
$validation->required('username')->like(qr/^[A-Za-z0-9]+$/)->not_in_resultset('username', $customer_rs);
|
|
||||||
|
|
||||||
my $user_rs = $c->schema->resultset('User');
|
my $user_rs = $c->schema->resultset('User');
|
||||||
$validation->required('email')->email->not_in_resultset('email', $user_rs);
|
$validation->required('email')->email->not_in_resultset('email', $user_rs);
|
||||||
|
|
||||||
#TODO test to see if post code is valid.
|
|
||||||
$validation->required('postcode');
|
|
||||||
|
|
||||||
#TODO should we enforce password requirements.
|
|
||||||
$validation->required('password');
|
$validation->required('password');
|
||||||
|
|
||||||
|
$validation->required('name');
|
||||||
|
$validation->required('postcode')->postcode;
|
||||||
$validation->required('usertype')->in('customer', 'organisation');
|
$validation->required('usertype')->in('customer', 'organisation');
|
||||||
|
|
||||||
my $usertype = $validation->param('usertype') || '';
|
my $usertype = $validation->param('usertype') || '';
|
||||||
|
|
||||||
if ( $usertype eq 'customer' ) {
|
if ( $usertype eq 'customer' ) {
|
||||||
|
|
||||||
my $age_rs = $c->schema->resultset('AgeRange');
|
my $age_rs = $c->schema->resultset('AgeRange');
|
||||||
$validation->required('age')->number->in_resultset('id', $age_rs);
|
$validation->required('age_range')->number->in_resultset('id', $age_rs);
|
||||||
|
|
||||||
} elsif ( $usertype eq 'organisation' ) {
|
} elsif ( $usertype eq 'organisation' ) {
|
||||||
|
|
||||||
$validation->required('street_name');
|
$validation->required('street_name');
|
||||||
$validation->required('town');
|
$validation->required('town');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $validation->has_error ) {
|
return $c->api_validation_error if $validation->has_error;
|
||||||
my $failed_vals = $validation->failed;
|
|
||||||
for my $val ( @$failed_vals ) {
|
|
||||||
my $check = shift @{ $validation->error($val) };
|
|
||||||
return $c->render(
|
|
||||||
json => {
|
|
||||||
success => Mojo::JSON->false,
|
|
||||||
message => $c->error_messages->{$val}->{$check}->{message},
|
|
||||||
},
|
|
||||||
status => $c->error_messages->{$val}->{$check}->{status},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($usertype eq 'customer'){
|
if ($usertype eq 'customer'){
|
||||||
|
|
||||||
|
@ -112,8 +79,8 @@ sub post_register{
|
||||||
})->update({ used => 1 });
|
})->update({ used => 1 });
|
||||||
$c->schema->resultset('User')->create({
|
$c->schema->resultset('User')->create({
|
||||||
customer => {
|
customer => {
|
||||||
username => $validation->param('username'),
|
name => $validation->param('name'),
|
||||||
age_range_id => $validation->param('age'),
|
age_range_id => $validation->param('age_range'),
|
||||||
postcode => $validation->param('postcode'),
|
postcode => $validation->param('postcode'),
|
||||||
},
|
},
|
||||||
email => $validation->param('email'),
|
email => $validation->param('email'),
|
||||||
|
@ -132,7 +99,7 @@ sub post_register{
|
||||||
})->update({ used => 1 });
|
})->update({ used => 1 });
|
||||||
$c->schema->resultset('User')->create({
|
$c->schema->resultset('User')->create({
|
||||||
organisation => {
|
organisation => {
|
||||||
name => $validation->param('username'),
|
name => $validation->param('name'),
|
||||||
street_name => $validation->param('street_name'),
|
street_name => $validation->param('street_name'),
|
||||||
town => $validation->param('town'),
|
town => $validation->param('town'),
|
||||||
postcode => $validation->param('postcode'),
|
postcode => $validation->param('postcode'),
|
||||||
|
|
|
@ -13,7 +13,7 @@ __PACKAGE__->add_columns(
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
"username" => {
|
"name" => {
|
||||||
data_type => "varchar",
|
data_type => "varchar",
|
||||||
size => 255,
|
size => 255,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
|
@ -32,8 +32,6 @@ __PACKAGE__->add_columns(
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("id");
|
__PACKAGE__->set_primary_key("id");
|
||||||
|
|
||||||
__PACKAGE__->add_unique_constraint(["username"]);
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"age_range",
|
"age_range",
|
||||||
"Pear::LocalLoop::Schema::Result::AgeRange",
|
"Pear::LocalLoop::Schema::Result::AgeRange",
|
||||||
|
|
|
@ -25,11 +25,11 @@ my $passwordReno = 'turks';
|
||||||
my $testJson = {
|
my $testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'Reno',
|
'name' => 'Reno',
|
||||||
'email' => $emailReno,
|
'email' => $emailReno,
|
||||||
'postcode' => 'E1 MP01',
|
'postcode' => 'SA4 3FA',
|
||||||
'password' => $passwordReno,
|
'password' => $passwordReno,
|
||||||
'age' => 1
|
'age_range' => 1
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)->or($dump_error)
|
->status_is(200)->or($dump_error)
|
||||||
|
@ -41,9 +41,9 @@ my $passwordBilly = 'Choco';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'organisation',
|
'usertype' => 'organisation',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'ChocoBillysGreens',
|
'name' => 'ChocoBillysGreens',
|
||||||
'email' => $emailBilly,
|
'email' => $emailBilly,
|
||||||
'postcode' => 'E4 C12',
|
'postcode' => 'ST20 0LG',
|
||||||
'password' => $passwordBilly,
|
'password' => $passwordBilly,
|
||||||
'street_name' => 'Chocobo Farm, Eastern Continent',
|
'street_name' => 'Chocobo Farm, Eastern Continent',
|
||||||
'town' => 'Gaia',
|
'town' => 'Gaia',
|
||||||
|
@ -58,11 +58,11 @@ my $passwordAdmin = 'ethics';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'admin',
|
'name' => 'admin',
|
||||||
'email' => $emailAdmin,
|
'email' => $emailAdmin,
|
||||||
'postcode' => 'NW1 W01',
|
'postcode' => 'HD5 9XU',
|
||||||
'password' => $passwordAdmin,
|
'password' => $passwordAdmin,
|
||||||
'age' => 2
|
'age_range' => 2
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
|
|
@ -25,11 +25,11 @@ my $passwordReno = 'turks';
|
||||||
my $testJson = {
|
my $testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'Reno',
|
'name' => 'Reno',
|
||||||
'email' => $emailReno,
|
'email' => $emailReno,
|
||||||
'postcode' => 'E1 MP01',
|
'postcode' => 'SA4 3FA',
|
||||||
'password' => $passwordReno,
|
'password' => $passwordReno,
|
||||||
'age' => 1
|
'age_range' => 1
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
@ -41,9 +41,9 @@ my $passwordBilly = 'Choco';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'organisation',
|
'usertype' => 'organisation',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'ChocoBillysGreens',
|
'name' => 'ChocoBillysGreens',
|
||||||
'email' => $emailBilly,
|
'email' => $emailBilly,
|
||||||
'postcode' => 'E4 C12',
|
'postcode' => 'ST20 0LG',
|
||||||
'password' => $passwordBilly,
|
'password' => $passwordBilly,
|
||||||
'street_name' => 'Chocobo Farm, Eastern Continent',
|
'street_name' => 'Chocobo Farm, Eastern Continent',
|
||||||
town => 'Gaia',
|
town => 'Gaia',
|
||||||
|
@ -59,11 +59,11 @@ my $passwordAdmin = 'ethics';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'admin',
|
'name' => 'admin',
|
||||||
'email' => $emailAdmin,
|
'email' => $emailAdmin,
|
||||||
'postcode' => 'NW1 W01',
|
'postcode' => 'HD5 9XU',
|
||||||
'password' => $passwordAdmin,
|
'password' => $passwordAdmin,
|
||||||
'age' => 2
|
'age_range' => 2
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
|
|
@ -19,11 +19,11 @@ $schema->resultset('AccountToken')->create({
|
||||||
my $test_json = {
|
my $test_json = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => $account_token,
|
'token' => $account_token,
|
||||||
'username' => 'RufusShinra',
|
'name' => 'RufusShinra',
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'age' => 1
|
'age_range' => 1
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $test_json)
|
$t->post_ok('/api/register' => json => $test_json)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
|
115
t/register.t
115
t/register.t
|
@ -7,6 +7,7 @@ use Test::Pear::LocalLoop;
|
||||||
my $framework = Test::Pear::LocalLoop->new;
|
my $framework = Test::Pear::LocalLoop->new;
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
|
my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text };
|
||||||
|
|
||||||
#Variables to be used for uniqueness when testing.
|
#Variables to be used for uniqueness when testing.
|
||||||
my @names = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
|
my @names = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
|
||||||
|
@ -20,7 +21,7 @@ $schema->resultset('AccountToken')->populate([
|
||||||
|
|
||||||
#No JSON sent
|
#No JSON sent
|
||||||
$t->post_ok('/api/register')
|
$t->post_ok('/api/register')
|
||||||
->status_is(400)
|
->status_is(400)->or($dump_error)
|
||||||
->json_is('/success', Mojo::JSON->false)
|
->json_is('/success', Mojo::JSON->false)
|
||||||
->json_like('/message', qr/JSON is missing/i);
|
->json_like('/message', qr/JSON is missing/i);
|
||||||
|
|
||||||
|
@ -32,11 +33,11 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
#token missing JSON
|
#token missing JSON
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
|
@ -48,11 +49,11 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => ' ',
|
'token' => ' ',
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(401)
|
->status_is(401)
|
||||||
|
@ -60,64 +61,49 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
->content_like(qr/token/i)
|
->content_like(qr/token/i)
|
||||||
->content_like(qr/invalid/i);
|
->content_like(qr/invalid/i);
|
||||||
|
|
||||||
#username missing JSON
|
#name missing JSON
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$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/no username sent/i);
|
->content_like(qr/no name sent/i);
|
||||||
|
|
||||||
|
|
||||||
#Blank username
|
#Blank name
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => '',
|
'name' => '',
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$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/blank/i)
|
->content_like(qr/blank/i)
|
||||||
->content_like(qr/username/i);
|
->content_like(qr/name/i);
|
||||||
|
|
||||||
#Not alpha numeric chars e.g. !
|
my $nameToReuse = shift(@names);
|
||||||
$testJson = {
|
|
||||||
'usertype' => 'customer',
|
|
||||||
'token' => shift(@tokens),
|
|
||||||
'username' => 'asa!',
|
|
||||||
'email' => shift(@emails),
|
|
||||||
'postcode' => 'LA1 1AA',
|
|
||||||
'password' => 'Meh',
|
|
||||||
'age' => 3
|
|
||||||
};
|
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
|
||||||
->status_is(400)
|
|
||||||
->json_is('/success', Mojo::JSON->false)
|
|
||||||
->content_like(qr/username/i);
|
|
||||||
|
|
||||||
my $usernameToReuse = shift(@names);
|
|
||||||
my $emailToReuse = shift(@emails);
|
my $emailToReuse = shift(@emails);
|
||||||
|
|
||||||
#Valid customer
|
#Valid customer
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => $usernameToReuse,
|
'name' => $nameToReuse,
|
||||||
'email' => $emailToReuse,
|
'email' => $emailToReuse,
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
@ -127,11 +113,11 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 2
|
'age_range' => 2
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
@ -141,39 +127,24 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 1
|
'age_range' => 1
|
||||||
};
|
};
|
||||||
$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);
|
||||||
|
|
||||||
#Username exists
|
|
||||||
$testJson = {
|
|
||||||
'usertype' => 'customer',
|
|
||||||
'token' => shift(@tokens),
|
|
||||||
'username' => $usernameToReuse,
|
|
||||||
'email' => shift(@emails),
|
|
||||||
'postcode' => 'LA1 1AA',
|
|
||||||
'password' => 'Meh',
|
|
||||||
'age' => 3
|
|
||||||
};
|
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
|
||||||
->status_is(403)
|
|
||||||
->json_is('/success', Mojo::JSON->false)
|
|
||||||
->content_like(qr/exists/i);
|
|
||||||
|
|
||||||
#email missing JSON
|
#email missing JSON
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
|
@ -184,11 +155,11 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => 'dfsd@.com',
|
'email' => 'dfsd@.com',
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 2
|
'age_range' => 2
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
|
@ -200,11 +171,11 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => 'dfsd@com',
|
'email' => 'dfsd@com',
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 2
|
'age_range' => 2
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
|
@ -216,11 +187,11 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => $emailToReuse,
|
'email' => $emailToReuse,
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 2
|
'age_range' => 2
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(403)
|
->status_is(403)
|
||||||
|
@ -232,10 +203,10 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
|
@ -248,10 +219,10 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
|
@ -263,11 +234,11 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
#usertype missing JSON
|
#usertype missing JSON
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 3
|
'age_range' => 3
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(400)
|
->status_is(400)
|
||||||
|
@ -278,7 +249,7 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'organisation1',
|
'usertype' => 'organisation1',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
|
@ -291,11 +262,11 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
->content_like(qr/invalid/i);
|
->content_like(qr/invalid/i);
|
||||||
|
|
||||||
|
|
||||||
#age missing JSON
|
#age_range missing JSON
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
|
@ -303,29 +274,29 @@ $testJson = {
|
||||||
$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/no age sent/i);
|
->content_like(qr/no age_range sent/i);
|
||||||
|
|
||||||
#Age is invalid
|
#Age is invalid
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
'age' => 'invalid'
|
'age_range' => '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/age/i)
|
->content_like(qr/age_range/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' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
|
@ -341,7 +312,7 @@ $t->post_ok('/api/register' => json => $testJson)
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'organisation',
|
'usertype' => 'organisation',
|
||||||
'token' => shift(@tokens),
|
'token' => shift(@tokens),
|
||||||
'username' => shift(@names),
|
'name' => shift(@names),
|
||||||
'email' => shift(@emails),
|
'email' => shift(@emails),
|
||||||
'postcode' => 'LA1 1AA',
|
'postcode' => 'LA1 1AA',
|
||||||
'password' => 'Meh',
|
'password' => 'Meh',
|
||||||
|
|
11
t/search.t
11
t/search.t
|
@ -7,6 +7,7 @@ use Test::Pear::LocalLoop;
|
||||||
my $framework = Test::Pear::LocalLoop->new;
|
my $framework = Test::Pear::LocalLoop->new;
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
|
my $dump_error = sub { diag $t->tx->res->to_string };
|
||||||
|
|
||||||
my @account_tokens = ('a', 'b');
|
my @account_tokens = ('a', 'b');
|
||||||
$schema->resultset('AccountToken')->populate([
|
$schema->resultset('AccountToken')->populate([
|
||||||
|
@ -30,14 +31,14 @@ my $passwordRufus = 'MakoGold';
|
||||||
my $testJson = {
|
my $testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'RufusShinra',
|
'name' => 'RufusShinra',
|
||||||
'email' => $emailRufus,
|
'email' => $emailRufus,
|
||||||
'postcode' => 'LA1 1CF',
|
'postcode' => 'RG26 5NU',
|
||||||
'password' => $passwordRufus,
|
'password' => $passwordRufus,
|
||||||
'age' => 1
|
'age_range' => 1
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)->or($dump_error)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true);
|
||||||
|
|
||||||
#test with an organisation.
|
#test with an organisation.
|
||||||
|
@ -47,7 +48,7 @@ my $passwordBilly = 'Choco';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'organisation',
|
'usertype' => 'organisation',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'ChocoBillysGreens',
|
'name' => 'ChocoBillysGreens',
|
||||||
'email' => $emailBilly,
|
'email' => $emailBilly,
|
||||||
'postcode' => 'LA1 1HT',
|
'postcode' => 'LA1 1HT',
|
||||||
'password' => $passwordBilly,
|
'password' => $passwordBilly,
|
||||||
|
|
16
t/upload.t
16
t/upload.t
|
@ -38,11 +38,11 @@ my $passwordRufus = 'MakoGold';
|
||||||
my $testJson = {
|
my $testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'RufusShinra',
|
'name' => 'RufusShinra',
|
||||||
'email' => $emailRufus,
|
'email' => $emailRufus,
|
||||||
'postcode' => 'E1 MP01',
|
'postcode' => 'GU10 5SA',
|
||||||
'password' => $passwordRufus,
|
'password' => $passwordRufus,
|
||||||
'age' => 1
|
'age_range' => 1
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
@ -54,11 +54,11 @@ my $passwordHojo = 'Mako';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'customer',
|
'usertype' => 'customer',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'ProfessorHojo',
|
'name' => 'ProfessorHojo',
|
||||||
'email' => $emailHojo,
|
'email' => $emailHojo,
|
||||||
'postcode' => 'E1 MP01',
|
'postcode' => 'DE15 9LT',
|
||||||
'password' => $passwordHojo,
|
'password' => $passwordHojo,
|
||||||
'age' => 1
|
'age_range' => 1
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $testJson)
|
$t->post_ok('/api/register' => json => $testJson)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
|
@ -70,9 +70,9 @@ my $passwordBilly = 'Choco';
|
||||||
$testJson = {
|
$testJson = {
|
||||||
'usertype' => 'organisation',
|
'usertype' => 'organisation',
|
||||||
'token' => shift(@account_tokens),
|
'token' => shift(@account_tokens),
|
||||||
'username' => 'ChocoBillysGreens',
|
'name' => 'ChocoBillysGreens',
|
||||||
'email' => $emailBilly,
|
'email' => $emailBilly,
|
||||||
'postcode' => 'E4 C12',
|
'postcode' => 'SO50 7NJ',
|
||||||
'password' => $passwordBilly,
|
'password' => $passwordBilly,
|
||||||
'street_name' => 'Chocobo Farm, Eastern Continent',
|
'street_name' => 'Chocobo Farm, Eastern Continent',
|
||||||
'town' => 'Gaia',
|
'town' => 'Gaia',
|
||||||
|
|
Reference in a new issue