From 00d32bf468ccc0ced1382199ee581591a3d809ee Mon Sep 17 00:00:00 2001 From: Ishan Arya Date: Wed, 24 Jul 2024 15:06:41 +0530 Subject: [PATCH] test: add test to cover self onboarding scenario --- internal/api/v1beta1/user_test.go | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/internal/api/v1beta1/user_test.go b/internal/api/v1beta1/user_test.go index 03f70819a..1fea02962 100644 --- a/internal/api/v1beta1/user_test.go +++ b/internal/api/v1beta1/user_test.go @@ -383,6 +383,40 @@ func TestCreateUser(t *testing.T) { }}, err: nil, }, + { + title: "should return success if user service return nil error", + setup: func(ctx context.Context, us *mocks.UserService, sds *mocks.ServiceDataService, rs *mocks.RelationService) context.Context { + ctx = user.SetContextWithEmail(ctx, "randomuser@gotocompany.com") + us.EXPECT().FetchCurrentUser(ctx).Return(user.User{}, user.ErrInvalidEmail) + us.EXPECT().Create(mock.AnythingOfType("*context.valueCtx"), user.User{ + Name: "random user", + Email: "randomuser@gotocompany.com", + Metadata: nil, + }).Return( + user.User{ + ID: "new-random-user", + Name: "random user", + Email: "randomuser@gotocompany.com", + }, nil) + return ctx + }, + req: &shieldv1beta1.CreateUserRequest{Body: &shieldv1beta1.UserRequestBody{ + Name: "random user", + Email: "randomuser@gotocompany.com", + Metadata: &structpb.Struct{}, + }}, + want: &shieldv1beta1.CreateUserResponse{User: &shieldv1beta1.User{ + Id: "new-random-user", + Name: "random user", + Email: "randomuser@gotocompany.com", + Metadata: &structpb.Struct{ + Fields: map[string]*structpb.Value{}, + }, + CreatedAt: timestamppb.New(time.Time{}), + UpdatedAt: timestamppb.New(time.Time{}), + }}, + err: nil, + }, } for _, tt := range table {