aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/report_new_update.t
blob: e20975c3a7b05e80bc2b1c0f8b98740e1668d329 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use FixMyStreet::TestMech;
use FixMyStreet::Script::Alerts;

# disable info logs for this test run
FixMyStreet::App->log->disable('info');
END { FixMyStreet::App->log->enable('info'); }

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

my $comment_user = $mech->create_user_ok('systemuser@example.org', name => 'Glos Council');
my $body = $mech->create_body_ok(2226, 'Gloucestershire County Council', {
    comment_user => $comment_user,
});

$mech->create_contact_ok(
    body_id => $body->id,
    category => 'Potholes',
    email => 'potholes@example.com',
);

my $user = $mech->log_in_ok('test-2@example.com');

subtest "test report creation with no initial auto-update" => sub {
    my $report = make_report();
    my $comment = FixMyStreet::DB->resultset('Comment')->count;
    is $comment, 0, 'No comments left';
    $report->delete;
};

my $template = FixMyStreet::DB->resultset("ResponseTemplate")->create({
    body => $body,
    state => 'confirmed',
    title => 'Initial email response',
    text => 'Thanks for your report. We will investigate within 5 working days.',
    auto_response => 1,
});
ok $template, 'Template created';

subtest "test report creation with initial auto-update" => sub {
    my $report = make_report();
    my $comment = FixMyStreet::DB->resultset('Comment')->single;
    is $comment->text, 'Thanks for your report. We will investigate within 5 working days.';
    is $comment->problem->id, $report->id;
    is $comment->user->id, $comment_user->id;
    is $comment->external_id, 'auto-internal';
    is $comment->name, 'Glos Council';

    FixMyStreet::Script::Alerts::send();
    my $email = $mech->get_email;
};

done_testing;

sub make_report {
    FixMyStreet::override_config {
        ALLOWED_COBRANDS => 'fixmystreet',
        MAPIT_URL => 'http://mapit.uk/',
    }, sub {
        $mech->get_ok('/around?pc=GL50+2PR');
        $mech->follow_link_ok({ text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
        $mech->submit_form_ok({
            with_fields => {
                title => "Test Report",
                detail => 'Test report details.',
                name => 'Joe Bloggs',
                category => 'Potholes',
            }
        }, "submit good details");
    };

    my $report = $user->problems->first;
    ok $report, "Found the report";

    return $report;
}