Skip to content

Commit

Permalink
Added tests for billable rate in time entries endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Jul 15, 2024
1 parent 7aab3d9 commit 555417d
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 555417d

Please sign in to comment.