1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

test: test the dashboard admins property (#8303)

This PR adds tests for the new admins property of the personal dashboard
API payload.

It checks that only user admins are added and that their image URL is
not an empty string. In doing this, also fixes an issue where the image
URL wouldn't be generated correctly.

## Discussion points

Some of the test feels like it might be better testing on a deeper level
(i.e. the account store). However, from an initial glance, I think that
would require more setup and work, so I'm leaving it in the dashboard
test for now as that's where it's ultimately useful. But we can discuss
if we should move it.
This commit is contained in:
Thomas Heartman 2024-09-30 15:38:00 +02:00 committed by GitHub
parent d7db80d948
commit e4cec6629d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 5 deletions

View File

@ -201,12 +201,13 @@ export class AccountStore implements IAccountStore {
async getAdmins(): Promise<MinimalUser[]> {
const rowToAdminUser = (row) => {
const user = rowToUser(row);
return {
id: row.id,
name: emptify(row.name),
username: emptify(row.username),
email: emptify(row.email),
imageUrl: emptify(row.image_url),
id: user.id,
name: user.name,
username: user.username,
email: user.email,
imageUrl: user.imageUrl,
};
};

View File

@ -217,3 +217,50 @@ test('should return personal dashboard project details', async () => {
],
});
});
test('should return Unleash admins', async () => {
await loginUser('new_user@test.com');
const adminRoleId = 1;
const userService = app.services.userService;
const admin = await userService.createUser({
username: 'admin',
rootRole: adminRoleId,
});
const admin2 = await userService.createUser({
username: 'John',
name: 'John Admin',
rootRole: adminRoleId,
});
// service account that shouldn't be listed in the output. Service
// accounts are enterprise functionality, so there's no service to
// call here
const [{ id: serviceAdminId }] = await db
.rawDatabase('users')
.insert({
username: 'service_admin',
is_service: true,
})
.returning('*');
await app.services.accessService.setUserRootRole(
serviceAdminId,
adminRoleId,
);
const { body } = await app.request.get(`/api/admin/personal-dashboard`);
expect(body.admins).toMatchObject([
{
id: admin.id,
username: admin.username,
imageUrl: expect.stringMatching(/^https:\/\/gravatar.com/),
},
{
id: admin2.id,
name: admin2.name,
username: admin2.username,
imageUrl: expect.stringMatching(/^https:\/\/gravatar.com/),
},
]);
});