From 80d50c14866f6e58ee57792a383920a7e8a1274a Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 19:38:12 -0300 Subject: Add media store config method --- t/60-media.t | 69 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 22 deletions(-) (limited to 't/60-media.t') diff --git a/t/60-media.t b/t/60-media.t index 602b0fc..5601d8a 100644 --- a/t/60-media.t +++ b/t/60-media.t @@ -3,39 +3,40 @@ use Test; use Matrix::Client::MediaStore; use Matrix::Client::Exception; -plan 6; - my $path = $*TMPDIR.add('matrix-client-test'); LEAVE { unlink $path; } $path.spurt("") unless $path.f; -# Mock the post-bin method of Matrix::Client::Requester. -my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { - has %.called-with; - method post-bin(Str $path, Buf $buf, :$content-type) { - %.called-with = $path; - %.called-with = $buf; - %.called-with = $content-type; +subtest 'Upload', { + plan 5; + # Mock the post-bin method of Matrix::Client::Requester. + my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + has %.called-with; + method post-bin(Str $path, Buf $buf, :$content-type) { + %.called-with = $path; + %.called-with = $buf; + %.called-with = $content-type; - class { method content { '{"content_uri": "bla" }' } } + class { method content { '{"content_uri": "bla" }' } } + } } -} -$media.upload($path, "something"); -is $media.called-with, '/upload?filename=something', "Send filename pass by parameter"; + $media.upload($path, "something"); + is $media.called-with, '/upload?filename=something', "Send filename pass by parameter"; -$media.upload($path, "something with spaces"); -is $media.called-with, '/upload?filename=something%20with%20spaces', "Escaped filename"; + $media.upload($path, "something with spaces"); + is $media.called-with, '/upload?filename=something%20with%20spaces', "Escaped filename"; -$media.upload($path); -is $media.called-with, "/upload?filename={$path.basename}", "Send file basename if not set"; -is $media.called-with, 'image/png', "By default use `image/png` MIME"; + $media.upload($path); + is $media.called-with, "/upload?filename={$path.basename}", "Send file basename if not set"; + is $media.called-with, 'image/png', "By default use `image/png` MIME"; -$media.upload($path, content-type => 'application/pdf'); -is $media.called-with, 'application/pdf', "Can change the content type"; + $media.upload($path, content-type => 'application/pdf'); + is $media.called-with, 'application/pdf', "Can change the content type"; +} -subtest { +subtest 'mxc parsing', { plan 2; my $media = Matrix::Client::MediaStore.new(:home-server("1234")); is $media.parse-mxc("mxc://matrix.org/123456.pdf"), { @@ -46,4 +47,28 @@ subtest { $media.parse-mxc("http://matrix.org/123456.pdf") }, X::Matrix::MXCParse, 'Dies with HTTP URI'; -}, 'mxc parsing'; +}; + +subtest 'config', { + # Mock the post-bin method of Matrix::Client::Requester. + plan 5; + my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + method get(Str $path) { + class { method content { '{"m.upload.size": 5000 }' } } + } + } + + isa-ok $media.config, Matrix::Response::MediaStore::Config, 'Can load Associative'; + is $media.config.upload-size, 5000, 'correct upload size'; + + my $empty-media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + method get(Str $path) { + class { method content { '{}' } } + } + } + + isa-ok $empty-media.config, Matrix::Response::MediaStore::Config, 'Can load empty configuration'; + is $empty-media.config.upload-size, Int, 'Unknown upload-size'; + nok $empty-media.config.upload-size.defined, 'upload-size not defined'; + +} -- cgit v1.2.3-54-g00ecf