2017-04-23 16:59:35 +01:00
use Mojo::Base - strict ;
use Test::More ;
use Mojo::JSON ;
use Test::Pear::LocalLoop ;
use DateTime ;
my $ framework = Test::Pear::LocalLoop - > new ;
my $ t = $ framework - > framework ;
my $ schema = $ t - > app - > schema ;
my $ account_token = 'a' ;
my $ email = 'test@example.com' ;
my $ password = 'abc123' ;
$ schema - > resultset ( 'AccountToken' ) - > create ( {
name = > $ account_token
} ) ;
$ framework - > register_customer ( {
'token' = > $ account_token ,
2017-04-25 21:44:13 +01:00
'full_name' = > 'Test User' ,
2017-07-27 14:18:22 +01:00
'display_name' = > 'Testing User' ,
2017-04-23 16:59:35 +01:00
'email' = > $ email ,
'postcode' = > 'LA1 1AA' ,
'password' = > $ password ,
2017-06-13 21:28:42 +01:00
year_of_birth = > 2006
2017-04-23 16:59:35 +01:00
} ) ;
my $ session_key = $ framework - > login ( {
email = > $ email ,
password = > $ password ,
} ) ;
2017-07-27 14:18:22 +01:00
$ t - > post_ok ( '/api/user' , json = > { session_key = > $ session_key } )
- > status_is ( 200 ) - > or ( $ framework - > dump_error )
- > json_is ( {
success = > Mojo::JSON - > true ,
full_name = > 'Test User' ,
display_name = > 'Testing User' ,
email = > $ email ,
postcode = > 'LA1 1AA' ,
2017-10-03 15:33:43 +01:00
location = > {
latitude = > undef ,
longitude = > undef ,
} ,
2017-07-27 14:18:22 +01:00
} ) ;
#with wrong password
$ t - > post_ok ( '/api/user/account' , json = > {
session_key = > $ session_key ,
full_name = > 'Test User 2' ,
display_name = > 'Testing User 2' ,
email = > 'test50@example.com' ,
postcode = > 'LA1 1AB' ,
password = > 'abc12431' ,
} )
- > status_is ( 401 ) - > or ( $ framework - > dump_error )
- > json_is ( {
success = > Mojo::JSON - > false ,
message = > 'password is invalid.' ,
} ) ;
# With valid details
$ t - > post_ok ( '/api/user/account' , json = > {
session_key = > $ session_key ,
full_name = > 'Test User 2' ,
display_name = > 'Testing User 2' ,
email = > 'test50@example.com' ,
postcode = > 'LA1 1AB' ,
password = > $ password ,
} )
- > status_is ( 200 ) - > or ( $ framework - > dump_error )
- > json_is ( {
success = > Mojo::JSON - > true ,
message = > 'Edited Account Successfully' ,
} ) ;
$ t - > post_ok ( '/api/user' , json = > { session_key = > $ session_key } )
- > status_is ( 200 ) - > or ( $ framework - > dump_error )
- > json_is ( {
success = > Mojo::JSON - > true ,
full_name = > 'Test User 2' ,
display_name = > 'Testing User 2' ,
email = > 'test50@example.com' ,
postcode = > 'LA1 1AB' ,
2017-10-03 15:33:43 +01:00
location = > {
latitude = > undef ,
longitude = > undef ,
} ,
2017-07-27 14:18:22 +01:00
} ) ;
$ t - > post_ok ( '/api/user/account' , json = > {
session_key = > $ session_key ,
full_name = > 'Test User 3' ,
display_name = > 'Testing User 3' ,
email = > 'test60@example.com' ,
postcode = > 'LA1 1AD' ,
password = > $ password ,
new_password = > 'abc124' ,
} )
- > status_is ( 200 ) - > or ( $ framework - > dump_error )
- > json_is ( {
success = > Mojo::JSON - > true ,
message = > 'Edited Account Successfully' ,
} ) ;
$ t - > post_ok ( '/api/user' , json = > { session_key = > $ session_key } )
- > status_is ( 200 ) - > or ( $ framework - > dump_error )
- > json_is ( {
success = > Mojo::JSON - > true ,
full_name = > 'Test User 3' ,
display_name = > 'Testing User 3' ,
email = > 'test60@example.com' ,
postcode = > 'LA1 1AD' ,
2017-10-03 15:33:43 +01:00
location = > {
latitude = > undef ,
longitude = > undef ,
} ,
2017-07-27 14:18:22 +01:00
} ) ;
$ session_key = $ framework - > login ( {
email = > 'test60@example.com' ,
password = > 'abc124' ,
} ) ;
2017-04-23 16:59:35 +01:00
done_testing ;