2024-07-22 14:17:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Http\Controllers\CsvController;
|
|
|
|
|
|
|
|
use App\Http\Controllers\CsvController\CsvDataHandling;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class CsvDataHandlingTest extends TestCase
|
|
|
|
{
|
2024-08-14 12:46:25 +02:00
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->csv_data_handling = new CsvDataHandling();
|
|
|
|
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleAgentIssue()
|
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIssueTotalTime()
|
|
|
|
{
|
|
|
|
// 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 12:46:25 +02:00
|
|
|
// Arrange
|
|
|
|
$array = [
|
|
|
|
'total_time_cost' => 0,
|
|
|
|
'agent_cost' => 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
$issue = [
|
|
|
|
['id' => 1, 'title' => 'Issue 1'],
|
|
|
|
['id' => 2, 'title' => 'Issue 2'],
|
|
|
|
];
|
|
|
|
|
|
|
|
$issue_time = [
|
|
|
|
['user_name' => 'agent1', 'time' => 5],
|
|
|
|
['user_name' => 'agent1', 'time' => 3],
|
|
|
|
['user_name' => 'agent2', 'time' => 10],
|
|
|
|
];
|
|
|
|
|
|
|
|
$company_agents = [
|
|
|
|
['name' => 'agent1', 'cost_per_hour' => 50],
|
|
|
|
['name' => 'agent2', 'cost_per_hour' => 60],
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->csv_data_handling->method('total_time_cost')
|
|
|
|
->with($array, 18)
|
|
|
|
->willReturn(['total_time_cost' => 1800]);
|
|
|
|
|
|
|
|
$this->csv_data_handling->method('agent_cost_calc')
|
|
|
|
->with($array, $company_agents, ['agent1' => 8, 'agent2' => 10])
|
|
|
|
->willReturn(['agent_cost' => 800]);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
$this->assertEquals(['total_time_cost' => 1800, 'agent_cost' => 800], $result);
|
2024-07-22 14:17:00 +02:00
|
|
|
}
|
|
|
|
}
|