Adding Telegram along some tests and a fix to add into @INC
lib in tests.
This commit is contained in:
parent
04008b578e
commit
825cd884fc
32
lib/DoctorAgustin/Telegram.pm
Normal file
32
lib/DoctorAgustin/Telegram.pm
Normal file
@ -0,0 +1,32 @@
|
||||
package DoctorAgustin::Telegram;
|
||||
|
||||
use v5.30.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Types::Standard qw/Str/;
|
||||
use Params::ValidationCompiler qw(validation_for);
|
||||
|
||||
{
|
||||
my $validator = validation_for(
|
||||
params => {
|
||||
telegram_token => { type => Str },
|
||||
}
|
||||
);
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $self = bless {}, $class;
|
||||
my %params = $validator->(@_);
|
||||
my $telegram_token = $params{telegram_token};
|
||||
$self->{telegram_token} = $telegram_token;
|
||||
return $self;
|
||||
}
|
||||
}
|
||||
|
||||
sub _telegram_token {
|
||||
my $self = shift;
|
||||
return $self->{telegram_token};
|
||||
}
|
||||
1;
|
83
t/00001-config.t
Normal file
83
t/00001-config.t
Normal file
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.30.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::Most tests => 5;
|
||||
use Test::MockModule;
|
||||
use Test::MockObject;
|
||||
|
||||
use Path::Tiny;
|
||||
use JSON;
|
||||
|
||||
BEGIN {
|
||||
unshift @INC, 'lib';
|
||||
use_ok 'DoctorAgustin::Config';
|
||||
}
|
||||
|
||||
{
|
||||
## GIVEN
|
||||
my $result = 'hola';
|
||||
my $readline_mockmodule = Test::MockModule->new('Term::ReadLine');
|
||||
my $logger_mockmodule = Test::MockModule->new('DoctorAgustin::Logger');
|
||||
my $readline_mockobject = Test::MockObject->new;
|
||||
my $new_home = Path::Tiny->tempdir;
|
||||
|
||||
local $ENV{HOME} = qq($new_home);
|
||||
|
||||
$readline_mockmodule->mock(
|
||||
new => sub {
|
||||
return $readline_mockobject;
|
||||
}
|
||||
);
|
||||
$logger_mockmodule->mock( _log => sub { shift; shift; say STDERR shift } );
|
||||
$readline_mockobject->mock(
|
||||
readline => sub {
|
||||
return $result;
|
||||
}
|
||||
);
|
||||
|
||||
## WHEN
|
||||
lives_ok {
|
||||
my $config = DoctorAgustin::Config->new;
|
||||
my $telegram_token = $config->telegram_token;
|
||||
|
||||
## THEN
|
||||
is $telegram_token, $result,
|
||||
'Telegram token is recovered ok when creating the config.';
|
||||
}
|
||||
'The configuration is got without dying';
|
||||
}
|
||||
|
||||
{
|
||||
## GIVEN
|
||||
my $result = 'hola';
|
||||
my $readline_mockmodule = Test::MockModule->new('Term::ReadLine');
|
||||
my $logger_mockmodule = Test::MockModule->new('DoctorAgustin::Logger');
|
||||
my $readline_mockobject = Test::MockObject->new;
|
||||
my $new_home = Path::Tiny->tempdir;
|
||||
my $config_dir = qq($new_home/.config/doctoragustin);
|
||||
my $config_file = qq($config_dir/config.json);
|
||||
|
||||
local $ENV{HOME} = qq($new_home);
|
||||
|
||||
path($config_dir)->mkpath;
|
||||
path($config_file)->spew( encode_json( { telegram_token => $result } ) );
|
||||
|
||||
$logger_mockmodule->mock( _log => sub { shift; shift; say STDERR shift } );
|
||||
|
||||
lives_ok {
|
||||
## WHEN
|
||||
|
||||
my $config = DoctorAgustin::Config->new;
|
||||
my $telegram_token = $config->telegram_token;
|
||||
|
||||
## THEN
|
||||
is $telegram_token, $result,
|
||||
'Telegram token is recovered ok when config exists.';
|
||||
}
|
||||
'The configuration is got without dying';
|
||||
|
||||
}
|
22
t/00002-telegram.t
Normal file
22
t/00002-telegram.t
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.30.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::Most tests => 3;
|
||||
use Test::MockModule;
|
||||
use Test::MockObject;
|
||||
|
||||
BEGIN {
|
||||
unshift @INC, 'lib';
|
||||
use_ok 'DoctorAgustin::Telegram';
|
||||
}
|
||||
|
||||
{
|
||||
my $result = 'hola';
|
||||
my $telegram = DoctorAgustin::Telegram->new (telegram_token => $result);
|
||||
ok $telegram->isa('DoctorAgustin::Telegram'), 'Telegram object created successfully.';
|
||||
is $telegram->_telegram_token, $result, 'Telegram token setup was successful.';
|
||||
}
|
Loading…
Reference in New Issue
Block a user