Fix bug in time-entry.update-multiple; Add computed property for client_id

This commit is contained in:
Constantin Graf
2024-10-08 19:15:16 +02:00
committed by Constantin Graf
parent b3b84db004
commit d5a4df738f
4 changed files with 123 additions and 1 deletions

View File

@@ -148,4 +148,35 @@ class TimeEntryModelTest extends ModelTestAbstract
$this->assertCount(1, $result);
$this->assertTrue($result->first()->is($timeEntry1));
}
public function test_computed_client_id_returns_null_when_no_project_is_assigned(): void
{
// Arrange
$timeEntry = TimeEntry::factory()->forProject(null)->create();
$timeEntry->client_id = null;
$timeEntry->save();
// Act
$timeEntry->setComputedAttributeValue('client_id');
$clientId = $timeEntry->client_id;
// Assert
$this->assertNull($clientId);
}
public function test_computed_client_id_returns_project_client_id(): void
{
// Arrange
$project = Project::factory()->create();
$timeEntry = TimeEntry::factory()->forProject($project)->create();
$timeEntry->client_id = null;
$timeEntry->save();
// Act
$timeEntry->setComputedAttributeValue('client_id');
$clientId = $timeEntry->client_id;
// Assert
$this->assertSame($project->client_id, $clientId);
}
}