iCal-Regelanwendung bei Zeitstempelupdates erlauben und Dialogfehler anzeigen
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m53s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m53s
This commit is contained in:
1 parent
678e15256d
commit
a0497fcccd
5 files changed
+170
-8
No files matched your search
@@ -28,6 +28,7 @@
|
||||
use App\Tenancy\TenantContext;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -378,6 +379,129 @@ public function test_a_newer_import_cannot_be_overwritten_by_an_old_analysis_dur
|
||||
$this->assertNull($channel->fresh()->ical_active_rules);
|
||||
}
|
||||
|
||||
#[DataProvider('timestampChanges')]
|
||||
public function test_timestamp_only_sync_updates_do_not_block_applying_rules_or_replace_newer_originals(bool $changeStamp, bool $changeModified): void
|
||||
{
|
||||
$channel = $this->channel();
|
||||
$initial = str_replace('DTSTAMP:20261027T090000Z', "DTSTAMP:20261027T090000Z\r\nLAST-MODIFIED:20261027T090000Z", self::calendar());
|
||||
$calendar = str_replace(
|
||||
['DTSTAMP:20261027T090000Z', 'LAST-MODIFIED:20261027T090000Z'],
|
||||
[$changeStamp ? 'DTSTAMP:20261027T090500Z' : 'DTSTAMP:20261027T090000Z', $changeModified ? 'LAST-MODIFIED:20261027T090500Z' : 'LAST-MODIFIED:20261027T090000Z'],
|
||||
$initial,
|
||||
);
|
||||
Http::preventStrayRequests();
|
||||
Http::fake(['https://portal.example/calendar.ics' => Http::sequence()->push($initial)->push($calendar)]);
|
||||
Mail::fake();
|
||||
$this->assertTrue(app(SyncChannel::class)->handle($channel)->successful);
|
||||
$this->travel(5)->minutes();
|
||||
$this->assertTrue(app(SyncChannel::class)->handle($channel)->successful);
|
||||
$block = $channel->blockedPeriods()->where('external_uid', 'one')->sole();
|
||||
$this->assertStringContainsString(($changeStamp ? 'DTSTAMP' : 'LAST-MODIFIED').':20261027T090500Z', $block->ical_raw);
|
||||
$original = $block->only(['id', 'external_uid', 'starts_on', 'ends_on', 'ical_raw', 'ical_properties']);
|
||||
$this->actingAs(User::factory()->create());
|
||||
|
||||
Livewire::test(ChannelRules::class, ['record' => $channel->id])
|
||||
->fillForm(['rules' => self::rules()])
|
||||
->mountAction('applyRules')->assertActionMounted('applyRules')
|
||||
->callMountedAction()->assertHasNoFormErrors()->assertActionNotMounted()
|
||||
->assertNotified('2 Einträge neu klassifiziert')
|
||||
->assertSee('Gespeicherter Entwurf und aktive Regeln stimmen überein.');
|
||||
|
||||
$this->assertEquals($original, $block->fresh()->only(array_keys($original)));
|
||||
$this->assertSame('portal_reservation', $block->fresh()->ical_event_type);
|
||||
$this->assertSame('Lea', $block->fresh()->guestName());
|
||||
$this->assertSame($channel->fresh()->ical_rules, $channel->fresh()->ical_active_rules);
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
|
||||
public static function timestampChanges(): array
|
||||
{
|
||||
return ['DTSTAMP' => [true, false], 'LAST-MODIFIED' => [false, true], 'both' => [true, true]];
|
||||
}
|
||||
|
||||
public function test_changed_import_closes_confirmation_and_shows_why_rules_were_not_activated(): void
|
||||
{
|
||||
$channel = $this->channel();
|
||||
$this->import($channel);
|
||||
$this->actingAs(User::factory()->create());
|
||||
$page = Livewire::test(ChannelRules::class, ['record' => $channel->id])
|
||||
->fillForm(['rules' => self::rules()])->mountAction('applyRules')->assertActionMounted('applyRules');
|
||||
$this->travel(5)->minutes();
|
||||
$block = $channel->blockedPeriods()->where('external_uid', 'one')->sole();
|
||||
$newEvent = app(ICalParser::class)->parseDocument(self::feed(self::event('one', 'Reserved - Noah')))['events'][0];
|
||||
$block->forceFill(['ical_raw' => $newEvent['raw'], 'ical_properties' => $newEvent['properties']])->saveQuietly();
|
||||
|
||||
$page->callMountedAction()->assertActionNotMounted()
|
||||
->assertNotified(Notification::make()->title('Regeln wurden nicht angewendet')
|
||||
->body('Der Importbestand hat sich seit der Vorschau geändert. Den Kalender erneut analysieren und die Vorschau prüfen.')
|
||||
->danger()->persistent())
|
||||
->assertSee('Es sind noch keine Erkennungsregeln aktiviert.');
|
||||
|
||||
$this->assertNull($channel->fresh()->ical_rules);
|
||||
$this->assertNull($channel->fresh()->ical_active_rules);
|
||||
$this->assertSame('unknown', $block->fresh()->ical_event_type);
|
||||
$this->assertSame($newEvent['raw'], $block->fresh()->ical_raw);
|
||||
$this->assertSame($newEvent['properties'], $block->fresh()->ical_properties);
|
||||
$this->assertCount(2, $page->get('data.rules'));
|
||||
}
|
||||
|
||||
public function test_invalid_extraction_is_visible_after_confirmation_and_can_be_corrected_without_losing_the_draft(): void
|
||||
{
|
||||
$channel = $this->channel();
|
||||
$this->actingAs(User::factory()->create());
|
||||
$rule = self::rule(['extractions' => [['field' => 'SUMMARY', 'target' => 'guest_full_name', 'method' => 'after', 'start' => '']]]);
|
||||
|
||||
$page = Livewire::test(ChannelRules::class, ['record' => $channel->id])
|
||||
->fillForm(['rules' => [$rule]])->mountAction('applyRules')->callMountedAction()
|
||||
->assertActionNotMounted()
|
||||
->assertNotified(Notification::make()->title('Regeln wurden nicht angewendet')
|
||||
->body('Für die Textextraktion die benötigten Anfangs- und Endtexte angeben.')->danger()->persistent());
|
||||
|
||||
$this->assertNull($channel->fresh()->ical_rules);
|
||||
$this->assertNull($channel->fresh()->ical_active_rules);
|
||||
$page->fillForm(['rules' => [self::rule()]])->mountAction('applyRules')->callMountedAction()
|
||||
->assertHasNoFormErrors()->assertActionNotMounted()->assertNotified('0 Einträge neu klassifiziert');
|
||||
$this->assertCount(1, $channel->fresh()->ical_active_rules);
|
||||
}
|
||||
|
||||
public function test_a_rule_using_a_changed_timestamp_requires_a_new_preview(): void
|
||||
{
|
||||
$channel = $this->channel();
|
||||
$this->import($channel);
|
||||
$rule = self::rule(['conditions' => [['field' => 'DTSTAMP', 'operator' => 'equals', 'value' => '20261027T090000Z']]]);
|
||||
app(SaveChannelRules::class)->handle($channel, [$rule]);
|
||||
$this->travel(5)->minutes();
|
||||
$block = $channel->blockedPeriods()->where('external_uid', 'one')->sole();
|
||||
$newEvent = app(ICalParser::class)->parseDocument(self::feed(str_replace('DTSTAMP:20261027T090000Z', 'DTSTAMP:20261027T090500Z', self::event('one', 'Reserved - Lea'))))['events'][0];
|
||||
$block->forceFill(['ical_raw' => $newEvent['raw'], 'ical_properties' => $newEvent['properties']])->saveQuietly();
|
||||
|
||||
try {
|
||||
app(ApplyChannelRules::class)->handle($channel->fresh());
|
||||
$this->fail('A changed rule result must require a new preview.');
|
||||
} catch (ValidationException $exception) {
|
||||
$this->assertArrayHasKey('rules', $exception->errors());
|
||||
}
|
||||
|
||||
$this->assertNull($channel->fresh()->ical_active_rules);
|
||||
$this->assertSame($newEvent['raw'], $block->fresh()->ical_raw);
|
||||
$this->assertSame('unknown', $block->fresh()->ical_event_type);
|
||||
}
|
||||
|
||||
public function test_main_form_validation_closes_confirmation_and_keeps_the_unsaved_fields(): void
|
||||
{
|
||||
$channel = $this->channel();
|
||||
$this->actingAs(User::factory()->create());
|
||||
|
||||
$page = Livewire::test(ChannelRules::class, ['record' => $channel->id])
|
||||
->fillForm(['rules' => [self::rule(['name' => ''])]])
|
||||
->mountAction('applyRules')->callMountedAction()->assertActionNotMounted()
|
||||
->assertHasErrors()->assertNotified('Regeln wurden nicht angewendet');
|
||||
|
||||
$this->assertCount(1, $page->get('data.rules'));
|
||||
$this->assertNull($channel->fresh()->ical_rules);
|
||||
$this->assertNull($channel->fresh()->ical_active_rules);
|
||||
}
|
||||
|
||||
public function test_ambiguous_duplicate_uids_with_different_original_fields_are_rejected(): void
|
||||
{
|
||||
$this->expectException(ChannelSyncException::class);
|
||||
|
||||
Reference in new issue
Block a user