mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-13 21:02:08 +08:00
fix: claim legacy and full stack certifications (#51506)
This commit is contained in:
parent
6cb78034aa
commit
e769f505b2
@ -14,7 +14,9 @@ import {
|
||||
certIds,
|
||||
oldDataVizId,
|
||||
currentCertifications,
|
||||
upcomingCertifications
|
||||
upcomingCertifications,
|
||||
legacyCertifications,
|
||||
legacyFullStackCertification
|
||||
} from '../../../../shared/config/certification-settings';
|
||||
import { reportError } from '../middlewares/sentry-error-handler.js';
|
||||
|
||||
@ -77,10 +79,15 @@ export function getFallbackFullStackDate(completedChallenges, completedDate) {
|
||||
return latestCertDate ? latestCertDate : completedDate;
|
||||
}
|
||||
|
||||
function ifNoCertification404(req, res, next) {
|
||||
export function ifNoCertification404(req, res, next) {
|
||||
const { certSlug } = req.body;
|
||||
if (!certSlug) return res.status(404).end();
|
||||
if (currentCertifications.includes(certSlug)) return next();
|
||||
if (
|
||||
currentCertifications.includes(certSlug) ||
|
||||
legacyCertifications.includes(certSlug) ||
|
||||
legacyFullStackCertification.includes(certSlug)
|
||||
)
|
||||
return next();
|
||||
if (
|
||||
process.env.SHOW_UPCOMING_CHANGES === 'true' &&
|
||||
upcomingCertifications.includes(certSlug)
|
||||
|
||||
@ -1,10 +1,94 @@
|
||||
import { getFallbackFullStackDate } from '../boot/certificate';
|
||||
import {
|
||||
getFallbackFullStackDate,
|
||||
ifNoCertification404
|
||||
} from '../boot/certificate';
|
||||
import { fullStackChallenges } from './fixtures';
|
||||
|
||||
export const mockReq = opts => {
|
||||
const req = {};
|
||||
return { ...req, ...opts };
|
||||
};
|
||||
|
||||
export const mockRes = opts => {
|
||||
const res = {};
|
||||
res.status = jest.fn().mockReturnValue(res);
|
||||
res.end = jest.fn().mockReturnValue(res);
|
||||
res.json = jest.fn().mockReturnValue(res);
|
||||
res.redirect = jest.fn().mockReturnValue(res);
|
||||
res.set = jest.fn().mockReturnValue(res);
|
||||
res.clearCookie = jest.fn().mockReturnValue(res);
|
||||
res.cookie = jest.fn().mockReturnValue(res);
|
||||
return { ...res, ...opts };
|
||||
};
|
||||
|
||||
describe('boot/certificate', () => {
|
||||
describe('getFallbackFullStackDate', () => {
|
||||
it('should return the date of the latest completed challenge', () => {
|
||||
expect(getFallbackFullStackDate(fullStackChallenges)).toBe(1685210952511);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ifNoCertification404', () => {
|
||||
it('declares a 404 when there is no certSlug in the body', () => {
|
||||
const req = mockReq({
|
||||
body: {}
|
||||
});
|
||||
const res = mockRes();
|
||||
const next = jest.fn();
|
||||
|
||||
ifNoCertification404(req, res, next);
|
||||
|
||||
expect(res.status).toHaveBeenCalledWith(404);
|
||||
expect(next).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('declares a 404 for an invalid certSlug in the body', () => {
|
||||
const req = mockReq({
|
||||
body: { certSlug: 'not-a-real-certSlug' }
|
||||
});
|
||||
const res = mockRes();
|
||||
const next = jest.fn();
|
||||
|
||||
ifNoCertification404(req, res, next);
|
||||
|
||||
expect(res.status).toHaveBeenCalledWith(404);
|
||||
expect(next).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls next for a valid certSlug of a current certification', () => {
|
||||
const req = mockReq({
|
||||
body: { certSlug: 'responsive-web-design' }
|
||||
});
|
||||
const res = mockRes();
|
||||
const next = jest.fn();
|
||||
|
||||
ifNoCertification404(req, res, next);
|
||||
|
||||
expect(next).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls next for a valid certSlug of a legacy certification', () => {
|
||||
const req = mockReq({
|
||||
body: { certSlug: 'legacy-front-end' }
|
||||
});
|
||||
const res = mockRes();
|
||||
const next = jest.fn();
|
||||
|
||||
ifNoCertification404(req, res, next);
|
||||
|
||||
expect(next).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls next for a valid certSlug of the legacy full stack certification', () => {
|
||||
const req = mockReq({
|
||||
body: { certSlug: 'full-stack' }
|
||||
});
|
||||
const res = mockRes();
|
||||
const next = jest.fn();
|
||||
|
||||
ifNoCertification404(req, res, next);
|
||||
|
||||
expect(next).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -62,6 +62,12 @@ export const legacyCertifications = [
|
||||
Certification.LegacyInfoSecQa
|
||||
] as const;
|
||||
|
||||
// The Legacy Full Stack certification can only be claimed when specific
|
||||
// "current" and "legacy" certifications have been claimed.
|
||||
export const legacyFullStackCertification = [
|
||||
Certification.LegacyFullStack
|
||||
] as const;
|
||||
|
||||
// "Upcoming" certifications are standard certifications that are not live unless
|
||||
// showUpcomingChanges is true.
|
||||
export const upcomingCertifications = [Certification.UpcomingPython] as const;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user