MCPcopy
hub / github.com/pocketbase/pocketbase / TestSendSystemAlertToAllSuperusers

Function TestSendSystemAlertToAllSuperusers

core/system_alert_test.go:63–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestSendSystemAlertToAllSuperusers(t *testing.T) {
64 t.Parallel()
65
66 testDataDir, err := os.MkdirTemp("", "sendSystemAlertToAllSuperusers_pb_data")
67 if err != nil {
68 t.Fatal(err)
69 }
70 defer os.RemoveAll(testDataDir)
71
72 testApp := NewBaseApp(BaseAppConfig{
73 DataDir: testDataDir,
74 })
75 defer testApp.ResetBootstrapState()
76
77 if err := testApp.Bootstrap(); err != nil {
78 t.Fatal(err)
79 }
80
81 if err := createTestSuperusers(testApp, 3); err != nil {
82 t.Fatal(err)
83 }
84
85 var sendCalls int
86 testApp.OnMailerSend().BindFunc(func(e *MailerEvent) error {
87 sendCalls++
88
89 if !strings.Contains(e.Message.Subject, "test_subject") {
90 t.Fatalf("Missing %q in Message.Subject:\n%s", "test_subject", e.Message.Subject)
91 }
92
93 if !strings.Contains(e.Message.HTML, "test_details") {
94 t.Fatalf("Missing %q in Message.HTML:\n%s", "test_details", e.Message.HTML)
95 }
96
97 return nil
98 })
99
100 sendSystemAlertToAllSuperusers(testApp, "test_subject", "test_details")
101
102 if sendCalls != 3 {
103 t.Fatalf("Expected 3 mail send calls, got %d", sendCalls)
104 }
105}
106
107func createTestSuperusers(app App, total int) error {
108 superusersCollection, err := app.FindCollectionByNameOrId(CollectionNameSuperusers)

Callers

nothing calls this directly

Calls 8

ResetBootstrapStateMethod · 0.95
BootstrapMethod · 0.95
OnMailerSendMethod · 0.95
NewBaseAppFunction · 0.85
createTestSuperusersFunction · 0.85
RemoveAllMethod · 0.45
BindFuncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…