App-Filite-Client
view release on metacpan or search on metacpan
t/unit/App/Filite/Client.t view on Meta::CPAN
=pod
=encoding utf-8
=head1 PURPOSE
Unit tests for L<App::Filite::Client>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2023 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use Test2::V0 -target => 'App::Filite::Client';
use Test2::Tools::Spec;
use Data::Dumper;
use JSON::PP qw( decode_json );
use FindBin qw( $Bin );
my $SHARE = "$Bin/../../../share";
describe "class `$CLASS`" => sub {
tests 'has a constructor' => sub {
can_ok( $CLASS, 'new' );
isa_ok( $CLASS, 'Class::Tiny::Object' );
};
};
describe "method `new_from_config`" => sub {
tests 'it works' => sub {
my $object = do {
local $ENV{'FILITE_CLIENT_CONFIG'} = "$SHARE/config.json";
$CLASS->new_from_config;
};
isa_ok( $object, $CLASS );
is( $object->password, 'abc123', 'password attribute' );
is( $object->server, 'example.com', 'server attribute' );
is( $object->errors, 0, 'errors attribute' );
isa_ok( $object->useragent, 'HTTP::Tiny' );
};
};
describe "method `share`" => sub {
my $guard;
my @calls;
my @input;
my @urls;
my $expected_calls;
my $expected_result;
before_case setup => sub {
$guard = mock $CLASS => override => [
share_file => sub { shift; push @calls, [ share_file => @_ ]; pop @urls; },
share_text => sub { shift; push @calls, [ share_text => @_ ]; pop @urls; },
share_link => sub { shift; push @calls, [ share_link => @_ ]; pop @urls; },
];
};
after_case teardown => sub {
@calls = ();
undef $guard;
};
case 'simple text' => sub {
@input = ( "$SHARE/file.txt", {} );
@urls = ( 'http://example.net/t/foo' );
$expected_result = $urls[0];
$expected_calls = [ [ share_text => @input ] ];
};
case 'simple file' => sub {
( run in 0.548 second using v1.01-cache-2.11-cpan-39bf76dae61 )