mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
Add unit tests to the admin hash generation, fix minor requests
This commit is contained in:
parent
efb4125181
commit
6c1b0010e6
@ -78,7 +78,7 @@ const AuthenticatedApp = () => {
|
||||
|
||||
const shouldShowLoader = isLoading || shouldShowNotDependentQueriesLoader;
|
||||
|
||||
const adminUserId = userInfo ? hashAdminUserEmail(userInfo) : '';
|
||||
const adminUserId = hashAdminUserEmail(userInfo);
|
||||
const appInfosValue = useMemo(() => {
|
||||
return {
|
||||
...appInfos,
|
||||
|
||||
@ -10,6 +10,9 @@ async function digestMessage(message) {
|
||||
}
|
||||
|
||||
export default async function hashAdminUserEmail(payload) {
|
||||
if (!payload) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
return await digestMessage(payload.email);
|
||||
} catch (error) {
|
||||
|
||||
@ -57,7 +57,7 @@ describe('Metrics', () => {
|
||||
|
||||
expect(getLanguagesInUse).toHaveBeenCalledWith();
|
||||
expect(send).toHaveBeenCalledWith('didChangeInterfaceLanguage', {
|
||||
groupProperties: {
|
||||
userProperties: {
|
||||
languagesInUse: ['en', 'fr', 'en'],
|
||||
},
|
||||
});
|
||||
|
||||
@ -17,7 +17,7 @@ const sendDidUpdateRolePermissions = async () => {
|
||||
const sendDidChangeInterfaceLanguage = async () => {
|
||||
const languagesInUse = await getService('user').getLanguagesInUse();
|
||||
// This event is anonymous
|
||||
strapi.telemetry.send('didChangeInterfaceLanguage', { groupProperties: { languagesInUse } });
|
||||
strapi.telemetry.send('didChangeInterfaceLanguage', { userProperties: { languagesInUse } });
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { generateAdminUserHash } = require('../admin-user-hash');
|
||||
const createContext = require('../../../../../../../test/helpers/create-context');
|
||||
|
||||
describe('user email hash', () => {
|
||||
test('should create a hash from admin email', () => {
|
||||
const state = {
|
||||
user: {
|
||||
email: 'testemail@strapi.io',
|
||||
},
|
||||
};
|
||||
|
||||
const ctx = createContext({}, { state });
|
||||
|
||||
const hash = crypto.createHash('sha256').update('testemail@strapi.io').digest('hex');
|
||||
|
||||
const adminUserId = generateAdminUserHash(ctx);
|
||||
expect(adminUserId).toBe(hash);
|
||||
});
|
||||
|
||||
test('should return empty string if user is not available on ctx', () => {
|
||||
const ctx = createContext({}, {});
|
||||
|
||||
const adminUserId = generateAdminUserHash(ctx);
|
||||
expect(adminUserId).toBe('');
|
||||
});
|
||||
});
|
||||
@ -74,7 +74,7 @@ module.exports = (strapi) => {
|
||||
event,
|
||||
adminUserId,
|
||||
deviceId,
|
||||
eventProperties: adminUserId ? payload.eventProperties : {},
|
||||
eventProperties: payload.eventProperties,
|
||||
userProperties: adminUserId
|
||||
? { ...anonymousUserProperties, ...payload.userProperties }
|
||||
: {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user