aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/controller/report_new.t4
-rw-r--r--t/app/controller/report_new_open311.t2
-rw-r--r--t/app/controller/token.t37
-rw-r--r--t/app/model/extra.t111
-rw-r--r--t/cobrand/bromley.t20
-rw-r--r--t/cobrand/zurich.t9
-rw-r--r--t/open311/populate-service-list.t21
7 files changed, 188 insertions, 16 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 25fa01a1f..3e1446068 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -999,7 +999,7 @@ for my $test (
host => 'www.fixmystreet.com',
postcode => 'EH99 1SP',
fms_extra_title => '',
- extra => undef,
+ extra => [],
user_title => undef,
},
{
@@ -1127,7 +1127,7 @@ for my $test (
my $report = $user->problems->first;
ok $report, "Found the report";
- my $extras = $report->extra;
+ my $extras = $report->get_extra_fields;
is $user->title, $test->{'user_title'}, 'user title correct';
is_deeply $extras, $test->{extra}, 'extra contains correct values';
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index 15ccef493..53b84b92d 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -158,7 +158,7 @@ foreach my $test (
my $prob = $user->problems->first;
ok $prob, 'problem created';
- is_deeply $prob->extra, $test->{extra}, 'extra open311 data added to problem';
+ is_deeply $prob->get_extra_fields, $test->{extra}, 'extra open311 data added to problem';
$user->problems->delete;
$user->delete;
diff --git a/t/app/controller/token.t b/t/app/controller/token.t
new file mode 100644
index 000000000..9ca8b905d
--- /dev/null
+++ b/t/app/controller/token.t
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+use Test::More;
+use utf8;
+
+use FixMyStreet::TestMech;
+use FixMyStreet::App;
+
+my $user = FixMyStreet::App->model('DB::User')->find_or_create({
+ name => 'Bob', email => 'bob@example.com',
+ });
+my $mech = FixMyStreet::TestMech->new;
+
+subtest 'Zurich special case for C::Tokens->problem_confirm' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => ['zurich'],
+ }, sub {
+ my $c = FixMyStreet::App->new;
+ my $zurich = $mech->create_body_ok( 1, 'Zurich' );
+ my ($report) = $mech->create_problems_for_body(
+ 1, $zurich->id,
+ {
+ state => 'unconfirmed',
+ confirmed => undef,
+ cobrand => 'zurich',
+ });
+
+ is $report->get_extra_metadata('email_confirmed'), undef, 'email_confirmed not yet set (sanity)';
+ my $token = $c->model('DB::Token')->create({ scope => 'problem', data => $report->id });
+
+ $mech->get_ok('/P/' . $token->token);
+ $report->discard_changes;
+ is $report->get_extra_metadata('email_confirmed'), 1, 'email_confirmed set by Zurich special case';
+ };
+};
+
+done_testing;
diff --git a/t/app/model/extra.t b/t/app/model/extra.t
new file mode 100644
index 000000000..21c37336e
--- /dev/null
+++ b/t/app/model/extra.t
@@ -0,0 +1,111 @@
+use strict;
+use warnings;
+use Test::More;
+use utf8;
+
+use FixMyStreet::App;
+use Data::Dumper;
+use DateTime;
+
+my $c = FixMyStreet::App->new;
+
+my $db = FixMyStreet::App->model('DB')->schema;
+$db->txn_begin;
+
+my $body = $db->resultset('Body')->create({ name => 'ExtraTestingBody' });
+
+my $serial = 1;
+sub get_test_contact {
+ my $extra = shift;
+ my $contact = $db->resultset('Contact')->create({
+ category => "Testing ${serial}",
+ body => $body,
+ email => 'test@example.com',
+ confirmed => 1,
+ deleted => 0,
+ editor => 'test script',
+ note => 'test script',
+ whenedited => DateTime->now(),
+ $extra ? ( extra => $extra ) : (),
+ });
+ $serial++;
+ return $contact;
+}
+
+subtest 'Old list layout transparently upgraded' => sub {
+
+ subtest 'layout' => sub {
+ my $contact = get_test_contact([]);
+
+ is_deeply $contact->get_extra(), { _fields => [] }, 'transparently upgraded to a hash';
+ };
+
+ subtest 'extra fields' => sub {
+ my $contact = get_test_contact([]);
+
+ is_deeply $contact->get_extra_fields(), [], 'No extra fields';
+
+ my @fields = ( { a => 1 }, { b => 2 } );
+ $contact->set_extra_fields(@fields);
+ is_deeply $contact->extra, { _fields => \@fields }, 'extra fields set...';
+ $contact->update;
+ $contact->discard_changes;
+ is_deeply $contact->extra, { _fields => \@fields }, '...and retrieved';
+ is_deeply $contact->get_extra_fields(), \@fields, 'extra fields returned';
+ };
+
+ subtest 'metadata' => sub {
+ my $contact = get_test_contact([]);
+ is_deeply $contact->get_extra_metadata_as_hashref(), {}, 'No extra metadata';
+
+ $contact->set_extra_metadata('foo' => 'bar');
+ is $contact->get_extra_metadata('foo'), 'bar', 'extra metadata set...';
+ $contact->update;
+ $contact->discard_changes;
+ is $contact->get_extra_metadata('foo'), 'bar', '... and retrieved';
+ is_deeply $contact->get_extra_metadata_as_hashref(), { foo => 'bar' }, 'No extra metadata';
+ };
+};
+
+subtest 'Default hash layout' => sub {
+ subtest 'layout' => sub {
+ my $contact = get_test_contact();
+
+ is_deeply $contact->get_extra(), {}, 'default layout is hash';
+ };
+
+ subtest 'extra fields' => sub {
+ my $contact = get_test_contact();
+
+ is_deeply $contact->get_extra_fields(), [], 'No extra fields';
+
+ my @fields = ( { a => 1 }, { b => 2 } );
+ $contact->set_extra_fields(@fields);
+ is_deeply $contact->get_extra_fields, \@fields, 'extra fields set...';
+ $contact->update;
+ $contact->discard_changes;
+ is_deeply $contact->get_extra_fields(), \@fields, '... and returned';
+ is_deeply $contact->extra, { _fields => \@fields }, '(sanity check layout)';
+ };
+
+ subtest 'metadata' => sub {
+ my $contact = get_test_contact();
+ is_deeply $contact->get_extra_metadata_as_hashref(), {}, 'No extra metadata';
+
+ $contact->set_extra_metadata('foo' => 'bar');
+ is $contact->get_extra_metadata('foo'), 'bar', 'extra metadata set...';
+ $contact->update;
+ $contact->discard_changes;
+ is $contact->get_extra_metadata( 'foo'), 'bar', '... and retrieved';
+ is_deeply $contact->get_extra_metadata_as_hashref(), { foo => 'bar' }, 'No extra metadata';
+
+ $contact->unset_extra_metadata('foo');
+ is $contact->get_extra_metadata('foo'), undef, 'extra metadata now unset';
+ $contact->update;
+ $contact->discard_changes;
+ is $contact->get_extra_metadata('foo'), undef, '... after retrieval';
+ };
+};
+
+$db->txn_rollback;
+done_testing();
diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t
index 6437ba3bd..fdded5606 100644
--- a/t/cobrand/bromley.t
+++ b/t/cobrand/bromley.t
@@ -8,6 +8,11 @@ my $mech = FixMyStreet::TestMech->new;
# Create test data
my $user = $mech->create_user_ok( 'bromley@example.com' );
my $body = $mech->create_body_ok( 2482, 'Bromley', id => 2482 );
+$mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Other',
+ email => 'LIGHT',
+);
my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', {
cobrand => 'bromley',
@@ -36,6 +41,21 @@ $mech->content_contains( 'marked as in progress' );
$mech->content_contains( 'marks it as unable to fix' );
$mech->content_contains( 'marked as no further action' );
+subtest 'testing special Open311 behaviour', sub {
+ $report->set_extra_fields();
+ $report->update;
+ $body->update( { send_method => 'Open311', endpoint => 'http://bromley.endpoint.example.com', jurisdiction => 'FMS', api_key => 'test' } );
+ FixMyStreet::override_config {
+ SEND_REPORTS_ON_STAGING => 1,
+ }, sub {
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+ };
+ $report->discard_changes;
+ ok $report->whensent, 'Report marked as sent';
+ is $report->send_method_used, 'Open311', 'Report sent via Open311';
+ is $report->external_id, 248, 'Report has right external ID';
+};
+
# Clean up
$mech->delete_user($user);
$mech->delete_problems_for_body( $body->id );
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index 203bbc0f8..31aceab28 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -17,13 +17,16 @@ use JSON;
# commonlib/bin/gettext-makemo FixMyStreet
use FixMyStreet;
+my $c = FixMyStreet::App->new();
+my $cobrand = FixMyStreet::Cobrand::Zurich->new({ c => $c });
+$c->stash->{cobrand} = $cobrand;
# This is a helper method that will send the reports but with the config
# correctly set - notably SEND_REPORTS_ON_STAGING needs to be true.
sub send_reports_for_zurich {
FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1 }, sub {
# Actually send the report
- FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+ $c->model('DB::Problem')->send_reports('zurich');
};
}
sub reset_report_state {
@@ -285,9 +288,9 @@ subtest "report_edit" => sub {
is ( $report->extra->{closed_overdue}, 0, 'Marking hidden from scratch also set closed_overdue' );
is get_moderated_count(), 1;
- is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'sanity check');
+ is ($cobrand->get_or_check_overdue($report), 0, 'sanity check');
$report->update({ created => $created->clone->subtract(days => 10) });
- is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'overdue call not increased');
+ is ($cobrand->get_or_check_overdue($report), 0, 'overdue call not increased');
reset_report_state($report, $created);
};
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index b343b206d..99663030a 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -254,14 +254,14 @@ subtest 'check meta data population' => sub {
$contact->discard_changes;
- is_deeply $contact->extra, $extra, 'meta data saved';
+ is_deeply $contact->get_extra_fields, $extra, 'meta data saved';
};
for my $test (
{
desc => 'check meta data added to existing contact',
has_meta => 1,
- orig_meta => undef,
+ orig_meta => [],
end_meta => [ {
variable => 'true',
code => 'type',
@@ -332,7 +332,7 @@ for my $test (
{
desc => 'check meta data removed',
has_meta => 0,
- end_meta => undef,
+ end_meta => [],
orig_meta => [ {
variable => 'true',
code => 'type',
@@ -363,8 +363,8 @@ for my $test (
{
desc => 'check empty meta data handled',
has_meta => 1,
- orig_meta => undef,
- end_meta => undef,
+ orig_meta => [],
+ end_meta => [],
meta_xml => '<?xml version="1.0" encoding="utf-8"?>
<service_definition>
<service_code>100</service_code>
@@ -408,7 +408,8 @@ for my $test (
}
);
- $contact->update( { extra => $test->{orig_meta} } );
+ $contact->set_extra_fields(@{$test->{orig_meta}});
+ $contact->update;
my $o = Open311->new(
jurisdiction => 'mysociety',
@@ -427,7 +428,7 @@ for my $test (
$contact->discard_changes;
- is_deeply $contact->extra, $test->{end_meta}, 'meta data saved';
+ is_deeply $contact->get_extra_fields, $test->{end_meta}, 'meta data saved';
};
}
@@ -530,7 +531,7 @@ subtest 'check attribute ordering' => sub {
$contact->discard_changes;
- is_deeply $contact->extra, $extra, 'meta data re-ordered correctly';
+ is_deeply $contact->get_extra_fields, $extra, 'meta data re-ordered correctly';
};
subtest 'check bromely skip code' => sub {
@@ -610,7 +611,7 @@ subtest 'check bromely skip code' => sub {
$contact->discard_changes;
- is_deeply $contact->extra, $extra, 'only non std bromley meta data saved';
+ is_deeply $contact->get_extra_fields, $extra, 'only non std bromley meta data saved';
$processor->_current_body( $body );
$processor->_add_meta_to_contact( $contact );
@@ -650,7 +651,7 @@ subtest 'check bromely skip code' => sub {
$contact->discard_changes;
- is_deeply $contact->extra, $extra, 'all meta data saved for non bromley';
+ is_deeply $contact->get_extra_fields, $extra, 'all meta data saved for non bromley';
};
sub get_standard_xml {