diff --git a/Build.PL b/Build.PL index 0ae1a95..141e2ec 100644 --- a/Build.PL +++ b/Build.PL @@ -14,6 +14,9 @@ my $build = Module::Build->new( 'DBD::Mock' => 0, 'DateTime' => 0, 'DateTime::Format::Pg' => 0, + 'Test::Most' => 0, + 'Test::MockObject' => 0, + 'Test::MockModule' => 0, }, install_path => { 'templates' => "$HOME/.local/share/peace/template", diff --git a/lib/Peace/DB.pm b/lib/Peace/DB.pm index d117fa8..9936dbf 100644 --- a/lib/Peace/DB.pm +++ b/lib/Peace/DB.pm @@ -40,11 +40,13 @@ my @migrations = ( uuid UUID NOT NULL DEFAULT gen_random_uuid(), date_creation timestamp DEFAULT NOW(), name TEXT NOT NULL, + description TEXT NOT NULL, url TEXT NOT NULL, developer UUID NOT NULL, price INTEGER NOT NULL, git_repo TEXT NOT NULL, flatpak_builder_file TEXT NOT NULL, + verified BOOL DEFAULT false, PRIMARY KEY (uuid), FOREIGN KEY (developer) REFERENCES developers (uuid) );', diff --git a/t/00007-application-model.t b/t/00007-application-model.t new file mode 100644 index 0000000..c0d1704 --- /dev/null +++ b/t/00007-application-model.t @@ -0,0 +1,111 @@ +#!/usr/bin/env perl + +use v5.30.0; + +use strict; +use warnings; + +use Test::Most tests => 4; +use Test::MockModule; + +use DBI; + +use Peace::Model::Developer; + +BEGIN { + use_ok 'Peace::Model::Application'; +} + +{ + ## GIVEN + ### Developer data + my $secret_bcrypt = 'hola'; + my $name = 'Larry'; + my $surname = 'Wall'; + my $email = 'larry@perl.org'; + my $country = 'US'; + my $verified = 0; + + ### Application data + my $app_name = 'Desfronificator'; + my $app_description = 'Desfronifies the files.'; + my $app_url = 'desfronificator.example.com'; + my $app_price = '4.20'; + my $app_flatpak_builder_file = + './resources/com.example.desfronificator.yml'; + my $app_verified = 0; + my $developer = Peace::Model::Developer->new( + secret_bcrypt => $secret_bcrypt, + name => $name, + surname => $surname, + email => $email, + country => $country, + verified => $verified, + ); + + ## WHEN + 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, + ); + + ## THEN + ok $application->isa('Peace::Model::Application'), + 'Application is made of application.'; +} + +{ + ## GIVEN + ### Developer data + my $secret_bcrypt = 'hola'; + my $name = 'Larry'; + my $surname = 'Wall'; + my $email = 'larry@perl.org'; + my $country = 'US'; + my $verified = 0; + + ### Application data + my $app_name = 'Desfronificator'; + my $app_description = 'Desfronifies the files.'; + my $app_url = 'desfronificator.example.com'; + my $app_price = '4.20'; + my $app_flatpak_builder_file = + './resources/com.example.desfronificator.yml'; + my $app_verified = 0; + my $dbh = DBI->connect( 'DBI:Mock:', '', '' ); + my $developer = Peace::Model::Developer->new( + secret_bcrypt => $secret_bcrypt, + name => $name, + surname => $surname, + email => $email, + country => $country, + verified => $verified, + ); + + + my $developer_dao = Test::MockModule->new('Peace::DAO::Developer'); + $developer_dao->mock( recover_by_uuid => sub { + return $developer; + }); + + ## WHEN + my $application = Peace::Model::Application->new( + developer_uuid => 'larryuuid', + name => $app_name, + description => $app_description, + url => $app_url, + price => $app_price, + flatpak_builder_file => $app_flatpak_builder_file, + verified => $app_verified, + dbh => $dbh, + ); + + ## THEN + ok $application->isa('Peace::Model::Application'); + ok $application->developer->isa('Peace::Model::Developer'); +}