-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathsave_contacts_test.go
59 lines (45 loc) · 1.61 KB
/
save_contacts_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
package contacts_test
import (
"bytes"
"context"
"testing"
"github.com/stretchr/testify/assert"
mockcontactsworkflow "github.com/uber/zanzibar/examples/example-gateway/build/endpoints/contacts/mock-workflow"
endpointContacts "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/endpoints-idl/endpoints/contacts/contacts"
ms "github.com/uber/zanzibar/examples/example-gateway/build/services/example-gateway/mock-service"
)
func TestSaveContactsCall(t *testing.T) {
ms := ms.MustCreateTestService(t)
ms.Start()
defer ms.Stop()
ms.MockClients().Contacts.ExpectSaveContacts().Success()
endpointRequest := &endpointContacts.Contacts_SaveContacts_Args{
SaveContactsRequest: &endpointContacts.SaveContactsRequest{
Contacts: []*endpointContacts.Contact{},
},
}
rawBody, _ := endpointRequest.MarshalJSON()
res, err := ms.MakeHTTPRequest(
"POST", "/contacts/foo/contacts", nil, bytes.NewReader(rawBody),
)
if !assert.NoError(t, err, "got http error") {
return
}
assert.Equal(t, "202 Accepted", res.Status)
}
func TestSaveContactsCallWorkflow(t *testing.T) {
mh, mc := mockcontactsworkflow.NewContactsSaveContactsWorkflowMock(t)
mc.Contacts.ExpectSaveContacts().Success()
endpointRequest := &endpointContacts.Contacts_SaveContacts_Args{
SaveContactsRequest: &endpointContacts.SaveContactsRequest{
UserUUID: "foo",
Contacts: []*endpointContacts.Contact{},
},
}
_, res, resHeaders, err := mh.Handle(context.Background(), nil, endpointRequest)
if !assert.NoError(t, err, "got error") {
return
}
assert.Nil(t, resHeaders)
assert.Equal(t, &endpointContacts.SaveContactsResponse{}, res)
}