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/v1/supplier/location.t

93 lines
2.1 KiB
Perl
Raw Permalink Normal View History

2017-09-27 17:01:06 +00:00
use Mojo::Base -strict;
use FindBin qw/ $Bin /;
use Test::More;
use Mojo::JSON;
use Test::Pear::LocalLoop;
use DateTime;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/../../../etc",
);
$framework->install_fixtures('full');
my $t = $framework->framework;
my $schema = $t->app->schema;
my $session_key = $framework->login({
email => 'org1@example.com',
password => 'abc123',
});
$t->post_ok('/api/upload' => json => {
transaction_value => 10,
transaction_type => 1,
purchase_time => "2017-08-14T11:29:07.965+01:00",
organisation_id => 2,
session_key => $session_key,
})
->status_is(200)
->json_is('/success', Mojo::JSON->true);
# Rough area around Lancaster
$t->post_ok('/api/v1/supplier/location' => json => {
session_key => $session_key,
north_east => {
latitude => 54.077665,
longitude => -2.761860,
},
south_west => {
latitude => 54.013361,
longitude => -2.857647,
},
})
->status_is(200)->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true)
->json_is('/suppliers', [
{
name => 'Test Org 2',
latitude => 54.04679,
longitude => -2.7963,
street_name => 'Test Street',
town => 'Lancaster',
postcode => 'LA1 1AG',
2017-09-27 17:01:06 +00:00
},
])
->json_is('/self', {
latitude => 54.04725,
longitude => -2.79611,
});
# Association pin
$t->post_ok('/api/v1/supplier/location/trail' => json => {
2017-11-27 17:17:22 +00:00
session_key => $session_key,
north_east => {
latitude => 54.077665,
longitude => -2.761860,
},
south_west => {
latitude => 54.013361,
longitude => -2.857647,
},
association => 'lis',
2017-11-27 17:17:22 +00:00
})
->status_is(200)->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true)
->json_is('/locations', [
{
name => 'Test Org 2',
latitude => 54.04679,
longitude => -2.7963,
street_name => 'Test Street',
town => 'Lancaster',
postcode => 'LA1 1AG',
},
])
->json_is('/self', {
latitude => 54.04725,
longitude => -2.79611,
});
2017-09-27 17:01:06 +00:00
done_testing;