mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor(api): simplify user tests (#51111)
This commit is contained in:
committed by
GitHub
parent
12abcf94b2
commit
c2fff83d41
@@ -1,6 +1,7 @@
|
||||
import request from 'supertest';
|
||||
|
||||
import { build } from './src/app';
|
||||
import { defaultUser } from './src/utils/default-user';
|
||||
|
||||
type FastifyTestInstance = Awaited<ReturnType<typeof build>>;
|
||||
|
||||
@@ -73,3 +74,23 @@ export function setupServer(): void {
|
||||
await fastifyTestInstance.close();
|
||||
});
|
||||
}
|
||||
|
||||
export const defaultUserId = '64c7810107dd4782d32baee7';
|
||||
export const defaultUserEmail = 'foo@bar.com';
|
||||
|
||||
export async function devLogin(): Promise<string[]> {
|
||||
await fastifyTestInstance.prisma.user.deleteMany({
|
||||
where: { email: 'foo@bar.com' }
|
||||
});
|
||||
|
||||
await fastifyTestInstance.prisma.user.create({
|
||||
data: {
|
||||
...defaultUser,
|
||||
id: defaultUserId,
|
||||
email: defaultUserEmail
|
||||
}
|
||||
});
|
||||
const res = await superRequest('/auth/dev-callback', { method: 'GET' });
|
||||
expect(res.status).toBe(200);
|
||||
return res.get('Set-Cookie');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user