diff --git a/.envexample b/.envexample deleted file mode 100644 index 6f320e5..0000000 --- a/.envexample +++ /dev/null @@ -1,64 +0,0 @@ -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" diff --git a/app/Console/Commands/csvExport.php b/app/Console/Commands/csvExport.php deleted file mode 100644 index 26b76dd..0000000 --- a/app/Console/Commands/csvExport.php +++ /dev/null @@ -1,99 +0,0 @@ -format('Y-m-d'); - return $d && $d == $stringDate; - } - return false; - } - - function checkInputDates(){ - $firstDay = $this->argument('firstDay'); - $lastDay = $this->argument('lastDay'); - try{ - if( $firstDay !== null && $lastDay !== null){ - $this->info('Rilevate date richieste, controllo la correttezza del formato.'); - if(!$this->checkDateValid($firstDay)) throw new InvalidArgumentException('Formato della prima data errata o data inesistente, formato richiesto Y-m-t, data fornita '. $firstDay); - if(!$this->checkDateValid($lastDay)) throw new InvalidArgumentException('Formato della seconda data errata o data inesistente, formato richiesto Y-m-t, data fornita '. $lastDay); - $this->info('Le date richieste sono correte.'); - return true; - } - } catch (\InvalidArgumentException $e){ - throw new InvalidArgumentException($e->getMessage()); - } - $this->info('Non sono state rilevate date custom'); - return true; - } - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() - { - // Write your script logic here - $this->info('Inizio esecuzione.'); - $this->info('Controllo se sono state inserite date custom.'); - $this->checkInputDates(); - $firstDay = $this->argument('firstDay') ? $this->argument('firstDay') : date('Y-m-01'); // First day of the current month; - $lastDay = $this->argument('lastDay') ? $this->argument('lastDay') : date('Y-m-t'); // Last day of the current month; - $this->info('Export da ' . $firstDay .' a '. $lastDay ); - $calculate_agent_cost = true; - $third_party_integrations_allow = true; - $third_party_integrations_nextcloud = true; - $third_party_integrations_open_project = false; - $email_send_allow = true; - $this->info( - 'Le seguenti opzioni sono attive ' - . ' calculate_agent_cost '. $calculate_agent_cost . '\n' - . ' third_party_integrations_allow '. $third_party_integrations_allow . '\n' - . ' third_party_integrations_nextcloud '. $third_party_integrations_nextcloud . '\n' - . ' third_party_integrations_open_project '. $third_party_integrations_open_project . '\n' - . ' email_send_allow '. $email_send_allow . '\n' - ); - $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']); - return Command::SUCCESS; - } -} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index c62f4d2..ad6e311 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,9 +2,6 @@ namespace App\Console; -use App\Console\Commands\csvExport; -use App\Http\Controllers\GiteaApiController\GiteaExport; -use Dotenv\Dotenv; use Illuminate\Console\Scheduling\Schedule; use Laravel\Lumen\Console\Kernel as ConsoleKernel; @@ -16,7 +13,7 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ - csvExport::class, + // ]; /** @@ -27,5 +24,6 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { + // } } diff --git a/app/Http/Controllers/CheckSimpleAuthController.php b/app/Http/Controllers/CheckSimpleAuthController.php index a47038e..ae79922 100644 --- a/app/Http/Controllers/CheckSimpleAuthController.php +++ b/app/Http/Controllers/CheckSimpleAuthController.php @@ -9,12 +9,12 @@ class CheckSimpleAuthController extends Controller { public function check(Request $req) { if ( - config('app.gitea_partner_organization') === $req->input('organization') + getenv('GITEA_PARTNER_ORGANIZATION') === $req->input('organization') && - config('app.app_password') === $req->input('password') + getenv('APP_PASSWORD') === $req->input('password') ) { return view('backend', [ - 'token' => config('app.gitea_token') + 'token' => getenv('GITEA_TOKEN') ]); } else { return redirect('/'); diff --git a/app/Http/Controllers/CsvController/CsvController.php b/app/Http/Controllers/CsvController/CsvController.php index 707b81f..b1cdec5 100644 --- a/app/Http/Controllers/CsvController/CsvController.php +++ b/app/Http/Controllers/CsvController/CsvController.php @@ -17,12 +17,11 @@ class CsvController extends Controller private $csv_data_handling; - public function __construct($calculate_agent_cost = false) + public function __construct() { - $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->calculate_agent_cost); - $this->third_party_integrations_allow = config('app.third_party_integrations_allow', false); + $this->csv_data_handling = new CsvDataHandling(); + $this->third_party_integrations_allow = env('THIRD_PARTY_INTEGRATIONS_ALLOW', false); } function create_columns(array $issue, array $issue_time, array $company_agents = []) @@ -30,7 +29,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, $this->calculate_agent_cost); + $array = $this->csv_data_handling->handle_csv_time($array, $issue, $issue_time, $company_agents); return $array; } catch (Error $e) { Log::error('E-CSV-COLUMNS - ' . $e->getMessage()); diff --git a/app/Http/Controllers/CsvController/CsvCostCalc/CsvAgentCost.php b/app/Http/Controllers/CsvController/CsvCostCalc/CsvAgentCost.php index 0bb6c0f..971b7b4 100644 --- a/app/Http/Controllers/CsvController/CsvCostCalc/CsvAgentCost.php +++ b/app/Http/Controllers/CsvController/CsvCostCalc/CsvAgentCost.php @@ -12,8 +12,8 @@ class CsvAgentCost public function __construct() { - $this->internal_percentage_to_deduct = (float) config('app.price_internal_percentage_to_deduct', null); - $this->partner_organitation = strtolower(config('app.gitea_partner_organization')); + $this->internal_percentage_to_deduct = (float) getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT', null); + $this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION')); $this->CsvMinuteCostCalc = new CsvMinuteCostCalc(); } diff --git a/app/Http/Controllers/CsvController/CsvCostCalc/CsvCostCalc.php b/app/Http/Controllers/CsvController/CsvCostCalc/CsvCostCalc.php index 6f1bbc6..0937c82 100644 --- a/app/Http/Controllers/CsvController/CsvCostCalc/CsvCostCalc.php +++ b/app/Http/Controllers/CsvController/CsvCostCalc/CsvCostCalc.php @@ -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($calculate_agent_cost = false) + public function __construct() { - $this->internal_percentage_to_deduct = config('app.price_internal_percentage_to_deduct'); - $this->partner_organitation = strtolower(config('app.gitea_partner_organization')); + $this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT'); + $this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION')); $this->CsvAgentCost = new CsvAgentCost(); $this->CsvTotalCostCalc = new CsvTotalCostCalc(); - $this->CsvSumTotalsCalc = new CsvSumTotalsCalc($calculate_agent_cost); + $this->CsvSumTotalsCalc = new CsvSumTotalsCalc(); } diff --git a/app/Http/Controllers/CsvController/CsvCostCalc/CsvMinuteCostCalc.php b/app/Http/Controllers/CsvController/CsvCostCalc/CsvMinuteCostCalc.php index 478b126..1d91c22 100644 --- a/app/Http/Controllers/CsvController/CsvCostCalc/CsvMinuteCostCalc.php +++ b/app/Http/Controllers/CsvController/CsvCostCalc/CsvMinuteCostCalc.php @@ -10,18 +10,18 @@ class CsvMinuteCostCalc { public function __construct() { - $this->internal_percentage_to_deduct = config('app.price_internal_percentage_to_deduct'); - $this->partner_organization = strtolower(config('app.gitea_partner_organization')); + $this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT'); + $this->partner_organization = strtolower(getenv('GITEA_PARTNER_ORGANIZATION')); $this->price_partner = [ - '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')), + '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')), '0'=>0, ]; $this->price_client = [ - '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')), + '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')), '0'=>0, ]; } diff --git a/app/Http/Controllers/CsvController/CsvCostCalc/CsvSumTotalsCalc.php b/app/Http/Controllers/CsvController/CsvCostCalc/CsvSumTotalsCalc.php index 8643a13..15986cf 100644 --- a/app/Http/Controllers/CsvController/CsvCostCalc/CsvSumTotalsCalc.php +++ b/app/Http/Controllers/CsvController/CsvCostCalc/CsvSumTotalsCalc.php @@ -7,9 +7,9 @@ class CsvSumTotalsCalc private $calculate_agent_cost; - public function __construct($calculate_agent_cost = false) + public function __construct() { - $this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost'); + $this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST'); } private function sum_total_cost(array $array) diff --git a/app/Http/Controllers/CsvController/CsvDataHandling.php b/app/Http/Controllers/CsvController/CsvDataHandling.php index 4c1c3fe..8c7eeb9 100644 --- a/app/Http/Controllers/CsvController/CsvDataHandling.php +++ b/app/Http/Controllers/CsvController/CsvDataHandling.php @@ -6,9 +6,9 @@ use App\Http\Controllers\CsvController\CsvCostCalc\CsvCostCalc; class CsvDataHandling { - public function __construct($calculate_agent_cost = false) + public function __construct() { - $this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost'); + $this->calculate_agent_cost = env('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 = [], $calculate_agent_cost = false) + function handle_csv_time(array $array, array $issue, array $issue_time, array $company_agents = []) { [$total_time, $agents_time] = $this->get_issue_total_time($issue_time); $array = $this->csv_cost_calc->total_time_cost($array, $total_time); diff --git a/app/Http/Controllers/GiteaApiController/GiteaApiController.php b/app/Http/Controllers/GiteaApiController/GiteaApiController.php index 08a3897..5442533 100644 --- a/app/Http/Controllers/GiteaApiController/GiteaApiController.php +++ b/app/Http/Controllers/GiteaApiController/GiteaApiController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers\GiteaApiController; use App\Http\Controllers\Controller; -use Illuminate\Support\Facades\Config; use Illuminate\Http\Request; class GiteaApiController extends Controller @@ -17,7 +16,7 @@ class GiteaApiController extends Controller public function export_closed_issues(Request $req) { - if ($req->input('token') != config('app.gitea_token')) { + if ($req->input('token') != getenv('GITEA_TOKEN')) { return redirect('/'); } $from = $req->input('from_year') . '-' . $req->input('from_month') . '-01'; @@ -25,7 +24,7 @@ class GiteaApiController extends Controller $res = $this->gitea_export->export_issues($from, $to, ['state' => $req->input('issues_type')]); return view('backend', [ - 'token' => config('app.gitea_token'), + 'token' => getenv('GITEA_TOKEN'), 'download' => $res ]); } diff --git a/app/Http/Controllers/GiteaApiController/GiteaExport.php b/app/Http/Controllers/GiteaApiController/GiteaExport.php index c9b1100..f79a1d9 100644 --- a/app/Http/Controllers/GiteaApiController/GiteaExport.php +++ b/app/Http/Controllers/GiteaApiController/GiteaExport.php @@ -8,8 +8,6 @@ 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 { @@ -27,33 +25,23 @@ class GiteaExport extends Controller private $third_party_services; private $email_send_allow; - - 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 - ) + public function __construct() { - - $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->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->issue_validation_controller = new IssueValidationController(); - $this->csv_controller = new CsvController($this->calculate_agent_cost); + $this->csv_controller = new CsvController(); $this->gitea_fetch = new GiteaFetch(); - $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); + $this->csv_cost_calc = new CsvCostCalc(); + $this->third_party_services = new ThirdPartyServices(); } - 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); @@ -73,15 +61,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; diff --git a/app/Http/Controllers/GiteaApiController/GiteaFetch.php b/app/Http/Controllers/GiteaApiController/GiteaFetch.php index 5f2b67f..d003ecb 100644 --- a/app/Http/Controllers/GiteaApiController/GiteaFetch.php +++ b/app/Http/Controllers/GiteaApiController/GiteaFetch.php @@ -19,10 +19,10 @@ class GiteaFetch extends Controller public function __construct() { - $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->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->giteaClient = new Client(null, null, $this->gitea_url); $this->giteaClient->authenticate($this->gitea_token, null, Client::AUTH_ACCESS_TOKEN); } diff --git a/app/Http/Controllers/IssueValidationController.php b/app/Http/Controllers/IssueValidationController.php index 6e01a5b..cb31ba0 100644 --- a/app/Http/Controllers/IssueValidationController.php +++ b/app/Http/Controllers/IssueValidationController.php @@ -17,17 +17,13 @@ class IssueValidationController extends Controller return $datetime->format('Y-m-d H:i:s'); } - function search_requested_by_and_kind_bug($issue_labels){ - $kind_requested_by = false; + function search_requested_by($issue_labels){ foreach ($issue_labels as $key => $label) { - if (!$kind_requested_by && strpos($label['name'],'RequestBy') !== false) { - $kind_requested_by = true; - } - if ( strpos($label['name'],'Bug') !== false) { - return false; + if (strpos($label['name'],'RequestBy') !== false) { + return true; } } - return $kind_requested_by; + return false; } function get_issue_total_time(array $issue_time) @@ -43,8 +39,8 @@ class IssueValidationController extends Controller function check_issue_is_billed(array $issue_labels, array $issue_time): bool { $issue_time = $this->get_issue_total_time($issue_time); $issue_time = (gmdate('H:i:s', $issue_time) !== '00:00:00'); - $label_requested_by_no_kind_bug = $this->search_requested_by_and_kind_bug($issue_labels); - return $issue_time && $label_requested_by_no_kind_bug; + $label_requested_by_index = $this->search_requested_by($issue_labels); + return $issue_time && $label_requested_by_index; } function handle_single_issue(string $from_date, string $to_date, array $issue, array $issue_time){ diff --git a/app/Http/Controllers/ThirdPartyServices/EmailService.php b/app/Http/Controllers/ThirdPartyServices/EmailService.php index 6df3df2..ccbbf71 100644 --- a/app/Http/Controllers/ThirdPartyServices/EmailService.php +++ b/app/Http/Controllers/ThirdPartyServices/EmailService.php @@ -15,9 +15,9 @@ class EmailService extends Controller public function __construct() { - $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('app.nextcloud_upload_folder_web_link', false); + $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); } function send_export_via_email(string $from_date, string $to_date, string $file_name){ try{ diff --git a/app/Http/Controllers/ThirdPartyServices/NextcloudService.php b/app/Http/Controllers/ThirdPartyServices/NextcloudService.php index 929526f..8c33ebb 100644 --- a/app/Http/Controllers/ThirdPartyServices/NextcloudService.php +++ b/app/Http/Controllers/ThirdPartyServices/NextcloudService.php @@ -17,11 +17,11 @@ class NextcloudService extends Controller public function __construct() { - $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); + $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); } function nextcloud_upload_csv(string $file_name, string $file_path) diff --git a/app/Http/Controllers/ThirdPartyServices/OpenProjectService.php b/app/Http/Controllers/ThirdPartyServices/OpenProjectService.php index 21fb69b..cefb82e 100644 --- a/app/Http/Controllers/ThirdPartyServices/OpenProjectService.php +++ b/app/Http/Controllers/ThirdPartyServices/OpenProjectService.php @@ -17,14 +17,14 @@ class OpenProjectService extends Controller public function __construct() { - $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); + $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); } private function open_project_project_member_task_id(stdClass $open_project_member) diff --git a/app/Http/Controllers/ThirdPartyServices/ThirdPartyServices.php b/app/Http/Controllers/ThirdPartyServices/ThirdPartyServices.php index 5cc35ab..2371d19 100644 --- a/app/Http/Controllers/ThirdPartyServices/ThirdPartyServices.php +++ b/app/Http/Controllers/ThirdPartyServices/ThirdPartyServices.php @@ -12,15 +12,15 @@ class ThirdPartyServices extends Controller private $third_party_integrations_nextcloud; private $third_party_integrations_open_project; - public function __construct($third_party_integrations_nextcloud, $third_party_integrations_open_project, $email_send_allow) + public function __construct() { - $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('app.email_send_allow', false); + $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->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 = config('app.gitea_calculate_agent_cost', false); + $this->calculate_agent_cost = env('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) diff --git a/bootstrap/app.php b/bootstrap/app.php index f5f6f4f..14ed0d0 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -6,7 +6,7 @@ require_once __DIR__.'/../vendor/autoload.php'; dirname(__DIR__) ))->bootstrap(); - +date_default_timezone_set(env('APP_TIMEZONE', 'UTC')); /* |-------------------------------------------------------------------------- @@ -23,10 +23,6 @@ $app = new Laravel\Lumen\Application( dirname(__DIR__) ); -$app->configure('app'); - -date_default_timezone_set(config('APP_TIMEZONE', 'UTC')); - $app->withFacades(); // $app->withEloquent(); @@ -63,6 +59,7 @@ $app->singleton( | */ +$app->configure('app'); /* |-------------------------------------------------------------------------- diff --git a/composer.lock b/composer.lock index e609df4..f6347d9 100644 --- a/composer.lock +++ b/composer.lock @@ -7576,7 +7576,7 @@ "homepage": "https://github.com/vlucas" } ], - "description": "Loads environment variables from `.env` to `config()`, `$_ENV` and `$_SERVER` automagically.", + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", "keywords": [ "dotenv", "env", diff --git a/config/app.php b/config/app.php deleted file mode 100644 index 2c7e90f..0000000 --- a/config/app.php +++ /dev/null @@ -1,66 +0,0 @@ - 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),]; diff --git a/config/mail.php b/config/mail.php index c7ef373..a4a02fe 100644 --- a/config/mail.php +++ b/config/mail.php @@ -9,20 +9,20 @@ return [ | | This option controls the default mailer that is used to send all email | messages unless another mailer is explicitly specified when sending - | the message. All additional mailers can be envured within the + | the message. All additional mailers can be configured within the | "mailers" array. Examples of each type of mailer are provided. | */ - 'default' => env('MAIL_MAILER', 'sendmail'), + 'default' => env('MAIL_MAILER', 'log'), /* |-------------------------------------------------------------------------- - | Mailer envurations + | Mailer Configurations |-------------------------------------------------------------------------- | - | Here you may envure all of the mailers used by your application plus - | their respective settings. Several examples have been envured for + | Here you may configure all of the mailers used by your application plus + | their respective settings. Several examples have been configured for | you and you are free to add your own as your application requires. | | Laravel supports a variety of mail "transport" drivers that can be used @@ -40,7 +40,7 @@ return [ 'transport' => 'smtp', 'url' => env('MAIL_URL'), 'host' => env('MAIL_HOST', '127.0.0.1'), - 'port' => env('MAIL_PORT', 1025), + 'port' => env('MAIL_PORT', 2525), 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), @@ -96,9 +96,8 @@ return [ */ 'from' => [ - 'address' => env('MAIL_FROM_ADDRESS', 'export-git@congegni.net'), - 'name' => env('MAIL_FROM_NAME', 'Congegni - Export git'), + 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), + 'name' => env('MAIL_FROM_NAME', 'Example'), ], - 'email_address_recepient' => env('EMAIL_ADDRESS_RECEPIENT', null), - 'email_prefix_subject' => env('EMAIL_PREFIX_SUBJECT', null), + ]; diff --git a/routes/web.php b/routes/web.php index 4c18625..580be77 100644 --- a/routes/web.php +++ b/routes/web.php @@ -36,6 +36,7 @@ $router->post('export', [ 'as' => 'export', 'uses' => 'GiteaApiController\GiteaApiController@export_closed_issues' ]); + // $router->post('backend', [ // 'as' => 'backend', // 'uses' => 'CheckSimpleAuthController@show' diff --git a/tests/CsvGenerationTest.php b/tests/CsvGenerationTest.php index 19c6c90..b39780e 100644 --- a/tests/CsvGenerationTest.php +++ b/tests/CsvGenerationTest.php @@ -2,132 +2,40 @@ 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 { - - - protected function setUp(): void + public function test_export_contains_correct_data() { - 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'; - } - 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); + $res = $this->post('/backend', array( + 'organization' => 'GruppoCO', + 'password' => getenv('APP_PASSWORD') + )); + $res->assertResponseOk(); - $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); - } + $beginningDateYear = '2024' ; + $beginningDateMonth = '04'; + $endDateYear = '2024'; + $endDateMonth = '05'; + $issueType = 'closed'; - 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; - } + $generatedCsv = $this->post('/export', array( + 'from_year' => $beginningDateYear, + 'from_month' => $beginningDateMonth, + 'to_year' => $endDateYear, + 'to_month' => $endDateMonth, + 'issues_type' => $issueType, + )); - //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); - } - } + $res->assertResponseOK(); - //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); - } - } + $generatedCsvHash = md5_file($generatedCsv); + $testFileHash = '07078b8e24768453b1e45236b13d347d'; - //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 + assertEquals($generatedCsvHash, $testFileHash); } } diff --git a/tests/Http/Controllers/CsvController/CsvControllerTest.php b/tests/Http/Controllers/CsvController/CsvControllerTest.php index 7e80658..4291c2e 100644 --- a/tests/Http/Controllers/CsvController/CsvControllerTest.php +++ b/tests/Http/Controllers/CsvController/CsvControllerTest.php @@ -3,18 +3,18 @@ namespace Tests\Http\Controllers\CsvController; use App\Http\Controllers\CsvController\CsvController; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class CsvControllerTest extends TestCase { -// public function testCreate_csv() -// { -// -// } -// -// public function testCreate_columns() -// { -// -// } + public function testCreate_csv() + { + + } + + public function testCreate_columns() + { + + } } diff --git a/tests/Http/Controllers/CsvController/CsvCostCalc/CsvAgentCostTest.php b/tests/Http/Controllers/CsvController/CsvCostCalc/CsvAgentCostTest.php index 5dd8b8a..4e0c0bb 100644 --- a/tests/Http/Controllers/CsvController/CsvCostCalc/CsvAgentCostTest.php +++ b/tests/Http/Controllers/CsvController/CsvCostCalc/CsvAgentCostTest.php @@ -4,15 +4,13 @@ namespace Tests\Http\Controllers\CsvController\CsvCostCalc; use App\Http\Controllers\CsvController\CsvCostCalc\CsvAgentCost; use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; use RuntimeException; class CsvAgentCostTest extends TestCase { -protected function setUp(): void - {parent::setUp(); - - parent::setUp(); + protected function setUp(): void + { $this->csv_agent_cost = new CsvAgentCost(); $this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class); $this->csv_agent_cost->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc; diff --git a/tests/Http/Controllers/CsvController/CsvCostCalc/CsvCostCalcTest.php b/tests/Http/Controllers/CsvController/CsvCostCalc/CsvCostCalcTest.php new file mode 100644 index 0000000..4ba1cac --- /dev/null +++ b/tests/Http/Controllers/CsvController/CsvCostCalc/CsvCostCalcTest.php @@ -0,0 +1,25 @@ +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 = [ diff --git a/tests/Http/Controllers/CsvController/CsvCostCalc/CsvSumTotalsCalcTest.php b/tests/Http/Controllers/CsvController/CsvCostCalc/CsvSumTotalsCalcTest.php index 170300d..81f9824 100644 --- a/tests/Http/Controllers/CsvController/CsvCostCalc/CsvSumTotalsCalcTest.php +++ b/tests/Http/Controllers/CsvController/CsvCostCalc/CsvSumTotalsCalcTest.php @@ -4,14 +4,13 @@ namespace Tests\Http\Controllers\CsvController\CsvCostCalc; use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc; use App\Http\Controllers\CsvController\CsvCostCalc\CsvTotalCostCalc; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class CsvSumTotalsCalcTest extends TestCase { -protected function setUp(): void - {parent::setUp(); - + protected function setUp(): void + { $this->CsvTotalCostCalc = new CsvTotalCostCalc(); $this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class); $this->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc; diff --git a/tests/Http/Controllers/CsvController/CsvCostCalc/CsvTotalCostCalcTest.php b/tests/Http/Controllers/CsvController/CsvCostCalc/CsvTotalCostCalcTest.php index 5db2958..94e6419 100644 --- a/tests/Http/Controllers/CsvController/CsvCostCalc/CsvTotalCostCalcTest.php +++ b/tests/Http/Controllers/CsvController/CsvCostCalc/CsvTotalCostCalcTest.php @@ -4,15 +4,14 @@ namespace Tests\Http\Controllers\CsvController\CsvCostCalc; use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc; use App\Http\Controllers\CsvController\CsvCostCalc\CsvTotalCostCalc; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class CsvTotalCostCalcTest extends TestCase { -protected function setUp(): void - {parent::setUp(); - + protected function setUp(): void + { $this->CsvTotalCostCalc = new CsvTotalCostCalc(); $this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class); $this->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc; diff --git a/tests/Http/Controllers/CsvController/CsvDataHandlingTest.php b/tests/Http/Controllers/CsvController/CsvDataHandlingTest.php index 3ef55da..bf942c4 100644 --- a/tests/Http/Controllers/CsvController/CsvDataHandlingTest.php +++ b/tests/Http/Controllers/CsvController/CsvDataHandlingTest.php @@ -6,13 +6,12 @@ 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 Tests\TestCase; +use PHPUnit\Framework\TestCase; class CsvDataHandlingTest extends TestCase { -protected function setUp(): void - {parent::setUp(); - + protected function setUp(): void + { $this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class); $this->csv_data_handling = new CsvDataHandling(); $this->csv_data_handling->csv_cost_calc->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc; diff --git a/tests/Http/Controllers/CsvController/CsvDataInitTest.php b/tests/Http/Controllers/CsvController/CsvDataInitTest.php index 55afbb8..952adf0 100644 --- a/tests/Http/Controllers/CsvController/CsvDataInitTest.php +++ b/tests/Http/Controllers/CsvController/CsvDataInitTest.php @@ -3,14 +3,13 @@ namespace Tests\Http\Controllers\CsvController; use App\Http\Controllers\CsvController\CsvDataInit; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class CsvDataInitTest extends TestCase { -protected function setUp(): void - {parent::setUp(); - + protected function setUp(): void + { $this->csv_data_init = new CsvDataInit(); } diff --git a/tests/Http/Controllers/GiteaApiController/GiteaApiControllerTest.php b/tests/Http/Controllers/GiteaApiController/GiteaApiControllerTest.php new file mode 100644 index 0000000..fa58d9c --- /dev/null +++ b/tests/Http/Controllers/GiteaApiController/GiteaApiControllerTest.php @@ -0,0 +1,15 @@ +issue_validation_controller = new IssueValidationController(); } public function testValidDateConversion() @@ -88,26 +87,19 @@ protected function setUp(): void public function testLabelExists() { - $labels = [['name' => 'RequestBy: User1'], ['name' => 'Piru']]; - $this->assertTrue($this->issue_validation_controller->search_requested_by_and_kind_bug($labels)); + $labels = [['name' => 'RequestBy: User1'], ['name' => 'Bug']]; + $this->assertTrue($this->issue_validation_controller->search_requested_by($labels)); } public function testLabelDoesNotExist() { $labels = [['name' => 'Bug'], ['name' => 'Feature']]; - $this->assertFalse($this->issue_validation_controller->search_requested_by_and_kind_bug($labels)); + $this->assertFalse($this->issue_validation_controller->search_requested_by($labels)); } public function testEmptyLabels() { $labels = []; - $this->assertFalse($this->issue_validation_controller->search_requested_by_and_kind_bug($labels)); + $this->assertFalse($this->issue_validation_controller->search_requested_by($labels)); } - - public function testKindBugExists() - { - $labels = [['name' => 'RequestBy: User1'], ['name' => 'Bug']]; - $this->assertFalse($this->issue_validation_controller->search_requested_by_and_kind_bug($labels)); - } - } diff --git a/tests/Http/Controllers/ThirdPartyServices/EmailServiceTest.php b/tests/Http/Controllers/ThirdPartyServices/EmailServiceTest.php new file mode 100644 index 0000000..9664ec8 --- /dev/null +++ b/tests/Http/Controllers/ThirdPartyServices/EmailServiceTest.php @@ -0,0 +1,15 @@ +post('/backend', array( 'organization' => 'GruppoCO', - 'password' => config('app.app_password') + 'password' => getenv('APP_PASSWORD') )); $res->assertResponseOk(); diff --git a/tests/UnitTest.php b/tests/UnitTest.php index 181c1fd..b4a1567 100644 --- a/tests/UnitTest.php +++ b/tests/UnitTest.php @@ -7,7 +7,7 @@ class UnitTest extends TestCase public function test_export_endpoint_works_for_logged_in_users() { $res = $this->post('/export', array( - 'token' => config('app.gitea_token'), + 'token' => getenv('GITEA_TOKEN'), 'from_month' => '10', 'from_year' => '2023', 'to_month' => '12',