193 lines
5.5 KiB
Perl
193 lines
5.5 KiB
Perl
|
use v5.30.0;
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
|
||
|
use Test::Most tests => 3;
|
||
|
|
||
|
use DBI;
|
||
|
use DateTime;
|
||
|
|
||
|
use Peace::Model::Developer;
|
||
|
use Peace::Model::Application;
|
||
|
use DateTime::Format::Pg;
|
||
|
use DateTime;
|
||
|
|
||
|
BEGIN {
|
||
|
use_ok 'Peace::DAO::Application';
|
||
|
}
|
||
|
|
||
|
{
|
||
|
## GIVEN
|
||
|
my $sql = <<'EOF';
|
||
|
INSERT INTO applications
|
||
|
(name, description, url,
|
||
|
developer, price, git_repo,
|
||
|
flatpak_builder_file, verified)
|
||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||
|
RETURNING uuid;
|
||
|
EOF
|
||
|
|
||
|
### Developer
|
||
|
my $uuid = 'hola';
|
||
|
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_name = 'Desfronificator';
|
||
|
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(
|
||
|
uuid => $uuid,
|
||
|
secret_bcrypt => $secret_bcrypt,
|
||
|
name => $name,
|
||
|
surname => $surname,
|
||
|
email => $email,
|
||
|
country => $country,
|
||
|
verified => $verified,
|
||
|
);
|
||
|
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,
|
||
|
git_repo => $app_git_repo,
|
||
|
);
|
||
|
|
||
|
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
|
||
|
|
||
|
$dbh->{mock_add_resultset} = {
|
||
|
sql => $sql,
|
||
|
results => [ ['uuid'], [$uuid], ]
|
||
|
};
|
||
|
$sql = <<'EOF';
|
||
|
SELECT uuid, date_creation, name,
|
||
|
description, url, developer,
|
||
|
price, git_repo, flatpak_builder_file,
|
||
|
verified
|
||
|
FROM applications
|
||
|
WHERE uuid = ?
|
||
|
EOF
|
||
|
my $datetime = DateTime->now;
|
||
|
my $formatter = DateTime::Format::Pg->new;
|
||
|
$dbh->{mock_add_resultset} = {
|
||
|
sql => $sql,
|
||
|
results => [
|
||
|
[
|
||
|
'uuid', 'date_creation',
|
||
|
'name', 'description',
|
||
|
'url', 'developer',
|
||
|
'price', 'git_repo',
|
||
|
'flatpak_builder_file', 'verified',
|
||
|
],
|
||
|
[
|
||
|
$uuid,
|
||
|
$formatter->format_datetime($datetime),
|
||
|
$app_name,
|
||
|
$app_description,
|
||
|
$app_url,
|
||
|
$developer->uuid,
|
||
|
$app_price,
|
||
|
$app_git_repo,
|
||
|
$app_flatpak_builder_file,
|
||
|
$app_verified
|
||
|
]
|
||
|
],
|
||
|
};
|
||
|
## WHEN
|
||
|
$application_dao->create( application => $application );
|
||
|
|
||
|
## THEN
|
||
|
is $application->uuid, $uuid,
|
||
|
'Application uuid correctly set after user creation.';
|
||
|
}
|
||
|
|
||
|
{
|
||
|
### Developer
|
||
|
my $uuid = 'hola';
|
||
|
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_name = 'Desfronificator';
|
||
|
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(
|
||
|
uuid => $uuid,
|
||
|
secret_bcrypt => $secret_bcrypt,
|
||
|
name => $name,
|
||
|
surname => $surname,
|
||
|
email => $email,
|
||
|
country => $country,
|
||
|
verified => $verified,
|
||
|
);
|
||
|
|
||
|
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
|
||
|
|
||
|
my $sql = <<'EOF';
|
||
|
SELECT uuid, date_creation, name,
|
||
|
description, url, developer,
|
||
|
price, git_repo, flatpak_builder_file,
|
||
|
verified
|
||
|
FROM applications
|
||
|
WHERE uuid = ?
|
||
|
EOF
|
||
|
my $datetime = DateTime->now;
|
||
|
my $formatter = DateTime::Format::Pg->new;
|
||
|
$dbh->{mock_add_resultset} = {
|
||
|
sql => $sql,
|
||
|
results => [
|
||
|
[
|
||
|
'uuid', 'date_creation',
|
||
|
'name', 'description',
|
||
|
'url', 'developer',
|
||
|
'price', 'git_repo',
|
||
|
'flatpak_builder_file', 'verified',
|
||
|
],
|
||
|
[
|
||
|
$uuid,
|
||
|
$formatter->format_datetime($datetime),
|
||
|
$app_name,
|
||
|
$app_description,
|
||
|
$app_url,
|
||
|
$developer->uuid,
|
||
|
$app_price,
|
||
|
$app_git_repo,
|
||
|
$app_flatpak_builder_file,
|
||
|
$app_verified
|
||
|
]
|
||
|
],
|
||
|
};
|
||
|
## WHEN
|
||
|
my $application = $application_dao->recover_by_uuid( uuid => $uuid );
|
||
|
|
||
|
## THEN
|
||
|
is $application->uuid, $uuid,
|
||
|
'Application uuid correctly recovered.';
|
||
|
}
|