refactor(api): simplify user tests (#51111)

This commit is contained in:
Oliver Eyton-Williams
2023-07-31 16:08:05 +02:00
committed by GitHub
parent 12abcf94b2
commit c2fff83d41
5 changed files with 52 additions and 55 deletions
+21
View File
@@ -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');
}