mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-12 02:02:15 +01:00
Added filled gaps to time entry aggregation; Moved aggregation to service
This commit is contained in:
@@ -5,7 +5,10 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Models\TimeEntry;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laravel\Passport\Passport;
|
||||
use TiMacDonald\Log\LogEntry;
|
||||
|
||||
class UserTimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
@@ -36,6 +39,28 @@ class UserTimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$response->assertJsonPath('data.id', $activeTimeEntry->getKey());
|
||||
}
|
||||
|
||||
public function test_my_active_endpoint_logs_a_warning_if_user_has_multiple_active_time_entries_and_return_the_latest_one(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
]);
|
||||
$activeTimeEntry1 = TimeEntry::factory()->forMember($data->member)->active()->start(Carbon::now()->subDay())->create();
|
||||
$activeTimeEntry2 = TimeEntry::factory()->forMember($data->member)->active()->start(Carbon::now())->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.users.time-entries.my-active'));
|
||||
|
||||
// Assert
|
||||
Log::assertLogged(fn (LogEntry $log) => $log->level === 'warning'
|
||||
&& $log->message === 'User has more than one active time entry.'
|
||||
&& $log->context === ['user' => $data->user->getKey()]
|
||||
);
|
||||
$response->assertSuccessful();
|
||||
$response->assertJsonPath('data.id', $activeTimeEntry2->getKey());
|
||||
}
|
||||
|
||||
public function test_my_active_endpoint_returns_not_found_if_user_has_no_active_time_entry(): void
|
||||
|
||||
Reference in New Issue
Block a user