-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompany-e2e_test.go
61 lines (51 loc) · 1.71 KB
/
company-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
package main
import (
"testing"
"github.com/kataras/iris/httptest"
uuid "github.com/satori/go.uuid"
)
func TestCompanyHandler(t *testing.T) {
app := irisHandler()
e := httptest.New(app, t)
aro := fetchToken(app, t)
e.POST("/companies").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"id": uuid.NewV4().String(),
"name": "charoen pokphand",
"address": "muara karang blok L9B no 12",
"company_type": "buyer",
}).
Expect().
Status(200).JSON().Equal(map[string]string{
"message": "company successfully created",
})
// A user should be able to fetch all companies
e.GET("/companies").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().
Status(200).JSON().Array().Length().
Equal(32)
// A user should be able to fetch a buyer
companyObj := e.GET("/companies/f40e4dd4-f441-428b-8ff3-f893cb176819").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().
Status(200).JSON().Object()
companyObj.Value("name").Equal("Japfa Comfeed Indonesia")
// A user should be able to update an existing buyer record
companyUpdatedRecord := e.PUT("/companies/f40e4dd4-f441-428b-8ff3-f893cb176819").
WithHeader("Authorization", "Bearer "+aro["token"]).
WithJSON(map[string]string{
"name": "Japfa Comfeed Indonesia Tbk.",
}).
Expect().
Status(200).JSON().Object()
companyUpdatedRecord.Value("name").Equal("Japfa Comfeed Indonesia Tbk.")
// A user should be able to soft delete a buyer record
e.DELETE("/companies/f40e4dd4-f441-428b-8ff3-f893cb176819").
WithHeader("Authorization", "Bearer "+aro["token"]).
Expect().
Status(200).JSON().Equal(map[string]string{
"message": "company record successfully deleted",
})
}