forked from gregtandiono/trade-wire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buyer-e2e_test.go
64 lines (54 loc) · 1.84 KB
/
buyer-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
package main
import (
"testing"
uuid "github.com/satori/go.uuid"
"gopkg.in/kataras/iris.v6/httptest"
)
func TestBuyerHandler(t *testing.T) {
app := irisHandler()
e := httptest.New(app, t)
aro := fetchToken(app, t)
e.POST("/buyers").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"id": uuid.NewV4().String(),
"name": "charoen pokphand",
"address": "muara karang blok L9B no 12",
"pic": `[
{"name": "hendra tjang", "telephone": "6281237738777"},
{"name": "felicia kurniawan", "telephone": "76632888"}
]`,
}).
Expect().
Status(200).JSON().Equal(map[string]string{
"message": "buyer successfully created",
})
// A user should be able to fetch all buyers
e.GET("/buyers").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().
Status(200).JSON().Array().Length().
Equal(22)
// A user should be able to fetch a buyer
buyerObj := e.GET("/buyers/f40e4dd4-f441-428b-8ff3-f893cb176819").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().
Status(200).JSON().Object()
buyerObj.Value("name").Equal("Japfa Comfeed Indonesia")
// A user should be able to update an existing buyer record
buyerUpdatedRecord := e.PUT("/buyers/f40e4dd4-f441-428b-8ff3-f893cb176819").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"name": "Japfa Comfeed Indonesia Tbk.",
}).
Expect().
Status(200).JSON().Object()
buyerUpdatedRecord.Value("name").Equal("Japfa Comfeed Indonesia Tbk.")
// A user should be able to soft delete a buyer record
e.DELETE("/buyers/f40e4dd4-f441-428b-8ff3-f893cb176819").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().
Status(200).JSON().Equal(map[string]string{
"message": "buyer record successfully deleted",
})
}