Refactor api login test

This commit is contained in:
Tom Bloor 2017-08-25 15:14:43 +01:00
parent 4a4c568fb7
commit 768cc38410

View file

@ -8,28 +8,22 @@ my $framework = Test::Pear::LocalLoop->new;
my $t = $framework->framework; my $t = $framework->framework;
my $schema = $t->app->schema; my $schema = $t->app->schema;
my $account_token = 'a'; my $user = {
my $email = 'rufus@shinra.energy'; token => 'a',
my $password = 'MakoGold'; usertype => 'customer',
display_name => 'Display Guy',
$schema->resultset('AccountToken')->create({ full_name => 'Real Name',
name => $account_token email => 'test@example.com',
}); postcode => 'LA1 1AA',
password => 'testerising',
my $test_json = { year_of_birth => 2006,
'usertype' => 'customer',
'token' => $account_token,
'display_name' => 'RufusShinra',
'full_name' => 'RufusShinra',
'email' => $email,
'postcode' => 'LA1 1AA',
'password' => $password,
year_of_birth => 2006
}; };
$t->post_ok('/api/register' => json => $test_json)
$schema->resultset('AccountToken')->create({ name => $user->{token} });
$t->post_ok('/api/register' => json => $user)
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
use Data::Dumper;
is $schema->resultset('User')->count, 1, 'found a user'; is $schema->resultset('User')->count, 1, 'found a user';
@ -48,8 +42,8 @@ $t->post_ok('/api/login' => json => {
->json_is('/success', Mojo::JSON->false); ->json_is('/success', Mojo::JSON->false);
$t->post_ok('/api/login' => json => { $t->post_ok('/api/login' => json => {
email => $email, email => $user->{email},
password => $password, password => $user->{password},
}) })
->status_is(200) ->status_is(200)
->json_is('/success', Mojo::JSON->true) ->json_is('/success', Mojo::JSON->true)