-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplexhooks_test.go
More file actions
108 lines (80 loc) · 3.56 KB
/
plexhooks_test.go
File metadata and controls
108 lines (80 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package plexhooks
import (
"encoding/json"
"io/ioutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Plexhooks", func() {
Context("a music play", func() {
It("parses it properly", func() {
body, err := ioutil.ReadFile("test-fixtures/music.json")
Expect(err).ShouldNot(HaveOccurred())
response, err := ParseWebhook(body)
Expect(err).ShouldNot(HaveOccurred())
responseString, err := json.Marshal(response)
Expect(err).ShouldNot(HaveOccurred())
newResponse, err := ParseWebhook(responseString)
Expect(err).ShouldNot(HaveOccurred())
Expect(response).To(Equal(newResponse))
Expect(newResponse.Event).To(Equal("media.play"))
Expect(newResponse.Account.Id).To(Equal(1))
Expect(newResponse.Server.Title).To(Equal("Office"))
Expect(newResponse.Player.Title).To(Equal("Plex Web (Safari)"))
Expect(newResponse.Metadata.Type).To(Equal("track"))
Expect(newResponse.Metadata.Title).To(Equal("Love The One You're With"))
})
})
Context("a tv play", func() {
It("parses it properly", func() {
body, err := ioutil.ReadFile("test-fixtures/tv.json")
Expect(err).ShouldNot(HaveOccurred())
response, err := ParseWebhook(body)
Expect(err).ShouldNot(HaveOccurred())
responseString, err := json.Marshal(response)
Expect(err).ShouldNot(HaveOccurred())
newResponse, err := ParseWebhook(responseString)
Expect(err).ShouldNot(HaveOccurred())
Expect(response).To(Equal(newResponse))
Expect(newResponse.User).To(Equal(true))
Expect(newResponse.Account.Title).To(Equal("testyboi"))
Expect(newResponse.Server.Title).To(Equal("nice"))
Expect(newResponse.Player.PublicAddress).To(Equal("200.200.200.200"))
Expect(newResponse.Metadata.Type).To(Equal("episode"))
Expect(newResponse.Metadata.Title).To(Equal("A Clone of My Own"))
Expect(newResponse.Metadata.Director[0].Tag).To(Equal("Rich Moore"))
Expect(newResponse.Metadata.Writer[0].Filter).To(Equal("writer=49503"))
})
})
Context("a movie play", func() {
It("parses it properly", func() {
body, err := ioutil.ReadFile("test-fixtures/movie.json")
Expect(err).ShouldNot(HaveOccurred())
response, err := ParseWebhook(body)
Expect(err).ShouldNot(HaveOccurred())
responseString, err := json.Marshal(response)
Expect(err).ShouldNot(HaveOccurred())
newResponse, err := ParseWebhook(responseString)
Expect(err).ShouldNot(HaveOccurred())
Expect(response).To(Equal(newResponse))
Expect(newResponse.User).To(Equal(true))
Expect(newResponse.Account.Title).To(Equal("testyboi"))
Expect(newResponse.Server.Title).To(Equal("what"))
Expect(newResponse.Player.PublicAddress).To(Equal("200.200.200.200"))
Expect(newResponse.Metadata.Type).To(Equal("movie"))
Expect(newResponse.Metadata.Studio).To(Equal("Hawk Films"))
Expect(newResponse.Metadata.ContentRating).To(Equal("PG"))
Expect(newResponse.Metadata.AudienceRating).To(Equal(float32(9.2)))
Expect(newResponse.Metadata.Director[0].Tag).To(Equal("Stanley Kubrick"))
Expect(newResponse.Metadata.Writer[0].Filter).To(Equal("writer=7"))
Expect(newResponse.Metadata.Producer[0].Id).To(Equal(42))
Expect(newResponse.Metadata.Country[0].Tag).To(Equal("United Kingdom"))
Expect(len(newResponse.Metadata.Role)).To(Equal(43))
Expect(newResponse.Metadata.Role[25].Tag).To(Equal("Anthony Herrick"))
Expect(len(newResponse.Metadata.Similar)).To(Equal(20))
Expect(newResponse.Metadata.Similar[8].Tag).To(Equal("Touch of Evil"))
Expect(len(newResponse.Metadata.Genre)).To(Equal(4))
Expect(newResponse.Metadata.Genre[3].Tag).To(Equal("War"))
})
})
})