Peace/db_tests/00003-application-dao.t

81 lines
2.2 KiB
Perl

#!/usr/bin/env perl
use v5.30.0;
use strict;
use warnings;
use Data::Dumper;
use Test::Most tests => 4;
use DateTime;
use Peace;
use Peace::DB;
use Peace::DAO::Developer;
use Peace::DAO::Application;
use Peace::Test::Mock::Model::Developer;
use Peace::Test::Mock::Model::Application;
{
## GIVEN
my $current_date = DateTime->now;
my $peace = Peace->new;
my $home = $ENV{HOME};
my $config =
$peace->plugin(
JSONConfig => { file => "$home/.config/peace/peace.conf" } );
my $dbh = Peace::DB->dbh( config => $config );
my $developer = Peace::Test::Mock::Model::Developer->new;
my $developer_dao = Peace::DAO::Developer->new( dbh => $dbh );
$developer_dao->create( developer => $developer );
my $application = Peace::Test::Mock::Model::Application->new;
$application->developer($developer);
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
## WHEN
$application_dao->create( application => $application );
## THEN
ok $application->uuid, 'Generated uuid.';
ok $application->date_creation > $current_date, 'The date is recent.';
}
{
## GIVEN
my $current_date = DateTime->now;
my $peace = Peace->new;
my $home = $ENV{HOME};
my $config =
$peace->plugin(
JSONConfig => { file => "$home/.config/peace/peace.conf" } );
my $dbh = Peace::DB->dbh( config => $config );
my $secret_bcrypt = 'hola';
my $developer = Peace::Test::Mock::Model::Developer->new;
my $developer_dao = Peace::DAO::Developer->new( dbh => $dbh );
$developer_dao->create( developer => $developer );
my $application = Peace::Test::Mock::Model::Application->new;
$application->developer($developer);
my $application_dao = Peace::DAO::Application->new( dbh => $dbh );
$application_dao->create( application => $application );
$developer->{dbh} = $dbh;
## WHEN
my $applications = $developer->applications;
## THEN
ok @$applications, 'Applications has at least a element.';
ok $applications->[0]->isa('Peace::Model::Application'),
'Application is made of developer.';
}