aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/json.t
blob: e5fda5d27c219224040cd0089413c45026f76723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;

use Test::More;

use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;

subtest "check that a bad request produces the right response" => sub {

    my $bad_date = "Invalid dates supplied";
    my $bad_type = "Invalid type supplied";

    my %tests = (
        ''                                                => $bad_date,
        'foo=bar'                                         => $bad_date,
        'type=&start_date=&end_date='                     => $bad_date,
        'type=&start_date=bad&end_date=2000-02-01'        => $bad_date,
        'type=&start_date=2000-01-01&end_date=bad'        => $bad_date,
        '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-01-01&end_date=2000-02-01'    => $bad_type,
        'type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type,
    );

    foreach my $q ( sort keys %tests ) {
        is_deeply                            #
          $mech->get_ok_json("/json?$q"),    #
          { error => $tests{$q} },           #
          "correct error for query '$q'";
    }

};

done_testing();