2024-07-22 14:17:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Http\Controllers\CsvController;
|
|
|
|
|
2024-08-14 13:52:30 +02:00
|
|
|
use App\Http\Controllers\CsvController\CsvCostCalc\CsvAgentCost;
|
|
|
|
use App\Http\Controllers\CsvController\CsvCostCalc\CsvCostCalc;
|
|
|
|
use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc;
|
2024-07-22 14:17:00 +02:00
|
|
|
use App\Http\Controllers\CsvController\CsvDataHandling;
|
2024-08-17 18:06:06 +02:00
|
|
|
use Tests\TestCase;
|
2024-07-22 14:17:00 +02:00
|
|
|
|
|
|
|
class CsvDataHandlingTest extends TestCase
|
|
|
|
{
|
2024-08-17 18:06:06 +02:00
|
|
|
protected function setUp(): void
|
|
|
|
{parent::setUp();
|
|
|
|
|
2024-08-14 12:46:25 +02:00
|
|
|
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
|
2024-08-14 13:52:30 +02:00
|
|
|
$this->csv_data_handling = new CsvDataHandling();
|
|
|
|
$this->csv_data_handling->csv_cost_calc->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc;
|
|
|
|
$this->csv_data_handling->csv_cost_calc->CsvAgentCost->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc;
|
|
|
|
$this->csv_data_handling->calculate_agent_cost = true; // Example percentage
|
|
|
|
$this->csv_data_handling->csv_cost_calc->CsvAgentCost->internal_percentage_to_deduct = 10; // Example percentage
|
2024-08-14 12:46:25 +02:00
|
|
|
}
|
|
|
|
|
2024-08-14 13:52:30 +02:00
|
|
|
public function testHandleAgentIssue()
|
2024-08-14 12:46:25 +02:00
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
$agents_issue_time = [];
|
|
|
|
$time = ['user_name' => 'agent1', 'time' => 5];
|
|
|
|
|
|
|
|
// Act
|
|
|
|
$result = $this->csv_data_handling->handle_agent_issue($agents_issue_time, $time);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
$this->assertEquals(['agent1' => 5], $result);
|
|
|
|
|
|
|
|
// Act with another entry for the same agent
|
|
|
|
$time = ['user_name' => 'agent1', 'time' => 3];
|
|
|
|
$result = $this->csv_data_handling->handle_agent_issue($result, $time);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
$this->assertEquals(['agent1' => 8], $result);
|
|
|
|
|
|
|
|
// Act with a different agent
|
|
|
|
$time = ['user_name' => 'agent2', 'time' => 10];
|
|
|
|
$result = $this->csv_data_handling->handle_agent_issue($result, $time);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
$this->assertEquals(['agent1' => 8, 'agent2' => 10], $result);
|
|
|
|
}
|
|
|
|
|
2024-08-14 13:52:30 +02:00
|
|
|
public function testGetIssueTotalTime()
|
2024-08-14 12:46:25 +02:00
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
$issue_time = [
|
|
|
|
['user_name' => 'agent1', 'time' => 5],
|
|
|
|
['user_name' => 'agent1', 'time' => 3],
|
|
|
|
['user_name' => 'agent2', 'time' => 10],
|
|
|
|
];
|
|
|
|
|
|
|
|
// Act
|
|
|
|
list($total_time, $agents_issue_time) = $this->csv_data_handling->get_issue_total_time($issue_time);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
$this->assertEquals(18, $total_time);
|
|
|
|
$this->assertEquals(['agent1' => 8, 'agent2' => 10], $agents_issue_time);
|
|
|
|
}
|
2024-07-22 14:17:00 +02:00
|
|
|
|
|
|
|
public function testHandle_csv_time()
|
|
|
|
{
|
2024-08-14 13:52:30 +02:00
|
|
|
|
2024-08-14 12:46:25 +02:00
|
|
|
$array = [
|
2024-08-14 13:52:30 +02:00
|
|
|
'Progetto' => ' test',
|
|
|
|
'#' => 169,
|
|
|
|
'Titolo' => 'Test',
|
|
|
|
'URL' => ' https://git.test.test/test/issues/169',
|
|
|
|
'Aperto_il' => ' 2024-07-19T10:43:07+02:00',
|
|
|
|
'Chiuso_il' => ' 2024-07-31T09:50:32+02:00',
|
|
|
|
'Etichette' => ' Priority/Medium,RequestBy/Customer,Status/Resolved,',
|
|
|
|
'Kind' => ',',
|
|
|
|
'Request By' => 'RequestBy/Client',
|
|
|
|
'Priority' => 'Priority/High',
|
2024-08-14 12:46:25 +02:00
|
|
|
];
|
|
|
|
|
2024-08-14 13:52:30 +02:00
|
|
|
$issue = [];
|
2024-08-14 12:46:25 +02:00
|
|
|
|
|
|
|
$issue_time = [
|
2024-08-14 13:52:30 +02:00
|
|
|
[
|
|
|
|
'id' => 1,
|
|
|
|
'created' => "2024-07-24T18:48:42+02:00",
|
|
|
|
'time' => 600,
|
|
|
|
'user_id' => 8,
|
|
|
|
'user_name' => "Agent1",
|
|
|
|
'issue_id' => 1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 2,
|
|
|
|
'created' => "2024-07-24T18:48:42+02:00",
|
|
|
|
'time' => 480,
|
|
|
|
'user_id' => 2,
|
|
|
|
'user_name' => "Agent2",
|
|
|
|
'issue_id' => 2,
|
|
|
|
],
|
2024-08-14 12:46:25 +02:00
|
|
|
];
|
|
|
|
|
2024-08-14 13:52:30 +02:00
|
|
|
$company_agents = ["Agent1", "Agent2"];
|
|
|
|
|
|
|
|
$expected = array_merge($array, [
|
|
|
|
'Tempo totale' => '00:18:00',
|
|
|
|
'Costo totale' => 180.00,
|
|
|
|
'Agent1' => '00:10:00',
|
|
|
|
'Agent1 costo' => 90.00,
|
|
|
|
'Agent2' => '00:08:00',
|
|
|
|
'Agent2 costo' => 72.00,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-08-14 12:46:25 +02:00
|
|
|
|
2024-08-14 13:52:30 +02:00
|
|
|
$this->mockCsvMinuteCostCalc
|
|
|
|
->method('select_correct_cost')
|
|
|
|
->with('RequestBy/Client', 'Priority/High')
|
|
|
|
->willReturn(10); // Mocked return value
|
2024-08-14 12:46:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
$result = $this->csv_data_handling->handle_csv_time($array, $issue, $issue_time, $company_agents);
|
2024-07-22 14:17:00 +02:00
|
|
|
|
2024-08-14 12:46:25 +02:00
|
|
|
// Assert
|
2024-08-14 13:52:30 +02:00
|
|
|
$this->assertEquals($expected, $result);
|
2024-07-22 14:17:00 +02:00
|
|
|
}
|
|
|
|
}
|