mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 11:42:15 +01:00
Added timezone for user; Moved dashboard to controller
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Service\TimezoneService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -14,13 +15,18 @@ class ProfileInformationTest extends TestCase
|
||||
|
||||
public function test_profile_information_can_be_updated(): void
|
||||
{
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
// Arrange
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
// Act
|
||||
$response = $this->put('/user/profile-information', [
|
||||
'name' => 'Test Name',
|
||||
'email' => 'test@example.com',
|
||||
'timezone' => app(TimezoneService::class)->getTimezones()[0],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$this->assertEquals('Test Name', $user->fresh()->name);
|
||||
$this->assertEquals('test@example.com', $user->fresh()->email);
|
||||
}
|
||||
|
||||
43
tests/Unit/Service/DashboardServiceTest.php
Normal file
43
tests/Unit/Service/DashboardServiceTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Service;
|
||||
|
||||
use App\Models\TimeEntry;
|
||||
use App\Models\User;
|
||||
use App\Service\DashboardService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DashboardServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_daily_tracked_hours_returns_correct_values(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->travelTo(Carbon::create(2024, 1, 1, 12, 0, 0, 'UTC'));
|
||||
$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'),
|
||||
]);
|
||||
|
||||
// Act
|
||||
$service = new DashboardService();
|
||||
$result = $service->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],
|
||||
], $result);
|
||||
}
|
||||
}
|
||||
26
tests/Unit/Service/TimezoneServiceTest.php
Normal file
26
tests/Unit/Service/TimezoneServiceTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Service;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class TimezoneServiceTest extends TestCase
|
||||
{
|
||||
public function test_get_timezones_returns_all_available_timezones(): void
|
||||
{
|
||||
// Arrange
|
||||
$service = new \App\Service\TimezoneService();
|
||||
|
||||
// Act
|
||||
$result = $service->getTimezones();
|
||||
|
||||
// Assert
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCount(419, $result);
|
||||
$this->assertContains('Europe/Vienna', $result);
|
||||
$this->assertContains('Europe/Berlin', $result);
|
||||
$this->assertContains('Europe/London', $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user