-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvariety-e2e_test.go
More file actions
63 lines (53 loc) · 1.95 KB
/
variety-e2e_test.go
File metadata and controls
63 lines (53 loc) · 1.95 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
package main
import (
"testing"
"trade-wire/fixtures"
"github.com/kataras/iris/httptest"
uuid "github.com/satori/go.uuid"
)
func TestVarietyHandler(t *testing.T) {
app := irisHandler()
e := httptest.New(app, t)
aro := fetchToken(app, t)
vid := fixtures.VarietyFixtures()["validVarietyRecord"]["id"]
cid := fixtures.CommodityFixtures()["validCommodityRecord"]["id"]
e.POST("/varieties").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"id": uuid.NewV4().String(),
"commodity_id": cid,
"name": "Australian Standard White (ASW)",
"origin": "australia",
"specs": "Protein min. 10.50%\n Moisture max. 13.50%\n Foreign matter max. 1.00%\n Bug Damage max.1.00%\n Test Weight min. 76kg/HL\n Aflatoxin max. 20ppb\n Vomitoxin max.2ppm",
}).
Expect().Status(200).JSON().Equal(map[string]string{
"message": "variety successfully created",
})
e.POST("/varieties").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"id": uuid.NewV4().String(),
"name": "Australian Standard White (ASW)",
"origin": "australia",
}).
Expect().Status(400).JSON().Equal(map[string]string{
"error": "failed to insert variety record",
})
varietyObj := e.GET("/varieties/"+vid).
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().Status(200).JSON().Object()
varietyObj.Value("name").Equal("Black Sea Wheat (BS Wheat)")
varietyObj.Value("origin").Equal("Black Sea")
varietyUpdatedRecord := e.PUT("/varieties/"+vid).
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"name": "Ukraine Milling Wheat (UMW)",
}).
Expect().Status(200).JSON().Object()
varietyUpdatedRecord.Value("name").Equal("Ukraine Milling Wheat (UMW)")
e.DELETE("/varieties/"+vid).
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().Status(200).JSON().Equal(map[string]string{
"message": "record successfully deleted",
})
}