Skip to content

Commit

Permalink
Update timeline API from Get to Post (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
hieven committed Jul 25, 2019
1 parent 8408949 commit 6800b3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
10 changes: 1 addition & 9 deletions src/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,14 @@ func (timeline *timeline) Feed(ctx context.Context, req *TimelineFeedRequest) (*
}

urlStru, _ := url.Parse(constants.TimelineFeedEndpoint) // TODO: handle error
query := urlStru.Query()

internalReq := &protos.TimelineFeedRequest{
UserID: req.UserID,
MaxID: req.MaxID,
RankToken: timeline.authManager.GenerateRankToken(req.UserID),
}

if internalReq.MaxID != "" {
query.Set("max_id", internalReq.MaxID)
}

urlStru.RawQuery = query.Encode()

_, body, _ := timeline.requestManager.Get(ctx, urlStru.String()) // TODO: handle error

_, body, _ := timeline.requestManager.Post(ctx, urlStru.String(), internalReq) // TODO: handle error
result := &protos.TimelineFeedResponse{}
json.Unmarshal([]byte(body), result) // TODO: handle error
return result, nil
Expand Down
22 changes: 14 additions & 8 deletions src/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("timeline", func() {

JustBeforeEach(func() {
mockAuthManager.On("GenerateRankToken", mock.Anything).Return(mockGenerateRankTokenResp)
mockRequestManager.On("Get", mock.Anything, mock.Anything).Return(nil, mockBody, nil)
mockRequestManager.On("Post", mock.Anything, mock.Anything, mock.Anything).Return(nil, mockBody, nil)

resp, err = client.Feed(ctx, req)

Expand All @@ -90,9 +90,9 @@ var _ = Describe("timeline", func() {
mockAuthManager.AssertCalled(GinkgoT(), "GenerateRankToken", req.UserID)
})

It("should call requestManager.Get", func() {
mockRequestManager.AssertNumberOfCalls(GinkgoT(), "Get", 1)
mockRequestManager.AssertCalled(GinkgoT(), "Get", mock.Anything, expURLStr)
It("should call requestManager.Post", func() {
mockRequestManager.AssertNumberOfCalls(GinkgoT(), "Post", 1)
mockRequestManager.AssertCalled(GinkgoT(), "Post", mock.Anything, expURLStr, mock.Anything)
})
})

Expand All @@ -111,12 +111,18 @@ var _ = Describe("timeline", func() {
Context("when MaxID is provided", func() {
BeforeEach(func() {
req.MaxID = "max id"

expURLQuery.Set("max_id", req.MaxID)
})

It("should add it to query string", func() {
mockRequestManager.AssertCalled(GinkgoT(), "Get", mock.Anything, expURLStr)
It("should add it to request body", func() {
mockRequestManager.AssertCalled(GinkgoT(), "Post",
mock.Anything,
mock.Anything,
mock.MatchedBy(func(internalReq *protos.TimelineFeedRequest) bool {
Expect(internalReq.MaxID).To(Equal(req.MaxID))

return true
}),
)
})
})
})
Expand Down

0 comments on commit 6800b3f

Please sign in to comment.