Added billable and project_id to time entry endpoints; Enhanced api docs; Added pagination

This commit is contained in:
Constantin Graf
2024-03-19 17:19:12 +01:00
parent 7cc686f230
commit 2133eb0c16
22 changed files with 616 additions and 309 deletions

View File

@@ -43,6 +43,8 @@ class ClientEndpointTest extends ApiEndpointTestAbstract
$response->assertJsonCount(4, 'data');
$response->assertJson(fn (AssertableJson $json) => $json
->has('data')
->has('links')
->has('meta')
->count('data', 4)
->where('data.0.id', $clients->sortByDesc('created_at')->get(0)->getKey())
->where('data.1.id', $clients->sortByDesc('created_at')->get(1)->getKey())

View File

@@ -43,6 +43,8 @@ class TagEndpointTest extends ApiEndpointTestAbstract
$response->assertJsonCount(4, 'data');
$response->assertJson(fn (AssertableJson $json) => $json
->has('data')
->has('links')
->has('meta')
->count('data', 4)
->where('data.0.id', $tags->sortByDesc('created_at')->get(0)->getKey())
->where('data.1.id', $tags->sortByDesc('created_at')->get(1)->getKey())

View File

@@ -314,6 +314,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
// Act
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
'description' => $timeEntryFake->description,
'billable' => $timeEntryFake->billable,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'end' => $timeEntryFake->end->toIso8601ZuluString(),
'tags' => $timeEntryFake->tags,
@@ -332,16 +333,18 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
'time-entries:create:own',
]);
$activeTimeEntry = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->active()->create();
$timeEntryFake = TimeEntry::factory()->forOrganization($data->organization)->withTags($data->organization)->make();
$timeEntryFake = TimeEntry::factory()->forOrganization($data->organization)->withTask($data->organization)->withTags($data->organization)->make();
Passport::actingAs($data->user);
// Act
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
'description' => $timeEntryFake->description,
'billable' => $timeEntryFake->billable,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'end' => null,
'tags' => $timeEntryFake->tags,
'user_id' => $data->user->getKey(),
'project_id' => $timeEntryFake->project_id,
'task_id' => $timeEntryFake->task_id,
]);
@@ -350,22 +353,53 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
$response->assertJsonPath('error', true);
}
public function test_store_endpoint_validation_fails_if_task_id_does_not_belong_to_project_id(): void
{
// Arrange
$data = $this->createUserWithPermission([
'time-entries:create:own',
]);
$timeEntryFake = TimeEntry::factory()->forOrganization($data->organization)->withTask($data->organization)->make();
$timeEntryFake2 = TimeEntry::factory()->forOrganization($data->organization)->withTask($data->organization)->make();
Passport::actingAs($data->user);
// Act
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
'description' => $timeEntryFake->description,
'billable' => $timeEntryFake->billable,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'end' => $timeEntryFake->end->toIso8601ZuluString(),
'tags' => $timeEntryFake->tags,
'user_id' => $data->user->getKey(),
'project_id' => $timeEntryFake->project_id,
'task_id' => $timeEntryFake2->task_id,
]);
// Assert
$response->assertStatus(422);
$response->assertJsonValidationErrors([
'task_id' => 'The task is not part of the given project.',
]);
}
public function test_store_endpoint_creates_new_time_entry_for_current_user(): void
{
// Arrange
$data = $this->createUserWithPermission([
'time-entries:create:own',
]);
$timeEntryFake = TimeEntry::factory()->forOrganization($data->organization)->make();
$timeEntryFake = TimeEntry::factory()->withTask($data->organization)->forOrganization($data->organization)->make();
Passport::actingAs($data->user);
// Act
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
'description' => $timeEntryFake->description,
'billable' => $timeEntryFake->billable,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'end' => $timeEntryFake->end->toIso8601ZuluString(),
'tags' => $timeEntryFake->tags,
'user_id' => $data->user->getKey(),
'project_id' => $timeEntryFake->project_id,
'task_id' => $timeEntryFake->task_id,
]);
@@ -389,6 +423,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
// Act
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
'billable' => $timeEntryFake->billable,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'user_id' => $data->user->getKey(),
]);
@@ -418,10 +453,12 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
// Act
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
'description' => $timeEntryFake->description,
'billable' => $timeEntryFake->billable,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'end' => $timeEntryFake->end->toIso8601ZuluString(),
'tags' => $timeEntryFake->tags,
'user_id' => $otherUser->getKey(),
'project_id' => $timeEntryFake->project_id,
'task_id' => $timeEntryFake->task_id,
]);
@@ -445,6 +482,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
// Act
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
'description' => $timeEntryFake->description,
'billable' => $timeEntryFake->billable,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'end' => $timeEntryFake->end->toIso8601ZuluString(),
'tags' => $timeEntryFake->tags,
@@ -473,6 +511,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
// Act
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
'description' => $timeEntryFake->description,
'billable' => $timeEntryFake->billable,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'end' => $timeEntryFake->end->toIso8601ZuluString(),
'tags' => $timeEntryFake->tags,