64 lines
1.8 KiB
Perl
64 lines
1.8 KiB
Perl
use 5.32.1;
|
|
|
|
use Test::Most tests => 7;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Const::Fast;
|
|
use Crypt::Bcrypt::Easy;
|
|
use DateTime;
|
|
use Scalar::Util 'blessed';
|
|
|
|
const my %REQUIRED_FIELDS_USER => (
|
|
username => 'example_username',
|
|
matrix_address => '@example_username:example_host.com',
|
|
password_bcrypt => bcrypt->crypt('example_password'),
|
|
is_confirmed => 1,
|
|
creation_date => DateTime->new( year => 2021, month => 06, day => 3 ),
|
|
last_connection => DateTime->now,
|
|
);
|
|
|
|
{
|
|
use_ok 'BeastBB::Model::User';
|
|
}
|
|
|
|
{
|
|
my $user = BeastBB::Model::User->new(%REQUIRED_FIELDS_USER);
|
|
ok defined $user && $user->isa('BeastBB::Model::User'),
|
|
'This user is made of BeastBB::Model::User.';
|
|
my $user_hash = $user->Hash;
|
|
%$user_hash = map {
|
|
my $value = $user_hash->{$_};
|
|
(
|
|
$_ => (
|
|
( blessed $value && $value->isa('DateTime') )
|
|
? "$value"
|
|
: $value
|
|
)
|
|
)
|
|
} keys %$user_hash;
|
|
is_deeply $user_hash, \%REQUIRED_FIELDS_USER, 'User has the expected hash.';
|
|
}
|
|
|
|
{
|
|
my $user = BeastBB::Model::User->new(%REQUIRED_FIELDS_USER);
|
|
ok $user->IdUser->IsError, 'Id user can not be retrieved before set.';
|
|
$user->SetIdUser(1);
|
|
ok !$user->IdUser->IsError, 'Id user can be retrieved after set.';
|
|
is $user->IdUser->Content, 1, 'Id user can be set on runtime.';
|
|
my $user_hash = $user->Hash;
|
|
%$user_hash = map {
|
|
my $value = $user_hash->{$_};
|
|
(
|
|
$_ => (
|
|
( blessed $value && $value->isa('DateTime') )
|
|
? "$value"
|
|
: $value
|
|
)
|
|
)
|
|
} keys %$user_hash;
|
|
is_deeply $user_hash, { %REQUIRED_FIELDS_USER, id_user => 1 },
|
|
'User has the expected hash with id set after creation.';
|
|
}
|