add: more tests
This commit is contained in:
parent
fcd76cf130
commit
3d08b14f11
6 changed files with 154 additions and 36 deletions
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Tests\Http\Controllers\CsvController;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -9,12 +12,15 @@ class CsvDataHandlingTest extends TestCase
|
|||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->csv_data_handling = new CsvDataHandling();
|
||||
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
public function handleAgentIssue()
|
||||
public function testHandleAgentIssue()
|
||||
{
|
||||
// Arrange
|
||||
$agents_issue_time = [];
|
||||
|
@ -41,7 +47,7 @@ class CsvDataHandlingTest extends TestCase
|
|||
$this->assertEquals(['agent1' => 8, 'agent2' => 10], $result);
|
||||
}
|
||||
|
||||
public function getIssueTotalTime()
|
||||
public function testGetIssueTotalTime()
|
||||
{
|
||||
// Arrange
|
||||
$issue_time = [
|
||||
|
@ -60,40 +66,64 @@ class CsvDataHandlingTest extends TestCase
|
|||
|
||||
public function testHandle_csv_time()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
$array = [
|
||||
'total_time_cost' => 0,
|
||||
'agent_cost' => 0,
|
||||
'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',
|
||||
];
|
||||
|
||||
$issue = [
|
||||
['id' => 1, 'title' => 'Issue 1'],
|
||||
['id' => 2, 'title' => 'Issue 2'],
|
||||
];
|
||||
$issue = [];
|
||||
|
||||
$issue_time = [
|
||||
['user_name' => 'agent1', 'time' => 5],
|
||||
['user_name' => 'agent1', 'time' => 3],
|
||||
['user_name' => 'agent2', 'time' => 10],
|
||||
[
|
||||
'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,
|
||||
],
|
||||
];
|
||||
|
||||
$company_agents = [
|
||||
['name' => 'agent1', 'cost_per_hour' => 50],
|
||||
['name' => 'agent2', 'cost_per_hour' => 60],
|
||||
];
|
||||
$company_agents = ["Agent1", "Agent2"];
|
||||
|
||||
$this->csv_data_handling->method('total_time_cost')
|
||||
->with($array, 18)
|
||||
->willReturn(['total_time_cost' => 1800]);
|
||||
$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,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$this->mockCsvMinuteCostCalc
|
||||
->method('select_correct_cost')
|
||||
->with('RequestBy/Client', 'Priority/High')
|
||||
->willReturn(10); // Mocked return value
|
||||
|
||||
$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);
|
||||
|
||||
// Assert
|
||||
$this->assertEquals(['total_time_cost' => 1800, 'agent_cost' => 800], $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@ class CsvDataInitTest extends TestCase
|
|||
|
||||
public function testInitialize_csv_data()
|
||||
{
|
||||
|
||||
|
||||
$issue = [
|
||||
'repository' => ['name' => 'test'],
|
||||
'number' => 0,
|
||||
|
|
|
@ -1,15 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Http\Controllers;
|
||||
namespace Tests\Controllers;
|
||||
|
||||
use App\Http\Controllers\IssueValidationController;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class IssueValidationControllerTest extends TestCase
|
||||
{
|
||||
|
||||
public function testHandle_single_issue()
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->issue_validation_controller = new IssueValidationController();
|
||||
}
|
||||
public function testValidDateConversion()
|
||||
{
|
||||
$this->assertEquals('2024-08-14 00:00:00', $this->issue_validation_controller->date_to_datetime('2024/08/14'));
|
||||
$this->assertEquals('2024-12-31 00:00:00', $this->issue_validation_controller->date_to_datetime('2024/12/31'));
|
||||
}
|
||||
|
||||
public function testInvalidDateFormat()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->issue_validation_controller->date_to_datetime('invalid-date');
|
||||
}
|
||||
|
||||
public function testIssueIsBilled()
|
||||
{
|
||||
$labels = [['name' => 'RequestBy: User1']];
|
||||
$issue_time = [['time' => 3600]]; // 1 hour
|
||||
$this->assertTrue($this->issue_validation_controller->check_issue_is_billed($labels, $issue_time));
|
||||
}
|
||||
|
||||
public function testIssueIsNotBilledDueToNoTime()
|
||||
{
|
||||
$labels = [['name' => 'RequestBy: User1']];
|
||||
$issue_time = [['time' => 0]];
|
||||
$this->assertFalse($this->issue_validation_controller->check_issue_is_billed($labels, $issue_time));
|
||||
}
|
||||
|
||||
public function testIssueIsNotBilledDueToNoLabel()
|
||||
{
|
||||
$labels = [['name' => 'Bug']];
|
||||
$issue_time = [['time' => 3600]];
|
||||
$this->assertFalse($this->issue_validation_controller->check_issue_is_billed($labels, $issue_time));
|
||||
}
|
||||
|
||||
public function testTotalTimeCalculation()
|
||||
{
|
||||
$issue_time = [['time' => 10], ['time' => 20], ['time' => 30]];
|
||||
$this->assertEquals(60, $this->issue_validation_controller->get_issue_total_time($issue_time));
|
||||
}
|
||||
|
||||
public function testEmptyTimeArray()
|
||||
{
|
||||
$issue_time = [];
|
||||
$this->assertEquals(0, $this->issue_validation_controller->get_issue_total_time($issue_time));
|
||||
}
|
||||
|
||||
public function testSingleTimeEntry()
|
||||
{
|
||||
$issue_time = [['time' => 15]];
|
||||
$this->assertEquals(15, $this->issue_validation_controller->get_issue_total_time($issue_time));
|
||||
}
|
||||
|
||||
public function testIssueWithinDateRangeAndBilled()
|
||||
{
|
||||
$issue = ['closed_at' => '2024-08-15T10:00:00Z', 'labels' => [['name' => 'RequestBy: User1']]];
|
||||
$issue_time = [['time' => 3600]]; // 1 hour
|
||||
$this->assertTrue($this->issue_validation_controller->handle_single_issue('2024-08-14', '2024-08-16', $issue, $issue_time));
|
||||
}
|
||||
|
||||
public function testIssueOutsideDateRange()
|
||||
{
|
||||
$issue = ['closed_at' => '2024-08-13T10:00:00Z', 'labels' => [['name' => 'RequestBy: User1']]];
|
||||
$issue_time = [['time' => 3600]];
|
||||
$this->assertFalse($this->issue_validation_controller->handle_single_issue('2024-08-14', '2024-08-16', $issue, $issue_time));
|
||||
}
|
||||
|
||||
public function testIssueNotBilled()
|
||||
{
|
||||
$issue = ['closed_at' => '2024-08-15T10:00:00Z', 'labels' => [['name' => 'Bug']]];
|
||||
$issue_time = [['time' => 0]];
|
||||
$this->assertFalse($this->issue_validation_controller->handle_single_issue('2024-08-14', '2024-08-16', $issue, $issue_time));
|
||||
}
|
||||
|
||||
public function testLabelExists()
|
||||
{
|
||||
$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($labels));
|
||||
}
|
||||
|
||||
public function testEmptyLabels()
|
||||
{
|
||||
$labels = [];
|
||||
$this->assertFalse($this->issue_validation_controller->search_requested_by($labels));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue