Fix fetching user members of an empty group (#1436)

Signed-off-by: Burak Sekili <buraksekili@gmail.com>
This commit is contained in:
Burak Sekili 2021-07-08 14:51:37 +03:00 committed by GitHub
parent 68af0e32b5
commit af0162f0df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions

View File

@ -168,12 +168,20 @@ func (ur userRepository) RetrieveAll(ctx context.Context, offset, limit uint64,
if mq != "" {
query = append(query, mq)
}
if len(userIDs) > 0 {
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, "','")))
}
if len(query) > 0 {
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{}{

View File

@ -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)