Update automated rule timestamp when adding/removing a category or label

This commit is contained in:
Víctor Falcón 2025-12-15 14:30:35 +01:00
parent bf0c9ae989
commit c9e08766c1
2 changed files with 30 additions and 0 deletions

View File

@ -44,6 +44,7 @@ class AutomationRuleController extends Controller
if (! empty($labelIds)) {
$rule->labels()->sync($labelIds);
$rule->touch();
}
return back();
@ -62,6 +63,7 @@ class AutomationRuleController extends Controller
$automationRule->update($validated);
$automationRule->labels()->sync($labelIds);
$automationRule->touch();
return back();
}

View File

@ -398,3 +398,31 @@ test('user cannot use another users label in rule', function () {
$response->assertSessionHasErrors('action_label_ids.0');
});
test('updating labels touches automation rule updated_at timestamp', function () {
$user = User::factory()->create();
$label1 = Label::factory()->create(['user_id' => $user->id]);
$label2 = Label::factory()->create(['user_id' => $user->id]);
$rule = AutomationRule::factory()->create(['user_id' => $user->id]);
$rule->labels()->attach($label1->id);
$originalUpdatedAt = $rule->updated_at;
$this->travel(2)->seconds();
$response = $this->actingAs($user)
->from(route('automation-rules.index'))
->patch(route('automation-rules.update', $rule), [
'title' => $rule->title,
'priority' => $rule->priority,
'rules_json' => json_encode($rule->rules_json),
'action_category_id' => $rule->action_category_id,
'action_note' => null,
'action_note_iv' => null,
'action_label_ids' => [$label2->id],
]);
$response->assertRedirect(route('automation-rules.index'));
$rule->refresh();
expect($rule->updated_at->isAfter($originalUpdatedAt))->toBeTrue();
});