-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserHandler_test.go
More file actions
75 lines (62 loc) · 1.71 KB
/
userHandler_test.go
File metadata and controls
75 lines (62 loc) · 1.71 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
package main
import (
"net/http"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
)
var _ = Describe("UserHandler", func() {
Describe("Main UserHandler test", func() {
var server *ghttp.Server
BeforeEach(func() {
server = ghttp.NewServer()
testJSON := []byte(
`{
"id": "10152725637197590",
"name": "Jay Cee",
"birthday": "1990-04-03T18:25:43.511Z",
"email": "test@mail.fr"
}`,
)
server.RouteToHandler("GET", "/test-user", ghttp.CombineHandlers(
ghttp.RespondWith(http.StatusOK, testJSON),
))
server.RouteToHandler("GET", "/ntm-api", ghttp.CombineHandlers(
ghttp.RespondWith(http.StatusOK, "Welcome to the NTM API!"),
))
server.RouteToHandler("POST", "/ntm-api/user/subscribe", registerAndLogginUser)
})
AfterEach(func() {
server.Close()
})
Describe("Test Get on main entry", func() {
Context("Test server", func() {
It("Should have a normal behaviour", func() {
response, err := http.Get(server.URL() + "/ntm-api")
Ω(server.ReceivedRequests()).Should(Not(BeNil()))
Ω(err).ShouldNot(HaveOccurred())
Ω(response).ShouldNot(BeNil())
})
})
})
Describe("Test getUserFromToken", func() {
t := &Token{}
Context("With correct url", func() {
It("Should succeed", func() {
confTest.FBURL = server.URL() + confTest.FBURL
u, err := getUserFromToken(t, confTest)
Ω(err).Should(BeNil())
Ω(u).ShouldNot(BeNil())
})
})
Context("With uncorrect url", func() {
It("Should fail", func() {
confTest.FBURL = server.URL() + "ok"
u, err := getUserFromToken(t, confTest)
Ω(err).ShouldNot(BeNil())
Ω(u).Should(BeNil())
})
})
})
})
})