aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand
diff options
context:
space:
mode:
Diffstat (limited to 't/cobrand')
-rw-r--r--t/cobrand/bucks.t2
-rw-r--r--t/cobrand/westminster.t218
2 files changed, 219 insertions, 1 deletions
diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t
index 6732eb29c..2d42dcd81 100644
--- a/t/cobrand/bucks.t
+++ b/t/cobrand/bucks.t
@@ -19,7 +19,7 @@ $mech->create_contact_ok(body_id => $district->id, category => 'Graffiti', email
my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Buckinghamshire');
$cobrand->mock('lookup_site_code', sub {
- my ($self, $row, $buffer) = @_;
+ my ($self, $row) = @_;
return "Road ID" if $row->latitude == 51.812244;
});
diff --git a/t/cobrand/westminster.t b/t/cobrand/westminster.t
new file mode 100644
index 000000000..2912f6ee5
--- /dev/null
+++ b/t/cobrand/westminster.t
@@ -0,0 +1,218 @@
+use CGI::Simple;
+use Test::MockModule;
+use FixMyStreet::TestMech;
+use FixMyStreet::Script::Reports;
+
+ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
+
+my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Westminster');
+$cobrand->mock('lookup_site_code', sub {
+ my ($self, $row) = @_;
+ return "My USRN" if $row->latitude == 51.501009;
+});
+
+my $body = $mech->create_body_ok(2504, 'Westminster City Council', {
+ send_method => 'Open311', api_key => 'key', 'endpoint' => 'e', 'jurisdiction' => 'j' });
+my $superuser = $mech->create_user_ok(
+ 'superuser@example.com',
+ name => 'Test Superuser',
+ is_superuser => 1
+);
+my $staff_user = $mech->create_user_ok(
+ 'westminster@example.com',
+ name => 'Test User',
+ from_body => $body
+);
+my ($report) = $mech->create_problems_for_body(1, $body->id, 'Title');
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'westminster',
+ MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => {
+ oidc_login => {
+ westminster => {
+ client_id => 'example_client_id',
+ secret => 'example_secret_key',
+ auth_uri => 'http://oidc.example.org/oauth2/v2.0/authorize',
+ token_uri => 'http://oidc.example.org/oauth2/v2.0/token',
+ display_name => 'MyWestminster'
+ }
+ }
+ }
+}, sub {
+ subtest 'Cobrand allows social auth' => sub {
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('westminster')->new();
+ ok $cobrand->social_auth_enabled;
+ };
+
+ subtest 'Login button displayed correctly' => sub {
+ $mech->get_ok("/auth");
+ $mech->content_contains("Sign in with MyWestminster");
+ };
+
+ subtest 'Reports do not have update form' => sub {
+ $mech->get_ok('/report/' . $report->id);
+ $mech->content_lacks('Provide an update');
+ };
+};
+
+subtest 'Reports have an update form for superusers' => sub {
+ # Westminster cobrand disables email signin, so we have to
+ # login and *then* set the cobrand.
+ $mech->log_in_ok( $superuser->email );
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'westminster',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->get_ok('/report/' . $report->id);
+ $mech->content_contains('Provide an update');
+ };
+
+ $mech->log_out_ok();
+};
+
+subtest 'Reports have an update form for staff users' => sub {
+ $mech->log_in_ok( $staff_user->email );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'westminster',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->get_ok('/report/' . $report->id);
+ $mech->content_contains('Provide an update');
+ };
+ $mech->log_out_ok();
+};
+
+for (
+ {
+ ALLOWED_COBRANDS => 'westminster',
+ MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => {
+ oidc_login => {
+ westminster => 0
+ }
+ }
+ },
+ {
+ ALLOWED_COBRANDS => 'westminster',
+ MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => {
+ oidc_login => {
+ hounslow => {
+ client_id => 'example_client_id',
+ secret => 'example_secret_key',
+ auth_uri => 'http://oidc.example.org/oauth2/v2.0/authorize',
+ token_uri => 'http://oidc.example.org/oauth2/v2.0/token',
+ display_name => 'MyHounslow'
+ }
+ }
+ }
+ },
+ {
+ ALLOWED_COBRANDS => 'westminster',
+ MAPIT_URL => 'http://mapit.uk/',
+ }
+) {
+ FixMyStreet::override_config $_, sub {
+ subtest 'Cobrand disallows social auth' => sub {
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('westminster')->new();
+ ok !$cobrand->social_auth_enabled;
+ };
+
+ subtest 'Login button not displayed' => sub {
+ $mech->get_ok("/auth");
+ $mech->content_lacks("Login with MyWestminster");
+ };
+ };
+}
+
+FixMyStreet::DB->resultset('Problem')->delete_all;
+$mech->create_contact_ok(body_id => $body->id, category => 'Abandoned bike', email => "BIKE");
+($report) = $mech->create_problems_for_body(1, $body->id, 'Bike', {
+ category => "Abandoned bike", cobrand => 'westminster',
+ latitude => 51.501009, longitude => -0.141588, areas => '2504',
+});
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'westminster' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ STAGING_FLAGS => { send_reports => 1, skip_checks => 0 },
+ COBRAND_FEATURES => { anonymous_account => { westminster => 'anon' } },
+}, sub {
+ subtest 'USRN set correctly' => sub {
+ my $test_data = FixMyStreet::Script::Reports::send();
+ my $req = $test_data->{test_req_used};
+ my $c = CGI::Simple->new($req->content);
+ is $c->param('service_code'), 'BIKE';
+ is $c->param('attribute[USRN]'), 'My USRN';
+ };
+};
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'westminster',
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+ subtest 'No reporter alert created' => sub {
+ my $user = $mech->log_in_ok('test@example.org');
+ $mech->get_ok('/');
+ $mech->submit_form_ok( { with_fields => { pc => 'SW1A1AA' } }, "submit location" );
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
+ $mech->submit_form_ok( { with_fields => {
+ title => 'Title', detail => 'Detail', category => 'Abandoned bike', name => 'Test Example',
+ } }, 'submitted okay' );
+ is $user->alerts->count, 0;
+ };
+};
+
+my $westminster = FixMyStreet::Cobrand::Westminster->new;
+subtest 'correct config returned for USRN/UPRN lookup' => sub {
+ my $actual = $westminster->lookup_site_code_config('USRN');
+ delete $actual->{accept_feature}; # is_deeply doesn't like code
+ is_deeply $actual, {
+ buffer => 1000,
+ proxy_url => "https://tilma.staging.mysociety.org/resource-proxy/proxy.php",
+ url => "https://westminster.assets/40/query",
+ property => 'USRN',
+ };
+ $actual = $westminster->lookup_site_code_config('UPRN');
+ delete $actual->{accept_feature}; # is_deeply doesn't like code
+ is_deeply $actual, {
+ buffer => 1000,
+ proxy_url => "https://tilma.staging.mysociety.org/resource-proxy/proxy.php",
+ url => "https://westminster.assets/25/query",
+ property => 'UPRN',
+ accept_types => {
+ Point => 1
+ },
+ };
+};
+
+subtest 'nearest UPRN returns correct point' => sub {
+ my $cfg = {
+ accept_feature => sub { 1 },
+ property => 'UPRN',
+ accept_types => {
+ Point => 1,
+ },
+ };
+ my $features = [
+ # A couple of incorrect geometry types to check they're ignored...
+ { geometry => { type => 'Polygon' } },
+ { geometry => { type => 'LineString',
+ coordinates => [ [ 527735, 181004 ], [ 527755, 181004 ] ] },
+ properties => { fid => '20100024' } },
+ # And two points which are further away than the above linestring,
+ # the second of which is the closest to our testing point.
+ { geometry => { type => 'Point',
+ coordinates => [ 527795, 181024 ] },
+ properties => { UPRN => '10012387122' } },
+ { geometry => { type => 'Point',
+ coordinates => [ 527739, 181009 ] },
+ properties => { UPRN => '10012387123' } },
+ ];
+ is $westminster->_nearest_feature($cfg, 527745, 180994, $features), '10012387123';
+};
+
+
+done_testing();