100 lines
3.4 KiB
PHP
100 lines
3.4 KiB
PHP
<?php
|
||
|
||
use App\Models\CabinetTabletSetting;
|
||
use Illuminate\Support\Carbon;
|
||
|
||
test('status endpoint returns full JSON response', function () {
|
||
CabinetTabletSetting::factory()->create([
|
||
'store_status' => 'auto',
|
||
'hours_thursday_open' => '10:00',
|
||
'hours_thursday_close' => '18:00',
|
||
'contact_phone' => '0521 98620100',
|
||
'contact_email' => 'info@cabinet-bielefeld.de',
|
||
'next_appointment_date' => '2026-03-01',
|
||
'next_appointment_time' => '14:00',
|
||
]);
|
||
|
||
// Thursday 12:00 – within opening hours
|
||
Carbon::setTestNow(Carbon::create(2026, 3, 5, 12, 0, 0, 'Europe/Berlin'));
|
||
|
||
$response = $this->getJson('/api/cabinet-tablet/status');
|
||
|
||
$response->assertSuccessful()
|
||
->assertJsonStructure([
|
||
'store_status',
|
||
'today_close',
|
||
'next_open',
|
||
'notice_headline',
|
||
'notice_subtext',
|
||
'override_open_today',
|
||
'override_close_today',
|
||
'next_appointment' => ['date', 'time'],
|
||
'hours' => ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'],
|
||
'contact' => ['phone', 'email'],
|
||
'updated_at',
|
||
])
|
||
->assertJsonPath('store_status', 'open')
|
||
->assertJsonPath('today_close', '18:00')
|
||
->assertJsonPath('hours.monday', '10:00 – 18:00')
|
||
->assertJsonPath('hours.sunday', 'Geschlossen')
|
||
->assertJsonPath('contact.phone', '0521 98620100')
|
||
->assertJsonPath('next_appointment.date', '2026-03-01')
|
||
->assertJsonPath('next_appointment.time', '14:00');
|
||
|
||
Carbon::setTestNow();
|
||
});
|
||
|
||
test('status endpoint returns closed with next_open outside opening hours', function () {
|
||
CabinetTabletSetting::factory()->create([
|
||
'store_status' => 'auto',
|
||
'hours_thursday_open' => '10:00',
|
||
'hours_thursday_close' => '18:00',
|
||
'hours_friday_open' => '10:00',
|
||
'hours_friday_close' => '18:00',
|
||
]);
|
||
|
||
// Thursday 20:00 – after closing
|
||
Carbon::setTestNow(Carbon::create(2026, 3, 5, 20, 0, 0, 'Europe/Berlin'));
|
||
|
||
$response = $this->getJson('/api/cabinet-tablet/status');
|
||
|
||
$response->assertSuccessful()
|
||
->assertJsonPath('store_status', 'closed')
|
||
->assertJsonPath('next_open.label', 'Morgen')
|
||
->assertJsonPath('next_open.time', '10:00');
|
||
|
||
Carbon::setTestNow();
|
||
});
|
||
|
||
test('status endpoint returns notice when notice mode is set', function () {
|
||
CabinetTabletSetting::factory()->create([
|
||
'store_status' => 'notice',
|
||
'notice_headline' => 'Urlaub',
|
||
'notice_subtext' => 'Wir sind vom 10.–20. März im Urlaub.',
|
||
]);
|
||
|
||
$response = $this->getJson('/api/cabinet-tablet/status');
|
||
|
||
$response->assertSuccessful()
|
||
->assertJsonPath('store_status', 'notice')
|
||
->assertJsonPath('notice_headline', 'Urlaub');
|
||
});
|
||
|
||
test('check endpoint returns updated_at and store_status but not full data', function () {
|
||
CabinetTabletSetting::factory()->create(['store_status' => 'auto']);
|
||
|
||
$response = $this->getJson('/api/cabinet-tablet/check');
|
||
|
||
$response->assertSuccessful()
|
||
->assertJsonStructure(['updated_at', 'store_status'])
|
||
->assertJsonMissingPath('hours');
|
||
});
|
||
|
||
test('status endpoint creates settings row if none exists', function () {
|
||
expect(CabinetTabletSetting::count())->toBe(0);
|
||
|
||
$response = $this->getJson('/api/cabinet-tablet/status');
|
||
|
||
$response->assertSuccessful();
|
||
expect(CabinetTabletSetting::count())->toBe(1);
|
||
});
|