Fix fetching user members of an empty group (#1436)
Signed-off-by: Burak Sekili <buraksekili@gmail.com>
This commit is contained in:
parent
68af0e32b5
commit
af0162f0df
|
@ -168,13 +168,21 @@ func (ur userRepository) RetrieveAll(ctx context.Context, offset, limit uint64,
|
|||
if mq != "" {
|
||||
query = append(query, mq)
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
query = append(query, fmt.Sprintf("id IN ('%s')", strings.Join(userIDs, "','")))
|
||||
}
|
||||
if len(query) > 0 {
|
||||
emq = fmt.Sprintf(" WHERE %s", strings.Join(query, " AND "))
|
||||
|
||||
if len(userIDs) == 0 {
|
||||
return users.UserPage{
|
||||
Users: []users.User{},
|
||||
PageMetadata: users.PageMetadata{
|
||||
Total: 0,
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
query = append(query, fmt.Sprintf("id IN ('%s')", strings.Join(userIDs, "','")))
|
||||
emq = fmt.Sprintf(" WHERE %s", strings.Join(query, " AND "))
|
||||
|
||||
q := fmt.Sprintf(`SELECT id, email, metadata FROM users %s ORDER BY email LIMIT :limit OFFSET :offset;`, emq)
|
||||
params := map[string]interface{}{
|
||||
"limit": limit,
|
||||
|
|
|
@ -137,6 +137,7 @@ func TestRetrieveAll(t *testing.T) {
|
|||
limit: nUsers,
|
||||
size: nUsers,
|
||||
total: nUsers,
|
||||
ids: ids,
|
||||
},
|
||||
"retrieve all users by email with limit and offset": {
|
||||
email: "All",
|
||||
|
@ -144,6 +145,7 @@ func TestRetrieveAll(t *testing.T) {
|
|||
limit: 5,
|
||||
size: 5,
|
||||
total: nUsers,
|
||||
ids: ids,
|
||||
},
|
||||
"retrieve all users by metadata": {
|
||||
email: "All",
|
||||
|
@ -152,6 +154,7 @@ func TestRetrieveAll(t *testing.T) {
|
|||
size: metaNum,
|
||||
total: nUsers,
|
||||
metadata: meta,
|
||||
ids: ids,
|
||||
},
|
||||
"retrieve users by metadata and ids": {
|
||||
email: "All",
|
||||
|
@ -169,6 +172,7 @@ func TestRetrieveAll(t *testing.T) {
|
|||
size: 0,
|
||||
total: nUsers,
|
||||
metadata: wrongMeta,
|
||||
ids: ids,
|
||||
},
|
||||
"retrieve users by wrong metadata and ids": {
|
||||
email: "All",
|
||||
|
@ -196,6 +200,15 @@ func TestRetrieveAll(t *testing.T) {
|
|||
ids: ids[0:5],
|
||||
metadata: meta,
|
||||
},
|
||||
"retrieve all users from empty ids": {
|
||||
email: "All",
|
||||
offset: 1,
|
||||
limit: 5,
|
||||
size: 0,
|
||||
total: nUsers,
|
||||
ids: []string{},
|
||||
metadata: meta,
|
||||
},
|
||||
}
|
||||
for desc, tc := range cases {
|
||||
page, err := userRepo.RetrieveAll(context.Background(), tc.offset, tc.limit, tc.ids, tc.email, tc.metadata)
|
||||
|
|
Loading…
Reference in New Issue