aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/admin/users_import.t
blob: df8884797d5d119b2aa4abb5cd316ade414c4609 (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
use FixMyStreet::TestMech;

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

my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1);
my $body = $mech->create_body_ok(2509, 'Haringey Borough Council');

$mech->log_in_ok( $superuser->email );

my $body_id = $body->id;
my $csv = <<EOF;
name,email,from_body,permissions,roles
Adrian,adrian\@example.org,$body_id,moderate:user_edit,
Belinda,belinda\@example.org,$body_id,,Customer Service
EOF

FixMyStreet::DB->resultset("Role")->create({
    body => $body,
    name => 'Customer Service',
});

subtest 'import CSV file' => sub {
    $mech->get_ok('/admin/users/import');
    $mech->submit_form_ok({ with_fields => {
        csvfile => [ [ undef, 'foo.csv', Content => $csv ], 1],
    }});
    $mech->content_contains('Created 2 new users');
    my $a = FixMyStreet::DB->resultset("User")->find({ email => 'adrian@example.org' });
    is $a->user_body_permissions->count, 2;
    my $b = FixMyStreet::DB->resultset("User")->find({ email => 'belinda@example.org' });
    is $b->roles->count, 1;
};

done_testing();