Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
idilhaq committed Nov 7, 2024
1 parent de31e06 commit 18f61c4
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions api/handler/v1beta1/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,65 @@ func (s *GrpcHandlersSuite) TestImportFromProvider() {
s.Equal(expectedResponse, res)
})
}

func (s *GrpcHandlersSuite) TestRevokeGrant() {
s.Run("should revoke grant on success", func() {
s.setup()

actor := "actor@example.com"
id := "test-id"
reason := "test-reason"

expectedGrant := &domain.Grant{
ID: id,
UpdatedAt: time.Now(),
}

req := &guardianv1beta1.RevokeGrantRequest{
Id: id,
Reason: reason,
}

s.grantService.EXPECT().
Revoke(mock.MatchedBy(func(ctx context.Context) bool { return true }), id, actor, reason).
Return(expectedGrant, nil).Once()

ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, actor)
res, err := s.grpcServer.RevokeGrant(ctx, req)

s.NoError(err)
s.Equal(expectedGrant.ID, res.Grant.Id)
s.Equal(timestamppb.New(expectedGrant.UpdatedAt), res.Grant.UpdatedAt)
})

s.Run("should revoke grant on success with SkipNotification and SkipRevokeInProvider true", func() {
s.setup()

actor := "actor@example.com"
id := "test-id"
reason := "test-reason"

expectedGrant := &domain.Grant{
ID: id,
UpdatedAt: time.Now(),
}

req := &guardianv1beta1.RevokeGrantRequest{
Id: id,
Reason: reason,
SkipNotification: true,
SkipRevokeInProvider: true,
}

s.grantService.EXPECT().
Revoke(mock.MatchedBy(func(ctx context.Context) bool { return true }), id, actor, reason, mock.AnythingOfType("grant.Option"), mock.AnythingOfType("grant.Option")).
Return(expectedGrant, nil).Once()

ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, actor)
res, err := s.grpcServer.RevokeGrant(ctx, req)

s.NoError(err)
s.Equal(expectedGrant.ID, res.Grant.Id)
s.Equal(timestamppb.New(expectedGrant.UpdatedAt), res.Grant.UpdatedAt)
})
}

0 comments on commit 18f61c4

Please sign in to comment.