mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor(client): simplify checks to see if a user has a certification (#64380)
This commit is contained in:
committed by
GitHub
parent
d828d5a076
commit
78b430c197
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user