Change registration to be the same as the api docs

This commit is contained in:
Tom Bloor 2017-04-22 19:35:19 +01:00
parent 7e5211b7b7
commit 1d1b4aa1cf
8 changed files with 91 additions and 154 deletions

View file

@ -25,11 +25,11 @@ my $passwordReno = 'turks';
my $testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
'username' => 'Reno',
'name' => 'Reno',
'email' => $emailReno,
'postcode' => 'E1 MP01',
'postcode' => 'SA4 3FA',
'password' => $passwordReno,
'age' => 1
'age_range' => 1
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)->or($dump_error)
@ -41,9 +41,9 @@ my $passwordBilly = 'Choco';
$testJson = {
'usertype' => 'organisation',
'token' => shift(@account_tokens),
'username' => 'ChocoBillysGreens',
'name' => 'ChocoBillysGreens',
'email' => $emailBilly,
'postcode' => 'E4 C12',
'postcode' => 'ST20 0LG',
'password' => $passwordBilly,
'street_name' => 'Chocobo Farm, Eastern Continent',
'town' => 'Gaia',
@ -58,11 +58,11 @@ my $passwordAdmin = 'ethics';
$testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
'username' => 'admin',
'name' => 'admin',
'email' => $emailAdmin,
'postcode' => 'NW1 W01',
'postcode' => 'HD5 9XU',
'password' => $passwordAdmin,
'age' => 2
'age_range' => 2
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)

View file

@ -25,11 +25,11 @@ my $passwordReno = 'turks';
my $testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
'username' => 'Reno',
'name' => 'Reno',
'email' => $emailReno,
'postcode' => 'E1 MP01',
'postcode' => 'SA4 3FA',
'password' => $passwordReno,
'age' => 1
'age_range' => 1
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)
@ -41,9 +41,9 @@ my $passwordBilly = 'Choco';
$testJson = {
'usertype' => 'organisation',
'token' => shift(@account_tokens),
'username' => 'ChocoBillysGreens',
'name' => 'ChocoBillysGreens',
'email' => $emailBilly,
'postcode' => 'E4 C12',
'postcode' => 'ST20 0LG',
'password' => $passwordBilly,
'street_name' => 'Chocobo Farm, Eastern Continent',
town => 'Gaia',
@ -59,11 +59,11 @@ my $passwordAdmin = 'ethics';
$testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
'username' => 'admin',
'name' => 'admin',
'email' => $emailAdmin,
'postcode' => 'NW1 W01',
'postcode' => 'HD5 9XU',
'password' => $passwordAdmin,
'age' => 2
'age_range' => 2
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)

View file

@ -19,11 +19,11 @@ $schema->resultset('AccountToken')->create({
my $test_json = {
'usertype' => 'customer',
'token' => $account_token,
'username' => 'RufusShinra',
'name' => 'RufusShinra',
'email' => $email,
'postcode' => 'LA1 1AA',
'password' => $password,
'age' => 1
'age_range' => 1
};
$t->post_ok('/api/register' => json => $test_json)
->status_is(200)

View file

@ -7,6 +7,7 @@ use Test::Pear::LocalLoop;
my $framework = Test::Pear::LocalLoop->new;
my $t = $framework->framework;
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.
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
$t->post_ok('/api/register')
->status_is(400)
->status_is(400)->or($dump_error)
->json_is('/success', Mojo::JSON->false)
->json_like('/message', qr/JSON is missing/i);
@ -32,11 +33,11 @@ $t->post_ok('/api/register' => json => $testJson)
#token missing JSON
$testJson = {
'usertype' => 'customer',
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
@ -48,11 +49,11 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'customer',
'token' => ' ',
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(401)
@ -60,64 +61,49 @@ $t->post_ok('/api/register' => json => $testJson)
->content_like(qr/token/i)
->content_like(qr/invalid/i);
#username missing JSON
#name missing JSON
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
->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 = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => '',
'name' => '',
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
->json_is('/success', Mojo::JSON->false)
->content_like(qr/blank/i)
->content_like(qr/username/i);
->content_like(qr/name/i);
#Not alpha numeric chars e.g. !
$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 $nameToReuse = shift(@names);
my $emailToReuse = shift(@emails);
#Valid customer
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => $usernameToReuse,
'name' => $nameToReuse,
'email' => $emailToReuse,
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)
@ -127,11 +113,11 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 2
'age_range' => 2
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)
@ -141,39 +127,24 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 1
'age_range' => 1
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)
->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
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
@ -184,11 +155,11 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => 'dfsd@.com',
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 2
'age_range' => 2
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
@ -200,11 +171,11 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => 'dfsd@com',
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 2
'age_range' => 2
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
@ -216,11 +187,11 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => $emailToReuse,
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 2
'age_range' => 2
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(403)
@ -232,10 +203,10 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'password' => 'Meh',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
@ -248,10 +219,10 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
@ -263,11 +234,11 @@ $t->post_ok('/api/register' => json => $testJson)
#usertype missing JSON
$testJson = {
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 3
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
@ -278,7 +249,7 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'organisation1',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
@ -291,11 +262,11 @@ $t->post_ok('/api/register' => json => $testJson)
->content_like(qr/invalid/i);
#age missing JSON
#age_range missing JSON
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
@ -303,29 +274,29 @@ $testJson = {
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
->json_is('/success', Mojo::JSON->false)
->content_like(qr/no age sent/i);
->content_like(qr/no age_range sent/i);
#Age is invalid
$testJson = {
'usertype' => 'customer',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age' => 'invalid'
'age_range' => 'invalid'
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
->json_is('/success', Mojo::JSON->false)
->content_like(qr/age/i)
->content_like(qr/age_range/i)
->content_like(qr/invalid/i);
#full address missing JSON
$testJson = {
'usertype' => 'organisation',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',
@ -341,7 +312,7 @@ $t->post_ok('/api/register' => json => $testJson)
$testJson = {
'usertype' => 'organisation',
'token' => shift(@tokens),
'username' => shift(@names),
'name' => shift(@names),
'email' => shift(@emails),
'postcode' => 'LA1 1AA',
'password' => 'Meh',

View file

@ -7,6 +7,7 @@ use Test::Pear::LocalLoop;
my $framework = Test::Pear::LocalLoop->new;
my $t = $framework->framework;
my $schema = $t->app->schema;
my $dump_error = sub { diag $t->tx->res->to_string };
my @account_tokens = ('a', 'b');
$schema->resultset('AccountToken')->populate([
@ -30,14 +31,14 @@ my $passwordRufus = 'MakoGold';
my $testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
'username' => 'RufusShinra',
'name' => 'RufusShinra',
'email' => $emailRufus,
'postcode' => 'LA1 1CF',
'postcode' => 'RG26 5NU',
'password' => $passwordRufus,
'age' => 1
'age_range' => 1
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)
->status_is(200)->or($dump_error)
->json_is('/success', Mojo::JSON->true);
#test with an organisation.
@ -47,7 +48,7 @@ my $passwordBilly = 'Choco';
$testJson = {
'usertype' => 'organisation',
'token' => shift(@account_tokens),
'username' => 'ChocoBillysGreens',
'name' => 'ChocoBillysGreens',
'email' => $emailBilly,
'postcode' => 'LA1 1HT',
'password' => $passwordBilly,

View file

@ -38,11 +38,11 @@ my $passwordRufus = 'MakoGold';
my $testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
'username' => 'RufusShinra',
'name' => 'RufusShinra',
'email' => $emailRufus,
'postcode' => 'E1 MP01',
'postcode' => 'GU10 5SA',
'password' => $passwordRufus,
'age' => 1
'age_range' => 1
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)
@ -54,11 +54,11 @@ my $passwordHojo = 'Mako';
$testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
'username' => 'ProfessorHojo',
'name' => 'ProfessorHojo',
'email' => $emailHojo,
'postcode' => 'E1 MP01',
'postcode' => 'DE15 9LT',
'password' => $passwordHojo,
'age' => 1
'age_range' => 1
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)
@ -70,9 +70,9 @@ my $passwordBilly = 'Choco';
$testJson = {
'usertype' => 'organisation',
'token' => shift(@account_tokens),
'username' => 'ChocoBillysGreens',
'name' => 'ChocoBillysGreens',
'email' => $emailBilly,
'postcode' => 'E4 C12',
'postcode' => 'SO50 7NJ',
'password' => $passwordBilly,
'street_name' => 'Chocobo Farm, Eastern Continent',
'town' => 'Gaia',