Skip to content

Commit 0d92260

Browse files
feat: add metadata lookup functionality to mockUserServiceReader
- Introduced a new MetadataLookup method in the mockUserServiceReader struct to handle user metadata lookups based on input format. - Enhanced the method to differentiate between canonical and search queries, updating user fields accordingly. - Added necessary imports to support string manipulation for input processing. Jira Ticket: https://linuxfoundation.atlassian.net/browse/LFXV2-493 Generated with [Cursor](https://cursor.com/) Signed-off-by: Mauricio Zanetti Salomao <mauriciozanetti86@gmail.com>
1 parent 73a72e9 commit 0d92260

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

internal/service/message_handler_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package service
66
import (
77
"context"
88
"encoding/json"
9+
"strings"
910
"testing"
1011

1112
"github.com/linuxfoundation/lfx-v2-auth-service/internal/domain/model"
@@ -46,8 +47,9 @@ func (m *mockUserServiceWriter) UpdateUser(ctx context.Context, user *model.User
4647

4748
// mockUserServiceReader is a mock implementation of UserServiceReader for testing
4849
type mockUserServiceReader struct {
49-
getUserFunc func(ctx context.Context, user *model.User) (*model.User, error)
50-
searchUserFunc func(ctx context.Context, user *model.User, criteria string) (*model.User, error)
50+
getUserFunc func(ctx context.Context, user *model.User) (*model.User, error)
51+
searchUserFunc func(ctx context.Context, user *model.User, criteria string) (*model.User, error)
52+
metadataLookupFunc func(ctx context.Context, input string, user *model.User) bool
5153
}
5254

5355
func (m *mockUserServiceReader) GetUser(ctx context.Context, user *model.User) (*model.User, error) {
@@ -64,6 +66,29 @@ func (m *mockUserServiceReader) SearchUser(ctx context.Context, user *model.User
6466
return user, nil
6567
}
6668

69+
func (m *mockUserServiceReader) MetadataLookup(ctx context.Context, input string, user *model.User) bool {
70+
if m.metadataLookupFunc != nil {
71+
return m.metadataLookupFunc(ctx, input, user)
72+
}
73+
74+
// Default implementation: follow the same logic as the real implementations
75+
input = strings.TrimSpace(input)
76+
77+
if strings.Contains(input, "|") {
78+
// Input contains "|", use as sub for canonical lookup
79+
user.Sub = input
80+
user.UserID = input
81+
user.Username = ""
82+
return true
83+
}
84+
85+
// Input doesn't contain "|", use for search query
86+
user.Username = input
87+
user.Sub = ""
88+
user.UserID = ""
89+
return false
90+
}
91+
6792
func TestMessageHandlerOrchestrator_UpdateUser(t *testing.T) {
6893
ctx := context.Background()
6994

0 commit comments

Comments
 (0)