From e2e1d1da44f2649d50ff582425fd69e014b7da00 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Tue, 14 Nov 2023 15:06:04 +0100 Subject: [PATCH] fix(graph users test): provide proto list value example on how to set language Co-authored-by: Florian Schade Signed-of-by: Christian Richter --- services/graph/pkg/service/v0/users.go | 2 +- services/graph/pkg/service/v0/users_test.go | 160 ++++++++++++++++---- 2 files changed, 135 insertions(+), 27 deletions(-) diff --git a/services/graph/pkg/service/v0/users.go b/services/graph/pkg/service/v0/users.go index c42b97f620..4ed06de33e 100644 --- a/services/graph/pkg/service/v0/users.go +++ b/services/graph/pkg/service/v0/users.go @@ -639,7 +639,7 @@ func (g Graph) DeleteUser(w http.ResponseWriter, r *http.Request) { render.NoContent(w, r) } -// PatchMe implements the Service Interface. Updates the specified attributes of the +// PatchMe implements the Service Interface. Updates the specified attributes of the current user func (g Graph) PatchMe(w http.ResponseWriter, r *http.Request) { logger := g.logger.SubloggerWithRequestID(r.Context()) logger.Debug().Msg("calling patch me") diff --git a/services/graph/pkg/service/v0/users_test.go b/services/graph/pkg/service/v0/users_test.go index 87074aa30c..44f271e3ff 100644 --- a/services/graph/pkg/service/v0/users_test.go +++ b/services/graph/pkg/service/v0/users_test.go @@ -13,14 +13,18 @@ import ( userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" - revactx "github.com/cs3org/reva/v2/pkg/ctx" - "github.com/cs3org/reva/v2/pkg/rgrpc/status" - "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" - cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" + "github.com/stretchr/testify/mock" + "go-micro.dev/v4/client" + "google.golang.org/grpc" + + revactx "github.com/cs3org/reva/v2/pkg/ctx" + "github.com/cs3org/reva/v2/pkg/rgrpc/status" + "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/owncloud/ocis/v2/ocis-pkg/shared" settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0" settings "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" @@ -29,9 +33,6 @@ import ( "github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults" identitymocks "github.com/owncloud/ocis/v2/services/graph/pkg/identity/mocks" service "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0" - "github.com/stretchr/testify/mock" - "go-micro.dev/v4/client" - "google.golang.org/grpc" ) type userList struct { @@ -105,13 +106,24 @@ var _ = Describe("Users", func() { }) It("gets the information", func() { - valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{ - Value: &settingsmsg.ValueWithIdentifier{ - Value: &settingsmsg.Value{ - : &settingsmsg.ListOptionValue{}, - } - }, - }, nil) + valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything). + Return(&settings.GetValueResponse{ + Value: &settingsmsg.ValueWithIdentifier{ + Value: &settingsmsg.Value{ + Value: &settingsmsg.Value_ListValue{ + ListValue: &settingsmsg.ListValue{ + Values: []*settingsmsg.ListOptionValue{ + { + Option: &settingsmsg.ListOptionValue_StringValue{ + StringValue: "it", + }, + }, + }, + }, + }, + }, + }, + }, nil) r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me", nil) r = r.WithContext(revactx.ContextSetUser(ctx, currentUser)) @@ -128,8 +140,24 @@ var _ = Describe("Users", func() { }, } identityBackend.On("GetUser", mock.Anything, mock.Anything, mock.Anything).Return(user, nil) - valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil) - + valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything). + Return(&settings.GetValueResponse{ + Value: &settingsmsg.ValueWithIdentifier{ + Value: &settingsmsg.Value{ + Value: &settingsmsg.Value_ListValue{ + ListValue: &settingsmsg.ListValue{ + Values: []*settingsmsg.ListOptionValue{ + { + Option: &settingsmsg.ListOptionValue_StringValue{ + StringValue: "it", + }, + }, + }, + }, + }, + }, + }, + }, nil) r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me?$expand=memberOf", nil) r = r.WithContext(revactx.ContextSetUser(ctx, currentUser)) svc.GetMe(rr, r) @@ -157,8 +185,24 @@ var _ = Describe("Users", func() { }, } roleService.On("ListRoleAssignments", mock.Anything, mock.Anything, mock.Anything).Return(&settings.ListRoleAssignmentsResponse{Assignments: assignments}, nil) - valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil) - + valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything). + Return(&settings.GetValueResponse{ + Value: &settingsmsg.ValueWithIdentifier{ + Value: &settingsmsg.Value{ + Value: &settingsmsg.Value_ListValue{ + ListValue: &settingsmsg.ListValue{ + Values: []*settingsmsg.ListOptionValue{ + { + Option: &settingsmsg.ListOptionValue_StringValue{ + StringValue: "it", + }, + }, + }, + }, + }, + }, + }, + }, nil) r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me?$expand=appRoleAssignments", nil) r = r.WithContext(revactx.ContextSetUser(ctx, currentUser)) svc.GetMe(rr, r) @@ -426,8 +470,24 @@ var _ = Describe("Users", func() { user.SetId("user1") identityBackend.On("GetUser", mock.Anything, mock.Anything, mock.Anything).Return(user, nil) - valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil) - + valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything). + Return(&settings.GetValueResponse{ + Value: &settingsmsg.ValueWithIdentifier{ + Value: &settingsmsg.Value{ + Value: &settingsmsg.Value_ListValue{ + ListValue: &settingsmsg.ListValue{ + Values: []*settingsmsg.ListOptionValue{ + { + Option: &settingsmsg.ListOptionValue_StringValue{ + StringValue: "it", + }, + }, + }, + }, + }, + }, + }, + }, nil) r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users", nil) rctx := chi.NewRouteContext() rctx.URLParams.Add("userID", *user.Id) @@ -470,8 +530,24 @@ var _ = Describe("Users", func() { }, }, }, nil) - valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil) - + valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything). + Return(&settings.GetValueResponse{ + Value: &settingsmsg.ValueWithIdentifier{ + Value: &settingsmsg.Value{ + Value: &settingsmsg.Value_ListValue{ + ListValue: &settingsmsg.ListValue{ + Values: []*settingsmsg.ListOptionValue{ + { + Option: &settingsmsg.ListOptionValue_StringValue{ + StringValue: "it", + }, + }, + }, + }, + }, + }, + }, + }, nil) r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users?$expand=drive", nil) rctx := chi.NewRouteContext() rctx.URLParams.Add("userID", *user.Id) @@ -506,8 +582,24 @@ var _ = Describe("Users", func() { }, }, }, nil) - valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil) - + valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything). + Return(&settings.GetValueResponse{ + Value: &settingsmsg.ValueWithIdentifier{ + Value: &settingsmsg.Value{ + Value: &settingsmsg.Value_ListValue{ + ListValue: &settingsmsg.ListValue{ + Values: []*settingsmsg.ListOptionValue{ + { + Option: &settingsmsg.ListOptionValue_StringValue{ + StringValue: "it", + }, + }, + }, + }, + }, + }, + }, + }, nil) r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users?$expand=drives", nil) rctx := chi.NewRouteContext() rctx.URLParams.Add("userID", *user.Id) @@ -538,8 +630,24 @@ var _ = Describe("Users", func() { }, } roleService.On("ListRoleAssignments", mock.Anything, mock.Anything, mock.Anything).Return(&settings.ListRoleAssignmentsResponse{Assignments: assignments}, nil) - valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil) - + valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything). + Return(&settings.GetValueResponse{ + Value: &settingsmsg.ValueWithIdentifier{ + Value: &settingsmsg.Value{ + Value: &settingsmsg.Value_ListValue{ + ListValue: &settingsmsg.ListValue{ + Values: []*settingsmsg.ListOptionValue{ + { + Option: &settingsmsg.ListOptionValue_StringValue{ + StringValue: "it", + }, + }, + }, + }, + }, + }, + }, + }, nil) r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users/user1?$expand=appRoleAssignments", nil) rctx := chi.NewRouteContext() rctx.URLParams.Add("userID", user.GetId())