Wire the app, worker, and cleanup entry points onto Prisma Client
Task 4 rewrote src/db.js and src/jobs/jobRepository.js to use Prisma instead of the hand-rolled mariadb pool. This updates every remaining call site (app.js, server.js, worker.js, cleanup.js) and the 5 test files that still referenced getPool/closePool/pool.query, so the app and full test suite compile and run against Prisma Client. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+19
-19
@@ -2,28 +2,28 @@ import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import { getPool, closePool } from '../src/db.js';
|
||||
import { getPrismaClient, closePrismaClient } from '../src/db.js';
|
||||
import { loadConfig } from '../src/config.js';
|
||||
import { ensureStorageDirs, uploadPath, outputPath } from '../src/storage.js';
|
||||
import { createJob, markDone, getJobByUuid } from '../src/jobs/jobRepository.js';
|
||||
import { runCleanup } from '../src/cleanup.js';
|
||||
|
||||
let pool;
|
||||
let prisma;
|
||||
let config;
|
||||
|
||||
beforeAll(async () => {
|
||||
config = { ...loadConfig(), storageDir: await fs.mkdtemp(path.join(os.tmpdir(), 'converter-cleanup-')) };
|
||||
await ensureStorageDirs(config);
|
||||
pool = getPool(config);
|
||||
prisma = getPrismaClient(config);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePool();
|
||||
await closePrismaClient();
|
||||
await fs.rm(config.storageDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await pool.query('DELETE FROM conversion_jobs');
|
||||
await prisma.conversionJob.deleteMany();
|
||||
});
|
||||
|
||||
describe('runCleanup', () => {
|
||||
@@ -31,7 +31,7 @@ describe('runCleanup', () => {
|
||||
const uuid = 'eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee';
|
||||
await fs.writeFile(uploadPath(config, uuid, 'png'), 'input bytes');
|
||||
await fs.writeFile(outputPath(config, uuid, 'webp'), 'output bytes');
|
||||
await createJob(pool, {
|
||||
await createJob(prisma, {
|
||||
uuid,
|
||||
family: 'image',
|
||||
sourceFormat: 'png',
|
||||
@@ -42,18 +42,18 @@ describe('runCleanup', () => {
|
||||
inputSizeBytes: 11,
|
||||
expiresAt: new Date(Date.now() - 1000),
|
||||
});
|
||||
const created = await getJobByUuid(pool, uuid);
|
||||
await markDone(pool, created.id, {
|
||||
const created = await getJobByUuid(prisma, uuid);
|
||||
await markDone(prisma, created.id, {
|
||||
outputPath: `${uuid}.webp`,
|
||||
outputMimeType: 'image/webp',
|
||||
outputSizeBytes: 12,
|
||||
conversionDurationSeconds: 0.5,
|
||||
});
|
||||
|
||||
const cleanedCount = await runCleanup(pool, config);
|
||||
const cleanedCount = await runCleanup(prisma, config);
|
||||
|
||||
expect(cleanedCount).toBe(1);
|
||||
const job = await getJobByUuid(pool, uuid);
|
||||
const job = await getJobByUuid(prisma, uuid);
|
||||
expect(job).not.toBeNull();
|
||||
expect(job.cleanedAt).not.toBeNull();
|
||||
await expect(fs.stat(uploadPath(config, uuid, 'png'))).rejects.toThrow();
|
||||
@@ -63,7 +63,7 @@ describe('runCleanup', () => {
|
||||
it('marks an expired pending job (with no output file) cleaned without throwing', async () => {
|
||||
const uuid = 'ffffffff-ffff-4fff-8fff-ffffffffffff';
|
||||
await fs.writeFile(uploadPath(config, uuid, 'png'), 'input bytes');
|
||||
await createJob(pool, {
|
||||
await createJob(prisma, {
|
||||
uuid,
|
||||
family: 'image',
|
||||
sourceFormat: 'png',
|
||||
@@ -75,17 +75,17 @@ describe('runCleanup', () => {
|
||||
expiresAt: new Date(Date.now() - 1000),
|
||||
});
|
||||
|
||||
const cleanedCount = await runCleanup(pool, config);
|
||||
const cleanedCount = await runCleanup(prisma, config);
|
||||
|
||||
expect(cleanedCount).toBe(1);
|
||||
const job = await getJobByUuid(pool, uuid);
|
||||
const job = await getJobByUuid(prisma, uuid);
|
||||
expect(job).not.toBeNull();
|
||||
expect(job.cleanedAt).not.toBeNull();
|
||||
});
|
||||
|
||||
it('leaves non-expired jobs untouched', async () => {
|
||||
const uuid = '12121212-1212-4212-8212-121212121212';
|
||||
await createJob(pool, {
|
||||
await createJob(prisma, {
|
||||
uuid,
|
||||
family: 'image',
|
||||
sourceFormat: 'png',
|
||||
@@ -97,17 +97,17 @@ describe('runCleanup', () => {
|
||||
expiresAt: new Date(Date.now() + 3600 * 1000),
|
||||
});
|
||||
|
||||
const cleanedCount = await runCleanup(pool, config);
|
||||
const cleanedCount = await runCleanup(prisma, config);
|
||||
|
||||
expect(cleanedCount).toBe(0);
|
||||
const job = await getJobByUuid(pool, uuid);
|
||||
const job = await getJobByUuid(prisma, uuid);
|
||||
expect(job).not.toBeNull();
|
||||
expect(job.cleanedAt).toBeNull();
|
||||
});
|
||||
|
||||
it('does not re-process an already cleaned expired job', async () => {
|
||||
const uuid = '13131313-1313-4313-8313-131313131313';
|
||||
await createJob(pool, {
|
||||
await createJob(prisma, {
|
||||
uuid,
|
||||
family: 'image',
|
||||
sourceFormat: 'png',
|
||||
@@ -119,8 +119,8 @@ describe('runCleanup', () => {
|
||||
expiresAt: new Date(Date.now() - 1000),
|
||||
});
|
||||
|
||||
const firstRun = await runCleanup(pool, config);
|
||||
const secondRun = await runCleanup(pool, config);
|
||||
const firstRun = await runCleanup(prisma, config);
|
||||
const secondRun = await runCleanup(prisma, config);
|
||||
|
||||
expect(firstRun).toBe(1);
|
||||
expect(secondRun).toBe(0);
|
||||
|
||||
Reference in New Issue
Block a user