Skip to content

Commit 0986dba

Browse files
author
hieven
committed
add inbox unit test
1 parent 7cc3d90 commit 0986dba

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/inbox_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/stretchr/testify/mock"
88

9+
"github.com/hieven/go-instagram/src/constants"
910
"github.com/hieven/go-instagram/src/protos"
1011
requestMocks "github.com/hieven/go-instagram/src/utils/request/mocks"
1112
. "github.com/onsi/ginkgo"
@@ -63,6 +64,46 @@ var _ = Describe("inbox", func() {
6364
Expect(err).To(BeNil())
6465
Expect(resp).NotTo(BeNil())
6566
})
67+
68+
It("should call Get", func() {
69+
mockRequestManager.AssertNumberOfCalls(GinkgoT(), "Get", 1)
70+
mockRequestManager.AssertCalled(GinkgoT(), "Get", mock.Anything, constants.InboxEndpoint)
71+
})
72+
})
73+
74+
Context("when cursor is provded", func() {
75+
BeforeEach(func() {
76+
req.Cursor = "cursor"
77+
})
78+
79+
It("should set query string", func() {
80+
mockRequestManager.AssertCalled(GinkgoT(), "Get", mock.Anything, constants.InboxEndpoint+"?cursor="+req.Cursor)
81+
})
6682
})
83+
84+
tests := []struct {
85+
desc string
86+
beforeFunc func()
87+
expectedErr error
88+
}{
89+
{
90+
desc: "when req is missing",
91+
beforeFunc: func() { req = nil },
92+
expectedErr: ErrRequestRequired,
93+
},
94+
}
95+
96+
for _, test := range tests {
97+
t := test
98+
Context(t.desc, func() {
99+
BeforeEach(t.beforeFunc)
100+
101+
It("should return error", func() {
102+
Expect(resp).To(BeNil())
103+
Expect(err).NotTo(BeNil())
104+
Expect(err).To(Equal(t.expectedErr))
105+
})
106+
})
107+
}
67108
})
68109
})

0 commit comments

Comments
 (0)