package db import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/xlgmokha/x/pkg/event" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" ) func TestWithPublishing(t *testing.T) { aggregator := event.New[*domain.Sparkle]() storage := NewRepository[*domain.Sparkle](WithPublishing(aggregator)) t.Run("Save", func(t *testing.T) { t.Run("publishes an event", func(t *testing.T) { called := false var payload *domain.Sparkle aggregator.SubscribeTo("after.create", func(item *domain.Sparkle) { called = true payload = item }) sparkle := &domain.Sparkle{Sparklee: "@tanuki", Reason: "because"} require.NoError(t, storage.Save(t.Context(), sparkle)) require.True(t, called) require.NotNil(t, payload) assert.Equal(t, sparkle, payload) }) }) }