mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 08:12:17 +01:00
Added week start
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Service;
|
||||
|
||||
use App\Enums\Weekday;
|
||||
use App\Models\TimeEntry;
|
||||
use App\Models\User;
|
||||
use App\Service\DashboardService;
|
||||
@@ -15,29 +16,115 @@ class DashboardServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected DashboardService $dashboardService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->dashboardService = app(DashboardService::class);
|
||||
}
|
||||
|
||||
public function test_daily_tracked_hours_returns_correct_values(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->travelTo(Carbon::create(2024, 1, 1, 12, 0, 0, 'UTC'));
|
||||
$this->travelTo(Carbon::create(2024, 1, 1, 12, 0, 0, 'Europe/Vienna'));
|
||||
$user = User::factory()->create([
|
||||
'timezone' => 'Europe/Vienna',
|
||||
]);
|
||||
$timeEntry = TimeEntry::factory()->forUser($user)->create([
|
||||
'start' => Carbon::create(2023, 12, 31, 0, 0, 0, 'UTC'),
|
||||
'end' => Carbon::create(2023, 12, 31, 0, 0, 40, 'UTC'),
|
||||
$timeEntry1 = TimeEntry::factory()->forUser($user)->create([
|
||||
// Note: The start time shifts in timezone Europe/Vienna to the next day
|
||||
'start' => Carbon::create(2023, 12, 30, 23, 0, 0, 'UTC'),
|
||||
'end' => Carbon::create(2023, 12, 30, 23, 0, 40, 'UTC'),
|
||||
]);
|
||||
$timeEntry2 = TimeEntry::factory()->forUser($user)->create([
|
||||
// Note: The start time NOT shifts in timezone Europe/Vienna to the next day
|
||||
'start' => Carbon::create(2023, 12, 30, 22, 59, 59, 'UTC'),
|
||||
'end' => Carbon::create(2023, 12, 30, 23, 0, 39, 'UTC'),
|
||||
]);
|
||||
|
||||
// Act
|
||||
$service = new DashboardService();
|
||||
$result = $service->getDailyTrackedHours($user, 5);
|
||||
$result = $this->dashboardService->getDailyTrackedHours($user, 5);
|
||||
|
||||
// Assert
|
||||
$this->assertSame([
|
||||
['2024-01-01', 0],
|
||||
['2023-12-31', 40],
|
||||
['2023-12-30', 0],
|
||||
['2023-12-29', 0],
|
||||
['2023-12-28', 0],
|
||||
[
|
||||
'date' => '2023-12-28',
|
||||
'duration' => 0,
|
||||
],
|
||||
[
|
||||
'date' => '2023-12-29',
|
||||
'duration' => 0,
|
||||
],
|
||||
[
|
||||
'date' => '2023-12-30',
|
||||
'duration' => 40,
|
||||
],
|
||||
[
|
||||
'date' => '2023-12-31',
|
||||
'duration' => 40,
|
||||
],
|
||||
[
|
||||
'date' => '2024-01-01',
|
||||
'duration' => 0,
|
||||
],
|
||||
], $result);
|
||||
}
|
||||
|
||||
public function test_weekly_history_returns_correct_values(): void
|
||||
{
|
||||
// Arrange
|
||||
// Note: Is a Monday
|
||||
$this->travelTo(Carbon::create(2024, 1, 1, 12, 0, 0, 'Europe/Vienna'));
|
||||
$user = User::factory()->create([
|
||||
'timezone' => 'Europe/Vienna',
|
||||
'week_start' => Weekday::Sunday,
|
||||
]);
|
||||
// Note: This is a Sunday
|
||||
$timeEntry1 = TimeEntry::factory()->forUser($user)->create([
|
||||
// Note: The start time shifts in timezone Europe/Vienna to the next day
|
||||
'start' => Carbon::create(2023, 12, 30, 23, 0, 0, 'UTC'),
|
||||
'end' => Carbon::create(2023, 12, 30, 23, 0, 40, 'UTC'),
|
||||
]);
|
||||
// Note: This is a Saturday
|
||||
$timeEntry2 = TimeEntry::factory()->forUser($user)->create([
|
||||
// Note: The start time NOT shifts in timezone Europe/Vienna to the next day
|
||||
'start' => Carbon::create(2023, 12, 30, 22, 59, 59, 'UTC'),
|
||||
'end' => Carbon::create(2023, 12, 30, 23, 0, 39, 'UTC'),
|
||||
]);
|
||||
|
||||
// Act
|
||||
$result = $this->dashboardService->getWeeklyHistory($user);
|
||||
|
||||
// Assert
|
||||
$this->assertSame([
|
||||
[
|
||||
'date' => '2023-12-31',
|
||||
'duration' => 40,
|
||||
],
|
||||
[
|
||||
'date' => '2024-01-01',
|
||||
'duration' => 0,
|
||||
],
|
||||
[
|
||||
'date' => '2024-01-02',
|
||||
'duration' => 0,
|
||||
],
|
||||
[
|
||||
'date' => '2024-01-03',
|
||||
'duration' => 0,
|
||||
],
|
||||
[
|
||||
'date' => '2024-01-04',
|
||||
'duration' => 0,
|
||||
],
|
||||
[
|
||||
'date' => '2024-01-05',
|
||||
'duration' => 0,
|
||||
],
|
||||
[
|
||||
'date' => '2024-01-06',
|
||||
'duration' => 0,
|
||||
],
|
||||
], $result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user