forked from mtusi2026/mtusi2026lab5
feat: accept uploads into staging with jobs, outbox and job processor
This commit is contained in:
@@ -8,6 +8,15 @@ import { randomUUID } from 'crypto';
|
||||
import request from 'supertest';
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { configureApp } from '../src/configure-app';
|
||||
import { PrismaService } from '../src/db/prisma.service';
|
||||
import { parseJobMessage } from '../src/jobs/job-message';
|
||||
import {
|
||||
JobProcessor,
|
||||
Outcome,
|
||||
ProcessorOptions,
|
||||
processorOptions,
|
||||
} from '../src/jobs/processor';
|
||||
import { S3Service } from '../src/storage/s3.service';
|
||||
|
||||
export const PASSWORD = 'Correct-Horse-Battery-42';
|
||||
|
||||
@@ -43,6 +52,30 @@ export async function createTestApp(
|
||||
return { app, server: app.getHttpServer() };
|
||||
}
|
||||
|
||||
export async function processAttachment(
|
||||
app: INestApplication,
|
||||
attachmentId: string,
|
||||
hooks: { afterStore?: () => Promise<void> } = {},
|
||||
options: Partial<ProcessorOptions> = {},
|
||||
): Promise<Outcome> {
|
||||
const prisma = app.get(PrismaService);
|
||||
const entry = await prisma.outboxEntry.findFirstOrThrow({
|
||||
where: { job: { attachmentId } },
|
||||
orderBy: { id: 'desc' },
|
||||
});
|
||||
const message = parseJobMessage(Buffer.from(JSON.stringify(entry.payload)));
|
||||
if (!message) {
|
||||
throw new Error('outbox payload does not match jobs.schema.json');
|
||||
}
|
||||
const processor = new JobProcessor(
|
||||
prisma,
|
||||
app.get(S3Service),
|
||||
{ ...processorOptions(), ...options },
|
||||
hooks,
|
||||
);
|
||||
return processor.handle(message);
|
||||
}
|
||||
|
||||
export function basic(username: string, password: string): string {
|
||||
return `Basic ${Buffer.from(`${username}:${password}`, 'utf8').toString('base64')}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user