-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommodity-e2e_test.go
80 lines (65 loc) · 2.3 KB
/
commodity-e2e_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
80
package main
import (
"testing"
uuid "github.com/satori/go.uuid"
"github.com/kataras/iris/httptest"
)
func TestCommodityHandler(t *testing.T) {
app := irisHandler()
e := httptest.New(app, t)
aro := fetchToken(app, t)
e.POST("/commodities").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"id": uuid.NewV4().String(),
"name": "soybean",
}).
Expect().Status(200).JSON().Equal(map[string]string{
"message": "commodity successfully created",
})
e.POST("/commodities").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"id": uuid.NewV4().String(),
}).
Expect().Status(400).JSON().Equal(map[string]string{
"error": "failed to insert commodity record",
})
e.GET("/commodities").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().Status(200).JSON().Array().Length().Equal(3)
commodityObj := e.GET("/commodities/75a5cdfe-ca69-4680-a903-af89eaaa4804").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().Status(200).JSON().Object()
commodityObj.Value("name").Equal("wheat")
e.GET("/commodities/75a5cdfe-ca69-4680-a903-af89eaaa4803").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().Status(400).JSON().Equal(map[string]string{
"error": "could not find record",
})
commodityUpdatedRecord := e.PUT("/commodities/75a5cdfe-ca69-4680-a903-af89eaaa4804").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"name": "soybean meal",
}).
Expect().Status(200).JSON().Object()
commodityUpdatedRecord.Value("name").Equal("soybean meal")
e.PUT("/commodities/75a5cdfe-ca69-4680-a903-af89eaaa4803").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"name": "soybean meal",
}).
Expect().Status(400).JSON().Equal(map[string]string{
"error": "failed to update record",
})
e.DELETE("/commodities/75a5cdfe-ca69-4680-a903-af89eaaa4804").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().Status(200).JSON().Equal(map[string]string{
"message": "record successfully deleted",
})
e.DELETE("/commodities/75a5cdfe-ca69-4680-a903-af89eaaa4803").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().Status(400).JSON().Equal(map[string]string{
"error": "failed to delete record",
})
}