mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
@@ -21,6 +21,7 @@ import jwtAuthz from './plugins/fastify-jwt-authz';
|
||||
import security from './plugins/security';
|
||||
import sessionAuth from './plugins/session-auth';
|
||||
import { settingRoutes } from './routes/settings';
|
||||
import { deprecatedEndpoints } from './routes/deprecated-endpoints';
|
||||
import { auth0Routes, devLoginCallback } from './routes/auth';
|
||||
import { testMiddleware } from './middleware';
|
||||
import prismaPlugin from './db/prisma';
|
||||
@@ -121,6 +122,7 @@ export const build = async (
|
||||
void fastify.register(devLoginCallback, { prefix: '/auth' });
|
||||
}
|
||||
void fastify.register(settingRoutes);
|
||||
void fastify.register(deprecatedEndpoints);
|
||||
|
||||
return fastify;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import request from 'supertest';
|
||||
|
||||
import { build } from '../app';
|
||||
import { endpoints } from './deprecated-endpoints';
|
||||
|
||||
describe('Deprecated endpoints', () => {
|
||||
let fastify: undefined | Awaited<ReturnType<typeof build>>;
|
||||
|
||||
beforeAll(async () => {
|
||||
fastify = await build();
|
||||
await fastify.ready();
|
||||
}, 20000);
|
||||
|
||||
afterAll(async () => {
|
||||
await fastify?.close();
|
||||
});
|
||||
|
||||
endpoints.forEach(([endpoint, method]) => {
|
||||
test(`${method} ${endpoint} returns 410 status code with "info" message`, async () => {
|
||||
const response = await request(fastify?.server)[
|
||||
method.toLowerCase() as 'get' | 'post'
|
||||
](endpoint);
|
||||
|
||||
expect(response.status).toBe(410);
|
||||
expect(response.body).toStrictEqual({
|
||||
message: {
|
||||
type: 'info',
|
||||
message: 'Please reload the app, this feature is no longer available.'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
FastifyPluginCallbackTypebox,
|
||||
Type
|
||||
} from '@fastify/type-provider-typebox';
|
||||
|
||||
type Endpoints = [string, 'GET' | 'POST'][];
|
||||
|
||||
export const endpoints: Endpoints = [
|
||||
['/refetch-user-completed-challenges', 'POST'],
|
||||
['/certificate/verify-can-claim-cert', 'GET'],
|
||||
['/api/github', 'GET']
|
||||
];
|
||||
|
||||
export const deprecatedEndpoints: FastifyPluginCallbackTypebox = (
|
||||
fastify,
|
||||
_options,
|
||||
done
|
||||
) => {
|
||||
endpoints.forEach(([endpoint, method]) => {
|
||||
fastify.route({
|
||||
method,
|
||||
url: endpoint,
|
||||
schema: {
|
||||
response: {
|
||||
410: Type.Object({
|
||||
message: Type.Object({
|
||||
type: Type.Literal('info'),
|
||||
message: Type.Literal(
|
||||
'Please reload the app, this feature is no longer available.'
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
handler: async (_req, reply) => {
|
||||
void reply.status(410);
|
||||
return {
|
||||
message: {
|
||||
type: 'info',
|
||||
message:
|
||||
'Please reload the app, this feature is no longer available.'
|
||||
}
|
||||
} as const;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
done();
|
||||
};
|
||||
Reference in New Issue
Block a user