Change to having display_name and full_name for customers

This commit is contained in:
Tom Bloor 2017-04-25 21:44:13 +01:00
parent 286ecf11e1
commit aed22d1c98
9 changed files with 133 additions and 70 deletions

View file

@ -11,6 +11,12 @@ has error_messages => sub {
name => { name => {
required => { message => 'No name sent or was blank.', status => 400 }, required => { message => 'No name sent or was blank.', status => 400 },
}, },
display_name => {
required => { message => 'No name sent or was blank.', status => 400 },
},
full_name => {
required => { message => 'No name sent or was blank.', status => 400 },
},
email => { email => {
required => { message => 'No email sent.', status => 400 }, required => { message => 'No email sent.', status => 400 },
email => { message => 'Email is invalid.', status => 400 }, email => { message => 'Email is invalid.', status => 400 },
@ -54,16 +60,18 @@ sub post_register{
$validation->required('email')->email->not_in_resultset('email', $user_rs); $validation->required('email')->email->not_in_resultset('email', $user_rs);
$validation->required('password'); $validation->required('password');
$validation->required('name');
$validation->required('postcode')->postcode; $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' ) {
$validation->required('display_name');
$validation->required('full_name');
my $age_rs = $c->schema->resultset('AgeRange'); my $age_rs = $c->schema->resultset('AgeRange');
$validation->required('age_range')->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('name');
$validation->required('street_name'); $validation->required('street_name');
$validation->required('town'); $validation->required('town');
} }
@ -79,7 +87,8 @@ sub post_register{
})->update({ used => 1 }); })->update({ used => 1 });
$c->schema->resultset('User')->create({ $c->schema->resultset('User')->create({
customer => { customer => {
name => $validation->param('name'), full_name => $validation->param('full_name'),
display_name => $validation->param('display_name'),
age_range_id => $validation->param('age_range'), age_range_id => $validation->param('age_range'),
postcode => $validation->param('postcode'), postcode => $validation->param('postcode'),
}, },

View file

@ -13,7 +13,12 @@ __PACKAGE__->add_columns(
is_auto_increment => 1, is_auto_increment => 1,
is_nullable => 0, is_nullable => 0,
}, },
"name" => { "display_name" => {
data_type => "varchar",
size => 255,
is_nullable => 0,
},
"full_name" => {
data_type => "varchar", data_type => "varchar",
size => 255, size => 255,
is_nullable => 0, is_nullable => 0,

View file

@ -25,7 +25,8 @@ my $passwordReno = 'turks';
my $testJson = { my $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@account_tokens), 'token' => shift(@account_tokens),
'name' => 'Reno', 'full_name' => 'Reno',
'display_name' => 'Reno',
'email' => $emailReno, 'email' => $emailReno,
'postcode' => 'SA4 3FA', 'postcode' => 'SA4 3FA',
'password' => $passwordReno, 'password' => $passwordReno,
@ -58,7 +59,8 @@ my $passwordAdmin = 'ethics';
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@account_tokens), 'token' => shift(@account_tokens),
'name' => 'admin', 'display_name' => 'admin',
'full_name' => 'admin',
'email' => $emailAdmin, 'email' => $emailAdmin,
'postcode' => 'HD5 9XU', 'postcode' => 'HD5 9XU',
'password' => $passwordAdmin, 'password' => $passwordAdmin,

View file

@ -25,7 +25,8 @@ my $passwordReno = 'turks';
my $testJson = { my $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@account_tokens), 'token' => shift(@account_tokens),
'name' => 'Reno', 'full_name' => 'Reno',
'display_name' => 'Reno',
'email' => $emailReno, 'email' => $emailReno,
'postcode' => 'SA4 3FA', 'postcode' => 'SA4 3FA',
'password' => $passwordReno, 'password' => $passwordReno,
@ -59,7 +60,8 @@ my $passwordAdmin = 'ethics';
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@account_tokens), 'token' => shift(@account_tokens),
'name' => 'admin', 'display_name' => 'admin',
'full_name' => 'admin',
'email' => $emailAdmin, 'email' => $emailAdmin,
'postcode' => 'HD5 9XU', 'postcode' => 'HD5 9XU',
'password' => $passwordAdmin, 'password' => $passwordAdmin,

View file

@ -19,7 +19,8 @@ $schema->resultset('AccountToken')->create({
my $test_json = { my $test_json = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => $account_token, 'token' => $account_token,
'name' => 'RufusShinra', 'display_name' => 'RufusShinra',
'full_name' => 'RufusShinra',
'email' => $email, 'email' => $email,
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => $password, 'password' => $password,

View file

@ -19,7 +19,8 @@ $schema->resultset('AccountToken')->create({
$framework->register_customer({ $framework->register_customer({
'token' => $account_token, 'token' => $account_token,
'name' => 'Test User', 'full_name' => 'Test User',
'display_name' => 'Test User',
'email' => $email, 'email' => $email,
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => $password, 'password' => $password,

View file

@ -10,8 +10,6 @@ my $schema = $t->app->schema;
my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text }; 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 @emails = ('a@a.com', 'b@a.com', 'c@a.com', 'd@a.com', 'e@a.com', 'f@a.com', 'g@a.com', 'h@a.com', 'i@a.com', 'j@a.com', 'k@a.com', 'l@a.com', 'm@a.com', 'n@a.com', 'o@a.com', 'p@a.com', 'q@a.com', 'r@a.com', 's@a.com', 't@a.com', 'u@a.com', 'v@a.com', 'w@a.com', 'x@a.com', 'y@a.com', 'z@a.com');
my @tokens = ('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 @tokens = ('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');
$schema->resultset('AccountToken')->populate([ $schema->resultset('AccountToken')->populate([
@ -33,8 +31,9 @@ $t->post_ok('/api/register' => json => $testJson)
#token missing JSON #token missing JSON
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'name' => shift(@names), 'full_name' => 'test name',
'email' => shift(@emails), 'display_name' => 'test name',
'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 3 'age_range' => 3
@ -44,13 +43,13 @@ $t->post_ok('/api/register' => json => $testJson)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/no token sent/i); ->content_like(qr/no token sent/i);
#Not valid token. #Not valid token.
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => ' ', 'token' => 'testing',
'name' => shift(@names), 'display_name' => 'test name',
'email' => shift(@emails), 'full_name' => 'test name',
'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 3 'age_range' => 3
@ -64,8 +63,23 @@ $t->post_ok('/api/register' => json => $testJson)
#name missing JSON #name missing JSON
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'a',
'email' => shift(@emails), 'full_name' => 'test name',
'email' => 'a@b.com',
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'age_range' => 3
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(400)
->json_is('/success', Mojo::JSON->false)
->content_like(qr/no name sent/i);
#name missing JSON
$testJson = {
'usertype' => 'customer',
'token' => 'a',
'display_name' => 'test name',
'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 3 'age_range' => 3
@ -75,13 +89,29 @@ $t->post_ok('/api/register' => json => $testJson)
->json_is('/success', Mojo::JSON->false) ->json_is('/success', Mojo::JSON->false)
->content_like(qr/no name sent/i); ->content_like(qr/no name sent/i);
#Blank name #Blank name
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'a',
'name' => '', 'display_name' => 'test name',
'email' => shift(@emails), 'full_name' => '',
'email' => 'a@b.com',
'postcode' => 'LA1 1AA',
'password' => 'Meh',
'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/name/i);
#Blank name
$testJson = {
'usertype' => 'customer',
'token' => 'a',
'display_name' => '',
'full_name' => 'test name',
'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 3 'age_range' => 3
@ -92,15 +122,14 @@ $t->post_ok('/api/register' => json => $testJson)
->content_like(qr/blank/i) ->content_like(qr/blank/i)
->content_like(qr/name/i); ->content_like(qr/name/i);
my $nameToReuse = shift(@names);
my $emailToReuse = shift(@emails);
#Valid customer #Valid customer
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'a',
'name' => $nameToReuse, 'full_name' => 'test name',
'email' => $emailToReuse, 'display_name' => 'test name',
'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 3 'age_range' => 3
@ -112,9 +141,10 @@ $t->post_ok('/api/register' => json => $testJson)
#Valid customer2 #Valid customer2
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'b',
'name' => shift(@names), 'full_name' => 'test name',
'email' => shift(@emails), 'display_name' => 'test name',
'email' => 'b@c.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 2 'age_range' => 2
@ -126,9 +156,10 @@ $t->post_ok('/api/register' => json => $testJson)
#Valid customer3 #Valid customer3
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'c',
'name' => shift(@names), 'full_name' => 'test name',
'email' => shift(@emails), 'display_name' => 'test name',
'email' => 'c@d.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 1 'age_range' => 1
@ -140,8 +171,9 @@ $t->post_ok('/api/register' => json => $testJson)
#email missing JSON #email missing JSON
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'd',
'name' => shift(@names), 'full_name' => 'test name',
'display_name' => 'test name',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 3 'age_range' => 3
@ -154,8 +186,9 @@ $t->post_ok('/api/register' => json => $testJson)
#invalid email 1 #invalid email 1
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'd',
'name' => shift(@names), 'full_name' => 'test name',
'display_name' => 'test name',
'email' => 'dfsd@.com', 'email' => 'dfsd@.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
@ -170,8 +203,9 @@ $t->post_ok('/api/register' => json => $testJson)
#invalid email 2 #invalid email 2
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'd',
'name' => shift(@names), 'full_name' => 'test name',
'display_name' => 'test name',
'email' => 'dfsd@com', 'email' => 'dfsd@com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
@ -186,9 +220,10 @@ $t->post_ok('/api/register' => json => $testJson)
#Email exists #Email exists
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'd',
'name' => shift(@names), 'full_name' => 'test name',
'email' => $emailToReuse, 'display_name' => 'test name',
'email' => 'a@b.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 2 'age_range' => 2
@ -202,9 +237,10 @@ $t->post_ok('/api/register' => json => $testJson)
#postcode missing JSON #postcode missing JSON
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'd',
'name' => shift(@names), 'full_name' => 'test name',
'email' => shift(@emails), 'display_name' => 'test name',
'email' => 'd@e.com',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 3 'age_range' => 3
}; };
@ -218,9 +254,10 @@ $t->post_ok('/api/register' => json => $testJson)
#password missing JSON #password missing JSON
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'd',
'name' => shift(@names), 'full_name' => 'test name',
'email' => shift(@emails), 'display_name' => 'test name',
'email' => 'd@e.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'age_range' => 3 'age_range' => 3
}; };
@ -233,9 +270,10 @@ $t->post_ok('/api/register' => json => $testJson)
#usertype missing JSON #usertype missing JSON
$testJson = { $testJson = {
'token' => shift(@tokens), 'token' => 'f',
'name' => shift(@names), 'full_name' => 'test name',
'email' => shift(@emails), 'display_name' => 'test name',
'email' => 'd@e.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 3 'age_range' => 3
@ -248,9 +286,9 @@ $t->post_ok('/api/register' => json => $testJson)
#Invalid user type #Invalid user type
$testJson = { $testJson = {
'usertype' => 'organisation1', 'usertype' => 'organisation1',
'token' => shift(@tokens), 'token' => 'f',
'name' => shift(@names), 'name' => 'test name',
'email' => shift(@emails), 'email' => 'org@org.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'fulladdress' => 'mary lane testing....' 'fulladdress' => 'mary lane testing....'
@ -265,9 +303,10 @@ $t->post_ok('/api/register' => json => $testJson)
#age_range missing JSON #age_range missing JSON
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'f',
'name' => shift(@names), 'display_name' => 'test name',
'email' => shift(@emails), 'full_name' => 'test name',
'email' => 'broke@example.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
}; };
@ -279,9 +318,10 @@ $t->post_ok('/api/register' => json => $testJson)
#Age is invalid #Age is invalid
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@tokens), 'token' => 'f',
'name' => shift(@names), 'full_name' => 'test name',
'email' => shift(@emails), 'display_name' => 'test name',
'email' => 'test@example.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'age_range' => 'invalid' 'age_range' => 'invalid'
@ -295,9 +335,9 @@ $t->post_ok('/api/register' => json => $testJson)
#full address missing JSON #full address missing JSON
$testJson = { $testJson = {
'usertype' => 'organisation', 'usertype' => 'organisation',
'token' => shift(@tokens), 'token' => 'f',
'name' => shift(@names), 'name' => 'test org',
'email' => shift(@emails), 'email' => 'org@org.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
}; };
@ -311,9 +351,9 @@ $t->post_ok('/api/register' => json => $testJson)
#Organisation valid #Organisation valid
$testJson = { $testJson = {
'usertype' => 'organisation', 'usertype' => 'organisation',
'token' => shift(@tokens), 'token' => 'f',
'name' => shift(@names), 'name' => 'org name',
'email' => shift(@emails), 'email' => 'org@org.com',
'postcode' => 'LA1 1AA', 'postcode' => 'LA1 1AA',
'password' => 'Meh', 'password' => 'Meh',
'street_name' => 'mary lane testing....', 'street_name' => 'mary lane testing....',

View file

@ -31,7 +31,8 @@ my $passwordRufus = 'MakoGold';
my $testJson = { my $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@account_tokens), 'token' => shift(@account_tokens),
'name' => 'RufusShinra', 'full_name' => 'RufusShinra',
'display_name' => 'RufusShinra',
'email' => $emailRufus, 'email' => $emailRufus,
'postcode' => 'RG26 5NU', 'postcode' => 'RG26 5NU',
'password' => $passwordRufus, 'password' => $passwordRufus,

View file

@ -38,7 +38,8 @@ my $passwordRufus = 'MakoGold';
my $testJson = { my $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@account_tokens), 'token' => shift(@account_tokens),
'name' => 'RufusShinra', 'full_name' => 'RufusShinra',
'display_name' => 'RufusShinra',
'email' => $emailRufus, 'email' => $emailRufus,
'postcode' => 'GU10 5SA', 'postcode' => 'GU10 5SA',
'password' => $passwordRufus, 'password' => $passwordRufus,
@ -54,7 +55,8 @@ my $passwordHojo = 'Mako';
$testJson = { $testJson = {
'usertype' => 'customer', 'usertype' => 'customer',
'token' => shift(@account_tokens), 'token' => shift(@account_tokens),
'name' => 'ProfessorHojo', 'display_name' => 'ProfessorHojo',
'full_name' => 'ProfessorHojo',
'email' => $emailHojo, 'email' => $emailHojo,
'postcode' => 'DE15 9LT', 'postcode' => 'DE15 9LT',
'password' => $passwordHojo, 'password' => $passwordHojo,