diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/report_new.t | 8 | ||||
-rw-r--r-- | t/open311.t | 92 |
2 files changed, 88 insertions, 12 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 625c7531f..0d9a45c40 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -293,7 +293,7 @@ foreach my $test ( is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; # click through to the report page - $mech->follow_link_ok( { text => 'skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # submit the main form @@ -473,7 +473,7 @@ subtest "test password errors for a user who is signing in as they report" => su "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( @@ -520,7 +520,7 @@ subtest "test report creation for a user who is signing in as they report" => su "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( @@ -614,7 +614,7 @@ foreach my $test ( "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # check that the fields are correctly prefilled diff --git a/t/open311.t b/t/open311.t index 2a5e5d11c..bec03f49e 100644 --- a/t/open311.t +++ b/t/open311.t @@ -53,8 +53,66 @@ my $problem = FixMyStreet::App->model('DB::Problem')->new( { id => 80, external_id => 81, state => 'confirmed', + title => 'a problem', + detail => 'problem detail', + category => 'pothole', + latitude => 1, + longitude => 2, + user => $user, } ); +subtest 'posting service request' => sub { + my $extra = { + url => 'http://example.com/report/1', + }; + + my $results = make_service_req( $problem, $extra, $problem->category, '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' ); + + is $results->{ res }, 248, 'got request id'; + + my $req = $o->test_req_used; + + my $description = <<EOT; +title: a problem + +detail: problem detail + +url: http://example.com/report/1 + +Submitted via FixMyStreet +EOT +; + + my $c = CGI::Simple->new( $results->{ req }->content ); + + is $c->param('email'), $user->email, 'correct email'; + is $c->param('first_name'), 'Test', 'correct first name'; + is $c->param('last_name'), 'User', 'correct last name'; + is $c->param('lat'), 1, 'latitide correct'; + is $c->param('long'), 2, 'longitude correct'; + is $c->param('description'), $description, 'descritpion correct'; + is $c->param('service_code'), 'pothole', 'service code correct'; +}; + +subtest 'extra values in service request' => sub { + $problem->extra([ + { + name => 'title', + value => 'A title', + } + ]); + + my $extra = { + url => 'http://example.com/report/1', + }; + + my $results = make_service_req( $problem, $extra, $problem->category, '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' ); + my $req = $o->test_req_used; + my $c = CGI::Simple->new( $results->{ req }->content ); + + is $c->param('attribute[title]'), 'A title', 'extra parameter used correctly'; +}; + my $comment = FixMyStreet::App->model('DB::Comment')->new( { id => 38362, user => $user, @@ -191,18 +249,36 @@ sub make_update_req { my $comment = shift; my $xml = shift; - my $o = Open311->new( test_mode => 1, end_point => 'http://localhost/o311' ); + return make_req( $comment, $xml, 'post_service_request_update', 'update.xml' ); +} + +sub make_service_req { + my $problem = shift; + my $extra = shift; + my $service_code = shift; + my $xml = shift; + + return make_req( $problem, $xml, 'send_service_request', 'requests.xml', $extra, $service_code ); +} + +sub make_req { + my $object = shift; + my $xml = shift; + my $method = shift; + my $path = shift; + my @args = @_; + + my $o = + Open311->new( test_mode => 1, end_point => 'http://localhost/o311' ); my $test_res = HTTP::Response->new(); - $test_res->code( 200 ); - $test_res->message( 'OK' ); - $test_res->content( $xml ); + $test_res->code(200); + $test_res->message('OK'); + $test_res->content($xml); - $o->test_get_returns( { - 'update.xml' => $test_res - } ); + $o->test_get_returns( { $path => $test_res } ); - my $res = $o->post_service_request_update( $comment ); + my $res = $o->$method($object, @args); my $req = $o->test_req_used; |