feat: step 11 done

This commit is contained in:
2026-04-29 19:24:45 +02:00
parent 4ae6c55e83
commit 155fda8b81
6 changed files with 284 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ defmodule BDS.CliSyncTest do
import Ecto.Query
alias BDS.CliSync
alias BDS.CliSync.Watcher
alias BDS.Repo
setup do
@@ -24,6 +25,25 @@ defmodule BDS.CliSyncTest do
assert is_integer(seen_notification.seen_at)
end
test "watcher broadcasts entity change events after database mutations are detected" do
Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, {:shared, self()})
Phoenix.PubSub.subscribe(BDS.PubSub, Watcher.topic())
watcher =
start_supervised!({Watcher, poll_interval_ms: 60_000, debounce_ms: 0})
Ecto.Adapters.SQL.Sandbox.allow(BDS.Repo, self(), watcher)
assert {:ok, notification} = CliSync.cli_mutation_performed("post", "post-1", :updated)
:ok = Watcher.poll_now(watcher)
assert_receive {:entity_changed, %{entity: "post", entity_id: "post-1", action: :updated}}, 500
seen_notification = Repo.get!(BDS.CliSync.Notification, notification.id)
assert is_integer(seen_notification.seen_at)
end
test "processed notifications are pruned after one hour and unprocessed notifications after one day" do
now = BDS.Persistence.now_ms()