Skip to content

Commit

Permalink
Fixed setting multiple time entry description to an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Oct 22, 2024
1 parent 5483073 commit 401cd4b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Http/Controllers/Api/V1/TimeEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ public function updateMultiple(Organization $organization, TimeEntryUpdateMultip

$changes = $request->validated('changes');

if ($request->has('changes.description')) {
$changes['description'] = $request->input('changes.description') ?? '';
}

if (isset($changes['member_id']) && ! $canAccessAll && $this->member($organization)->getKey() !== $changes['member_id']) {
throw new AuthorizationException;
}
Expand Down
45 changes: 45 additions & 0 deletions tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,51 @@ public function test_update_multiple_updates_own_time_entries_and_fails_for_time
]);
}

public function test_update_multiple_updates_sets_description_to_empty_if_the_client_sends_null(): void
{
// Arrange
$data = $this->createUserWithPermission([
'time-entries:update:own',
]);
$timeEntry1 = TimeEntry::factory()->forMember($data->member)->create([
'description' => '',
]);
$timeEntry2 = TimeEntry::factory()->forMember($data->member)->create([
'description' => 'test',
]);
Passport::actingAs($data->user);

// Act
$response = $this->patchJson(route('api.v1.time-entries.update-multiple', [$data->organization->getKey()]), [
'ids' => [
$timeEntry1->getKey(),
$timeEntry2->getKey(),
],
'changes' => [
'description' => null,
],
]);

// Assert
$response->assertValid();
$response->assertStatus(200);
$response->assertExactJson([
'success' => [
$timeEntry1->getKey(),
$timeEntry2->getKey(),
],
'error' => [],
]);
$this->assertDatabaseHas(TimeEntry::class, [
'id' => $timeEntry1->getKey(),
'description' => '',
]);
$this->assertDatabaseHas(TimeEntry::class, [
'id' => $timeEntry2->getKey(),
'description' => '',
]);
}

public function test_update_multiple_updates_all_time_entries_and_fails_for_time_entries_of_other_users_and_and_other_organizations_with_all_time_entries_permission(): void
{
// Arrange
Expand Down

0 comments on commit 401cd4b

Please sign in to comment.