File Coverage

File:t/controller-attachment.t
Coverage:100.0%

linestmtbrancondsubpodtimecode
1#!/usr/bin/env perl
2
1
1
1863
3
use v5.24;
3
4
1
1
1
163
67144
3
use Test2::V0;
5
6
1
1
1
1
1
1
1
1588
11496
5
503
3
1
11
use ok('Yukki::Web::Context');
7
1
1
1
1
1
1
1
361
1
4
556
2
1
12
use ok('Yukki::Web::Controller::Attachment');
8
9
1
92673
my $mock_file = mock 'Yukki::Model::File' => (
10    add_constructor => [new => 'hash'],
11    add => [
12        fetch => 'fake content',
13    ],
14);
15
16my $mock_repo = mock 'Yukki::Model::Repository' => (
17    add_constructor => [new => 'hash'],
18    add => [
19
1
4
        file => sub { Yukki::Model::File->new },
20
1
362
    ],
21);
22
23my $mock_app = mock 'Yukki::Web' => (
24    add_constructor => [new => 'hash'],
25    add => [
26
1
29
        model => sub { Yukki::Model::Repository->new },
27
1
249
    ],
28);
29
1
236
my $app = Yukki::Web->new;
30
1
9
isa_ok $app, 'Yukki::Web';
31
32
1
258
my $attachment = Yukki::Web::Controller::Attachment->new(
33    app => $app,
34);
35
36{
37
1
6
    my $ctx = Yukki::Web::Context->new(
38        env => {},
39    );
40
41
1
31
    $ctx->request->path_parameters->{action} = 'invalid';
42
43    like dies {
44
1
12
            $attachment->fire($ctx);
45        },
46
1
67
        qr/attachment action does not exist/,
47        'no action causes exception';
48}
49
50{
51
1
1
1
1482
190
20
    my $ctx = Yukki::Web::Context->new(
52        env => {},
53    );
54
55
1
30
    $ctx->request->path_parameters->{action} = 'download';
56
1
63
    $ctx->request->path_parameters->{repository} = 'x';
57
1
43
    $ctx->request->path_parameters->{file} = ['y'];
58
59
1
32
    $attachment->fire($ctx);
60
61
1
60
    is $ctx->response->content_type, 'application/octet', 'CT for downloads';
62
1
441
    is $ctx->response->body, ['fake content'], 'response body contains expected content';
63}
64
65
1
578
done_testing;