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:
parent
d7db80d948
commit
e4cec6629d
@ -201,12 +201,13 @@ export class AccountStore implements IAccountStore {
|
|||||||
|
|
||||||
async getAdmins(): Promise<MinimalUser[]> {
|
async getAdmins(): Promise<MinimalUser[]> {
|
||||||
const rowToAdminUser = (row) => {
|
const rowToAdminUser = (row) => {
|
||||||
|
const user = rowToUser(row);
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: user.id,
|
||||||
name: emptify(row.name),
|
name: user.name,
|
||||||
username: emptify(row.username),
|
username: user.username,
|
||||||
email: emptify(row.email),
|
email: user.email,
|
||||||
imageUrl: emptify(row.image_url),
|
imageUrl: user.imageUrl,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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/),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user