refactor(client): simplify checks to see if a user has a certification (#64380)

This commit is contained in:
Oliver Eyton-Williams
2025-12-15 15:17:35 +01:00
committed by GitHub
parent d828d5a076
commit 78b430c197
3 changed files with 41 additions and 66 deletions
+31 -1
View File
@@ -4,7 +4,8 @@ import {
linkedInCredentialIds,
certToTitleMap,
certToIdMap,
certSlugTypeMap
certSlugTypeMap,
isCertified
} from './certification-settings';
describe('linkedInCredentialIds', () => {
@@ -49,3 +50,32 @@ describe('certSlugTypeMap', () => {
expect(uniqueTypes).toEqual(types);
});
});
describe('isCertified', () => {
it('should return true if a user has the specified certification', () => {
const cert = Certification.RespWebDesignV9;
const user = {
isRespWebDesignCertV9: true
};
expect(isCertified(user, cert)).toBe(true);
});
it('should return false if a user does not have the specified certification', () => {
const cert = Certification.JsAlgoDataStruct;
const user = {
isRespWebDesignCertV9: true
};
expect(isCertified(user, cert)).toBe(false);
});
it('should return false if the certification does not exist', () => {
const cert = 'NonExistentCert' as Certification;
const user = {
isRespWebDesignCertV9: true
};
expect(isCertified(user, cert)).toBe(false);
});
});
+8
View File
@@ -251,6 +251,14 @@ export type CertificationFlags = {
[key in UserCertFlag]: boolean;
};
export function isCertified(
user: Partial<CertificationFlags>,
cert: Certification
): boolean {
const certFlag = certSlugTypeMap[cert];
return Boolean(user[certFlag]);
}
// TODO: use i18n keys instead of hardcoded titles
export const certToTitleMap: Record<Certification, string> = {
// Legacy certifications