Adding tests for the developer model.

This commit is contained in:
sergiotarxz 2022-03-16 16:11:27 +01:00
parent 156e69c825
commit 5576588705
3 changed files with 116 additions and 0 deletions

View File

@ -14,6 +14,9 @@ my $build = Module::Build->new(
'DBD::Mock' => 0,
'DateTime' => 0,
'DateTime::Format::Pg' => 0,
'Test::Most' => 0,
'Test::MockObject' => 0,
'Test::MockModule' => 0,
},
install_path => {
'templates' => "$HOME/.local/share/peace/template",

View File

@ -40,11 +40,13 @@ my @migrations = (
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
date_creation timestamp DEFAULT NOW(),
name TEXT NOT NULL,
description TEXT NOT NULL,
url TEXT NOT NULL,
developer UUID NOT NULL,
price INTEGER NOT NULL,
git_repo TEXT NOT NULL,
flatpak_builder_file TEXT NOT NULL,
verified BOOL DEFAULT false,
PRIMARY KEY (uuid),
FOREIGN KEY (developer) REFERENCES developers (uuid)
);',

111
t/00007-application-model.t Normal file
View File

@ -0,0 +1,111 @@
#!/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');
}