| 1 | package e2e_test |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "strings" |
| 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 Title and Topic Handling", func() { |
| 16 | ginkgo.When("running e2e tests against a real Zulip server", func() { |
| 17 | ginkgo.It("should use title as topic when no topic is configured", func() { |
| 18 | serviceURLStr := buildServiceURL() |
| 19 | if serviceURLStr == "" { |
| 20 | ginkgo.Skip("Zulip server not configured, skipping title-as-topic 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: title used as topic", &types.Params{ |
| 31 | "title": "e2e-title-as-topic", |
| 32 | }) |
| 33 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 34 | }) |
| 35 | |
| 36 | ginkgo.It("should preserve explicit topic when title is also provided", func() { |
| 37 | serviceURLStr := buildServiceURL() |
| 38 | if serviceURLStr == "" { |
| 39 | ginkgo.Skip("Zulip server not configured, skipping topic-preservation test") |
| 40 | } |
| 41 | |
| 42 | serviceURL, err := url.Parse(serviceURLStr) |
| 43 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 44 | |
| 45 | service := &zulip.Service{} |
| 46 | err = service.Initialize(serviceURL, testutils.TestLogger()) |
| 47 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 48 | |
| 49 | err = service.Send("E2E Test: body content", &types.Params{ |
| 50 | "topic": "e2e-explicit-topic", |
| 51 | "title": "E2E Notification Title", |
| 52 | }) |
| 53 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 54 | }) |
| 55 | |
| 56 | ginkgo.It("should send a message with a long title used as topic", func() { |
| 57 | serviceURLStr := buildServiceURL() |
| 58 | if serviceURLStr == "" { |
| 59 | ginkgo.Skip("Zulip server not configured, skipping long title test") |
| 60 | } |
| 61 | |
| 62 | serviceURL, err := url.Parse(serviceURLStr) |
| 63 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 64 | |
| 65 | service := &zulip.Service{} |
| 66 | err = service.Initialize(serviceURL, testutils.TestLogger()) |
| 67 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 68 | |
| 69 | longTitle := strings.Repeat("x", 50) |
| 70 | err = service.Send("E2E Test: long title as topic", &types.Params{ |
| 71 | "title": longTitle, |
| 72 | }) |
| 73 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 74 | }) |
| 75 | |
| 76 | ginkgo.It("should send message with topic only and no title", func() { |
| 77 | serviceURLStr := buildServiceURL() |
| 78 | if serviceURLStr == "" { |
| 79 | ginkgo.Skip("Zulip server not configured, skipping topic-only test") |
| 80 | } |
| 81 | |
| 82 | serviceURL, err := url.Parse(serviceURLStr) |
| 83 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 84 | |
| 85 | service := &zulip.Service{} |
| 86 | err = service.Initialize(serviceURL, testutils.TestLogger()) |
| 87 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 88 | |
| 89 | err = service.Send("E2E Test: topic only", &types.Params{ |
| 90 | "topic": "e2e-topic-only", |
| 91 | }) |
| 92 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 93 | }) |
| 94 | |
| 95 | ginkgo.It("should send message with title only and no topic", func() { |
| 96 | serviceURLStr := buildServiceURL() |
| 97 | if serviceURLStr == "" { |
| 98 | ginkgo.Skip("Zulip server not configured, skipping title-only test") |
| 99 | } |
| 100 | |
| 101 | serviceURL, err := url.Parse(serviceURLStr) |
| 102 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 103 | |
| 104 | service := &zulip.Service{} |
| 105 | err = service.Initialize(serviceURL, testutils.TestLogger()) |
| 106 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 107 | |
| 108 | err = service.Send("E2E Test: title only", &types.Params{ |
| 109 | "title": "e2e-title-only", |
| 110 | }) |
| 111 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 112 | }) |
| 113 | }) |
| 114 | }) |