diff options
Diffstat (limited to 't/app/model')
-rw-r--r-- | t/app/model/alert_type.t | 2 | ||||
-rw-r--r-- | t/app/model/photoset.t | 76 | ||||
-rw-r--r-- | t/app/model/problem.t | 28 | ||||
-rw-r--r-- | t/app/model/questionnaire.t | 4 | ||||
-rw-r--r-- | t/app/model/token.t | 66 |
5 files changed, 99 insertions, 77 deletions
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index 528c4d354..2620dd68c 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -87,7 +87,7 @@ my $comment2 = FixMyStreet::App->model('DB::Comment')->find_or_create( } ); -$comment->confirmed( \"ms_current_timestamp() - '3 days'::interval" ); +$comment->confirmed( \"current_timestamp - '3 days'::interval" ); $comment->update; my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( diff --git a/t/app/model/photoset.t b/t/app/model/photoset.t new file mode 100644 index 000000000..9e566f873 --- /dev/null +++ b/t/app/model/photoset.t @@ -0,0 +1,76 @@ +use strict; +use warnings; +use Test::More; +use Test::Exception; +use utf8; + +use FixMyStreet::App; +use Data::Dumper; +use DateTime; +use Path::Tiny 'path'; +use File::Temp 'tempdir'; + +my $dt = DateTime->now; + +my $c = FixMyStreet::App->new; +my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); +local $c->config->{UPLOAD_DIR} = $UPLOAD_DIR; + +my $user = $c->model('DB::User')->find_or_create({ + name => 'Bob', email => 'bob@example.com', +}); + +my $image_path = path('t/app/controller/sample.jpg'); + +my $db = FixMyStreet::App->model('DB')->schema; +$db->txn_begin; + +sub make_report { + my $photo_data = shift; + return $db->resultset('Problem')->create({ + postcode => 'BR1 3SB', + bodies_str => '', + areas => ",,", + category => 'Other', + title => 'test', + detail => 'test', + used_map => 't', + name => 'Anon', + anonymous => 't', + state => 'confirmed', + confirmed => $dt, + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '51.4129', + longitude => '0.007831', + user => $user, + photo => $photo_data, + }); +} + + +subtest 'Photoset with photo inline in DB' => sub { + my $report = make_report( $image_path->slurp ); + my $photoset = $report->get_photoset($c); + is $photoset->num_images, 1, 'Found just 1 image'; +}; + +$image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) ); +subtest 'Photoset with 1 referenced photo' => sub { + my $report = make_report( '0123456789012345678901234567890123456789' ); + my $photoset = $report->get_photoset($c); + is $photoset->num_images, 1, 'Found just 1 image'; +}; + +subtest 'Photoset with 1 referenced photo' => sub { + my $report = make_report( '0123456789012345678901234567890123456789,0123456789012345678901234567890123456789,0123456789012345678901234567890123456789' ); + my $photoset = $report->get_photoset($c); + is $photoset->num_images, 3, 'Found 3 images'; +}; + +$db->txn_rollback; + +done_testing(); diff --git a/t/app/model/problem.t b/t/app/model/problem.t index ad82a62a5..82569d72a 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -457,7 +457,8 @@ foreach my $test ( { email_count => 1, to => qr'Gloucestershire County Council" <2226@example', dear => qr'Dear Gloucestershire County Council,', - body => $body_ids{2226} . '|' . $body_ids{2649}, + body => $body_ids{2226}, + body_missing => $body_ids{2649}, missing => qr'problem might be the responsibility of Fife.*Council'ms, }, { %common, @@ -524,14 +525,15 @@ foreach my $test ( { { whensent => undef } - )->update( { whensent => \'ms_current_timestamp()' } ); + )->update( { whensent => \'current_timestamp' } ); $problem->discard_changes; $problem->update( { bodies_str => $test->{ body }, + bodies_missing => $test->{ body_missing }, state => 'confirmed', - confirmed => \'ms_current_timestamp()', - whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()', + confirmed => \'current_timestamp', + whensent => $test->{ unset_whendef } ? undef : \'current_timestamp', category => $test->{ category } || 'potholes', name => $test->{ name }, cobrand => $test->{ cobrand } || 'fixmystreet', @@ -598,13 +600,13 @@ subtest 'check can set mutiple emails as a single contact' => sub { { whensent => undef } - )->update( { whensent => \'ms_current_timestamp()' } ); + )->update( { whensent => \'current_timestamp' } ); $problem->discard_changes; $problem->update( { bodies_str => $contact->{ body_id }, state => 'confirmed', - confirmed => \'ms_current_timestamp()', + confirmed => \'current_timestamp', whensent => undef, category => 'trees', name => 'Test User', @@ -632,13 +634,13 @@ subtest 'check can turn on report sent email alerts' => sub { { whensent => undef } - )->update( { whensent => \'ms_current_timestamp()' } ); + )->update( { whensent => \'current_timestamp' } ); $problem->discard_changes; $problem->update( { bodies_str => $body_ids{2651}, state => 'confirmed', - confirmed => \'ms_current_timestamp()', + confirmed => \'current_timestamp', whensent => undef, category => 'potholes', name => 'Test User', @@ -677,14 +679,14 @@ subtest 'check iOS app store test reports not sent' => sub { { whensent => undef } - )->update( { whensent => \'ms_current_timestamp()' } ); + )->update( { whensent => \'current_timestamp' } ); $problem->discard_changes; $problem->update( { bodies_str => $body_ids{2651}, title => 'App store test', state => 'confirmed', - confirmed => \'ms_current_timestamp()', + confirmed => \'current_timestamp', whensent => undef, category => 'potholes', send_fail_count => 0, @@ -706,14 +708,14 @@ subtest 'check reports from abuser not sent' => sub { { whensent => undef } - )->update( { whensent => \'ms_current_timestamp()' } ); + )->update( { whensent => \'current_timestamp' } ); $problem->discard_changes; $problem->update( { bodies_str => $body_ids{2651}, title => 'Report', state => 'confirmed', - confirmed => \'ms_current_timestamp()', + confirmed => \'current_timestamp', whensent => undef, category => 'potholes', send_fail_count => 0, @@ -728,7 +730,7 @@ subtest 'check reports from abuser not sent' => sub { $problem->update( { state => 'confirmed', - confirmed => \'ms_current_timestamp()', + confirmed => \'current_timestamp', whensent => undef, } ); diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t index be5b433c1..240d6d050 100644 --- a/t/app/model/questionnaire.t +++ b/t/app/model/questionnaire.t @@ -25,8 +25,8 @@ my $problem = FixMyStreet::App->model('DB::Problem')->create( service => '', cobrand => 'default', cobrand_data => '', - confirmed => \"ms_current_timestamp() - '5 weeks'::interval", - whensent => \"ms_current_timestamp() - '5 weeks'::interval", + confirmed => \"current_timestamp - '5 weeks'::interval", + whensent => \"current_timestamp - '5 weeks'::interval", user => $user, anonymous => 0, } diff --git a/t/app/model/token.t b/t/app/model/token.t index 637477fa3..d72574bb1 100644 --- a/t/app/model/token.t +++ b/t/app/model/token.t @@ -7,17 +7,6 @@ use Test::More; use FixMyStreet; use FixMyStreet::App; -use mySociety::AuthToken; -use mySociety::DBHandle 'dbh'; - -# set things up so that code using mySociety::DBHandle is happy -FixMyStreet->configure_mysociety_dbhandle(); - -# NOTE - remember that you need to explicitly dbh()->commit after making -# database changes with the mySociety::* modules. - -# create a token using DBIC and check we can read it using AuthToken, and vice -# versa my %tests = ( nested_hash => { foo => 'bar', and => [ 'baz', 'bundy' ] }, @@ -27,76 +16,31 @@ my %tests = ( my $token_rs = FixMyStreet::App->model('DB::Token'); -# create using DBIC foreach my $test_data_name ( sort keys %tests ) { my $test_data = $tests{$test_data_name}; - pass "--- testing DBIC create using '$test_data_name'"; + pass "--- testing token creation using '$test_data_name'"; my $dbic_token = $token_rs->create( { scope => 'testing', data => $test_data } ); my $token = $dbic_token->token; ok $token, "stored token '$token'"; - is_deeply $dbic_token->data, $test_data, "data stored correctly using DBIC"; + is_deeply $dbic_token->data, $test_data, "data stored correctly"; - # read back using DBIC + # read back from database is_deeply $token_rs->find( { token => $token, scope => 'testing' } )->data, $test_data, - "data read back correctly with DBIC"; - - # read back using mySociety::AuthToken - is_deeply mySociety::AuthToken::retrieve( 'testing', $token ), - $test_data, "data read back correctly with m::AT"; + "data read back correctly"; # delete token ok $dbic_token->delete, "delete token"; is $token_rs->find( { token => $token, scope => 'testing' } ), undef, - "token gone for DBIC"; - - # read back using mySociety::AuthToken - is mySociety::AuthToken::retrieve( 'testing', $token ), - undef, "token gone with m::AT"; - -} - -# create using m::AT -foreach my $test_data_name ( sort keys %tests ) { - my $test_data = $tests{$test_data_name}; - - pass "--- testing m::AT create using '$test_data_name'"; - - my $token = mySociety::AuthToken::store( 'testing', $test_data ); - dbh->commit(); - ok $token, "stored token '$token'"; - - # read back using DBIC - is_deeply $token_rs->find( { token => $token, scope => 'testing' } )->data, - $test_data, - "data read back correctly with DBIC"; - - # read back using mySociety::AuthToken - is_deeply mySociety::AuthToken::retrieve( 'testing', $token ), - $test_data, "data read back correctly with m::AT"; - - # delete token - ok mySociety::AuthToken::destroy( 'testing', $token ), "destroy token"; - dbh->commit(); - - is $token_rs->find( { token => $token, scope => 'testing' } ), - undef, - "token gone for DBIC"; - - # read back using mySociety::AuthToken - is mySociety::AuthToken::retrieve( 'testing', $token ), - undef, "token gone with m::AT"; - + "token gone"; } - - # Test that the inflation and deflation works as expected { my $token = |