feat: deprecated endpoint (#50403)

* feat: deprecated endpoints
This commit is contained in:
Niraj Nandish
2023-05-17 11:24:57 +04:00
committed by GitHub
parent 0fef335292
commit 5bc14c21b9
3 changed files with 84 additions and 0 deletions
+2
View File
@@ -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.'
}
});
});
});
});
+49
View File
@@ -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();
};