-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dave Cross
committed
Aug 20, 2019
1 parent
eced7fd
commit 7eaffab
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use Plack::Test; | ||
use HTTP::Request::Common; | ||
use JSON; | ||
|
||
use lib 'lib'; | ||
use Lystyng; | ||
use Lystyng::Schema; | ||
|
||
my $app = Lystyng->to_app; | ||
my $test = Plack::Test->create($app); | ||
|
||
my $sch = eval { Lystyng::Schema->get_schema }; | ||
BAIL_OUT($@) if $@; | ||
|
||
my $test_user_data = { | ||
username => 'test', | ||
name => 'Test User', | ||
email => 'test@example.com', | ||
password => 'TEST', | ||
password2 => 'TEST', | ||
}; | ||
|
||
# Ensure test user doesn't exist | ||
my $test_user = $sch->resultset('User')->find({ | ||
username => $test_user_data->{username}, | ||
}); | ||
$test_user->delete if $test_user; | ||
|
||
my $res = $test->request(POST '/register', | ||
Content_type => 'application/json', | ||
Content => encode_json($test_user_data), | ||
); | ||
|
||
my $user = $sch->resultset('User')->find({ | ||
username => $test_user_data->{username}, | ||
}); | ||
|
||
$res = $test->request(POST "/user/$test_user_data->{username}/list/add", | ||
Content_type => 'application/json', | ||
Content => encode_json({ | ||
title => 'Test List', | ||
slug => 'test_list', | ||
description => 'A test list', | ||
}), | ||
); | ||
|
||
ok($res, 'Got a response from adding a list'); | ||
is($res->code, 200, 'Status is 200'); | ||
|
||
my $list = $user->lists->first; | ||
|
||
my $url = "/user/$test_user_data->{username}/list/test_list/item"; | ||
$res = $test->request(POST $url, | ||
Content_type => 'application/json', | ||
Content => encode_json({ | ||
seq_no => 1, | ||
title => 'Test List Item', | ||
description => 'A test list item', | ||
}), | ||
); | ||
|
||
ok($res, 'Got a response from adding a list item'); | ||
is($res->code, 200, 'Status is 200'); | ||
|
||
$res = $test->request(GET "/user/$test_user_data->{username}/list/test_list"); | ||
|
||
ok($res, 'Got a response from getting a list'); | ||
is($res->code, 200, 'Status is 200'); | ||
|
||
# Clean up after ourselves | ||
$_->list_items->delete for $user->lists; | ||
$user->lists->delete; | ||
$user->delete; | ||
|
||
done_testing; |