aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/json.t
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-05-20 17:33:34 +0100
committerEdmund von der Burg <evdb@mysociety.org>2011-05-20 17:33:34 +0100
commit1e67ddbedf6481e3e8650a498679eafd710230ca (patch)
treefc7710f6df69f03a4474e366e76bfce18a14a0fb /t/app/controller/json.t
parenta10e70f9acb9a7e95698ef361b8b3a412d160521 (diff)
port json.cgi code to Catalyst
Diffstat (limited to 't/app/controller/json.t')
-rw-r--r--t/app/controller/json.t75
1 files changed, 74 insertions, 1 deletions
diff --git a/t/app/controller/json.t b/t/app/controller/json.t
index e5fda5d27..2c9ff4a61 100644
--- a/t/app/controller/json.t
+++ b/t/app/controller/json.t
@@ -6,9 +6,10 @@ use Test::More;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
-subtest "check that a bad request produces the right response" => sub {
+subtest "check that a bad request produces the appropriate response" => sub {
my $bad_date = "Invalid dates supplied";
+ my $mad_date = "Start date after end date";
my $bad_type = "Invalid type supplied";
my %tests = (
@@ -20,6 +21,8 @@ subtest "check that a bad request produces the right response" => sub {
'type=&start_date=2000-02-31&end_date=2000-02-01' => $bad_date,
'type=&start_date=2000-01-01&end_date=2000-02-31' => $bad_date,
+ 'type=&start_date=2000-02-01&end_date=2000-01-01' => $mad_date,
+
'type=&start_date=2000-01-01&end_date=2000-02-01' => $bad_type,
'type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type,
);
@@ -33,4 +36,74 @@ subtest "check that a bad request produces the right response" => sub {
};
+is_deeply #
+ $mech->get_ok_json(
+ "/json?type=new_problems&start_date=2000-01-01&end_date=2000-02-01"), #
+ [], #
+ "correct response";
+
+# put an entry in the database for this test
+my $user = $mech->create_user_ok('test@example.com');
+
+my $problem_args = {
+ postcode => 'sw1a 1aa',
+ council => '2501',
+ areas => ',105164,11806,11827,2247,2501,34817,42011,66045,70786,8519,',
+ category => 'test category',
+ title => 'Test title',
+ detail => 'Test detail',
+ used_map => 't',
+ name => 'Test Name',
+ created => '2000-01-01 12:00:00',
+ confirmed => '2000-01-01 12:01:00',
+ state => 'confirmed',
+ lang => 'en-gb',
+ service => '',
+ cobrand => '',
+ cobrand_data => '',
+ lastupdate => '2000-01-01 12:00:00',
+ whensent => undef,
+ send_questionnaire => 't',
+ latitude => '51.4531988729771',
+ longitude => '-0.23021896608596',
+};
+my $problem = $user->add_to_problems( { %$problem_args, anonymous => 0 } );
+my $anon_problem = $user->add_to_problems( { %$problem_args, anonymous => 1 } );
+
+ok $problem, "created normal test problem";
+ok $anon_problem, "created anon test problem";
+
+is_deeply #
+ $mech->get_ok_json(
+ "/json?type=new_problems&start_date=2000-01-01&end_date=2000-02-01"), #
+ [
+ {
+ 'anonymous' => 0,
+ 'category' => 'test category',
+ 'confirmed' => '2000-01-01 12:01:00',
+ 'council' => 'Wandsworth Borough Council',
+ 'detail' => 'Test detail',
+ 'id' => $problem->id,
+ 'name' => 'Test Name',
+ 'service' => 'Web interface',
+ 'title' => 'Test title',
+ 'whensent' => undef
+ },
+ {
+ 'anonymous' => 1,
+ 'category' => 'test category',
+ 'confirmed' => '2000-01-01 12:01:00',
+ 'council' => 'Wandsworth Borough Council',
+ 'detail' => 'Test detail',
+ 'id' => $anon_problem->id,
+ 'name' => '',
+ 'service' => 'Web interface',
+ 'title' => 'Test title',
+ 'whensent' => undef
+ }
+ ],
+ "correct response";
+
+$mech->delete_user($user);
+
done_testing();