mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
feat(automations): add event trigger params
This commit is contained in:
parent
6fa2e52361
commit
f09e302d4f
4 changed files with 63 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
||||||
|
"""``EventTriggerParams`` — params for the ``event`` trigger type."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
|
||||||
|
class EventTriggerParams(BaseModel):
|
||||||
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
|
event_type: str = Field(
|
||||||
|
...,
|
||||||
|
min_length=1,
|
||||||
|
description="Event type to listen for.",
|
||||||
|
examples=["document.indexed"],
|
||||||
|
)
|
||||||
|
filter: dict[str, Any] = Field(
|
||||||
|
default_factory=dict,
|
||||||
|
description="JSON filter matched against the event payload.",
|
||||||
|
examples=[{"document_type": "FILE"}],
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
"""``EventTriggerParams`` contract: an event_type to listen for + an optional filter."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from app.automations.triggers.builtin.event.params import EventTriggerParams
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.unit
|
||||||
|
|
||||||
|
|
||||||
|
def test_accepts_event_type_and_filter() -> None:
|
||||||
|
params = EventTriggerParams(
|
||||||
|
event_type="document.indexed",
|
||||||
|
filter={"document_type": "FILE"},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert params.event_type == "document.indexed"
|
||||||
|
assert params.filter == {"document_type": "FILE"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_filter_defaults_to_empty() -> None:
|
||||||
|
params = EventTriggerParams(event_type="document.indexed")
|
||||||
|
|
||||||
|
assert params.filter == {}
|
||||||
|
|
||||||
|
|
||||||
|
def test_event_type_is_required() -> None:
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
EventTriggerParams(filter={"x": 1})
|
||||||
|
|
||||||
|
|
||||||
|
def test_event_type_must_not_be_blank() -> None:
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
EventTriggerParams(event_type="")
|
||||||
|
|
||||||
|
|
||||||
|
def test_extra_keys_are_forbidden() -> None:
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
EventTriggerParams(event_type="document.indexed", typo=True)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue