Adding a release dao test, refactoring the tests of application dao.
This commit is contained in:
parent
898b1af4a6
commit
a4dfabde09
@ -75,7 +75,7 @@ EOF
|
||||
SELECT uuid, date_creation,
|
||||
application, name, tag
|
||||
FROM releases
|
||||
WHERE uuid = ?
|
||||
WHERE uuid = ?;
|
||||
EOF
|
||||
if ( !defined $result ) {
|
||||
die "Release with uuid $uuid not found.";
|
||||
|
@ -6,12 +6,12 @@ use warnings;
|
||||
use Test::Most tests => 5;
|
||||
|
||||
use DBI;
|
||||
use DateTime;
|
||||
|
||||
use Peace::Model::Developer;
|
||||
use Peace::Model::Application;
|
||||
use DateTime::Format::Pg;
|
||||
use DateTime;
|
||||
use DateTime::Format::Pg;
|
||||
|
||||
use Peace::Test::Mock::Model::Developer;
|
||||
use Peace::Test::Mock::Model::Application;
|
||||
|
||||
BEGIN {
|
||||
use_ok 'Peace::DAO::Application';
|
||||
@ -27,49 +27,14 @@ INSERT INTO applications
|
||||
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_flatpak_repo =
|
||||
'https://nightly.gnome.org/gnome-nightly.flatpakrepo';
|
||||
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,
|
||||
flatpak_repo => $app_flatpak_repo,
|
||||
verified => $app_verified,
|
||||
git_repo => $app_git_repo,
|
||||
);
|
||||
my $developer = Peace::Test::Mock::Model::Developer->new;
|
||||
$developer->uuid('hola');
|
||||
|
||||
my $application = Peace::Test::Mock::Model::Application->new;
|
||||
my $uuid = 'hola';
|
||||
|
||||
|
||||
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
|
||||
|
||||
@ -101,15 +66,15 @@ EOF
|
||||
[
|
||||
$uuid,
|
||||
$formatter->format_datetime($datetime),
|
||||
$app_name,
|
||||
$app_description,
|
||||
$app_url,
|
||||
$application->name,
|
||||
$application->description,
|
||||
$application->url,
|
||||
$developer->uuid,
|
||||
$app_price,
|
||||
$app_git_repo,
|
||||
$app_flatpak_builder_file,
|
||||
$app_flatpak_repo,
|
||||
$app_verified
|
||||
$application->price,
|
||||
$application->git_repo,
|
||||
$application->flatpak_builder_file,
|
||||
$application->flatpak_repo,
|
||||
$application->verified
|
||||
]
|
||||
],
|
||||
};
|
||||
@ -122,39 +87,13 @@ 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_flatpak_repo =
|
||||
'https://nightly.gnome.org/gnome-nightly.flatpakrepo';
|
||||
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 $developer = Peace::Test::Mock::Model::Developer->new;
|
||||
my $application_mock = Peace::Test::Mock::Model::Application->new;
|
||||
my $uuid = 'hola';
|
||||
|
||||
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
|
||||
$application_mock->developer->uuid('hola');
|
||||
|
||||
my $sql = <<'EOF';
|
||||
SELECT uuid, date_creation, name,
|
||||
@ -180,15 +119,15 @@ EOF
|
||||
[
|
||||
$uuid,
|
||||
$formatter->format_datetime($datetime),
|
||||
$app_name,
|
||||
$app_description,
|
||||
$app_url,
|
||||
$developer->uuid,
|
||||
$app_price,
|
||||
$app_git_repo,
|
||||
$app_flatpak_builder_file,
|
||||
$app_flatpak_repo,
|
||||
$app_verified
|
||||
$application_mock->name,
|
||||
$application_mock->description,
|
||||
$application_mock->url,
|
||||
$application_mock->developer->uuid,
|
||||
$application_mock->price,
|
||||
$application_mock->git_repo,
|
||||
$application_mock->flatpak_builder_file,
|
||||
$application_mock->flatpak_repo,
|
||||
$application_mock->verified,
|
||||
]
|
||||
],
|
||||
};
|
||||
@ -210,24 +149,9 @@ FROM applications
|
||||
WHERE developer = ?;
|
||||
EOF
|
||||
|
||||
### Developer data
|
||||
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:', '', '' );
|
||||
my $developer = Peace::Model::Developer->new(
|
||||
uuid => $uuid,
|
||||
secret_bcrypt => $secret_bcrypt,
|
||||
name => $name,
|
||||
surname => $surname,
|
||||
email => $email,
|
||||
country => $country,
|
||||
verified => $verified,
|
||||
);
|
||||
my $developer = Peace::Test::Mock::Model::Developer->new;
|
||||
$developer->uuid('hola');
|
||||
|
||||
### Application data
|
||||
my $app_uuid = 'denuheesuehs';
|
||||
|
65
t/00010-release-dao.t
Normal file
65
t/00010-release-dao.t
Normal file
@ -0,0 +1,65 @@
|
||||
use v5.30.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::Most tests => 3;
|
||||
|
||||
use DBI;
|
||||
|
||||
use DateTime;
|
||||
use DateTime::Format::Pg;
|
||||
|
||||
use Peace::Test::Mock::Model::Application;
|
||||
use Peace::Test::Mock::Model::Release;
|
||||
|
||||
BEGIN {
|
||||
use_ok 'Peace::DAO::Release';
|
||||
}
|
||||
|
||||
{
|
||||
## GIVEN
|
||||
my $release = Peace::Test::Mock::Model::Release->new;
|
||||
my $sql = <<'EOF';
|
||||
INSERT INTO releases
|
||||
(application, tag, name)
|
||||
VALUES (?, ?, ?)
|
||||
RETURNING uuid;
|
||||
EOF
|
||||
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
|
||||
$release->application->uuid('hola');
|
||||
my $datetime = DateTime->now;
|
||||
my $uuid = 'hola';
|
||||
$dbh->{mock_add_resultset} = {
|
||||
sql => $sql,
|
||||
results => [ ['uuid'], [$uuid], ]
|
||||
};
|
||||
$sql = <<'EOF';
|
||||
SELECT uuid, date_creation,
|
||||
application, name, tag
|
||||
FROM releases
|
||||
WHERE uuid = ?;
|
||||
EOF
|
||||
my $iso8601 = DateTime::Format::Pg->new;
|
||||
$dbh->{mock_add_resultset} = {
|
||||
sql => $sql,
|
||||
results => [
|
||||
[ 'uuid', 'date_creation', 'application', 'name', 'tag' ],
|
||||
[
|
||||
$uuid,
|
||||
$iso8601->format_datetime($datetime),
|
||||
$release->application->uuid,
|
||||
$release->name, $release->tag
|
||||
]
|
||||
]
|
||||
};
|
||||
|
||||
my $release_dao = Peace::DAO::Release->new( dbh => $dbh );;
|
||||
|
||||
## WHEN
|
||||
$release_dao->create( release => $release );
|
||||
|
||||
## THEN
|
||||
is $release->uuid, $uuid, 'Release uuid set.';
|
||||
ok $release->date_creation == $datetime, 'Release date_creation set';
|
||||
}
|
Loading…
Reference in New Issue
Block a user