-
-
Notifications
You must be signed in to change notification settings - Fork 37k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |