2022-03-15 02:45:16 +01:00
|
|
|
use v5.30.0;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2022-03-17 02:41:47 +01:00
|
|
|
use Test::Most tests => 6;
|
|
|
|
use Test::MockModule;
|
|
|
|
|
|
|
|
use DBI;
|
|
|
|
|
|
|
|
use Peace::Model::Application;
|
2022-03-15 02:45:16 +01:00
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use_ok 'Peace::Model::Developer';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
## GIVEN
|
|
|
|
my $secret_bcrypt = 'hola';
|
|
|
|
my $name = 'Larry';
|
|
|
|
my $surname = 'Wall';
|
|
|
|
my $email = 'larry@perl.org';
|
|
|
|
my $country = 'US';
|
|
|
|
my $verified = 0;
|
|
|
|
## WHEN
|
|
|
|
my $developer = Peace::Model::Developer->new(
|
|
|
|
secret_bcrypt => $secret_bcrypt,
|
|
|
|
name => $name,
|
|
|
|
surname => $surname,
|
|
|
|
email => $email,
|
|
|
|
country => $country,
|
|
|
|
verified => $verified,
|
|
|
|
);
|
|
|
|
## THEN
|
|
|
|
ok $developer->isa('Peace::Model::Developer'),
|
|
|
|
'Instanced developer is made of Peace::Model::Developer.';
|
|
|
|
is $developer->secret_bcrypt, $secret_bcrypt, 'Secret is correctly setup';
|
|
|
|
is $developer->uuid, undef, 'Uuid is undef.';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
## GIVEN
|
|
|
|
my $uuid = 'example';
|
|
|
|
my $secret_bcrypt = 'hola';
|
|
|
|
my $name = 'Larry';
|
|
|
|
my $surname = 'Wall';
|
|
|
|
my $email = 'larry@perl.org';
|
|
|
|
my $country = 'US';
|
|
|
|
my $verified = 0;
|
|
|
|
|
|
|
|
my $developer = Peace::Model::Developer->new(
|
|
|
|
secret_bcrypt => $secret_bcrypt,
|
|
|
|
name => $name,
|
|
|
|
surname => $surname,
|
|
|
|
email => $email,
|
|
|
|
country => $country,
|
|
|
|
verified => $verified
|
|
|
|
);
|
|
|
|
|
|
|
|
## WHEN
|
|
|
|
$developer->uuid($uuid);
|
|
|
|
|
|
|
|
## THEN
|
|
|
|
is $developer->uuid, $uuid, 'Uuid can be set.';
|
|
|
|
}
|
2022-03-17 02:41:47 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
## GIVEN
|
|
|
|
|
|
|
|
my $application_dao_mock = Test::MockModule->new('Peace::DAO::Application');
|
|
|
|
### Developer data
|
|
|
|
my $uuid = 'example';
|
|
|
|
my $secret_bcrypt = 'hola';
|
|
|
|
my $name = 'Larry';
|
|
|
|
my $surname = 'Wall';
|
|
|
|
my $email = 'larry@perl.org';
|
|
|
|
my $country = 'US';
|
|
|
|
my $verified = 0;
|
|
|
|
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
|
|
|
|
|
|
|
|
### Application data
|
|
|
|
my $app_name0 = 'Desfronificator';
|
|
|
|
my $app_name1 = 'Desfronificator 1.0';
|
|
|
|
my $app_description = 'Desfronifies the files.';
|
|
|
|
my $app_url = 'https://desfronificator.example.com';
|
|
|
|
my $app_price = '4.20';
|
|
|
|
my $app_git_repo =
|
|
|
|
'https://git.desfronificator.example.com/larry/desfronificator.git';
|
|
|
|
my $app_flatpak_builder_file =
|
|
|
|
'./resources/com.example.desfronificator.yml';
|
|
|
|
my $app_verified = 0;
|
|
|
|
|
|
|
|
my $developer = Peace::Model::Developer->new(
|
|
|
|
secret_bcrypt => $secret_bcrypt,
|
|
|
|
name => $name,
|
|
|
|
surname => $surname,
|
|
|
|
email => $email,
|
|
|
|
country => $country,
|
|
|
|
verified => $verified,
|
|
|
|
dbh => $dbh,
|
|
|
|
);
|
|
|
|
|
|
|
|
my $applications = [
|
|
|
|
Peace::Model::Application->new(
|
|
|
|
name => $app_name0,
|
|
|
|
description => $app_description,
|
|
|
|
url => $app_url,
|
|
|
|
price => $app_price,
|
|
|
|
git_repo => $app_git_repo,
|
|
|
|
flatpak_builder_file => $app_flatpak_builder_file,
|
|
|
|
verified => $app_verified,
|
|
|
|
developer => $developer,
|
|
|
|
),
|
|
|
|
Peace::Model::Application->new(
|
|
|
|
name => $app_name0,
|
|
|
|
description => $app_description,
|
|
|
|
url => $app_url,
|
|
|
|
price => $app_price,
|
|
|
|
git_repo => $app_git_repo,
|
|
|
|
flatpak_builder_file => $app_flatpak_builder_file,
|
|
|
|
verified => $app_verified,
|
|
|
|
developer => $developer,
|
|
|
|
),
|
|
|
|
|
|
|
|
];
|
|
|
|
$application_dao_mock->mock(
|
|
|
|
recover_by_developer => sub {
|
|
|
|
return $applications;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
## WHEN
|
|
|
|
my $new_applications = $developer->applications;
|
|
|
|
|
|
|
|
## THEN
|
|
|
|
is_deeply $new_applications, $applications,
|
|
|
|
'Applications are correctly recovered from the developer.';
|
|
|
|
}
|