Add still-running email preference

This commit is contained in:
Constantin Graf
2026-08-31 11:14:39 +02:00
committed by Gregor Vostrak
parent db9ca51fc4
commit 593372bae5
11 changed files with 114 additions and 2 deletions

View File

@@ -159,4 +159,26 @@ class TimeEntrySendStillRunningMailsCommandTest extends TestCaseWithDatabase
$this->assertSame("Sending still running time entry emails...\n".
"Finished sending 0 still running time entry emails...\n", $output);
}
public function test_does_not_send_emails_to_users_who_disabled_them(): void
{
// Arrange
$user = $this->createUserWithPermission();
$user->user->send_time_entry_still_running_email = false;
$user->user->save();
$timeEntry = TimeEntry::factory()->forMember($user->member)->create([
'start' => Carbon::now()->subHours(8)->subSecond(),
'end' => null,
]);
// Act
$exitCode = $this->withoutMockingConsoleOutput()->artisan('time-entry:send-still-running-mails');
// Assert
Mail::assertNothingOutgoing();
$this->assertNull($timeEntry->fresh()->still_active_email_sent_at);
$this->assertSame(Command::SUCCESS, $exitCode);
$this->assertSame("Sending still running time entry emails...\n".
"Finished sending 0 still running time entry emails...\n", Artisan::output());
}
}

View File

@@ -45,6 +45,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
'profile_photo_url' => $data->user->profile_photo_url,
'timezone' => $data->user->timezone,
'week_start' => $data->user->week_start->value,
'send_time_entry_still_running_email' => true,
],
]);
}
@@ -131,7 +132,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
$response->assertJsonValidationErrors('organization_id');
}
public function test_update_changes_user_name_timezone_and_week_start(): void
public function test_update_changes_user_profile_settings(): void
{
// Arrange
$data = $this->createUserWithPermission();
@@ -142,6 +143,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
'name' => 'Updated Name',
'timezone' => 'America/New_York',
'week_start' => Weekday::Sunday->value,
'send_time_entry_still_running_email' => false,
]);
// Assert
@@ -152,6 +154,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
'name' => 'Updated Name',
'timezone' => 'America/New_York',
'week_start' => Weekday::Sunday->value,
'send_time_entry_still_running_email' => false,
],
]);
@@ -159,6 +162,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
$this->assertSame('Updated Name', $user->name);
$this->assertSame('America/New_York', $user->timezone);
$this->assertSame(Weekday::Sunday, $user->week_start);
$this->assertFalse($user->send_time_entry_still_running_email);
}
public function test_update_does_not_change_user_fields_that_are_not_given(): void
@@ -503,6 +507,22 @@ class UserEndpointTest extends ApiEndpointTestAbstract
$response->assertJsonValidationErrors(['week_start']);
}
public function test_update_fails_if_send_time_entry_still_running_email_is_not_boolean(): void
{
// Arrange
$data = $this->createUserWithPermission();
Passport::actingAs($data->user);
// Act
$response = $this->putJson(route('api.v1.users.update', $data->user->getKey()), [
'send_time_entry_still_running_email' => 'not-a-boolean',
]);
// Assert
$response->assertUnprocessable();
$response->assertJsonValidationErrors(['send_time_entry_still_running_email']);
}
public function test_update_fails_if_photo_is_not_a_string(): void
{
// Arrange