Debian Codegraph @

testing/e2e/zulip/basic_test.go

raw
1 package e2e_test
2
3 import (
4 "net/url"
5 "os"
6
7 "github.com/onsi/ginkgo/v2"
8 "github.com/onsi/gomega"
9
10 "github.com/nicholas-fedor/shoutrrr/internal/testutils"
11 "github.com/nicholas-fedor/shoutrrr/pkg/services/chat/zulip"
12 "github.com/nicholas-fedor/shoutrrr/pkg/types"
13 )
14
15 var _ = ginkgo.Describe("Zulip E2E Basic Tests", func() {
16 ginkgo.When("running e2e tests against a real Zulip server", func() {
17 ginkgo.It("should send a basic text message to a stream", func() {
18 serviceURLStr := buildServiceURL()
19 if serviceURLStr == "" {
20 ginkgo.Skip("Zulip server not configured, skipping basic message test")
21 }
22
23 serviceURL, err := url.Parse(serviceURLStr)
24 gomega.Expect(err).NotTo(gomega.HaveOccurred())
25
26 service := &zulip.Service{}
27 err = service.Initialize(serviceURL, testutils.TestLogger())
28 gomega.Expect(err).NotTo(gomega.HaveOccurred())
29
30 err = service.Send("E2E Test: Basic text notification", nil)
31 gomega.Expect(err).NotTo(gomega.HaveOccurred())
32 })
33
34 ginkgo.It("should send a message with a custom topic via params", func() {
35 serviceURLStr := buildServiceURL()
36 if serviceURLStr == "" {
37 ginkgo.Skip("Zulip server not configured, skipping topic test")
38 }
39
40 serviceURL, err := url.Parse(serviceURLStr)
41 gomega.Expect(err).NotTo(gomega.HaveOccurred())
42
43 service := &zulip.Service{}
44 err = service.Initialize(serviceURL, testutils.TestLogger())
45 gomega.Expect(err).NotTo(gomega.HaveOccurred())
46
47 err = service.Send("E2E Test: Custom topic notification", &types.Params{
48 "topic": "e2e-testing",
49 })
50 gomega.Expect(err).NotTo(gomega.HaveOccurred())
51 })
52
53 ginkgo.It("should send a message with stream via params override", func() {
54 serviceURLStr := buildServiceURL()
55 if serviceURLStr == "" {
56 ginkgo.Skip("Zulip server not configured, skipping stream params test")
57 }
58
59 serviceURL, err := url.Parse(serviceURLStr)
60 gomega.Expect(err).NotTo(gomega.HaveOccurred())
61
62 service := &zulip.Service{}
63 err = service.Initialize(serviceURL, testutils.TestLogger())
64 gomega.Expect(err).NotTo(gomega.HaveOccurred())
65
66 // Override stream via params using the same stream from config
67 stream := os.Getenv("SHOUTRRR_ZULIP_STREAM")
68 if stream == "" {
69 stream = "general"
70 }
71
72 err = service.Send("E2E Test: Stream via params notification", &types.Params{
73 "stream": stream,
74 })
75 gomega.Expect(err).NotTo(gomega.HaveOccurred())
76 })
77
78 ginkgo.It("should send a direct message when DM recipient is configured", func() {
79 serviceURLStr := buildServiceURL()
80
81 dmTo := os.Getenv("SHOUTRRR_ZULIP_DM_TO")
82 if dmTo == "" {
83 // Fall back to the bot's own email to exercise the DM code path
84 // without requiring an extra env var. Self-DMs are usually allowed
85 // and validate the type/to/JSON recipient formatting.
86 dmTo = os.Getenv("SHOUTRRR_ZULIP_BOT_MAIL")
87 }
88
89 if serviceURLStr == "" || dmTo == "" {
90 ginkgo.Skip("Zulip DM recipient not configured, skipping direct message E2E test")
91 }
92
93 serviceURL, err := url.Parse(serviceURLStr)
94 gomega.Expect(err).NotTo(gomega.HaveOccurred())
95
96 service := &zulip.Service{}
97 err = service.Initialize(serviceURL, testutils.TestLogger())
98 gomega.Expect(err).NotTo(gomega.HaveOccurred())
99
100 err = service.Send("E2E Test: Direct message notification", &types.Params{
101 "type": "direct",
102 "to": dmTo,
103 })
104 gomega.Expect(err).NotTo(gomega.HaveOccurred())
105 })
106 })
107
108 ginkgo.When("no server is configured", func() {
109 ginkgo.It("should return the correct service ID", func() {
110 service := &zulip.Service{}
111 gomega.Expect(service.GetID()).To(gomega.Equal("zulip"))
112 })
113 })
114 })