Skip to content

Commit

Permalink
enhancement: return a drive item from the update share drive item api…
Browse files Browse the repository at this point in the history
… endpoint
  • Loading branch information
fschade committed Apr 24, 2024
1 parent 1512323 commit 0406662
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 12 additions & 5 deletions services/graph/pkg/service/v0/api_drives_drive_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,27 @@ func (api DrivesDriveItemApi) UpdateDriveItem(w http.ResponseWriter, r *http.Req
request.UpdateMask.Paths = append(request.UpdateMask.Paths, _fieldMaskPathHidden)
},
)
if err != nil {
api.logger.Debug().Err(err).Msg(ErrUpdateShares.Error())
ErrUpdateShares.Render(w, r)
return
}

driveItems, err := api.baseGraphService.CS3ReceivedSharesToDriveItems(r.Context(), updatedShares)
switch {
case err != nil:
break
case len(updatedShares) == 0:
err = ErrNoShares
case len(driveItems) != 1:
err = ErrDriveItemConversion
}
if err != nil {
api.logger.Debug().Err(err).Msg(ErrUpdateShares.Error())
ErrUpdateShares.Render(w, r)
api.logger.Debug().Err(err).Msg(ErrDriveItemConversion.Error())
ErrDriveItemConversion.Render(w, r)
return
}

render.Status(r, http.StatusOK)
render.JSON(w, r, updatedShares[0])
render.JSON(w, r, driveItems[0])
}

// CreateDriveItem creates a drive item
Expand Down
15 changes: 13 additions & 2 deletions services/graph/pkg/service/v0/api_drives_drive_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,17 @@ var _ = Describe("DrivesDriveItemApi", func() {
Return([]*collaborationv1beta1.ReceivedShare{}, nil).
Once()

baseGraphProvider.
EXPECT().
CS3ReceivedSharesToDriveItems(mock.Anything, mock.Anything).
Return(nil, nil).
Once()

drivesDriveItemApi.UpdateDriveItem(w, r)
Expect(w.Code).To(Equal(http.StatusBadRequest))

jsonData := gjson.Get(w.Body.String(), "error")
Expect(jsonData.Get("code").String() + ": " + jsonData.Get("message").String()).To(Equal(svc.ErrUpdateShares.Error()))
Expect(jsonData.Get("code").String() + ": " + jsonData.Get("message").String()).To(Equal(svc.ErrDriveItemConversion.Error()))
})

It("successfully updates the share", func() {
Expand Down Expand Up @@ -744,7 +750,6 @@ var _ = Describe("DrivesDriveItemApi", func() {
EXPECT().
UpdateShares(mock.Anything, mock.Anything, mock.Anything).
RunAndReturn(func(ctx context.Context, shares []*collaborationv1beta1.ReceivedShare, closure svc.UpdateShareClosure) ([]*collaborationv1beta1.ReceivedShare, error) {

updateReceivedShareRequest := &collaborationv1beta1.UpdateReceivedShareRequest{
Share: &collaborationv1beta1.ReceivedShare{
Share: &collaborationv1beta1.Share{
Expand All @@ -765,6 +770,12 @@ var _ = Describe("DrivesDriveItemApi", func() {
}).
Once()

baseGraphProvider.
EXPECT().
CS3ReceivedSharesToDriveItems(mock.Anything, mock.Anything).
Return([]libregraph.DriveItem{{}}, nil).
Once()

drivesDriveItemApi.UpdateDriveItem(w, r)
Expect(w.Code).To(Equal(http.StatusOK))
})
Expand Down

0 comments on commit 0406662

Please sign in to comment.