mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Added tag endpoints
This commit is contained in:
@@ -243,6 +243,7 @@ class ProjectEndpointTest extends ApiEndpointTestAbstract
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(204);
|
||||
$response->assertNoContent();
|
||||
$this->assertDatabaseMissing(Project::class, [
|
||||
'id' => $project->getKey(),
|
||||
]);
|
||||
|
||||
218
tests/Unit/Endpoint/Api/V1/TagEndpointTest.php
Normal file
218
tests/Unit/Endpoint/Api/V1/TagEndpointTest.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Laravel\Passport\Passport;
|
||||
|
||||
class TagEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
public function test_index_endpoint_fails_if_user_has_no_permission_to_view_tags(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$tags = Tag::factory()->forOrganization($data->organization)->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.tags.index', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_index_endpoint_returns_list_of_all_tags_of_organization_ordered_by_created_at_desc_per_default(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tags:view',
|
||||
]);
|
||||
$tags = Tag::factory()->forOrganization($data->organization)->createMany(4);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.tags.index', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(4, 'data');
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->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())
|
||||
->where('data.2.id', $tags->sortByDesc('created_at')->get(2)->getKey())
|
||||
->where('data.3.id', $tags->sortByDesc('created_at')->get(3)->getKey())
|
||||
);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_user_has_no_permission_to_create_tags(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.tags.store', [$data->organization->getKey()]), [
|
||||
'name' => 'Test Tag',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_new_tag(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tags:create',
|
||||
]);
|
||||
$tagFake = Tag::factory()->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.tags.store', [$data->organization->getKey()]), [
|
||||
'name' => $tagFake->name,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.name', $tagFake->name)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_user_has_no_permission_to_update_tags(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$tag = Tag::factory()->forOrganization($data->organization)->create();
|
||||
$tagFake = Tag::factory()->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.tags.update', [$data->organization->getKey(), $tag->getKey()]), [
|
||||
'name' => $tagFake->name,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_user_is_not_part_of_tag_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tags:update',
|
||||
]);
|
||||
$otherOrganization = Organization::factory()->create();
|
||||
$tag = Tag::factory()->forOrganization($otherOrganization)->create();
|
||||
$tagFake = Tag::factory()->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.tags.update', [$data->organization->getKey(), $tag->getKey()]), [
|
||||
'name' => $tagFake->name,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(403);
|
||||
$this->assertDatabaseHas(Tag::class, [
|
||||
'id' => $tag->getKey(),
|
||||
'name' => $tag->name,
|
||||
'organization_id' => $otherOrganization->getKey(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_updates_tag(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tags:update',
|
||||
]);
|
||||
$tag = Tag::factory()->forOrganization($data->organization)->create();
|
||||
$tagFake = Tag::factory()->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.tags.update', [$data->organization->getKey(), $tag->getKey()]), [
|
||||
'name' => $tagFake->name,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->where('data.name', $tagFake->name)
|
||||
);
|
||||
$this->assertDatabaseHas(Tag::class, [
|
||||
'name' => $tagFake->name,
|
||||
'organization_id' => $data->organization->getKey(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_destroy_endpoint_fails_if_user_has_no_permission_to_delete_tags(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$tag = Tag::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.tags.destroy', [$data->organization->getKey(), $tag->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_destroy_endpoint_fails_if_user_is_not_part_of_tag_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tags:delete',
|
||||
]);
|
||||
$otherOrganization = Organization::factory()->create();
|
||||
$tag = Tag::factory()->forOrganization($otherOrganization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.tags.destroy', [$data->organization->getKey(), $tag->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(403);
|
||||
$this->assertDatabaseHas(Tag::class, [
|
||||
'id' => $tag->getKey(),
|
||||
'name' => $tag->name,
|
||||
'organization_id' => $otherOrganization->getKey(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_destroy_endpoint_deletes_tag(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'tags:delete',
|
||||
]);
|
||||
$tag = Tag::factory()->forOrganization($data->organization)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.tags.destroy', [$data->organization->getKey(), $tag->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(204);
|
||||
$response->assertNoContent();
|
||||
$this->assertDatabaseMissing(Tag::class, [
|
||||
'id' => $tag->getKey(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,12 @@ namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Models\TimeEntry;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Laravel\Passport\Passport;
|
||||
use TiMacDonald\Log\LogEntry;
|
||||
|
||||
class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
@@ -95,7 +99,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertJsonPath('data.0.id', $timeEntry->getKey());
|
||||
}
|
||||
|
||||
public function test_index_endpoint_returns_time_entries_for_all_users_in_organization(): void
|
||||
public function test_index_endpoint_returns_time_entries_for_all_users_in_organization_default_sort_by_start_date_desc(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
@@ -105,7 +109,15 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
$data->organization->users()->attach($user, [
|
||||
'role' => 'employee',
|
||||
]);
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forUser($user)->create();
|
||||
$timeEntry1 = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->create([
|
||||
'start' => Carbon::now()->subDay(),
|
||||
]);
|
||||
$timeEntry2 = TimeEntry::factory()->forOrganization($data->organization)->forUser($user)->create([
|
||||
'start' => Carbon::now()->subDays(2),
|
||||
]);
|
||||
$timeEntry3 = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->create([
|
||||
'start' => Carbon::now()->subDays(3),
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
@@ -113,7 +125,182 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('data.0.id', $timeEntry->getKey());
|
||||
$response->assertJsonPath('data.0.id', $timeEntry1->getKey());
|
||||
$response->assertJsonPath('data.1.id', $timeEntry2->getKey());
|
||||
$response->assertJsonPath('data.2.id', $timeEntry3->getKey());
|
||||
}
|
||||
|
||||
public function test_index_endpoint_returns_only_active_time_entries(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:own',
|
||||
]);
|
||||
$activeTimeEntry = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->active()->create();
|
||||
$nonActiveTimeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->createMany(3);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.index', [
|
||||
$data->organization->getKey(),
|
||||
'active' => true,
|
||||
'user_id' => $data->user->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(1, 'data');
|
||||
$response->assertJsonPath('data.0.id', $activeTimeEntry->getKey());
|
||||
}
|
||||
|
||||
public function test_index_endpoint_filter_only_full_dates_returns_time_entries_for_the_whole_day_case_less_time_entries_than_limit(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:own',
|
||||
]);
|
||||
$timeEntries = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)->createMany(3);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.index', [
|
||||
$data->organization->getKey(),
|
||||
'only_full_dates' => true,
|
||||
'limit' => 5,
|
||||
'user_id' => $data->user->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(3, 'data');
|
||||
}
|
||||
|
||||
public function test_index_endpoint_filter_only_full_dates_returns_time_entries_for_the_whole_day_case_more_time_entries_than_limit(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:own',
|
||||
]);
|
||||
$timeEntriesDay1 = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->startBetween(Carbon::now()->subDay()->startOfDay(), Carbon::now()->subDay()->endOfDay())
|
||||
->createMany(3);
|
||||
$timeEntriesDay2 = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->startBetween(Carbon::now()->subDays(2)->startOfDay(), Carbon::now()->subDays(2)->endOfDay())
|
||||
->createMany(3);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.index', [
|
||||
$data->organization->getKey(),
|
||||
'only_full_dates' => true,
|
||||
'limit' => 5,
|
||||
'user_id' => $data->user->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(3, 'data');
|
||||
}
|
||||
|
||||
public function test_index_endpoint_filter_only_full_dates_returns_time_entries_for_the_whole_day_case_more_time_entries_in_latest_day_than_limit(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:own',
|
||||
]);
|
||||
$timeEntriesDay1 = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->startBetween(Carbon::now()->subDay()->startOfDay(), Carbon::now()->subDay()->endOfDay())
|
||||
->createMany(7);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.index', [
|
||||
$data->organization->getKey(),
|
||||
'only_full_dates' => true,
|
||||
'limit' => 5,
|
||||
'user_id' => $data->user->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
Log::assertLogged(fn (LogEntry $log) => $log->level === 'warning'
|
||||
&& $log->message === 'User has has more than 5 time entries on one date'
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonCount(7, 'data');
|
||||
}
|
||||
|
||||
public function test_index_endpoint_before_filter_returns_time_entries_before_date(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:own',
|
||||
]);
|
||||
$timeEntriesAfter = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->startBetween(Carbon::now()->subDay()->startOfDay(), Carbon::now())
|
||||
->createMany(3);
|
||||
$timeEntriesBefore = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->startBetween(Carbon::now()->subDays(2)->startOfDay(), Carbon::now()->subDays(2)->endOfDay())
|
||||
->createMany(3);
|
||||
$timeEntriesDirectlyBeforeLimit = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->create([
|
||||
'start' => Carbon::now()->subDays(2)->endOfDay(),
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.index', [
|
||||
$data->organization->getKey(),
|
||||
'before' => Carbon::now()->subDay()->startOfDay()->toIso8601ZuluString(),
|
||||
'user_id' => $data->user->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->count('data', 4)
|
||||
->where('data.0.id', $timeEntriesDirectlyBeforeLimit->getKey())
|
||||
->where('data.1.id', $timeEntriesBefore->sortByDesc('start')->get(0)->getKey())
|
||||
->where('data.2.id', $timeEntriesBefore->sortByDesc('start')->get(1)->getKey())
|
||||
->where('data.3.id', $timeEntriesBefore->sortByDesc('start')->get(2)->getKey())
|
||||
);
|
||||
}
|
||||
|
||||
public function test_index_endpoint_after_filter_returns_time_entries_after_date(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:view:own',
|
||||
]);
|
||||
$timeEntriesAfter = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->startBetween(Carbon::now()->startOfDay(), Carbon::now())
|
||||
->createMany(3);
|
||||
$timeEntriesBefore = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->startBetween(Carbon::now()->subDay()->startOfDay(), Carbon::now()->subDay()->endOfDay())
|
||||
->createMany(3);
|
||||
$timeEntriesDirectlyAfterLimit = TimeEntry::factory()->forOrganization($data->organization)->forUser($data->user)
|
||||
->create([
|
||||
'start' => Carbon::now()->startOfDay(),
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-entries.index', [
|
||||
$data->organization->getKey(),
|
||||
'after' => Carbon::now()->subDay()->endOfDay()->toIso8601ZuluString(), // yesterday
|
||||
'user_id' => $data->user->getKey(),
|
||||
]));
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->has('data')
|
||||
->count('data', 4)
|
||||
->where('data.0.id', $timeEntriesAfter->sortByDesc('start')->get(0)->getKey())
|
||||
->where('data.1.id', $timeEntriesAfter->sortByDesc('start')->get(1)->getKey())
|
||||
->where('data.2.id', $timeEntriesAfter->sortByDesc('start')->get(2)->getKey())
|
||||
->where('data.3.id', $timeEntriesDirectlyAfterLimit->getKey())
|
||||
);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_user_has_no_permission_to_create_time_entries(): void
|
||||
@@ -127,8 +314,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $data->user->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -138,6 +325,31 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_user_already_has_active_time_entry_and_tries_to_start_new_one(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'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();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => null,
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $data->user->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(400);
|
||||
$response->assertJsonPath('error', true);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_new_time_entry_for_current_user(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -150,8 +362,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $data->user->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -166,6 +378,30 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_new_time_entry_with_minimal_fields(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:create:own',
|
||||
]);
|
||||
$timeEntryFake = TimeEntry::factory()->forOrganization($data->organization)->make();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'user_id' => $data->user->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $response->json('data.id'),
|
||||
'user_id' => $data->user->getKey(),
|
||||
'task_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_user_has_no_permission_to_create_time_entries_for_others(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -182,8 +418,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $otherUser->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -209,8 +445,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $otherUser->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -237,8 +473,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $data->user->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -264,8 +500,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $data->user->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -292,8 +528,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $user->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -316,8 +552,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $data->user->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -349,8 +585,8 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'description' => $timeEntryFake->description,
|
||||
'start' => $timeEntryFake->start->toIso8601String(),
|
||||
'end' => $timeEntryFake->end->toIso8601String(),
|
||||
'start' => $timeEntryFake->start->toIso8601ZuluString(),
|
||||
'end' => $timeEntryFake->end->toIso8601ZuluString(),
|
||||
'tags' => $timeEntryFake->tags,
|
||||
'user_id' => $user->getKey(),
|
||||
'task_id' => $timeEntryFake->task_id,
|
||||
@@ -448,6 +684,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(204);
|
||||
$response->assertNoContent();
|
||||
$this->assertDatabaseMissing(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
]);
|
||||
@@ -471,6 +708,7 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(204);
|
||||
$response->assertNoContent();
|
||||
$this->assertDatabaseMissing(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user