129 lines
3.6 KiB
Perl
129 lines
3.6 KiB
Perl
|
use v5.30.0;
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
|
||
|
use Test::Most tests => 6;
|
||
|
|
||
|
use DBI;
|
||
|
use DateTime;
|
||
|
|
||
|
use Peace::Model::Developer;
|
||
|
use DateTime::Format::Pg;
|
||
|
use DateTime;
|
||
|
|
||
|
BEGIN {
|
||
|
use_ok 'Peace::DAO::Developer';
|
||
|
}
|
||
|
|
||
|
{
|
||
|
## GIVEN
|
||
|
my $sql = <<'EOF';
|
||
|
INSERT INTO developers (secret_bcrypt, name, surname, email, country, verified)
|
||
|
VALUES (?, ?, ?, ?, ?, ?)
|
||
|
RETURNING uuid;
|
||
|
EOF
|
||
|
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(
|
||
|
name => $name,
|
||
|
surname => $surname,
|
||
|
email => $email,
|
||
|
country => $country,
|
||
|
secret_bcrypt => $secret_bcrypt,
|
||
|
verified => $verified,
|
||
|
);
|
||
|
my $developer_dao = Peace::DAO::Developer->new( dbh => $dbh );
|
||
|
|
||
|
$dbh->{mock_add_resultset} = {
|
||
|
sql => $sql,
|
||
|
results => [ ['uuid'], [$uuid], ]
|
||
|
};
|
||
|
$sql = <<'EOF';
|
||
|
SELECT uuid, date_creation, secret_bcrypt, name, surname, email, stripe_id, country, verified
|
||
|
FROM developers
|
||
|
WHERE uuid = ?;
|
||
|
EOF
|
||
|
my $datetime = DateTime->now;
|
||
|
my $formatter = DateTime::Format::Pg->new;
|
||
|
$dbh->{mock_add_resultset} = {
|
||
|
sql => $sql,
|
||
|
results => [
|
||
|
[
|
||
|
'uuid', 'name',
|
||
|
'surname', 'email',
|
||
|
'country', 'verified',
|
||
|
'secret_bcrypt', 'date_creation',
|
||
|
'stripe_id'
|
||
|
],
|
||
|
[
|
||
|
$uuid, $name, $surname, $email, $country, $verified,
|
||
|
$secret_bcrypt, $formatter->format_datetime($datetime), undef
|
||
|
]
|
||
|
],
|
||
|
};
|
||
|
## WHEN
|
||
|
$developer_dao->create( developer => $developer );
|
||
|
|
||
|
## THEN
|
||
|
is $developer->uuid, $uuid,
|
||
|
'Developer id correctly set after user creation.';
|
||
|
}
|
||
|
|
||
|
{
|
||
|
## GIVEN
|
||
|
my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
|
||
|
my $developer_dao = Peace::DAO::Developer->new( dbh => $dbh );
|
||
|
my $sql = <<'EOF';
|
||
|
SELECT uuid, date_creation, secret_bcrypt, name, surname, email, stripe_id, country, verified
|
||
|
FROM developers
|
||
|
WHERE uuid = ?;
|
||
|
EOF
|
||
|
my $uuid = 'hola';
|
||
|
my $name = 'Larry';
|
||
|
my $surname = 'Wall';
|
||
|
my $email = 'larry@perl.org';
|
||
|
my $country = 'US';
|
||
|
my $verified = 0;
|
||
|
my $formatter = DateTime::Format::Pg->new;
|
||
|
my $datetime = DateTime->now;
|
||
|
my $date_creation = DateTime->now;
|
||
|
my $secret_bcrypt = 'hola';
|
||
|
my $stripe_id = undef;
|
||
|
|
||
|
$dbh->{mock_add_resultset} = {
|
||
|
sql => $sql,
|
||
|
results => [
|
||
|
[
|
||
|
'uuid', 'name',
|
||
|
'surname', 'email',
|
||
|
'country', 'verified',
|
||
|
'secret_bcrypt', 'date_creation',
|
||
|
'stripe_id'
|
||
|
],
|
||
|
[
|
||
|
$uuid, $name, $surname, $email, $country, $verified,
|
||
|
$secret_bcrypt, $formatter->format_datetime($datetime), undef
|
||
|
]
|
||
|
],
|
||
|
};
|
||
|
|
||
|
## WHEN
|
||
|
my $developer = $developer_dao->recover_by_uuid( uuid => $uuid );
|
||
|
|
||
|
## THEN
|
||
|
is $developer->uuid, $uuid, 'Uuid is recovered correctly';
|
||
|
is $developer->date_creation, $date_creation,
|
||
|
'Date creation is recovered correctly';
|
||
|
is $developer->secret_bcrypt, $secret_bcrypt,
|
||
|
'Secret is recovered correctly';
|
||
|
is $developer->stripe_id, $stripe_id, 'Secret is recovered correctly';
|
||
|
|
||
|
}
|