DoctorKarma/t/00003-model-user.t
sergiotarxz 883f16d368 Adding ability to substract karma and a test to control a bug where
karma was not modified in the method karma from user.
2022-02-07 23:57:09 +01:00

60 lines
1.4 KiB
Perl

#!/usr/bin/env perl
use v5.30.0;
use strict;
use warnings;
use Test::Most tests => 7;
use Test::MockModule;
use Test::MockObject;
BEGIN {
unshift @INC, 'lib';
use_ok 'DoctorKarma::Model::User';
}
{
## GIVEN
my $expected_username = 'sergiotarxz';
my $expected_firstname = 'sergiotarxz';
my $expected_karma = 0;
my $expected_id_user = 100;
## WHEN
my $user = DoctorKarma::Model::User->new(
id_user => $expected_id_user,
username => $expected_username,
first_name => $expected_firstname,
karma => $expected_karma,
);
## THEN
ok $user->isa('DoctorKarma::Model::User'), 'User created succesfully.';
is $user->username, $expected_username, 'Username matchs.';
is $user->karma, $expected_karma, 'Karma matchs.';
is $user->first_name, $expected_firstname, 'Firstname matchs.';
is $user->id_user, $expected_id_user, 'Id_User matchs.';
}
{
## GIVEN
my $expected_username = 'sergiotarxz';
my $expected_firstname = 'sergiotarxz';
my $expected_karma = 100;
my $expected_id_user = 100;
my $user = DoctorKarma::Model::User->new(
id_user => $expected_id_user,
username => $expected_username,
first_name => $expected_firstname,
karma => 0,
);
## WHEN
$user->karma($expected_karma);
## THEN
is $user->karma, $expected_karma, 'The karma is the actually expected after edition.';
}