fix: env vars handled via conf file, add: functional tests

This commit is contained in:
Michael 2024-08-17 18:06:06 +02:00
parent 3d08b14f11
commit 21c4330f16
39 changed files with 416 additions and 172 deletions

64
.envexample Normal file
View File

@ -0,0 +1,64 @@
APP_NAME=Lumen
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_TIMEZONE=UTC
APP_PASSWORD=test
LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=
GITEA_CALCULATE_AGENT_COST=true
#YOUR ORG NAME
GITEA_MAIN_COMPANY_ORGANIZATION=""
#YOUR PARTNER ORG NAME
GITEA_PARTNER_ORGANIZATION="PARTNER"
#YOUR GITEA INSTANCE NAME
GITEA_URL="https://git.test.test"
#GITEA API TOKEN
GITEA_TOKEN="1234567889"
#SET THE PARTNER PRICES
PRICE_PARTNER_HIGH=0
PRICE_PARTNER_NORMAL=0
PRICE_PARTNER_LOW=0
#SET THE CLIENT PRICES
PRICE_CLIENT_HIGH=0
PRICE_CLIENT_NORMAL=0
PRICE_CLIENT_LOW=0
#SET A
PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT=0
THIRD_PARTY_INTEGRATIONS_ALLOW=false
THIRD_PARTY_INTEGRATIONS_NEXTCLOUD=false
THIRD_PARTY_INTEGRATIONS_OPEN_PROJECT=false
NEXTCLOUD_URL=https://test.test.net
NEXTCLOUD_USER=test
NEXTCLOUD_PASSWORD=test
NEXTCLOUD_UPLOAD_FOLDER_PATH=Automazione
NEXTCLOUD_UPLOAD_FOLDER_WEB_LINK=https://test.test.test/1/1
OPEN_PROJECT_URL=https://test.test.test
OPEN_PROJECT_TOKEN=12345676
OPEN_PROJECT_PROJECT_ID=1
OPEN_PROJECT_GROUP_ID=1
OPEN_PROJECT_WORK_PACKAGE_TYPE_ID=1
OPEN_PROJECT_WORK_PACKAGE_USER_OWNER_ID=1
OPEN_PROJECT_TASK_NAME=Assistenza
# {"Nickname openproject":"Nickname Git"}
OPEN_PROJECT_SPECIAL_NICKS_LIST={"test":"test"}
EMAIL_SEND_ALLOW=false
EMAIL_ADDRESS_RECEPIENT=test@test.test
EMAIL_PREFIX_SUBJECT="Nuovo export Assistenza"
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=export-git@test.net
MAIL_FROM_NAME="Export git"

View File

@ -2,6 +2,8 @@
namespace App\Console;
use App\Http\Controllers\GiteaApiController\GiteaExport;
use Dotenv\Dotenv;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
@ -24,6 +26,24 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
//
$schedule->call(function () {
$firstDay = date('Y-m-01'); // First day of the current month
$lastDay = date('Y-m-t'); // Last day of the current month
$calculate_agent_cost = true;
$third_party_integrations_allow = true;
$third_party_integrations_nextcloud = true;
$third_party_integrations_open_project = false;
$email_send_allow = true;
$gitea_export = new GiteaExport(
$calculate_agent_cost,
$third_party_integrations_allow,
$third_party_integrations_nextcloud,
$third_party_integrations_open_project,
$email_send_allow,
);
$gitea_export->export_issues($firstDay, $lastDay, ['state' => 'closed']);
})->monthly();
}
}

View File

@ -9,12 +9,12 @@ class CheckSimpleAuthController extends Controller
{
public function check(Request $req) {
if (
getenv('GITEA_PARTNER_ORGANIZATION') === $req->input('organization')
config('app.gitea_partner_organization') === $req->input('organization')
&&
getenv('APP_PASSWORD') === $req->input('password')
config('app.app_password') === $req->input('password')
) {
return view('backend', [
'token' => getenv('GITEA_TOKEN')
'token' => config('app.gitea_token')
]);
} else {
return redirect('/');

View File

@ -17,11 +17,12 @@ class CsvController extends Controller
private $csv_data_handling;
public function __construct()
public function __construct($calculate_agent_cost = false)
{
$this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost');
$this->csv_data_init = new CsvDataInit();
$this->csv_data_handling = new CsvDataHandling();
$this->third_party_integrations_allow = env('THIRD_PARTY_INTEGRATIONS_ALLOW', false);
$this->csv_data_handling = new CsvDataHandling($this->calculate_agent_cost);
$this->third_party_integrations_allow = config('app.third_party_integrations_allow', false);
}
function create_columns(array $issue, array $issue_time, array $company_agents = [])
@ -29,7 +30,7 @@ class CsvController extends Controller
try {
$array = $this->csv_data_init->initialize_csv_data($issue);
$array = $this->csv_data_init->handle_labels($array, $issue['labels']);
$array = $this->csv_data_handling->handle_csv_time($array, $issue, $issue_time, $company_agents);
$array = $this->csv_data_handling->handle_csv_time($array, $issue, $issue_time, $company_agents, $this->calculate_agent_cost);
return $array;
} catch (Error $e) {
Log::error('E-CSV-COLUMNS - ' . $e->getMessage());

View File

@ -12,8 +12,8 @@ class CsvAgentCost
public function __construct()
{
$this->internal_percentage_to_deduct = (float) getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT', null);
$this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
$this->internal_percentage_to_deduct = (float) config('app.price_internal_percentage_to_deduct', null);
$this->partner_organitation = strtolower(config('app.gitea_partner_organization'));
$this->CsvMinuteCostCalc = new CsvMinuteCostCalc();
}

View File

@ -8,13 +8,13 @@ class CsvCostCalc
* @var CsvMinuteCostCalc|(CsvMinuteCostCalc&object&\PHPUnit\Framework\MockObject\MockObject)|(CsvMinuteCostCalc&\PHPUnit\Framework\MockObject\MockObject)|(object&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject
*/
public function __construct()
public function __construct($calculate_agent_cost = false)
{
$this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT');
$this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
$this->internal_percentage_to_deduct = config('app.price_internal_percentage_to_deduct');
$this->partner_organitation = strtolower(config('app.gitea_partner_organization'));
$this->CsvAgentCost = new CsvAgentCost();
$this->CsvTotalCostCalc = new CsvTotalCostCalc();
$this->CsvSumTotalsCalc = new CsvSumTotalsCalc();
$this->CsvSumTotalsCalc = new CsvSumTotalsCalc($calculate_agent_cost);
}

View File

@ -10,18 +10,18 @@ class CsvMinuteCostCalc
{
public function __construct()
{
$this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT');
$this->partner_organization = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
$this->internal_percentage_to_deduct = config('app.price_internal_percentage_to_deduct');
$this->partner_organization = strtolower(config('app.gitea_partner_organization'));
$this->price_partner = [
'high' => $this->calculate_minute_cost((int)getenv('PRICE_PARTNER_HIGH')),
'normal' => $this->calculate_minute_cost((int)getenv('PRICE_PARTNER_NORMAL')),
'low' => $this->calculate_minute_cost((int)getenv('PRICE_PARTNER_LOW')),
'high' => $this->calculate_minute_cost((int)config('app.price_partner_high')),
'normal' => $this->calculate_minute_cost((int)config('app.price_partner_normal')),
'low' => $this->calculate_minute_cost((int)config('app.price_partner_low')),
'0'=>0,
];
$this->price_client = [
'high' => $this->calculate_minute_cost((int)getenv('PRICE_CLIENT_HIGH')),
'normal' => $this->calculate_minute_cost((int)getenv('PRICE_CLIENT_NORMAL')),
'low' => $this->calculate_minute_cost((int)getenv('PRICE_CLIENT_LOW')),
'high' => $this->calculate_minute_cost((int)config('app.price_client_high')),
'normal' => $this->calculate_minute_cost((int)config('app.price_client_normal')),
'low' => $this->calculate_minute_cost((int)config('app.price_client_low')),
'0'=>0,
];
}

View File

@ -7,9 +7,9 @@ class CsvSumTotalsCalc
private $calculate_agent_cost;
public function __construct()
public function __construct($calculate_agent_cost = false)
{
$this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST');
$this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost');
}
private function sum_total_cost(array $array)

View File

@ -6,9 +6,9 @@ use App\Http\Controllers\CsvController\CsvCostCalc\CsvCostCalc;
class CsvDataHandling
{
public function __construct()
public function __construct($calculate_agent_cost = false)
{
$this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST');
$this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost');
$this->csv_cost_calc = new CsvCostCalc();
}
@ -33,7 +33,7 @@ class CsvDataHandling
return [$total_issue_time, $agents_issue_time];
}
function handle_csv_time(array $array, array $issue, array $issue_time, array $company_agents = [])
function handle_csv_time(array $array, array $issue, array $issue_time, array $company_agents = [], $calculate_agent_cost = false)
{
[$total_time, $agents_time] = $this->get_issue_total_time($issue_time);
$array = $this->csv_cost_calc->total_time_cost($array, $total_time);

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\GiteaApiController;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Http\Request;
class GiteaApiController extends Controller
@ -16,7 +17,7 @@ class GiteaApiController extends Controller
public function export_closed_issues(Request $req)
{
if ($req->input('token') != getenv('GITEA_TOKEN')) {
if ($req->input('token') != config('app.gitea_token')) {
return redirect('/');
}
$from = $req->input('from_year') . '-' . $req->input('from_month') . '-01';
@ -24,7 +25,7 @@ class GiteaApiController extends Controller
$res = $this->gitea_export->export_issues($from, $to, ['state' => $req->input('issues_type')]);
return view('backend', [
'token' => getenv('GITEA_TOKEN'),
'token' => config('app.gitea_token'),
'download' => $res
]);
}

View File

@ -8,6 +8,8 @@ use App\Http\Controllers\CsvController\CsvCostCalc\CsvCostCalc;
use App\Http\Controllers\IssueValidationController;
use App\Http\Controllers\ThirdPartyServices\ThirdPartyServices;
use OwenVoke\Gitea\Client;
use Illuminate\Support\Facades\Config;
class GiteaExport extends Controller
{
@ -25,23 +27,33 @@ class GiteaExport extends Controller
private $third_party_services;
private $email_send_allow;
public function __construct()
public function __construct(
$calculate_agent_cost = false,
$third_party_integrations_allow = false,
$third_party_integrations_nextcloud = false,
$third_party_integrations_open_project = false,
$email_send_allow = false
)
{
$this->third_party_integrations_allow = env('THIRD_PARTY_INTEGRATIONS_ALLOW', false);
$this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST', false);
$this->email_send_allow = env('EMAIL_SEND_ALLOW', false);
$this->email_address = env('EMAIL_ADDRESS', false);
$this->email_prefix_subject = env('EMAIL_PREFIX_SUBJECT', false);
$this->giteaClient = new Client(null, null, getenv('GITEA_URL'));
$this->giteaClient->authenticate(getenv('GITEA_TOKEN'), null, Client::AUTH_ACCESS_TOKEN);
$this->third_party_integrations_allow = $third_party_integrations_allow || config('app.third_party_integrations_allow', false);
$this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost', false);
$this->email_address = config('email.email_address', false);
$this->email_prefix_subject = config('email.email_prefix_subject', false);
$gitea_url = config('app.gitea_url');
$gitea_token = config('app.gitea_token');
$this->giteaClient = new Client(null, null, $gitea_url);
$this->giteaClient->authenticate($gitea_token, null, Client::AUTH_ACCESS_TOKEN);
$this->issue_validation_controller = new IssueValidationController();
$this->csv_controller = new CsvController();
$this->csv_controller = new CsvController($this->calculate_agent_cost);
$this->gitea_fetch = new GiteaFetch();
$this->csv_cost_calc = new CsvCostCalc();
$this->third_party_services = new ThirdPartyServices();
$this->csv_cost_calc = new CsvCostCalc($this->calculate_agent_cost);
$this->third_party_services = new ThirdPartyServices($third_party_integrations_nextcloud, $third_party_integrations_open_project, $email_send_allow);
}
private function handle_repos(string $from_date, string $to_date, array $repositories, array $issues_params){
private function handle_repos(string $from_date, string $to_date, array $repositories, array $issues_params)
{
$data = [];
foreach ($repositories as $repository) {
$issues = $this->gitea_fetch->get_issues($repository['name'], $issues_params);
@ -61,15 +73,15 @@ class GiteaExport extends Controller
function export_issues(string $from_date, string $to_date, array $issues_params)
{
$repositories = $this->gitea_fetch->get_repositories();
$data = $this->handle_repos($from_date, $to_date, $repositories, $issues_params);
$data = $this->handle_repos($from_date, $to_date, $repositories, $issues_params);
if (count($data) > 0) {
$company_agents = $this->calculate_agent_cost ? $this->gitea_fetch->get_company_agents() : [];
$data = $this->csv_cost_calc->sum_costs($data, $company_agents);
$csv_file = $this->csv_controller->create_csv($issues_params['state'], $from_date, $to_date, $data);
if($this->third_party_integrations_allow) {
if ($this->third_party_integrations_allow) {
$this->third_party_services->handle_third_party_services($csv_file['file_name'], $csv_file['file_path'], $data, $company_agents, $from_date, $to_date);
}
isset($csv_file['file_path']) ?? unlink($csv_file['file_path']);
isset($csv_file['file_path']) ?? unlink($csv_file['file_path']);
readfile($csv_file['file_path']);
unlink($csv_file['file_path']);
return true;

View File

@ -19,10 +19,10 @@ class GiteaFetch extends Controller
public function __construct()
{
$this->main_company_organization = getenv('GITEA_MAIN_COMPANY_ORGANIZATION');
$this->partner_organization = getenv('GITEA_PARTNER_ORGANIZATION');
$this->gitea_url = getenv('GITEA_URL');
$this->gitea_token = getenv('GITEA_TOKEN');
$this->main_company_organization = config('app.gitea_main_company_organization');
$this->partner_organization = config('app.gitea_partner_organization');
$this->gitea_url = config('app.gitea_url');
$this->gitea_token = config('app.gitea_token');
$this->giteaClient = new Client(null, null, $this->gitea_url);
$this->giteaClient->authenticate($this->gitea_token, null, Client::AUTH_ACCESS_TOKEN);
}

View File

@ -15,9 +15,9 @@ class EmailService extends Controller
public function __construct()
{
$this->email_address_recepient = env('EMAIL_ADDRESS_RECEPIENT', null);
$this->email_prefix_subject = env('EMAIL_PREFIX_SUBJECT', null);
$this->nextcloud_upload_folder_web_link = env('NEXTCLOUD_UPLOAD_FOLDER_WEB_LINK', false);
$this->email_address_recepient = config('mail.email_address_recepient', null);
$this->email_prefix_subject = config('mail.email_prefix_subject', null);
$this->nextcloud_upload_folder_web_link = config('mail.nextcloud_upload_folder_web_link', false);
}
function send_export_via_email(string $from_date, string $to_date, string $file_name){
try{

View File

@ -17,11 +17,11 @@ class NextcloudService extends Controller
public function __construct()
{
$this->nextcloud_url = env('NEXTCLOUD_URL', false);
$this->nextcloud_user = env('NEXTCLOUD_USER', false);
$this->nextcloud_password = env('NEXTCLOUD_PASSWORD', false);
$this->nextcloud_upload_folder_path = env('NEXTCLOUD_UPLOAD_FOLDER_PATH', false);
$this->nextcloud_upload_folder_web_link = env('NEXTCLOUD_UPLOAD_FOLDER_WEB_LINK', false);
$this->nextcloud_url = config('app.nextcloud_url', false);
$this->nextcloud_user = config('app.nextcloud_user', false);
$this->nextcloud_password = config('app.nextcloud_password', false);
$this->nextcloud_upload_folder_path = config('app.nextcloud_upload_folder_path', false);
$this->nextcloud_upload_folder_web_link = config('app.nextcloud_upload_folder_web_link', false);
}
function nextcloud_upload_csv(string $file_name, string $file_path)

View File

@ -17,14 +17,14 @@ class OpenProjectService extends Controller
public function __construct()
{
$this->open_project_url = env('OPEN_PROJECT_URL', false);
$this->open_project_token = env('OPEN_PROJECT_TOKEN', false);
$this->open_project_project_id = env('OPEN_PROJECT_PROJECT_ID', false);
$this->open_project_task_name = env('OPEN_PROJECT_TASK_NAME', false);
$this->open_project_group_id = env('OPEN_PROJECT_GROUP_ID', false);
$this->open_project_special_nicks_list = env('OPEN_PROJECT_SPECIAL_NICKS_LIST', false);
$this->open_project_work_package_type_id = env('OPEN_PROJECT_WORK_PACKAGE_TYPE_ID', false);
$this->open_project_work_package_user_owner_id = env('OPEN_PROJECT_WORK_PACKAGE_USER_OWNER_ID', false);
$this->open_project_url = config('app.open_project_url', false);
$this->open_project_token = config('app.open_project_token', false);
$this->open_project_project_id = config('app.open_project_project_id', false);
$this->open_project_task_name = config('app.open_project_task_name', false);
$this->open_project_group_id = config('app.open_project_group_id', false);
$this->open_project_special_nicks_list = config('app.open_project_special_nicks_list', false);
$this->open_project_work_package_type_id = config('app.open_project_work_package_type_id', false);
$this->open_project_work_package_user_owner_id = config('app.open_project_work_package_user_owner_id', false);
}
private function open_project_project_member_task_id(stdClass $open_project_member)

View File

@ -12,15 +12,15 @@ class ThirdPartyServices extends Controller
private $third_party_integrations_nextcloud;
private $third_party_integrations_open_project;
public function __construct()
public function __construct($third_party_integrations_nextcloud, $third_party_integrations_open_project, $email_send_allow)
{
$this->third_party_integrations_nextcloud = env('THIRD_PARTY_INTEGRATIONS_NEXTCLOUD', false);
$this->third_party_integrations_open_project = env('THIRD_PARTY_INTEGRATIONS_OPEN_PROJECT', false);
$this->email_send_allow = env('EMAIL_SEND_ALLOW', false);
$this->third_party_integrations_nextcloud = $third_party_integrations_nextcloud || config('app.third_party_integrations_nextcloud', false);
$this->third_party_integrations_open_project = $third_party_integrations_open_project || config('app.third_party_integrations_open_project', false);
$this->email_send_allow = $email_send_allow || config('email.email_send_allow', false);
$this->nextcloud_service = new \App\Http\Controllers\ThirdPartyServices\NextcloudService();
$this->open_project_service = new \App\Http\Controllers\ThirdPartyServices\OpenProjectService();
$this->email_service = new \App\Http\Controllers\ThirdPartyServices\EmailService();
$this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST', false);
$this->calculate_agent_cost = config('app.gitea_calculate_agent_cost', false);
}
function handle_third_party_services(string $file_name, string $file_path, array $issues, array $company_agents, string $from_date, string $to_date)

View File

@ -6,7 +6,7 @@ require_once __DIR__.'/../vendor/autoload.php';
dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
/*
|--------------------------------------------------------------------------
@ -23,6 +23,10 @@ $app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
$app->configure('app');
date_default_timezone_set(config('APP_TIMEZONE', 'UTC'));
$app->withFacades();
// $app->withEloquent();
@ -59,7 +63,6 @@ $app->singleton(
|
*/
$app->configure('app');
/*
|--------------------------------------------------------------------------

66
config/app.php Normal file
View File

@ -0,0 +1,66 @@
<?php
use Illuminate\Support\Facades\Facade;
return [
'name' => env('APP_NAME', 'Lumen'),
'app_env' => env('APP_ENV', ' local'),
'app_key' => env('APP_KEY', ''),
'app_debug' => env('APP_DEBUG', ' true'),
'app_url' => env('APP_URL', 'http://localhost'),
'app_timezone' => env('APP_TIMEZONE', ' UTC'),
'app_password' => env('APP_PASSWORD', ' test'),
'third_party_integrations_allow' => env('third_party_integrations_allow', false),
'calculate_agent_cost' => env('calculate_agent_cost', false),
'email_send_allow' => env('email_send_allow', false),
'email_address' => env('email_address', false),
'email_prefix_subject' => env('email_prefix_subject', false),
'log_channel' => env('LOG_CHANNEL', ' stack'),
'log_slack_webhook_url' => env('LOG_SLACK_WEBHOOK_URL', ''),
'gitea_calculate_agent_cost' => env('GITEA_CALCULATE_AGENT_COST', false),
#YOUR ORG NAME
'gitea_main_company_organization' => env('GITEA_MAIN_COMPANY_ORGANIZATION', null),
#YOUR PARTNER ORG NAME
'gitea_partner_organization' => env('GITEA_PARTNER_ORGANIZATION', null),
#YOUR GITEA INSTANCE NAME
'gitea_url' => env('GITEA_URL', null),
#GITEA API TOKEN
'gitea_token' => env('GITEA_TOKEN', null),
#SET THE PARTNER PRICES
'price_partner_high' => env('PRICE_PARTNER_HIGH', 0),
'price_partner_normal' => env('PRICE_PARTNER_NORMAL', 0),
'price_partner_low' => env('PRICE_PARTNER_LOW', 0),
#SET THE CLIENT PRICES
'price_client_high' => env('PRICE_CLIENT_HIGH', 0),
'price_client_normal' => env('PRICE_CLIENT_NORMAL', 0),
'price_client_low' => env('PRICE_CLIENT_LOW', 0),
#SET A
'price_internal_percentage_to_deduct' => env('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT', 0),
'third_party_integrations_nextcloud' => env('THIRD_PARTY_INTEGRATIONS_NEXTCLOUD', false),
'third_party_integrations_open_project' => env('THIRD_PARTY_INTEGRATIONS_OPEN_PROJECT', false),
'nextcloud_url' => env('NEXTCLOUD_URL', null),
'nextcloud_user' => env('NEXTCLOUD_USER', null),
'nextcloud_password' => env('NEXTCLOUD_PASSWORD', null),
'nextcloud_upload_folder_path' => env('NEXTCLOUD_UPLOAD_FOLDER_PATH', null),
'nextcloud_upload_folder_web_link' => env('NEXTCLOUD_UPLOAD_FOLDER_WEB_LINK', null),
'open_project_url' => env('OPEN_PROJECT_URL', null),
'open_project_token' => env('OPEN_PROJECT_TOKEN', null),
'open_project_project_id' => env('OPEN_PROJECT_PROJECT_ID', null),
'open_project_group_id' => env('OPEN_PROJECT_GROUP_ID', null),
'open_project_work_package_type_id' => env('OPEN_PROJECT_WORK_PACKAGE_TYPE_ID', null),
'open_project_work_package_user_owner_id' => env('OPEN_PROJECT_WORK_PACKAGE_USER_OWNER_ID', null),
'open_project_task_name' => env('OPEN_PROJECT_TASK_NAME', null),
# {"Nickname openproject":"Nickname Git"}
'open_project_special_nicks_list' => env('OPEN_PROJECT_SPECIAL_NICKS_LIST', null),
'test_export_date_yyyy' => env('TEST_EXPORT_DATE_YYYY', null),
'test_export_date_mm' => env('TEST_EXPORT_DATE_MM', null),
'test_export_total_cost' => env('TEST_EXPORT_TOTAL_COST', null),
'test_export_agents_cost' => env('TEST_EXPORT_AGENTS_COST', null),
'test_export_agent_percentage_deducted' => env('TEST_EXPORT_AGENT_PERCENTAGE_DEDUCTED', null),
'test_file_hash_with_agents' => env('TEST_FILE_HASH_WITH_AGENT', null),
'test_file_hash_without_agents' => env('TEST_FILE_HASH_WITHOUT_AGENT', null),
'test_export_total_cost_minus_percentage' => env('TEST_EXPORT_TOTAL_COST_MINUS_PERCENTAGE', null),];

View File

@ -14,7 +14,7 @@ return [
|
*/
'default' => env('MAIL_MAILER', 'log'),
'default' => config('MAIL_MAILER', 'log'),
/*
|--------------------------------------------------------------------------
@ -38,14 +38,14 @@ return [
'smtp' => [
'transport' => 'smtp',
'url' => env('MAIL_URL'),
'host' => env('MAIL_HOST', '127.0.0.1'),
'port' => env('MAIL_PORT', 2525),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'url' => config('MAIL_URL'),
'host' => config('MAIL_HOST', '127.0.0.1'),
'port' => config('MAIL_PORT', 1025),
'encryption' => config('MAIL_ENCRYPTION', 'tls'),
'username' => config('MAIL_USERNAME'),
'password' => config('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN'),
'local_domain' => config('MAIL_EHLO_DOMAIN'),
],
'ses' => [
@ -54,7 +54,7 @@ return [
'postmark' => [
'transport' => 'postmark',
// 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'),
// 'message_stream_id' => config('POSTMARK_MESSAGE_STREAM_ID'),
// 'client' => [
// 'timeout' => 5,
// ],
@ -62,12 +62,12 @@ return [
'sendmail' => [
'transport' => 'sendmail',
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
'path' => config('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
'channel' => config('MAIL_LOG_CHANNEL'),
],
'array' => [
@ -96,8 +96,12 @@ return [
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
'address' => config('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => config('MAIL_FROM_NAME', 'Example'),
],
'email_address_recepient' => env('EMAIL_ADDRESS_RECEPIENT', null),
'email_prefix_subject' => env('EMAIL_PREFIX_SUBJECT', null),
'mail_from_address' => env('MAIL_FROM_ADDRESS', 'export - git@test . net'),
'mail_from_name' => env('MAIL_FROM_NAME', "Export git"),
];

View File

@ -36,7 +36,6 @@ $router->post('export', [
'as' => 'export',
'uses' => 'GiteaApiController\GiteaApiController@export_closed_issues'
]);
// $router->post('backend', [
// 'as' => 'backend',
// 'uses' => 'CheckSimpleAuthController@show'

View File

@ -2,40 +2,132 @@
namespace Tests;
use App\Http\Controllers\GiteaApiController\GiteaExport;
use Tests\TestCase;
use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
class CsvGenerationTest extends TestCase
{
public function test_export_contains_correct_data()
protected function setUp(): void
{
parent::setUp();
$this->test_date_year = config('app.test_export_date_yyyy');
$this->test_date_month = config('app.test_export_date_mm');
$this->test_export_total_cost = config('app.test_export_total_cost');
$this->test_export_total_cost_minus_percentage = config('app.test_export_total_cost_minus_percentage');
$this->test_export_agents_cost = json_decode(config('app.test_export_agents_cost'));
$this->test_export_agent_percentage_deducted = json_decode(config('app.test_export_agent_percentage_deducted'));
$this->test_file_hash_without_agents = config('app.test_file_hash_without_agents');
$this->test_file_hash_with_agents = config('app.test_file_hash_with_agents');
$this->issueType = 'closed';
}
$res = $this->post('/backend', array(
'organization' => 'GruppoCO',
'password' => getenv('APP_PASSWORD')
));
$res->assertResponseOk();
private function test_total_cost($parsed_generated_csv){
$total_cost_index = array_search('Costo totale',$parsed_generated_csv[0]);
$total_cost_column = array_column($parsed_generated_csv,$total_cost_index);
array_shift($total_cost_column);
array_pop($total_cost_column);
$total_cost_sum = 0;
foreach($total_cost_column as $row){
$total_cost_sum += (float) $row;
}
$this->assertEquals($this->test_export_total_cost, $total_cost_sum);
}
public function test_export_values_without_agents_cost()
{
$gitea_export = new GiteaExport();
$export_date =$this->test_date_year .'-'. $this->test_date_month .'-';
$gitea_export->export_issues($export_date . '01', $export_date . '31', ['state' => 'closed']);
$generated_csv_string = ob_get_contents();
$generated_csv = explode("\n", $generated_csv_string);
$parsed_generated_csv = array_map(function($row) {
return str_getcsv($row);
}, $generated_csv);
$beginningDateYear = '2024' ;
$beginningDateMonth = '04';
$endDateYear = '2024';
$endDateMonth = '05';
$issueType = 'closed';
$generated_csv_hash = md5($generated_csv_string);
$this->assertEquals($generated_csv_hash, $this->test_file_hash_without_agents);
//Check if total sum is the same both on the csv and the env var
$this->test_total_cost($parsed_generated_csv);
}
$generatedCsv = $this->post('/export', array(
'from_year' => $beginningDateYear,
'from_month' => $beginningDateMonth,
'to_year' => $endDateYear,
'to_month' => $endDateMonth,
'issues_type' => $issueType,
));
function extract_agents_column($parsed_generated_csv, $test_export_agents_cost){
foreach ($test_export_agents_cost as $agent_name => $agent_total_cost){
$agent_position = array_search($agent_name,$parsed_generated_csv[0]);
if(!$agent_position) break;
$agents_columns[$agent_name] = [
'agent_time' => array_column($parsed_generated_csv,$agent_position),
'agent_cost' => array_column($parsed_generated_csv,$agent_position+1),
];
array_shift($agents_columns[$agent_name]['agent_time']);
array_shift($agents_columns[$agent_name]['agent_cost']);
}
return $agents_columns;
}
$res->assertResponseOK();
//Check for each agent, if their total costs is the same as the env reference
private function test_single_agent_cost($agents_columns, $parsed_generated_csv_header){
foreach($agents_columns as $agent_name => $agent_column){
$agent_total = end($agent_column['agent_cost']);
$this->assertEquals($this->test_export_agents_cost->$agent_name, $agent_total);
}
}
$generatedCsvHash = md5_file($generatedCsv);
$testFileHash = '07078b8e24768453b1e45236b13d347d';
//Check for each agent, if their cost column sum is the same as their env total cost reference
private function test_single_agent_total_sum($agents_columns){
foreach($agents_columns as $agent_name => $agent_column){
$agent_total = 0;
foreach(array_slice($agent_column['agent_cost'], 0, -1) as $agent_cost){
$agent_total += (float)$agent_cost;
}
$test = (string) $agent_total;
$this->assertEquals($this->test_export_agents_cost->$agent_name, $test);
}
}
assertEquals($generatedCsvHash, $testFileHash);
//Check if the total sum - % to deduct is the same as the agents cost total sum
private function test_agents_total_cost_equals_total_sum_minus_percentage($agents_columns){
$agents_total_cost_calculated = 0;
foreach($agents_columns as $agent_name => $agent_column){
$agent_cost_voice = (float)end($agent_column['agent_cost']);
$agents_total_cost_calculated = $agents_total_cost_calculated + $agent_cost_voice;
}
$this->assertEquals($this->test_export_total_cost_minus_percentage, $agents_total_cost_calculated);
}
//Check if the total sum - % to deduct is the same as the agents cost total sum
public function test_export_values_with_agents_cost()
{
$calculate_agent_cost = true;
$gitea_export = new GiteaExport(
$calculate_agent_cost,
);
$export_date =$this->test_date_year .'-'. $this->test_date_month .'-';
$gitea_export->export_issues($export_date . '01', $export_date . '31', ['state' => 'closed']);
$generated_csv_string = ob_get_contents();
$generated_csv = explode("\n", $generated_csv_string);
$parsed_generated_csv = array_map(function($row) {
return str_getcsv($row);
}, $generated_csv);
$agents_columns = $this->extract_agents_column($parsed_generated_csv, $this->test_export_agents_cost);
//Check if hash of generated csv and env reference are the same
$this->assertEquals(md5($generated_csv_string), $this->test_file_hash_with_agents);
//Check if total sum is the same both on the csv and the env var
$this->test_total_cost($parsed_generated_csv);
//Check for each agent, if their total costs is the same as the env reference
$this->test_single_agent_cost($agents_columns,$parsed_generated_csv[0]);
//Check for each agent, if their cost column sum is the same as their env total cost reference
$this->test_single_agent_total_sum($agents_columns);
//Check if the total sum - % to deduct is the same as the agents cost total sum
$this->test_agents_total_cost_equals_total_sum_minus_percentage($agents_columns);
//TODO RECALCULATE EACH AGENT COST WITH TEST PRICE
}
}

View File

@ -3,18 +3,18 @@
namespace Tests\Http\Controllers\CsvController;
use App\Http\Controllers\CsvController\CsvController;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class CsvControllerTest extends TestCase
{
public function testCreate_csv()
{
}
public function testCreate_columns()
{
}
// public function testCreate_csv()
// {
//
// }
//
// public function testCreate_columns()
// {
//
// }
}

View File

@ -4,13 +4,15 @@ namespace Tests\Http\Controllers\CsvController\CsvCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvAgentCost;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
use RuntimeException;
class CsvAgentCostTest extends TestCase
{
protected function setUp(): void
{
protected function setUp(): void
{parent::setUp();
parent::setUp();
$this->csv_agent_cost = new CsvAgentCost();
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
$this->csv_agent_cost->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc;

View File

@ -1,25 +0,0 @@
<?php
namespace Tests\Http\Controllers\CsvController\CsvCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvCostCalc;
use PHPUnit\Framework\TestCase;
class CsvCostCalcTest extends TestCase
{
public function testTotal_time_cost()
{
}
public function testAgent_cost_calc()
{
}
public function testSum_costs()
{
}
}

View File

@ -3,7 +3,7 @@
namespace Tests\Http\Controllers\CsvController\CsvCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class CsvMinuteCostCalcTest extends TestCase
{
@ -12,7 +12,7 @@ class CsvMinuteCostCalcTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->csv_minute_cost_calc = new CsvMinuteCostCalc(); // Replace CsvMinuteCostCalc with the actual class name
$this->csv_minute_cost_calc->partner_organization = 'PartnerOrg'; // Set up the partner organization
$this->csv_minute_cost_calc->price_partner = [

View File

@ -4,13 +4,14 @@ namespace Tests\Http\Controllers\CsvController\CsvCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvTotalCostCalc;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class CsvSumTotalsCalcTest extends TestCase
{
protected function setUp(): void
{
protected function setUp(): void
{parent::setUp();
$this->CsvTotalCostCalc = new CsvTotalCostCalc();
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
$this->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc;

View File

@ -4,14 +4,15 @@ namespace Tests\Http\Controllers\CsvController\CsvCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvTotalCostCalc;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class CsvTotalCostCalcTest extends TestCase
{
protected function setUp(): void
{
protected function setUp(): void
{parent::setUp();
$this->CsvTotalCostCalc = new CsvTotalCostCalc();
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
$this->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc;

View File

@ -6,12 +6,13 @@ use App\Http\Controllers\CsvController\CsvCostCalc\CsvAgentCost;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc;
use App\Http\Controllers\CsvController\CsvDataHandling;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class CsvDataHandlingTest extends TestCase
{
protected function setUp(): void
{
protected function setUp(): void
{parent::setUp();
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
$this->csv_data_handling = new CsvDataHandling();
$this->csv_data_handling->csv_cost_calc->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc;

View File

@ -3,13 +3,14 @@
namespace Tests\Http\Controllers\CsvController;
use App\Http\Controllers\CsvController\CsvDataInit;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class CsvDataInitTest extends TestCase
{
protected function setUp(): void
{
protected function setUp(): void
{parent::setUp();
$this->csv_data_init = new CsvDataInit();
}

View File

@ -3,7 +3,7 @@
namespace Tests\Http\Controllers\GiteaApiController;
use App\Http\Controllers\GiteaApiController\GiteaApiController;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class GiteaApiControllerTest extends TestCase
{

View File

@ -3,7 +3,7 @@
namespace Tests\Http\Controllers\GiteaApiController;
use App\Http\Controllers\GiteaApiController\GiteaExport;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class GiteaExportTest extends TestCase
{

View File

@ -3,7 +3,7 @@
namespace Tests\Http\Controllers\GiteaApiController;
use App\Http\Controllers\GiteaApiController\GiteaFetch;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class GiteaFetchTest extends TestCase
{

View File

@ -4,13 +4,14 @@ namespace Tests\Controllers;
use App\Http\Controllers\IssueValidationController;
use Exception;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class IssueValidationControllerTest extends TestCase
{
protected function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->issue_validation_controller = new IssueValidationController();
}
public function testValidDateConversion()

View File

@ -3,7 +3,7 @@
namespace Tests\Http\Controllers\ThirdPartyServices;
use App\Http\Controllers\ThirdPartyServices\EmailService;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class EmailServiceTest extends TestCase
{

View File

@ -3,7 +3,7 @@
namespace Tests\Http\Controllers\ThirdPartyServices;
use App\Http\Controllers\ThirdPartyServices\NextcloudService;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class NextcloudServiceTest extends TestCase
{

View File

@ -3,7 +3,7 @@
namespace Tests\Http\Controllers\ThirdPartyServices;
use App\Http\Controllers\ThirdPartyServices\OpenProjectService;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class OpenProjectServiceTest extends TestCase
{

View File

@ -3,7 +3,7 @@
namespace Tests\Http\Controllers\ThirdPartyServices;
use App\Http\Controllers\ThirdPartyServices\ThirdPartyServices;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class ThirdPartyServicesTest extends TestCase
{

View File

@ -36,7 +36,7 @@ class PagesTest extends TestCase
{
$res = $this->post('/backend', array(
'organization' => 'GruppoCO',
'password' => getenv('APP_PASSWORD')
'password' => config('app.app_password')
));
$res->assertResponseOk();

View File

@ -7,7 +7,7 @@ class UnitTest extends TestCase
public function test_export_endpoint_works_for_logged_in_users()
{
$res = $this->post('/export', array(
'token' => getenv('GITEA_TOKEN'),
'token' => config('app.gitea_token'),
'from_month' => '10',
'from_year' => '2023',
'to_month' => '12',