| 1 | import test from "ava";
|
| 2 | import { PrismaClient } from '@prisma/client';
|
| 3 | import { PrismaPg } from '@prisma/adapter-pg';
|
| 4 | import request from 'supertest';
|
| 5 | import bcrypt from 'bcryptjs';
|
| 6 | import 'dotenv/config';
|
| 7 | import { Express } from 'express';
|
| 8 | import { createApp } from '../../src/createApp';
|
| 9 |
|
| 10 | let prisma: PrismaClient;
|
| 11 | let app: Express;
|
| 12 |
|
| 13 | test.before(() => {
|
| 14 | process.env.NODE_ENV = 'test';
|
| 15 |
|
| 16 | const connectionString = process.env.DATABASE_URL || 'postgres://user:password@orbit_db:5432/orbit_test';
|
| 17 | const adapter = new PrismaPg({ connectionString });
|
| 18 | prisma = new PrismaClient({ adapter });
|
| 19 |
|
| 20 | // Create Express app with test Prisma client
|
| 21 | app = createApp(prisma);
|
| 22 | });
|
| 23 |
|
| 24 | test.beforeEach(async () => {
|
| 25 | // Clean database before each test
|
| 26 | try {
|
| 27 | await prisma.user.deleteMany({});
|
| 28 | } catch (err) {
|
| 29 | console.error('Error cleaning test DB:', err);
|
| 30 | }
|
| 31 | });
|
| 32 |
|
| 33 | test.after.always(async () => {
|
| 34 | await prisma?.$disconnect();
|
| 35 | });
|
| 36 |
|
| 37 | //test("DELETE /users/:id deletes a user", async (t) => {
|
| 38 | // t.pass()
|
| 39 | // // Create a user first
|
| 40 | // const user = await prisma.user.create({
|
| 41 | // data: {
|
| 42 | // email: "delete@example.com",
|
| 43 | // firstName: "Delete",
|
| 44 | // lastName: "Me",
|
| 45 | // encryptedPassword: bcrypt.hashSync("password", 10)
|
| 46 | // }
|
| 47 | // });
|
| 48 | //
|
| 49 | // await request(app)
|
| 50 | // .delete(`/users/${user.id}`)
|
| 51 | // .expect(204);
|
| 52 | //
|
| 53 | // // Verify user was deleted
|
| 54 | // const dbUser = await prisma.user.findUnique({
|
| 55 | // where: { id: user.id }
|
| 56 | // });
|
| 57 | // t.is(dbUser, null);
|
| 58 | //});
|