diff --git a/tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php b/tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php index 97fc4abd..fe6224fc 100644 --- a/tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php +++ b/tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php @@ -906,6 +906,36 @@ public function test_store_endpoint_creates_new_time_entry_for_current_user(): v ]); } + public function test_store_endpoints_sets_billable_rate(): void + { + // Arrange + $data = $this->createUserWithPermission([ + 'time-entries:create:own', + ]); + $timeEntryFake = TimeEntry::factory()->withTask($data->organization)->forOrganization($data->organization)->make(); + $project = Project::factory()->forOrganization($data->organization)->billable()->create(); + Passport::actingAs($data->user); + + // Act + $response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [ + 'billable' => true, + 'start' => $timeEntryFake->start->toIso8601ZuluString(), + 'end' => $timeEntryFake->end->toIso8601ZuluString(), + 'member_id' => $data->member->getKey(), + 'project_id' => $project->getKey(), + ]); + + // Assert + $response->assertStatus(201); + $this->assertDatabaseHas(TimeEntry::class, [ + 'id' => $response->json('data.id'), + 'member_id' => $data->member->getKey(), + 'task_id' => null, + 'project_id' => $project->getKey(), + 'billable_rate' => $project->billable_rate, + ]); + } + public function test_store_endpoint_creates_new_time_entry_with_minimal_fields(): void { // Arrange @@ -1180,6 +1210,37 @@ public function test_update_endpoint_updates_time_entry_for_current_user(): void ]); } + public function test_update_endpoints_sets_billable_rate(): void + { + // Arrange + $data = $this->createUserWithPermission([ + 'time-entries:update:own', + ]); + $timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->create(); + $timeEntryFake = TimeEntry::factory()->withTags($data->organization)->forOrganization($data->organization)->make(); + $project = Project::factory()->forOrganization($data->organization)->billable()->create(); + Passport::actingAs($data->user); + + // Act + $response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [ + 'billable' => true, + 'start' => $timeEntryFake->start->toIso8601ZuluString(), + 'end' => $timeEntryFake->end->toIso8601ZuluString(), + 'member_id' => $data->member->getKey(), + 'project_id' => $project->getKey(), + ]); + + // Assert + $response->assertStatus(200); + $this->assertDatabaseHas(TimeEntry::class, [ + 'id' => $timeEntry->getKey(), + 'member_id' => $data->member->getKey(), + 'task_id' => null, + 'project_id' => $project->getKey(), + 'billable_rate' => $project->billable_rate, + ]); + } + public function test_update_endpoint_updates_time_entry_for_current_user_but_does_not_send_member_id(): void { // Arrange