aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/MapIt.pm36
-rw-r--r--t/cobrand/fixamingata.t23
2 files changed, 59 insertions, 0 deletions
diff --git a/t/MapIt.pm b/t/MapIt.pm
new file mode 100644
index 000000000..ebef934e1
--- /dev/null
+++ b/t/MapIt.pm
@@ -0,0 +1,36 @@
+package t::MapIt;
+
+use JSON;
+use Web::Simple;
+
+use mySociety::Locale;
+
+has json => (
+ is => 'lazy',
+ default => sub {
+ JSON->new->pretty->allow_blessed->convert_blessed;
+ },
+);
+
+sub dispatch_request {
+ my $self = shift;
+
+ sub (GET + /postcode/*) {
+ my ($self, $postcode) = @_;
+ my $response = $self->postcode($postcode);
+ # We must make sure we output correctly for testing purposes, we might
+ # be within a different locale here...
+ my $json = mySociety::Locale::in_gb_locale {
+ $self->json->encode($response) };
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
+}
+
+sub postcode {
+ my ($self, $postcode) = @_;
+ return {
+ wgs84_lat => 51.5, wgs84_lon => 2.1, postcode => $postcode,
+ };
+}
+
+__PACKAGE__->run_if_script;
diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t
index 105847576..714d475e1 100644
--- a/t/cobrand/fixamingata.t
+++ b/t/cobrand/fixamingata.t
@@ -1,12 +1,16 @@
use strict;
use warnings;
use Test::More;
+use LWP::Protocol::PSGI;
BEGIN {
use FixMyStreet;
FixMyStreet->test_mode(1);
}
+use t::MapIt;
+use mySociety::Locale;
+
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -96,6 +100,25 @@ like $email->header('Content-Type'), qr/iso-8859-1/, 'encoding looks okay';
like $email->body, qr/V=E4nligen,/, 'signature looks correct';
$mech->clear_emails_ok;
+subtest "Test ajax decimal points" => sub {
+ # The following line is so we are definitely not in Swedish before
+ # requesting the page, so that the code performs a full switch to Swedish
+ mySociety::Locale::push('en-gb');
+
+ # A note to the future - the run_if_script line must be within a subtest
+ # otherwise it fails to work
+ LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.sweden');
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixamingata' ],
+ MAPIT_URL => 'http://mapit.sweden/'
+ }, sub {
+ $mech->get_ok('/ajax/lookup_location?term=12345');
+ # We want an actual decimal point in a JSON response...
+ $mech->content_contains('51.5');
+ };
+};
+
END {
$mech->delete_problems_for_body(1);
ok $mech->host("www.fixmystreet.com"), "change host back";