-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie_test.go
79 lines (70 loc) · 1.76 KB
/
movie_test.go
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
package movielite
import (
"net/http"
"testing"
"github.com/steinfletcher/apitest"
jsonpath "github.com/steinfletcher/apitest-jsonpath"
"github.com/ms900ft/movielite/models"
)
func TestGetMovie(t *testing.T) {
apitest.New(). // configuration
Handler(S.Router).
Get("/api/movie/1").
Expect(t).
Assert(jsonpath.Present(`$.meta`)).
Assert(jsonpath.Contains(`$.title`, "kehraus")).
Assert(jsonpath.Contains(`$.meta.Title`, "Kehraus")).
Status(http.StatusOK).
End()
}
func TestGetMovies(t *testing.T) {
apitest.New(). // configuration
Handler(S.Router).
Get("/api/movie").
Expect(t).
Assert(jsonpath.GreaterThan(`$`, 1)).
Status(http.StatusOK).
End()
}
func TestUpdateMovie(t *testing.T) {
mo := models.Movie{}
apitest.New(). // configuration
Handler(S.Router).
Put("/api/movie/1").
JSON(mo).
Expect(t).
Assert(jsonpath.Contains(`$.error`, "Movie.Title")).
Status(http.StatusBadRequest).
End()
mo.Title = "Patersonx"
apitest.New(). // configuration
Handler(S.Router).
Put("/api/movie/1").
JSON(mo).
Expect(t).
Assert(jsonpath.Contains(`$.title`, "Patersonx")).
Assert(jsonpath.NotPresent(`$.meta`)).
Status(http.StatusOK).
End()
mo.Title = "Paterson"
apitest.New(). // configuration
Handler(S.Router).
Put("/api/movie/1").
JSON(mo).
Expect(t).
Assert(jsonpath.Contains(`$.title`, "Paterson")).
Assert(jsonpath.Present(`$.meta`)).
Status(http.StatusOK).
End()
mo.Title = "Nachtblende"
apitest.New(). // configuration
Handler(S.Router).
Put("/api/movie/1").
JSON(mo).
Expect(t).
Assert(jsonpath.Contains(`$.title`, "Nachtblende")).
Assert(jsonpath.NotPresent(`$.meta`)).
Assert(jsonpath.Present(`$.multiplechoice`)).
Status(http.StatusOK).
End()
}