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,12 +168,20 @@ func (ur userRepository) RetrieveAll(ctx context.Context, offset, limit uint64,
|
||||||
if mq != "" {
|
if mq != "" {
|
||||||
query = append(query, 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, "','")))
|
query = append(query, fmt.Sprintf("id IN ('%s')", strings.Join(userIDs, "','")))
|
||||||
}
|
|
||||||
if len(query) > 0 {
|
|
||||||
emq = fmt.Sprintf(" WHERE %s", strings.Join(query, " AND "))
|
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)
|
q := fmt.Sprintf(`SELECT id, email, metadata FROM users %s ORDER BY email LIMIT :limit OFFSET :offset;`, emq)
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
|
|
|
@ -137,6 +137,7 @@ func TestRetrieveAll(t *testing.T) {
|
||||||
limit: nUsers,
|
limit: nUsers,
|
||||||
size: nUsers,
|
size: nUsers,
|
||||||
total: nUsers,
|
total: nUsers,
|
||||||
|
ids: ids,
|
||||||
},
|
},
|
||||||
"retrieve all users by email with limit and offset": {
|
"retrieve all users by email with limit and offset": {
|
||||||
email: "All",
|
email: "All",
|
||||||
|
@ -144,6 +145,7 @@ func TestRetrieveAll(t *testing.T) {
|
||||||
limit: 5,
|
limit: 5,
|
||||||
size: 5,
|
size: 5,
|
||||||
total: nUsers,
|
total: nUsers,
|
||||||
|
ids: ids,
|
||||||
},
|
},
|
||||||
"retrieve all users by metadata": {
|
"retrieve all users by metadata": {
|
||||||
email: "All",
|
email: "All",
|
||||||
|
@ -152,6 +154,7 @@ func TestRetrieveAll(t *testing.T) {
|
||||||
size: metaNum,
|
size: metaNum,
|
||||||
total: nUsers,
|
total: nUsers,
|
||||||
metadata: meta,
|
metadata: meta,
|
||||||
|
ids: ids,
|
||||||
},
|
},
|
||||||
"retrieve users by metadata and ids": {
|
"retrieve users by metadata and ids": {
|
||||||
email: "All",
|
email: "All",
|
||||||
|
@ -169,6 +172,7 @@ func TestRetrieveAll(t *testing.T) {
|
||||||
size: 0,
|
size: 0,
|
||||||
total: nUsers,
|
total: nUsers,
|
||||||
metadata: wrongMeta,
|
metadata: wrongMeta,
|
||||||
|
ids: ids,
|
||||||
},
|
},
|
||||||
"retrieve users by wrong metadata and ids": {
|
"retrieve users by wrong metadata and ids": {
|
||||||
email: "All",
|
email: "All",
|
||||||
|
@ -196,6 +200,15 @@ func TestRetrieveAll(t *testing.T) {
|
||||||
ids: ids[0:5],
|
ids: ids[0:5],
|
||||||
metadata: meta,
|
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 {
|
for desc, tc := range cases {
|
||||||
page, err := userRepo.RetrieveAll(context.Background(), tc.offset, tc.limit, tc.ids, tc.email, tc.metadata)
|
page, err := userRepo.RetrieveAll(context.Background(), tc.offset, tc.limit, tc.ids, tc.email, tc.metadata)
|
||||||
|
|
Loading…
Reference in New Issue