Peace/t/00007-application-model.t
2022-03-16 16:13:44 +01:00

113 lines
3.1 KiB
Perl

#!/usr/bin/env perl
use v5.30.0;
use strict;
use warnings;
use Test::Most tests => 4;
use Test::MockModule;
use DBI;
use Peace::Model::Developer;
BEGIN {
use_ok 'Peace::Model::Application';
}
{
## GIVEN
### Developer data
my $secret_bcrypt = 'hola';
my $name = 'Larry';
my $surname = 'Wall';
my $email = 'larry@perl.org';
my $country = 'US';
my $verified = 0;
### Application data
my $app_name = 'Desfronificator';
my $app_description = 'Desfronifies the files.';
my $app_url = 'desfronificator.example.com';
my $app_price = '4.20';
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,
);
## WHEN
my $application = Peace::Model::Application->new(
developer => $developer,
name => $app_name,
description => $app_description,
url => $app_url,
price => $app_price,
flatpak_builder_file => $app_flatpak_builder_file,
verified => $app_verified,
);
## THEN
ok $application->isa('Peace::Model::Application'),
'Application is made of application.';
}
{
## GIVEN
### Developer data
my $secret_bcrypt = 'hola';
my $name = 'Larry';
my $surname = 'Wall';
my $email = 'larry@perl.org';
my $country = 'US';
my $verified = 0;
### Application data
my $app_name = 'Desfronificator';
my $app_description = 'Desfronifies the files.';
my $app_url = 'desfronificator.example.com';
my $app_price = '4.20';
my $app_flatpak_builder_file =
'./resources/com.example.desfronificator.yml';
my $app_verified = 0;
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
my $developer = Peace::Model::Developer->new(
secret_bcrypt => $secret_bcrypt,
name => $name,
surname => $surname,
email => $email,
country => $country,
verified => $verified,
);
my $developer_dao = Test::MockModule->new('Peace::DAO::Developer');
$developer_dao->mock(
recover_by_uuid => sub {
return $developer;
}
);
## WHEN
my $application = Peace::Model::Application->new(
developer_uuid => 'larryuuid',
name => $app_name,
description => $app_description,
url => $app_url,
price => $app_price,
flatpak_builder_file => $app_flatpak_builder_file,
verified => $app_verified,
dbh => $dbh,
);
## THEN
ok $application->isa('Peace::Model::Application');
ok $application->developer->isa('Peace::Model::Developer');
}