From 414acd76fb09ebd033b54a19cc5397dc2c3e1047 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 18 Sep 2017 11:11:53 +0100 Subject: [PATCH 1/4] Transaction API errors improved --- lib/Pear/LocalLoop/Controller/Api/Upload.pm | 25 ++++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Upload.pm b/lib/Pear/LocalLoop/Controller/Api/Upload.pm index e7ae0d5..0a75f3f 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Upload.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Upload.pm @@ -54,13 +54,13 @@ has error_messages => sub { in => { message => 'transaction_type is not a valid value.', status => 400 }, }, transaction_value => { - required => { message => 'transaction_value is missing', status => 400 }, - number => { message => 'transaction_value does not look like a number', status => 400 }, - gt_num => { message => 'transaction_value cannot be equal to or less than zero', status => 400 }, + required => { message => 'transaction amount is missing', status => 400 }, + number => { message => 'transaction amount does not look like a number', status => 400 }, + gt_num => { message => 'transaction amount cannot be equal to or less than zero', status => 400 }, }, purchase_time => { - required => { message => 'purchase_time is missing', status => 400 }, - is_full_iso_datetime => { message => 'purchase_time is in incorrect format', status => 400 }, + required => { message => 'purchase time is missing', status => 400 }, + is_full_iso_datetime => { message => 'purchase time is in incorrect format', status => 400 }, }, file => { required => { message => 'No file uploaded', status => 400 }, @@ -68,15 +68,18 @@ has error_messages => sub { filetype => { message => 'File must be of type image/jpeg', status => 400 }, }, organisation_id => { - required => { message => 'organisation_id is missing', status => 400 }, - number => { message => 'organisation_id is not a number', status => 400 }, - in_resultset => { message => 'organisation_id does not exist in the database', status => 400 }, + required => { message => 'existing organisation ID is missing', status => 400 }, + number => { message => 'organisation ID is not a number', status => 400 }, + in_resultset => { message => 'organisation ID does not exist in the database', status => 400 }, }, organisation_name => { - required => { message => 'organisation_name is missing', status => 400 }, + required => { message => 'organisation name is missing', status => 400 }, + }, + town => { + required => { message => 'town/city is missing', status => 400 }, }, search_name => { - required => { message => 'search_name is missing', status => 400 }, + required => { message => 'search name is missing', status => 400 }, }, postcode => { required => { message => 'postcode is missing', status => 400 }, @@ -139,7 +142,7 @@ sub post_upload { # Unknown Organisation $validation->required('organisation_name'); $validation->optional('street_name'); - $validation->optional('town'); + $validation->required('town'); $validation->optional('postcode')->postcode; return $c->api_validation_error if $validation->has_error; From dd36cd0c0c68ffd4f13bb2cd954f73567a633164 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 18 Sep 2017 11:31:57 +0100 Subject: [PATCH 2/4] Feedback API error improved --- lib/Pear/LocalLoop/Controller/Api/Feedback.pm | 2 +- lib/Pear/LocalLoop/Controller/Api/Upload.pm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Feedback.pm b/lib/Pear/LocalLoop/Controller/Api/Feedback.pm index eafce88..f33eaec 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Feedback.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Feedback.pm @@ -5,7 +5,7 @@ has error_messages => sub { return { email => { required => { message => 'Email is required', status => 400 }, - in_resultset => { message => 'Change meeee', status => 400 }, + in_resultset => { message => 'Email does not exist in database', status => 400 }, }, feedbacktext => { required => { message => 'Feedback is required', status => 400 }, diff --git a/lib/Pear/LocalLoop/Controller/Api/Upload.pm b/lib/Pear/LocalLoop/Controller/Api/Upload.pm index 0a75f3f..f921d11 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Upload.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Upload.pm @@ -50,8 +50,8 @@ The postcode of an organisation, optional key. Used when transaction_Type is 3. has error_messages => sub { return { transaction_type => { - required => { message => 'transaction_type is missing.', status => 400 }, - in => { message => 'transaction_type is not a valid value.', status => 400 }, + required => { message => 'transaction type is missing.', status => 400 }, + in => { message => 'transaction type is not a valid value.', status => 400 }, }, transaction_value => { required => { message => 'transaction amount is missing', status => 400 }, From 9e56383b4600b07c7b0edbfc47a51549889bc659 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 18 Sep 2017 11:34:22 +0100 Subject: [PATCH 3/4] User and Register API errors improved --- lib/Pear/LocalLoop/Controller/Api/Register.pm | 20 +++++++++---------- lib/Pear/LocalLoop/Controller/Api/User.pm | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Register.pm b/lib/Pear/LocalLoop/Controller/Api/Register.pm index 8ba4f11..822087d 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Register.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Register.pm @@ -9,18 +9,18 @@ has error_messages => sub { in_resultset => { message => 'Token invalid or has been used.', status => 401 }, }, name => { - required => { message => 'No name sent or was blank.', status => 400 }, + required => { message => 'No organisation name sent or was blank.', status => 400 }, }, display_name => { - required => { message => 'No name sent or was blank.', status => 400 }, + required => { message => 'No display name sent or was blank.', status => 400 }, }, full_name => { - required => { message => 'No name sent or was blank.', status => 400 }, + required => { message => 'No full name sent or was blank.', status => 400 }, }, email => { required => { message => 'No email sent.', status => 400 }, email => { message => 'Email is invalid.', status => 400 }, - not_in_resultset => { message => 'Email exists.', status => 403 }, + not_in_resultset => { message => 'Email already in use.', status => 403 }, }, postcode => { required => { message => 'No postcode sent.', status => 400 }, @@ -34,16 +34,16 @@ has error_messages => sub { in => { message => '"usertype" is invalid.', status => 400 }, }, year_of_birth => { - required => { message => 'No year_of_birth sent.', status => 400 }, - number => { message => 'year_of_birth is invalid', status => 400 }, - gt_num => { message => 'year_of_birth must be within last 150 years', status => 400 }, - lt_num => { message => 'year_of_birth must be atleast 10 years ago', status => 400 }, + required => { message => 'No year of birth sent.', status => 400 }, + number => { message => 'year of birth is invalid', status => 400 }, + gt_num => { message => 'year of birth must be within last 150 years', status => 400 }, + lt_num => { message => 'year of birth must be atleast 10 years ago', status => 400 }, }, street_name => { - required => { message => 'No street_name sent.', status => 400 }, + required => { message => 'No street name sent.', status => 400 }, }, town => { - required => { message => 'No town sent.', status => 400 }, + required => { message => 'No town/city sent.', status => 400 }, }, }; }; diff --git a/lib/Pear/LocalLoop/Controller/Api/User.pm b/lib/Pear/LocalLoop/Controller/Api/User.pm index 0c0a2f3..d85e2d8 100644 --- a/lib/Pear/LocalLoop/Controller/Api/User.pm +++ b/lib/Pear/LocalLoop/Controller/Api/User.pm @@ -28,10 +28,10 @@ has error_messages => sub { required => { message => 'No password sent.', status => 400 }, }, street_name => { - required => { message => 'No street_name sent.', status => 400 }, + required => { message => 'No street name sent.', status => 400 }, }, town => { - required => { message => 'No town sent.', status => 400 }, + required => { message => 'No town/city sent.', status => 400 }, }, sector => { required => { message => 'No sector sent.', status => 400 }, From 5b3ef1bf2781f2c84b36f247e50f25436afe1e0c Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 18 Sep 2017 12:05:30 +0100 Subject: [PATCH 4/4] Tests fixed --- t/api/register.t | 12 ++++++------ t/api/upload.t | 28 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/t/api/register.t b/t/api/register.t index 203cde4..fd16642 100644 --- a/t/api/register.t +++ b/t/api/register.t @@ -73,7 +73,7 @@ $testJson = { $t->post_ok('/api/register' => json => $testJson) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/no name sent/i); + ->content_like(qr/no display name sent/i); #name missing JSON $testJson = { 'usertype' => 'customer', @@ -87,7 +87,7 @@ $testJson = { $t->post_ok('/api/register' => json => $testJson) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/no name sent/i); + ->content_like(qr/no full name sent/i); #Blank name $testJson = { @@ -235,7 +235,7 @@ $t->post_ok('/api/register' => json => $testJson) ->status_is(403) ->json_is('/success', Mojo::JSON->false) ->content_like(qr/email/i) - ->content_like(qr/exists/i); + ->content_like(qr/already in use/i); #postcode missing JSON $testJson = { @@ -315,7 +315,7 @@ $testJson = { $t->post_ok('/api/register' => json => $testJson) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/no year_of_birth sent/i); + ->content_like(qr/no year of birth sent/i); #Age is invalid $testJson = { @@ -331,7 +331,7 @@ $testJson = { $t->post_ok('/api/register' => json => $testJson) ->status_is(400) ->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); #full address missing JSON @@ -347,7 +347,7 @@ $testJson = { $t->post_ok('/api/register' => json => $testJson) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/no street_name sent/i); + ->content_like(qr/no street name sent/i); #TODO Validation of full address diff --git a/t/api/upload.t b/t/api/upload.t index 74b3409..0522345 100644 --- a/t/api/upload.t +++ b/t/api/upload.t @@ -123,7 +123,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/transaction_value is missing/i); + ->content_like(qr/transaction amount is missing/i); print "test 7 - transaction_value non-numbers\n"; $json = { @@ -137,7 +137,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/transaction_value does not look like a number/i); + ->content_like(qr/transaction amount does not look like a number/i); print "test 8 - transaction_value equal to zero\n"; $json = { @@ -151,7 +151,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/transaction_value cannot be equal to or less than zero/i); + ->content_like(qr/transaction amount cannot be equal to or less than zero/i); print "test 9 - transaction_value less than zero\n"; $json = { @@ -165,7 +165,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/transaction_value cannot be equal to or less than zero/i); + ->content_like(qr/transaction amount cannot be equal to or less than zero/i); print "test 10 - transaction_type missing\n"; $json = { @@ -177,7 +177,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/transaction_type is missing/i); + ->content_like(qr/transaction type is missing/i); print "test 11 - transaction_type invalid.\n"; $json = { @@ -191,7 +191,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/transaction_type is not a valid value/i); + ->content_like(qr/transaction type is not a valid value/i); print "test 12 - file not uploaded.\n"; $json = { @@ -220,7 +220,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/organisation_id is missing/i); + ->content_like(qr/organisation ID is missing/i); print "test 14 - organisation_id for non-existent id. (type 1: already validated)\n"; $json = { @@ -234,7 +234,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/organisation_id does not exist in the database/i); + ->content_like(qr/organisation ID does not exist in the database/i); print "test 15 - valid addition. (type 1: already validated)\n"; is $schema->resultset('Transaction')->count, 1, "1 transaction"; @@ -268,7 +268,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/organisation_name is missing/i); + ->content_like(qr/organisation name is missing/i); print "test 17 - add valid transaction (type 3: new organisation)\n"; is $schema->resultset('Organisation')->search({ pending => 1 })->count, 0, "No pending organisations"; @@ -306,7 +306,7 @@ $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->or($framework->dump_error) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/organisation_id is missing/i); + ->content_like(qr/organisation ID is missing/i); print "test 19 - organisation_id not a number (type 2: existing organisation)\n"; $json = { @@ -320,7 +320,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/organisation_id is not a number/i); + ->content_like(qr/organisation ID is not a number/i); print "test 20 - id does not exist (type 2: existing organisation)\n"; $json = { @@ -334,7 +334,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/organisation_id does not exist in the database/i); + ->content_like(qr/organisation ID does not exist in the database/i); print "test 21 - purchase_time is missing\n"; is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions"; @@ -385,7 +385,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/organisation_id does not exist in the database/i); + ->content_like(qr/organisation ID does not exist in the database/i); is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions"; print "test 25 - Logout Hojo\n"; @@ -475,7 +475,7 @@ $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jp $t->post_ok('/api/upload' => form => $upload ) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->json_like('/message', qr/organisation_id does not exist in the database/); + ->json_like('/message', qr/organisation ID does not exist in the database/); is $schema->resultset('Transaction')->count, 6, "6 transaction"; done_testing();