Skip to content

Commit

Permalink
feat: deprecated endpoint (#50403)
Browse files Browse the repository at this point in the history
* feat: deprecated endpoints
  • Loading branch information
Nirajn2311 committed May 17, 2023
1 parent 0fef335 commit 5bc14c2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -121,6 +122,7 @@ export const build = async (
void fastify.register(devLoginCallback, { prefix: '/auth' });
}
void fastify.register(settingRoutes);
void fastify.register(deprecatedEndpoints);

return fastify;
};
33 changes: 33 additions & 0 deletions api/src/routes/deprecated-endpoints.test.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 49 additions & 0 deletions api/src/routes/deprecated-endpoints.ts
Original file line number Diff line number Diff line change
@@ -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();
};

0 comments on commit 5bc14c2

Please sign in to comment.