| 1 | package e2e_test |
| 2 | |
| 3 | import ( |
| 4 | "github.com/onsi/ginkgo/v2" |
| 5 | "github.com/onsi/gomega" |
| 6 | |
| 7 | "github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy" |
| 8 | "github.com/nicholas-fedor/shoutrrr/pkg/types" |
| 9 | ) |
| 10 | |
| 11 | var _ = ginkgo.Describe("ntfy E2E Message Features Tests", func() { |
| 12 | ginkgo.When("running e2e tests against a real ntfy server", func() { |
| 13 | ginkgo.BeforeEach(func() { |
| 14 | if !isNtfyServerAvailable() { |
| 15 | ginkgo.Skip("ntfy server not available, skipping e2e tests") |
| 16 | } |
| 17 | }) |
| 18 | |
| 19 | ginkgo.It("should send a message with a click action", func() { |
| 20 | serviceURLStr := buildServiceURL() |
| 21 | service := initializeService(serviceURLStr) |
| 22 | |
| 23 | topic := service.Config.Topic |
| 24 | message := "E2E Test: Click action message" |
| 25 | |
| 26 | gomega.Expect(service.Send(message, &types.Params{ |
| 27 | "click": "https://example.com", |
| 28 | })).NotTo(gomega.HaveOccurred()) |
| 29 | |
| 30 | verifyMessageReceived(topic, message) |
| 31 | }) |
| 32 | |
| 33 | ginkgo.It("should send a message with an attachment URL", func() { |
| 34 | serviceURLStr := buildServiceURL() |
| 35 | service := initializeService(serviceURLStr) |
| 36 | |
| 37 | topic := service.Config.Topic |
| 38 | message := "E2E Test: Attachment message" |
| 39 | |
| 40 | gomega.Expect(service.Send(message, &types.Params{ |
| 41 | "attach": "https://example.com/image.png", |
| 42 | })).NotTo(gomega.HaveOccurred()) |
| 43 | |
| 44 | verifyMessageReceived(topic, message) |
| 45 | }) |
| 46 | |
| 47 | ginkgo.It("should send a message with actions", func() { |
| 48 | serviceURLStr := buildServiceURL() |
| 49 | service := initializeService(serviceURLStr) |
| 50 | |
| 51 | topic := service.Config.Topic |
| 52 | message := "E2E Test: Actions message" |
| 53 | |
| 54 | gomega.Expect(service.Send(message, &types.Params{ |
| 55 | "actions": "action=view,label=Open,url=https://example.com", |
| 56 | })).NotTo(gomega.HaveOccurred()) |
| 57 | |
| 58 | verifyMessageReceived(topic, message) |
| 59 | }) |
| 60 | |
| 61 | ginkgo.It("should send a message with delay", func() { |
| 62 | serviceURLStr := buildServiceURL() |
| 63 | service := initializeService(serviceURLStr) |
| 64 | |
| 65 | message := "E2E Test: Delayed message" |
| 66 | |
| 67 | gomega.Expect(service.Send(message, &types.Params{ |
| 68 | "delay": "10s", |
| 69 | })).NotTo(gomega.HaveOccurred()) |
| 70 | |
| 71 | // Delayed messages may not appear immediately, so we just verify no error |
| 72 | ginkgo.GinkgoWriter.Write([]byte("Delayed message sent successfully\n")) |
| 73 | }) |
| 74 | |
| 75 | ginkgo.It("should send a message with email notification", func() { |
| 76 | ginkgo.Skip("email notifications require server-side configuration") |
| 77 | |
| 78 | serviceURLStr := buildServiceURL() |
| 79 | service := initializeService(serviceURLStr) |
| 80 | |
| 81 | topic := service.Config.Topic |
| 82 | message := "E2E Test: Email notification" |
| 83 | |
| 84 | gomega.Expect(service.Send(message, &types.Params{ |
| 85 | "email": "[email protected]", |
| 86 | })).NotTo(gomega.HaveOccurred()) |
| 87 | |
| 88 | verifyMessageReceived(topic, message) |
| 89 | }) |
| 90 | |
| 91 | ginkgo.It("should send a message with icon", func() { |
| 92 | serviceURLStr := buildServiceURL() |
| 93 | service := initializeService(serviceURLStr) |
| 94 | |
| 95 | topic := service.Config.Topic |
| 96 | message := "E2E Test: Icon message" |
| 97 | |
| 98 | gomega.Expect(service.Send(message, &types.Params{ |
| 99 | "icon": "https://example.com/icon.png", |
| 100 | })).NotTo(gomega.HaveOccurred()) |
| 101 | |
| 102 | verifyMessageReceived(topic, message) |
| 103 | }) |
| 104 | |
| 105 | ginkgo.It("should send a message with filename", func() { |
| 106 | ginkgo.Skip("attachments require server-side configuration") |
| 107 | |
| 108 | serviceURLStr := buildServiceURL() |
| 109 | service := initializeService(serviceURLStr) |
| 110 | |
| 111 | topic := service.Config.Topic |
| 112 | message := "E2E Test: Filename message" |
| 113 | |
| 114 | gomega.Expect(service.Send(message, &types.Params{ |
| 115 | "filename": "report.pdf", |
| 116 | })).NotTo(gomega.HaveOccurred()) |
| 117 | |
| 118 | verifyMessageReceived(topic, message) |
| 119 | }) |
| 120 | |
| 121 | ginkgo.It("should send a message with multiple tags", func() { |
| 122 | serviceURLStr := buildServiceURL() |
| 123 | service := initializeService(serviceURLStr) |
| 124 | |
| 125 | topic := service.Config.Topic |
| 126 | message := "E2E Test: Multiple tags message" |
| 127 | |
| 128 | gomega.Expect(service.Send(message, &types.Params{ |
| 129 | "tags": "warning,skull,fire", |
| 130 | })).NotTo(gomega.HaveOccurred()) |
| 131 | |
| 132 | verifyMessageReceivedWithTags(topic, message, []string{"warning", "skull", "fire"}) |
| 133 | }) |
| 134 | |
| 135 | ginkgo.It("should send a message with combined params", func() { |
| 136 | serviceURLStr := buildServiceURL() |
| 137 | service := initializeService(serviceURLStr) |
| 138 | |
| 139 | topic := service.Config.Topic |
| 140 | message := "E2E Test: Combined params message" |
| 141 | |
| 142 | gomega.Expect(service.Send(message, &types.Params{ |
| 143 | "title": "Combined", |
| 144 | "priority": "5", |
| 145 | "tags": "warning,skull", |
| 146 | })).NotTo(gomega.HaveOccurred()) |
| 147 | |
| 148 | verifyMessageReceivedWithTitle(topic, message, "Combined") |
| 149 | }) |
| 150 | }) |
| 151 | |
| 152 | ginkgo.When("no server is configured", func() { |
| 153 | ginkgo.It("should return the correct service ID", func() { |
| 154 | service := &ntfy.Service{} |
| 155 | gomega.Expect(service.GetID()).To(gomega.Equal("ntfy")) |
| 156 | }) |
| 157 | }) |
| 158 | }) |