aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand/restriction.t
blob: 873a396b7fae89f7243e7f61df401bc66b2a76c0 (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
use strict;
use warnings;

package FixMyStreet::Cobrand::Tester;

use parent 'FixMyStreet::Cobrand::Default';

sub problems_restriction {
    my ($self, $rs) = @_;
    return $rs->search({ cobrand => 'tester' });
}

sub updates_restriction {
    my ($self, $rs) = @_;
    return $rs->search({ 'problem.cobrand' => 'tester' }, { join => 'problem' });
}

package main;

use Test::More;
use FixMyStreet::TestMech;

my $c = FixMyStreet::App->new;
my $cobrand = FixMyStreet::Cobrand::Tester->new({c => $c});
$c->stash->{cobrand} = $cobrand;

my $mech = FixMyStreet::TestMech->new;

my ($prob1) = $mech->create_problems_for_body(1, 1234, 'Title');
my ($prob2) = $mech->create_problems_for_body(1, 1234, 'Title', { cobrand => 'tester' });
$mech->create_problems_for_body(1, 1234, 'Title', { latitude => 0, longitude => 0 });
$mech->create_problems_for_body(1, 1234, 'Title', { cobrand => 'tester', latitude => 0, longitude => 0 });

for (1..2) {
    $c->model('DB::Comment')->create({
        problem_id => $_ == 1 ? $prob1->id : $prob2->id,
        user_id => $prob2->user_id,
        name => 'User',
        mark_fixed => 'false',
        text => 'This is some update text',
        state => 'confirmed',
        cobrand => 'tester',
        anonymous => 'f',
    });
}

is($c->model('DB::Problem')->count, 4, 'Four reports in database');
is($cobrand->problems->count, 2, 'Two reports in the right cobrand');
is($cobrand->updates->count, 1, 'One update in the right cobrand');

my $nearby = $c->model('DB::Nearby')->nearby($c, 5, [], 10, 0.003, 0.004);
is(@$nearby, 1, 'One report close to the origin point');

$mech->delete_problems_for_body(1234);
done_testing();