mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(api): /showCert not returning user full name (#57666)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -7,11 +7,24 @@ import {
|
||||
} from '../../../jest.utils';
|
||||
import { getFallbackFullStackDate } from '../helpers/certificate-utils';
|
||||
|
||||
const DATE_NOW = Date.now();
|
||||
|
||||
describe('certificate routes', () => {
|
||||
setupServer();
|
||||
|
||||
describe('Unauthenticated user', () => {
|
||||
beforeAll(async () => resetDefaultUser());
|
||||
beforeAll(async () => {
|
||||
await resetDefaultUser();
|
||||
|
||||
jest.useFakeTimers({
|
||||
doNotFake: ['nextTick']
|
||||
});
|
||||
jest.setSystemTime(DATE_NOW);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
describe('GET /certificate/showCert/:username/:certSlug', () => {
|
||||
beforeEach(async () => {
|
||||
@@ -204,6 +217,70 @@ describe('certificate routes', () => {
|
||||
expect(response.status).toBe(200);
|
||||
});
|
||||
|
||||
test('should not return user full name if `showName` is `false`', async () => {
|
||||
await fastifyTestInstance.prisma.user.update({
|
||||
where: { id: defaultUserId },
|
||||
data: {
|
||||
profileUI: {
|
||||
showTimeLine: true,
|
||||
showCerts: true,
|
||||
isLocked: false,
|
||||
showName: false
|
||||
},
|
||||
isJsAlgoDataStructCert: true,
|
||||
completedChallenges: [
|
||||
{
|
||||
id: '561abd10cb81ac38a17513bc', // Cert ID
|
||||
completedDate: DATE_NOW
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
const response = await superRequest(
|
||||
'/certificate/showCert/foobar/javascript-algorithms-and-data-structures',
|
||||
{
|
||||
method: 'GET'
|
||||
}
|
||||
);
|
||||
|
||||
// TODO: delete this assertion once there's only one status 200 response
|
||||
expect(response.body).toHaveProperty('username', 'foobar');
|
||||
expect(response.body).not.toHaveProperty('name');
|
||||
expect(response.status).toBe(200);
|
||||
});
|
||||
|
||||
test('should return user full name if `showName` is `true`', async () => {
|
||||
await fastifyTestInstance.prisma.user.update({
|
||||
where: { id: defaultUserId },
|
||||
data: {
|
||||
profileUI: {
|
||||
showTimeLine: true,
|
||||
showCerts: true,
|
||||
isLocked: false,
|
||||
showName: true
|
||||
},
|
||||
isJsAlgoDataStructCert: true,
|
||||
completedChallenges: [
|
||||
{
|
||||
id: '561abd10cb81ac38a17513bc', // Cert ID
|
||||
completedDate: DATE_NOW
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
const response = await superRequest(
|
||||
'/certificate/showCert/foobar/javascript-algorithms-and-data-structures',
|
||||
{
|
||||
method: 'GET'
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.body).toHaveProperty('name', 'foobar');
|
||||
expect(response.status).toBe(200);
|
||||
});
|
||||
|
||||
test('should return cert-not-found if there is no cert with that slug', async () => {
|
||||
const response = await superRequest(
|
||||
'/certificate/showCert/foobar/not-a-valid-cert-slug',
|
||||
|
||||
@@ -85,14 +85,7 @@ export const certSlug = {
|
||||
certSlug: Type.Enum(Certification),
|
||||
certTitle: Type.String(),
|
||||
username: Type.String(),
|
||||
date: Type.Number(),
|
||||
completionTime: Type.Number()
|
||||
}),
|
||||
Type.Object({
|
||||
certSlug: Type.Enum(Certification),
|
||||
certTitle: Type.String(),
|
||||
username: Type.String(),
|
||||
name: Type.String(),
|
||||
name: Type.Optional(Type.String()),
|
||||
date: Type.Number(),
|
||||
completionTime: Type.Number()
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user