How do I test that my Category
resource is sending notifications?
Here my resource definition
defmodule MyApp.KnowledgeBase.Category do
use Ash.Resource,
domain: Helpcenter.KnowledgeBase,
data_layer: AshPostgres.DataLayer,
# Tell Ash to broadcast/ Emit events via pubsub
notifiers: Ash.Notifier.PubSub
pub_sub do
module HelpcenterWeb.Endpoint
prefix "categories"
publish_all :update, [[:id, nil]]
publish_all :create, [[:id, nil]]
publish_all :destroy, [[:id, nil]]
end
end
Here is the test:
test "'categories' event should be published on create" do
Helpcenter.KnowledgeBase.Category
|> Ash.Changeset.for_create(:create, %{
name: "Art 1",
slug: "art-1",
description: "descrpt-1"
})
|> Ash.create()
assert_receive {:broadcast, "categories", "create", %Ash.Notifier.Notification{}}
end
The above tests returns:
Assertion failed, no matching message after 100ms
The process mailbox is empty.