-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ZMS-3253 ZMS-3466 ZMS-3415 ZMS-1891): Replicate frontend validation in the backend for the availability opening hours to improve data integrity and frontend validation messaging #817
fix(ZMS-3253 ZMS-3466 ZMS-3415 ZMS-1891): Replicate frontend validation in the backend for the availability opening hours to improve data integrity and frontend validation messaging #817
Conversation
…orm error messaging
This reverts commit ce5d795.
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here are both complete test methods with weekday support: public function testDuplicateOverlappingAvailability()
{
$input = (new Entity)->createExample();
$currentTimestamp = time();
$testDate = $currentTimestamp + (20 * 24 * 60 * 60);
$weekday = (int)date('N', $testDate);
$input['startDate'] = $testDate;
$input['endDate'] = $currentTimestamp + (50 * 24 * 60 * 60);
$input['startTime'] = "09:00:00";
$input['endTime'] = "17:00:00";
$input['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$input['scope'] = [
"id" => 312,
"dayoff" => [
[
"id" => 35,
"date" => $currentTimestamp + (70 * 24 * 60 * 60),
"name" => "1. Mai",
"lastChange" => $currentTimestamp
],
[
"id" => 36,
"date" => $currentTimestamp + (140 * 24 * 60 * 60),
"name" => "Christi Himmelfahrt",
"lastChange" => $currentTimestamp
]
]
];
$input['kind'] = "default";
$entity = (new Query())->writeEntity($input);
$secondEntity = (new Query())->writeEntity($input);
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Duplicate Entry 1",
"startDate" => $testDate,
"endDate" => $testDate,
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => [
[
"id" => 35,
"date" => $currentTimestamp + (70 * 24 * 60 * 60),
"name" => "1. Mai",
"lastChange" => $currentTimestamp
],
[
"id" => 36,
"date" => $currentTimestamp + (140 * 24 * 60 * 60),
"name" => "Christi Himmelfahrt",
"lastChange" => $currentTimestamp
]
]
]
],
[
"id" => $secondEntity->getId(),
"description" => "Duplicate Entry 2",
"startDate" => $testDate,
"endDate" => $testDate,
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => [
[
"id" => 35,
"date" => $currentTimestamp + (70 * 24 * 60 * 60),
"name" => "1. Mai",
"lastChange" => $currentTimestamp
],
[
"id" => 36,
"date" => $currentTimestamp + (140 * 24 * 60 * 60),
"name" => "Christi Himmelfahrt",
"lastChange" => $currentTimestamp
]
]
]
]
],
'selectedDate' => date('Y-m-d', $testDate)
])
], []);
}
public function testOverlappingAvailability()
{
$input = (new Entity)->createExample();
$currentTimestamp = time();
$testDate = $currentTimestamp + (20 * 24 * 60 * 60);
$weekday = (int)date('N', $testDate);
$input['startDate'] = $testDate;
$input['endDate'] = $currentTimestamp + (50 * 24 * 60 * 60);
$input['startTime'] = "09:00:00";
$input['endTime'] = "17:00:00";
$input['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$input['scope'] = [
"id" => 312,
"dayoff" => [
[
"id" => 35,
"date" => $currentTimestamp + (70 * 24 * 60 * 60),
"name" => "1. Mai",
"lastChange" => $currentTimestamp
],
[
"id" => 36,
"date" => $currentTimestamp + (140 * 24 * 60 * 60),
"name" => "Christi Himmelfahrt",
"lastChange" => $currentTimestamp
]
]
];
$input['kind'] = "default";
$secondInput = (new Entity)->createExample();
$secondInput['startDate'] = $testDate;
$secondInput['endDate'] = $currentTimestamp + (50 * 24 * 60 * 60);
$secondInput['startTime'] = "10:00:00";
$secondInput['endTime'] = "20:00:00";
$secondInput['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$secondInput['scope'] = $input['scope'];
$secondInput['kind'] = "default";
$entity = (new Query())->writeEntity($input);
$secondEntity = (new Query())->writeEntity($secondInput);
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Overlapping Entry 1",
"startDate" => $testDate,
"endDate" => $testDate,
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => [
[
"id" => 35,
"date" => $currentTimestamp + (70 * 24 * 60 * 60),
"name" => "1. Mai",
"lastChange" => $currentTimestamp
],
[
"id" => 36,
"date" => $currentTimestamp + (140 * 24 * 60 * 60),
"name" => "Christi Himmelfahrt",
"lastChange" => $currentTimestamp
]
]
]
],
[
"id" => $secondEntity->getId(),
"description" => "Overlapping Entry 2",
"startDate" => $testDate,
"endDate" => $testDate,
"startTime" => "10:00:00",
"endTime" => "20:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => [
[
"id" => 35,
"date" => $currentTimestamp + (70 * 24 * 60 * 60),
"name" => "1. Mai",
"lastChange" => $currentTimestamp
],
[
"id" => 36,
"date" => $currentTimestamp + (140 * 24 * 60 * 60),
"name" => "Christi Himmelfahrt",
"lastChange" => $currentTimestamp
]
]
]
]
],
'selectedDate' => date('Y-m-d', $testDate)
])
], []);
} Key changes:
✏️ Learnings added
🧠 Learnings used
|
@coderabbitai still fails
Why use similar to AvailabilityAddTest in AvailabilityAddUpdate AvailabilityAddTest
AvailabilityUpdateTest
|
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here's how to fix both test methods in AvailabilityUpdateTest to match AvailabilityAddTest's pattern: public function testOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = time() + (2 * 24 * 60 * 60);
$weekday = (int)date('N', $startDate);
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => 21202,
"description" => "Overlapping Entry 1",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
],
[
"id" => 21203,
"description" => "Overlapping Entry 2",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "10:00:00",
"endTime" => "18:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
}
public function testDuplicateOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = time() + (3 * 24 * 60 * 60);
$weekday = (int)date('N', $startDate);
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => 21202,
"description" => "Duplicate Entry 1",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
],
[
"id" => 21203,
"description" => "Duplicate Entry 2",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
} Key changes:
✏️ Learnings added
|
@coderabbitai new error
|
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here's how to fix both test methods in AvailabilityUpdateTest: public function testOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = time() + (2 * 24 * 60 * 60);
$weekday = (int)date('N', $startDate);
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate + (24 * 60 * 60);
$input['startTime'] = "09:00:00";
$input['endTime'] = "17:00:00";
$input['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$input['scope'] = [
"id" => 312,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$entity = (new Query())->writeEntity($input);
// Create second entity
$secondInput = $input;
$secondInput['startTime'] = "10:00:00";
$secondInput['endTime'] = "18:00:00";
$secondEntity = (new Query())->writeEntity($secondInput);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Overlapping Entry 1",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
],
[
"id" => $secondEntity->getId(),
"description" => "Overlapping Entry 2",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "10:00:00",
"endTime" => "18:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
}
public function testDuplicateOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = time() + (3 * 24 * 60 * 60);
$weekday = (int)date('N', $startDate);
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate + (24 * 60 * 60);
$input['startTime'] = "09:00:00";
$input['endTime'] = "17:00:00";
$input['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$input['scope'] = [
"id" => 312,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$entity = (new Query())->writeEntity($input);
// Create second entity with same times
$secondEntity = (new Query())->writeEntity($input);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Duplicate Entry 1",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
],
[
"id" => $secondEntity->getId(),
"description" => "Duplicate Entry 2",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
} The key changes:
✏️ Learnings added
|
@coderabbitai still fails
Is there anything missing in AvailabilityUpdate?
|
Oops, something went wrong! Please try again later. 🐰 💔 |
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed:
Length of output: 16697 @ThomasAFink Here's the fixed test methods: public function testOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = time() + (2 * 24 * 60 * 60);
$weekday = (int)date('N', $startDate);
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate + (24 * 60 * 60);
$input['startTime'] = "09:00:00";
$input['endTime'] = "17:00:00";
$input['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$input['bookable'] = [
'startInDays' => 0,
'endInDays' => 60
];
$input['scope'] = [
"id" => 312,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$entity = (new Query())->writeEntity($input);
// Create second entity
$secondInput = $input;
$secondInput['startTime'] = "10:00:00";
$secondInput['endTime'] = "18:00:00";
$secondEntity = (new Query())->writeEntity($secondInput);
// Try to update both entities with overlapping times
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Overlapping Entry 1",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 60
],
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
],
[
"id" => $secondEntity->getId(),
"description" => "Overlapping Entry 2",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "10:00:00",
"endTime" => "18:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 60
],
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
}
public function testDuplicateOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = time() + (3 * 24 * 60 * 60);
$weekday = (int)date('N', $startDate);
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate + (24 * 60 * 60);
$input['startTime'] = "09:00:00";
$input['endTime'] = "17:00:00";
$input['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$input['bookable'] = [
'startInDays' => 0,
'endInDays' => 60
];
$input['scope'] = [
"id" => 312,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$entity = (new Query())->writeEntity($input);
// Create second entity with same times
$secondEntity = (new Query())->writeEntity($input);
// Try to update both entities with same times
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Duplicate Entry 1",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 60
],
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
],
[
"id" => $secondEntity->getId(),
"description" => "Duplicate Entry 2",
"startDate" => $startDate,
"endDate" => $startDate + (24 * 60 * 60),
"startTime" => "09:00:00",
"endTime" => "17:00:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 60
],
"scope" => [
"id" => 312,
"dayoff" => $dayoffData
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
} Key changes:
✏️ Learnings added
|
@coderabbitai maybe we should use this example
|
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here are the updated test methods based on the real-world example: public function testOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = strtotime('2025-03-04'); // A Tuesday
$weekday = 4; // Tuesday
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate;
$input['startTime'] = "14:00:00";
$input['endTime'] = "17:40:00";
$input['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$input['bookable'] = [
'startInDays' => 0,
'endInDays' => 90
];
$input['scope'] = [
"id" => 392,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$input['slotTimeInMinutes'] = 5;
$input['allexWochen'] = 0;
$input['jedexteWoche'] = 0;
$input['workstationCount'] = [
'public' => 6,
'callcenter' => 6,
'intern' => 0
];
$entity = (new Query())->writeEntity($input);
// Create second entity with overlapping time
$secondInput = $input;
$secondInput['startTime'] = "15:00:00";
$secondInput['endTime'] = "17:40:00";
$secondEntity = (new Query())->writeEntity($secondInput);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Overlapping Entry 1",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"allexWochen" => 0,
"jedexteWoche" => 0,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
],
[
"id" => $secondEntity->getId(),
"description" => "Overlapping Entry 2",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "15:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"allexWochen" => 0,
"jedexteWoche" => 0,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
}
public function testDuplicateOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = strtotime('2025-03-04'); // A Tuesday
$weekday = 4; // Tuesday
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate;
$input['startTime'] = "14:00:00";
$input['endTime'] = "17:40:00";
$input['weekday'] = array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
);
$input['bookable'] = [
'startInDays' => 0,
'endInDays' => 90
];
$input['scope'] = [
"id" => 392,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$input['slotTimeInMinutes'] = 5;
$input['allexWochen'] = 0;
$input['jedexteWoche'] = 0;
$input['workstationCount'] = [
'public' => 6,
'callcenter' => 6,
'intern' => 0
];
$entity = (new Query())->writeEntity($input);
// Create second entity with exact same times
$secondEntity = (new Query())->writeEntity($input);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Duplicate Entry 1",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"allexWochen" => 0,
"jedexteWoche" => 0,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
],
[
"id" => $secondEntity->getId(),
"description" => "Duplicate Entry 2",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => array_combine(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
array_map(function($i) use ($weekday) { return $i === $weekday ? '4' : '0'; }, range(1, 7))
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"allexWochen" => 0,
"jedexteWoche" => 0,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
} Key changes:
✏️ Learnings added
|
@coderabbitai why is it still failing???
|
Oops, something went wrong! Please try again later. 🐰 💔 |
@coderabbitai let's set all the weekdays in all the availabilities to force overlap for certain.
|
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here's how to modify both test methods to set all weekdays to '4': // Replace the weekday array generation in both test methods:
$input['weekday'] = array_fill_keys(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
'4'
);
// And in the test data JSON:
"weekday" => array_fill_keys(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
'4'
), This will make the availabilities active on all days, ensuring that overlaps are detected regardless of the selected weekday. ✏️ Learnings added
🧠 Learnings used
|
@coderabbitai give full code for both tests |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here are both complete test methods with all weekdays set to '4': public function testOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = strtotime('2025-03-04'); // A Tuesday
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate;
$input['startTime'] = "14:00:00";
$input['endTime'] = "17:40:00";
$input['weekday'] = array_fill_keys(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
'4'
);
$input['bookable'] = [
'startInDays' => 0,
'endInDays' => 90
];
$input['scope'] = [
"id" => 392,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$input['slotTimeInMinutes'] = 5;
$input['workstationCount'] = [
'public' => 6,
'callcenter' => 6,
'intern' => 0
];
$entity = (new Query())->writeEntity($input);
// Create second entity with overlapping time
$secondInput = $input;
$secondInput['startTime'] = "15:00:00";
$secondInput['endTime'] = "17:40:00";
$secondEntity = (new Query())->writeEntity($secondInput);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Overlapping Entry 1",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => array_fill_keys(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
'4'
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
],
[
"id" => $secondEntity->getId(),
"description" => "Overlapping Entry 2",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "15:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => array_fill_keys(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
'4'
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
}
public function testDuplicateOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = strtotime('2025-03-04'); // A Tuesday
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate;
$input['startTime'] = "14:00:00";
$input['endTime'] = "17:40:00";
$input['weekday'] = array_fill_keys(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
'4'
);
$input['bookable'] = [
'startInDays' => 0,
'endInDays' => 90
];
$input['scope'] = [
"id" => 392,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$input['slotTimeInMinutes'] = 5;
$input['workstationCount'] = [
'public' => 6,
'callcenter' => 6,
'intern' => 0
];
$entity = (new Query())->writeEntity($input);
// Create second entity with exact same times
$secondEntity = (new Query())->writeEntity($input);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Duplicate Entry 1",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => array_fill_keys(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
'4'
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
],
[
"id" => $secondEntity->getId(),
"description" => "Duplicate Entry 2",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => array_fill_keys(
['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
'4'
),
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
} The key changes:
This should ensure that overlaps are detected regardless of the selected weekday. ✏️ Learnings added
|
@coderabbitai something must be wrong in AvailabilityUpdate compared to AvailabilityAdd. Check the code.
error_logs
|
Oops, something went wrong! Please try again later. 🐰 💔 |
1 similar comment
Oops, something went wrong! Please try again later. 🐰 💔 |
@coderabbitai the weekdays must be
instead of
give full code for both functions |
Tip For best results, initiate chat on the files or code changes. @ThomasAFink Here are both complete test methods with correct weekday values: public function testOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = strtotime('2025-03-04'); // A Tuesday
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate;
$input['startTime'] = "14:00:00";
$input['endTime'] = "17:40:00";
$input['weekday'] = [
'sunday' => '1',
'monday' => '2',
'tuesday' => '4',
'wednesday' => '8',
'thursday' => '16',
'friday' => '32',
'saturday' => '64'
];
$input['bookable'] = [
'startInDays' => 0,
'endInDays' => 90
];
$input['scope'] = [
"id" => 392,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$input['slotTimeInMinutes'] = 5;
$input['workstationCount'] = [
'public' => 6,
'callcenter' => 6,
'intern' => 0
];
$entity = (new Query())->writeEntity($input);
// Create second entity with overlapping time
$secondInput = $input;
$secondInput['startTime'] = "15:00:00";
$secondInput['endTime'] = "17:40:00";
$secondEntity = (new Query())->writeEntity($secondInput);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Overlapping Entry 1",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => [
'sunday' => '1',
'monday' => '2',
'tuesday' => '4',
'wednesday' => '8',
'thursday' => '16',
'friday' => '32',
'saturday' => '64'
],
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
],
[
"id" => $secondEntity->getId(),
"description" => "Overlapping Entry 2",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "15:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => [
'sunday' => '1',
'monday' => '2',
'tuesday' => '4',
'wednesday' => '8',
'thursday' => '16',
'friday' => '32',
'saturday' => '64'
],
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
}
public function testDuplicateOverlappingAvailability()
{
$this->setWorkstation();
$this->expectException(AvailabilityUpdateFailed::class);
$startDate = strtotime('2025-03-04'); // A Tuesday
$dayoffData = [
[
"id" => "302",
"date" => 1458860400,
"lastChange" => 1566566540,
"name" => "Karfreitag"
]
];
// Create first entity
$input = (new Entity)->createExample();
$input['startDate'] = $startDate;
$input['endDate'] = $startDate;
$input['startTime'] = "14:00:00";
$input['endTime'] = "17:40:00";
$input['weekday'] = [
'sunday' => '1',
'monday' => '2',
'tuesday' => '4',
'wednesday' => '8',
'thursday' => '16',
'friday' => '32',
'saturday' => '64'
];
$input['bookable'] = [
'startInDays' => 0,
'endInDays' => 90
];
$input['scope'] = [
"id" => 392,
"dayoff" => $dayoffData
];
$input['kind'] = "default";
$input['slotTimeInMinutes'] = 5;
$input['workstationCount'] = [
'public' => 6,
'callcenter' => 6,
'intern' => 0
];
$entity = (new Query())->writeEntity($input);
// Create second entity with exact same times
$secondEntity = (new Query())->writeEntity($input);
$this->render([], [
'__body' => json_encode([
'availabilityList' => [
[
"id" => $entity->getId(),
"description" => "Duplicate Entry 1",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => [
'sunday' => '1',
'monday' => '2',
'tuesday' => '4',
'wednesday' => '8',
'thursday' => '16',
'friday' => '32',
'saturday' => '64'
],
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
],
[
"id" => $secondEntity->getId(),
"description" => "Duplicate Entry 2",
"startDate" => $startDate,
"endDate" => $startDate,
"startTime" => "14:00:00",
"endTime" => "17:40:00",
"kind" => "default",
"weekday" => [
'sunday' => '1',
'monday' => '2',
'tuesday' => '4',
'wednesday' => '8',
'thursday' => '16',
'friday' => '32',
'saturday' => '64'
],
"bookable" => [
'startInDays' => 0,
'endInDays' => 90
],
"scope" => [
"id" => 392,
"dayoff" => $dayoffData
],
"slotTimeInMinutes" => 5,
"workstationCount" => [
'public' => 6,
'callcenter' => 6,
'intern' => 0
]
]
],
'selectedDate' => date('Y-m-d', $startDate)
])
], []);
} ✏️ Learnings added
|
@coderabbitai there must be something wrong with AvailabilityUpdate compared to AvailabilityAdd
|
Tip For best results, initiate chat on the files or code changes. @ThomasAFink I found the issue. The date handling in AvailabilityUpdate is different from AvailabilityAdd. Here's the fix needed in AvailabilityUpdate: // In AvailabilityUpdate, change this block:
$startDate = (new \DateTimeImmutable())->setTimestamp($newAvailability->startDate)->format('Y-m-d');
$endDate = (new \DateTimeImmutable())->setTimestamp($newAvailability->endDate)->format('Y-m-d');
$startDateTime = new \DateTimeImmutable("{$startDate} {$newAvailability->startTime}");
$endDateTime = new \DateTimeImmutable("{$endDate} {$newAvailability->endTime}");
// To match AvailabilityAdd's implementation:
$startDate = (new \DateTimeImmutable())->setTimestamp($newAvailability->startDate);
$endDate = (new \DateTimeImmutable())->setTimestamp($newAvailability->endDate);
$startDateTime = new \DateTimeImmutable("{$startDate->format('Y-m-d')} {$newAvailability->startTime}");
$endDateTime = new \DateTimeImmutable("{$endDate->format('Y-m-d')} {$newAvailability->endTime}"); The current code in AvailabilityUpdate converts dates to strings too early, which affects validation and conflict detection. The fix ensures dates remain as DateTime objects until final formatting, matching AvailabilityAdd's behavior. ✏️ Learnings added
|
@coderabbitai still fails
|
Oops, something went wrong! Please try again later. 🐰 💔 |
1 similar comment
Oops, something went wrong! Please try again later. 🐰 💔 |
@coderabbitai we need new backend validation if a date does not fall on the correct weekday let's say I create series only for tuesday and thursday but the date range is two days 07-02-2024 - 08-02-2024 a friday and saturday then we should not be able to add or update the opening hours. Also if no day is selected at all we shouldn'T be able to add or update the opening hours. so we need two new validation messages as well. only focus on the backend first. |
Oops, something went wrong! Please try again later. 🐰 💔 |
Pull Request Checklist (Feature Branch to
next
):next
Branch in meinen Feature-Branch gemergt.Summary by CodeRabbit