aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model/photoset.t
blob: d171ba88b7747e2d44d05d02c84b9b5cbd236e09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use FixMyStreet::Test;
use Test::Exception;

use FixMyStreet::DB;
use DateTime;
use Path::Tiny 'path';
use File::Temp 'tempdir';

my $dt = DateTime->now;

my $UPLOAD_DIR = tempdir( CLEANUP => 1 );

my $db = FixMyStreet::DB->schema;

my $user = $db->resultset('User')->find_or_create({ name => 'Bob', email => 'bob@example.com' });

FixMyStreet::override_config {
    UPLOAD_DIR => $UPLOAD_DIR,
}, sub {

my $image_path = path('t/app/controller/sample.jpg');

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();
    is $photoset->num_images, 1, 'Found just 1 image';
    is $photoset->data, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg';
};

$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();
    is $photoset->num_images, 1, 'Found just 1 image';
};

subtest 'Photoset with 3 referenced photo' => sub {
    my $report = make_report( '0123456789012345678901234567890123456789,0123456789012345678901234567890123456789,0123456789012345678901234567890123456789' );
    my $photoset = $report->get_photoset();
    is $photoset->num_images, 3, 'Found 3 images';
};

};

done_testing();