mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-13 08:13:18 +01:00
Added billable and project_id to time entry endpoints; Enhanced api docs; Added pagination
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user