66 lines
1.5 KiB
Perl
66 lines
1.5 KiB
Perl
|
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';
|
||
|
}
|