diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/photo.t | 36 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 21 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 55 |
3 files changed, 106 insertions, 6 deletions
diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t index dbbc697d7..e9183836b 100644 --- a/t/app/controller/photo.t +++ b/t/app/controller/photo.t @@ -66,7 +66,43 @@ subtest "Check multiple upload worked" => sub { 'Returned upload_fileid contains expected hash, 3 times'); my $image_file = path($UPLOAD_DIR, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg'); ok $image_file->exists, 'File uploaded to temp'; + + $mech->submit_form_ok({ with_fields => { name => 'Bob Jones' } }); + ok $mech->success, 'Made request with multiple photo upload'; }; }; +subtest "Check photo uploading URL works" => sub { + my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); + + # submit initial pc form + FixMyStreet::override_config { + UPLOAD_DIR => $UPLOAD_DIR, + }, sub { + $mech->post( '/photo/upload', + Content_Type => 'form-data', + Content => { + photo1 => [ $sample_file, undef, Content_Type => 'application/octet-stream' ], + }, + ); + ok $mech->success, 'Made request with multiple photo upload'; + is $mech->content, '{"id":"74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg"}'; + my $image_file = path($UPLOAD_DIR, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg'); + ok $image_file->exists, 'File uploaded to temp'; + }; +}; + +subtest "Check photo URL endpoints work" => sub { + my $p = FixMyStreet::DB->resultset("Problem")->first; + + $mech->get_ok('/photo/temp.74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg'); + my $image_file = FixMyStreet->path_to('web/photo/temp.74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg'); + ok -e $image_file, 'File uploaded to temp'; + $mech->get_ok('/photo/' . $p->id . '.jpeg'); + $image_file = FixMyStreet->path_to('web/photo/' . $p->id . '.jpeg'); + ok -e $image_file, 'File uploaded to temp'; + my $res = $mech->get('/photo/0.jpeg'); + is $res->code, 404, "got 404"; +}; + done_testing(); diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index c6d112df7..75542d759 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -52,7 +52,7 @@ like $plain->body, qr/fill in our short questionnaire/i, "got questionnaire emai like $plain->body_str, qr/Testing \x{2013} Detail/, 'email contains encoded character'; is $plain->header('Content-Type'), 'text/plain; charset="utf-8"', 'in the right character set'; -my $url = $mech->get_link_from_email($email); +my $url = $mech->get_link_from_email($email, 0, 1); my ($token) = $url =~ m{/Q/(\S+)}; ok $token, "extracted questionnaire token '$token'"; $mech->clear_emails_ok; @@ -108,6 +108,23 @@ foreach my $test ( }; } +subtest "If been_fixed is provided in the URL" => sub { + $mech->get_ok("/Q/" . $token->token . "?been_fixed=Yes"); + $mech->content_contains('id="been_fixed_yes" value="Yes" checked'); + $report->discard_changes; + is $report->state, 'fixed - user'; + $questionnaire->discard_changes; + is $questionnaire->old_state, 'confirmed'; + is $questionnaire->new_state, 'fixed - user'; + $mech->submit_form_ok({ with_fields => { been_fixed => 'Unknown', reported => 'Yes', another => 'No' } }); + $report->discard_changes; + is $report->state, 'confirmed'; + $questionnaire->discard_changes; + is $questionnaire->old_state, 'confirmed'; + is $questionnaire->new_state, 'unknown'; + $questionnaire->update({ whenanswered => undef, ever_reported => undef, old_state => undef, new_state => undef }); +}; + $mech->get_ok("/Q/" . $token->token); $mech->title_like( qr/Questionnaire/ ); $mech->submit_form_ok( ); @@ -399,7 +416,7 @@ FixMyStreet::override_config { $mech->clear_emails_ok; $body =~ s/\s+/ /g; like $body, qr/fill in our short questionnaire/i, "got questionnaire email"; - my $url = $mech->get_link_from_email($email); + my $url = $mech->get_link_from_email($email, 0, 1); ($token) = $url =~ m{/Q/(\S+)}; ok $token, "extracted questionnaire token '$token'"; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index aefe77e47..aba7340b0 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -146,6 +146,42 @@ subtest "unconfirmed updates not displayed" => sub { }; subtest "several updates shown in correct order" => sub { + my @qs; + for my $fields ( { # One with an associated update below + problem_id => $report_id, + whensent => '2011-03-10 12:23:16', + whenanswered => '2011-03-10 12:23:16', + old_state => 'confirmed', + new_state => 'confirmed', + }, + { # One with no associated update + problem_id => $report_id, + whensent => '2011-03-11 12:23:16', + whenanswered => '2011-03-11 12:23:16', + old_state => 'confirmed', + new_state => 'confirmed', + }, + { # One with no associated update, different state (doesn't match problem state, never mind) + problem_id => $report_id, + whensent => '2011-03-12 12:23:16', + whenanswered => '2011-03-12 12:23:16', + old_state => 'investigating', + new_state => 'investigating', + }, + { # One for the fixed update + problem_id => $report_id, + whensent => '2011-03-15 08:12:36', + whenanswered => '2011-03-15 08:12:36', + old_state => 'confirmed', + new_state => 'fixed - user', + }, + ) { + my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( + $fields + ); + push @qs, $q; + } + for my $fields ( { problem_id => $report_id, user_id => $user2->id, @@ -180,16 +216,27 @@ subtest "several updates shown in correct order" => sub { my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( $fields ); + if ($fields->{text} eq 'Second update') { + $comment->set_extra_metadata(questionnaire_id => $qs[0]->id); + $comment->update; + } + if ($fields->{text} eq 'Third update') { + $comment->set_extra_metadata(questionnaire_id => $qs[3]->id); + $comment->update; + } } $mech->get_ok("/report/$report_id"); my $meta = $mech->extract_update_metas; - is scalar @$meta, 4, 'number of updates'; + is scalar @$meta, 6, 'number of updates'; is $meta->[0], 'Posted by Other User at 12:23, Thu 10 March 2011', 'first update'; - is $meta->[1], 'Posted by Main User at 12:23, Thu 10 March 2011', 'second update'; - is $meta->[2], 'State changed to: Fixed', 'third update, part 1'; - is $meta->[3], 'Posted anonymously at 08:12, Tue 15 March 2011', 'third update, part 2'; + is $meta->[1], 'Posted by Main User at 12:23, Thu 10 March 2011 Still open, via questionnaire', 'second update'; + is $meta->[2], 'Still open, via questionnaire, 12:23, Fri 11 March 2011', 'questionnaire'; + is $meta->[3], 'Still open, via questionnaire, 12:23, Sat 12 March 2011', 'questionnaire'; + is $meta->[4], 'State changed to: Fixed', 'third update, part 1'; + is $meta->[5], 'Posted anonymously at 08:12, Tue 15 March 2011', 'third update, part 2'; + $report->questionnaires->delete; }; for my $test ( |