This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/t/api/user.t

58 lines
1.4 KiB
Perl
Raw Normal View History

2017-04-23 15:59:35 +00: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,
'full_name' => 'Test User',
'display_name' => 'Test User',
2017-04-23 15:59:35 +00:00
'email' => $email,
'postcode' => 'LA1 1AA',
'password' => $password,
'age_range' => 1
});
my $session_key = $framework->login({
email => $email,
password => $password,
});
my $json_no_date = { session_key => $session_key };
$t->post_ok('/api/user/day', json => $json_no_date)
->status_is(200)
->json_is('/success', Mojo::JSON->true);
my $json_invalid_date = {
session_key => $session_key,
day => 'invalid',
};
$t->post_ok('/api/user/day', json => $json_invalid_date)
->status_is(400)->or($framework->dump_error)
->json_is('/success', Mojo::JSON->false)
->json_like('/message', qr/Invalid ISO8601 Datetime/);
my $json_valid_date = {
session_key => $session_key,
day => $t->app->datetime_formatter->format_datetime(DateTime->now),
};
$t->post_ok('/api/user/day', json => $json_valid_date)
->status_is(200)->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true);
done_testing;