aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Mock/Bing.pm30
-rw-r--r--t/geocode/bing.t24
2 files changed, 54 insertions, 0 deletions
diff --git a/t/Mock/Bing.pm b/t/Mock/Bing.pm
index 3dfb8fbe0..77045950f 100644
--- a/t/Mock/Bing.pm
+++ b/t/Mock/Bing.pm
@@ -14,6 +14,36 @@ has json => (
sub dispatch_request {
my $self = shift;
+ sub (GET + /REST/v1/Locations + ?*) {
+ my ($self, $query) = @_;
+ my $results = [ {
+ point => { coordinates => [ 51, -1 ] },
+ name => 'Constitution Hill, London, SW1A',
+ address => {
+ addressLine => 'Constitution Hill',
+ locality => 'London',
+ countryRegion => 'United Kingdom',
+ }
+ } ];
+ if ($query->{q} =~ /two results/) {
+ push @$results, {
+ point => { coordinates => [ 51, -1 ] },
+ name => 'Constitution Hill again, United Kingdom',
+ address => {
+ addressLine => 'Constitution Hill again',
+ locality => 'London',
+ countryRegion => 'United Kingdom',
+ }
+ };
+ }
+ my $data = {
+ statusCode => 200,
+ resourceSets => [ { resources => $results } ],
+ };
+ my $json = $self->json->encode($data);
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
+
sub (GET + /REST/v1/Locations/* + ?*) {
my ($self, $location, $query) = @_;
my $data = {
diff --git a/t/geocode/bing.t b/t/geocode/bing.t
new file mode 100644
index 000000000..32cffaa4e
--- /dev/null
+++ b/t/geocode/bing.t
@@ -0,0 +1,24 @@
+use FixMyStreet::Test;
+use FixMyStreet::Geocode::Bing;
+use Catalyst::Test 'FixMyStreet::App';
+use t::Mock::Bing;
+
+my $c = ctx_request('/');
+
+FixMyStreet::override_config {
+ GEOCODING_DISAMBIGUATION => { bing_culture => 'en-GB' }
+}, sub {
+ my $r = FixMyStreet::Geocode::Bing->string('a result', $c);
+ ok $r->{latitude};
+ ok $r->{longitude};
+};
+
+FixMyStreet::override_config {
+ GEOCODING_DISAMBIGUATION => { bing_country => 'United Kingdom' }
+}, sub {
+ my $r = FixMyStreet::Geocode::Bing->string('two results', $c);
+ is scalar @{$r->{error}}, 2;
+ is $r->{error}[1]{address}, 'Constitution Hill again, London';
+};
+
+done_testing;