Debian Codegraph @

testing/e2e/homeassistant/basic_test.go

raw
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/types"
8 )
9
10 var _ = ginkgo.Describe("Home Assistant E2E", func() {
11 ginkgo.BeforeEach(func() {
12 if !isHomeAssistantAvailable() {
13 ginkgo.Skip("Home Assistant is not available, skipping e2e tests")
14 }
15 })
16
17 ginkgo.It("should create a persistent notification", func() {
18 rawURL := withNid(serviceURL(), "shoutrrr_e2e")
19 service := initializeService(rawURL)
20
21 message := "E2E Test: persistent notification"
22 gomega.Expect(service.Send(message, nil)).NotTo(gomega.HaveOccurred())
23
24 state := fetchPersistentNotification(accessToken(rawURL), "shoutrrr_e2e")
25 gomega.Expect(state.Message).To(gomega.Equal(message))
26 })
27
28 ginkgo.It("should include a title", func() {
29 rawURL := withNid(serviceURL(), "shoutrrr_e2e_title")
30 service := initializeService(rawURL)
31
32 params := types.Params{"title": "E2E Title"}
33 gomega.Expect(service.Send("E2E Test: titled notification", &params)).
34 NotTo(gomega.HaveOccurred())
35
36 state := fetchPersistentNotification(accessToken(rawURL), "shoutrrr_e2e_title")
37 gomega.Expect(state.Title).To(gomega.Equal("E2E Title"))
38 gomega.Expect(state.Message).To(gomega.Equal("E2E Test: titled notification"))
39 })
40
41 ginkgo.It("should replace a persistent notification when nid is reused", func() {
42 rawURL := withNid(serviceURL(), "shoutrrr_e2e_replace")
43 service := initializeService(rawURL)
44
45 gomega.Expect(service.Send("first message", nil)).NotTo(gomega.HaveOccurred())
46 gomega.Expect(service.Send("second message", nil)).NotTo(gomega.HaveOccurred())
47
48 state := fetchPersistentNotification(accessToken(rawURL), "shoutrrr_e2e_replace")
49 gomega.Expect(state.Message).To(gomega.Equal("second message"))
50 })
51
52 ginkgo.It("should send over HTTP when disabletls is set", func() {
53 gomega.Expect(serviceURL()).To(gomega.ContainSubstring("disabletls"))
54
55 rawURL := withNid(serviceURL(), "shoutrrr_e2e_http")
56 service := initializeService(rawURL)
57
58 gomega.Expect(service.Send("E2E Test: HTTP", nil)).NotTo(gomega.HaveOccurred())
59
60 state := fetchPersistentNotification(accessToken(rawURL), "shoutrrr_e2e_http")
61 gomega.Expect(state.Message).To(gomega.Equal("E2E Test: HTTP"))
62 })
63
64 ginkgo.It("should reject an unauthorized token", func() {
65 rawURL := "homeassistant://invalid-token@localhost:8123/?disabletls=yes"
66 service := initializeService(rawURL)
67
68 err := service.Send("should fail", nil)
69 gomega.Expect(err).To(gomega.HaveOccurred())
70 })
71 })