Fixed test case and travelTo function in test cases

This commit is contained in:
Constantin Graf
2024-06-05 23:13:04 +02:00
committed by Constantin Graf
parent 86555664c5
commit b0cdeb3e33
5 changed files with 40 additions and 16 deletions

View File

@@ -240,39 +240,36 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
public function test_index_endpoint_filter_only_full_dates_returns_time_entries_for_the_whole_day_case_more_time_entries_than_limit_with_a_timezone_edge_case(): void
{
// Arrange
$now = Carbon::create(2024, 1, 1, 12, 0, 0, 'Europe/Vienna');
$this->freezeTime($now);
$data = $this->createUserWithPermission([
'time-entries:view:own',
]);
$data->user->timezone = 'America/New_York';
$data->user->save();
/**
* We create in the eyes of the users timezone 2 time entries yesterday, 5 time entries two days ago, and 3 time entries three days ago
* We create in the eyes of the users timezone 2 time entries yesterday, 2 time entries two days ago, and 3 time entries three days ago
* The time entries are created in a way that they jump to the next day if the endpoint ignores the users timezone and just uses UTC
*/
// Note: This entry is yesterday in user timezone and yesterday in UTC
$timeEntriesDay1InUserTimeZone = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)
->state([
'start' => Carbon::now($data->user->timezone)->subDay()->startOfDay()->utc(),
'start' => Carbon::now()->timezone($data->user->timezone)->subDay()->startOfDay()->utc(),
])
->createMany(2);
//dump($timeEntriesDay1InUserTimeZone->first()->refresh()->start->toImmutable()->timezone('UTC')->toDateString());
//dump($timeEntriesDay1InUserTimeZone->first()->refresh()->start->toImmutable()->timezone($data->user->timezone)->toDateString());
// Note: This entry is yesterday in UTC timezone, but two days ago in user timezone
$timeEntriesDay1InUTC = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)
->state([
'start' => Carbon::now('UTC')->subDay()->startOfDay()->utc(),
'start' => Carbon::now()->utc()->subDay()->startOfDay()->utc(),
])
->createMany(2);
//dump($timeEntriesDay1InUTC->first()->refresh()->start->toImmutable()->timezone('UTC')->toDateString());
//dump($timeEntriesDay1InUTC->first()->refresh()->start->toImmutable()->timezone($data->user->timezone)->toDateString());
// Note: This entry is two days ago in user timezone
$timeEntriesDay2InUserTimeZone = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)
->state([
'start' => Carbon::now($data->user->timezone)->subDays(2)->startOfDay()->utc(),
'start' => Carbon::now()->timezone($data->user->timezone)->subDays(2)->startOfDay()->utc(),
])
->createMany(3);
Passport::actingAs($data->user);
// Act
@@ -291,12 +288,21 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
public function test_index_endpoint_filter_only_full_dates_returns_time_entries_for_the_whole_day_case_more_time_entries_in_latest_day_than_limit(): void
{
// Arrange
$now = Carbon::create(2024, 1, 1, 12, 0, 0, 'Europe/Vienna');
$this->freezeTime($now);
$data = $this->createUserWithPermission([
'time-entries:view:own',
]);
$timeEntriesDay1 = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)
->startBetween(Carbon::now()->subDay()->startOfDay(), Carbon::now()->subDay()->endOfDay(), true)
->state([
'start' => Carbon::now()->timezone($data->user->timezone)->subDay()->startOfDay()->utc(),
])
->createMany(7);
$timeEntriesDay2 = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)
->state([
'start' => Carbon::now()->timezone($data->user->timezone)->subDays(2)->endOfDay()->utc(),
])
->createMany(3);
Passport::actingAs($data->user);
// Act