feat: v2.2 batch (calendar, self-service, sort, description, filename search, stats, collab, invoice) on pre-redesign base
This commit is contained in:
1 parent
453bece72c
commit
7204dd6b60
108 files changed
+10400
-105
No files matched your search
@@ -12,6 +12,10 @@ import { startPostgres } from "./postgres";
|
||||
const testDb = await startPostgres({
|
||||
through: "0001_editorial_approval_notice.sql",
|
||||
migrationsDir: "drizzle-history/pre-squash-2026-08",
|
||||
alsoApply: [
|
||||
"drizzle/0002_release_notes_calendar.sql",
|
||||
"drizzle/0003_collab_invoice_activity.sql",
|
||||
],
|
||||
});
|
||||
|
||||
afterAll(() => testDb.stop());
|
||||
|
||||
@@ -8,6 +8,10 @@ import { startPostgres } from "./postgres";
|
||||
const testDb = await startPostgres({
|
||||
through: "0001_editorial_approval_notice.sql",
|
||||
migrationsDir: "drizzle-history/pre-squash-2026-08",
|
||||
alsoApply: [
|
||||
"drizzle/0002_release_notes_calendar.sql",
|
||||
"drizzle/0003_collab_invoice_activity.sql",
|
||||
],
|
||||
});
|
||||
|
||||
afterAll(() => testDb.stop());
|
||||
|
||||
+10
-1
@@ -30,7 +30,11 @@ export type PostgresTestDatabase = {
|
||||
};
|
||||
|
||||
export async function startPostgres(
|
||||
{ through, migrationsDir }: { through?: string; migrationsDir?: string } = {},
|
||||
{
|
||||
through,
|
||||
migrationsDir,
|
||||
alsoApply = [],
|
||||
}: { through?: string; migrationsDir?: string; alsoApply?: string[] } = {},
|
||||
): Promise<PostgresTestDatabase> {
|
||||
const container = await new PostgreSqlContainer("postgres:17-alpine")
|
||||
.withDatabase("portal")
|
||||
@@ -44,6 +48,11 @@ export async function startPostgres(
|
||||
if (through && throughIndex < 0) throw new Error(`Unknown migration: ${through}`);
|
||||
let appliedMigrationCount = throughIndex + 1;
|
||||
await applyMigrationFiles(pool, migrationsDir, migrationFiles.slice(0, appliedMigrationCount));
|
||||
// Additive current-chain migrations (new tables/columns) that the historical
|
||||
// chain predates, so current service code can run against the old schema.
|
||||
for (const file of alsoApply) {
|
||||
await pool.query(await readFile(path.join(process.cwd(), file), "utf8"));
|
||||
}
|
||||
|
||||
const db = drizzle({ client: pool, schema });
|
||||
|
||||
|
||||
@@ -70,11 +70,19 @@ async function seedEditorial({
|
||||
priceCents = 1_500,
|
||||
albumId: grantedAlbumId = albumId,
|
||||
revoked = false,
|
||||
collabEnabled = false,
|
||||
flatrateActive = false,
|
||||
flatratePriceCents = null,
|
||||
flatrateAssetLimit = null,
|
||||
}: {
|
||||
status?: "active" | "suspended" | "pending_approval";
|
||||
priceCents?: number | null;
|
||||
albumId?: string;
|
||||
revoked?: boolean;
|
||||
collabEnabled?: boolean;
|
||||
flatrateActive?: boolean;
|
||||
flatratePriceCents?: number | null;
|
||||
flatrateAssetLimit?: number | null;
|
||||
} = {}) {
|
||||
const userId = randomUUID();
|
||||
const editorialId = randomUUID();
|
||||
@@ -92,6 +100,10 @@ async function seedEditorial({
|
||||
loginEmail: `${userId}@example.com`,
|
||||
status,
|
||||
currentPriceCents: priceCents,
|
||||
collabEnabled,
|
||||
flatrateActive,
|
||||
flatratePriceCents,
|
||||
flatrateAssetLimit,
|
||||
});
|
||||
await database.insert(albumGrants).values({
|
||||
editorialAccountId: editorialId,
|
||||
@@ -572,6 +584,55 @@ test("repeat ownership is scoped to the active editorial", async () => {
|
||||
).rejects.toMatchObject({ code: "USAGE_NOT_FOUND" });
|
||||
});
|
||||
|
||||
test("collab usages are free and flagged when the editorial is enabled", async () => {
|
||||
const editorialId = await seedEditorial({ collabEnabled: true });
|
||||
const { usageService } = createServices();
|
||||
|
||||
const intent = await usageService.createNewUsage({ ...newInput(editorialId), collab: true });
|
||||
|
||||
expect(intent.priceCents).toBe(0);
|
||||
const [usage] = await database
|
||||
.select({ collab: usages.collab, priceCents: usages.priceCents })
|
||||
.from(usages)
|
||||
.where(eq(usages.id, intent.usageId));
|
||||
expect(usage).toEqual({ collab: true, priceCents: 0 });
|
||||
const [audit] = await database
|
||||
.select({ newValues: auditEvents.newValues })
|
||||
.from(auditEvents)
|
||||
.where(and(eq(auditEvents.entityId, intent.usageId), eq(auditEvents.eventType, "billable_usage_created")));
|
||||
expect(audit.newValues).toMatchObject({ collab: true, priceCents: 0 });
|
||||
});
|
||||
|
||||
test("collab usages are rejected when the editorial is not enabled", async () => {
|
||||
const editorialId = await seedEditorial({ collabEnabled: false });
|
||||
const { usageService } = createServices();
|
||||
|
||||
await expect(
|
||||
usageService.createNewUsage({ ...newInput(editorialId), collab: true }),
|
||||
).rejects.toMatchObject({ code: "COLLAB_NOT_ENABLED" });
|
||||
});
|
||||
|
||||
test("collab usages do not consume the flatrate asset limit", async () => {
|
||||
const editorialId = await seedEditorial({
|
||||
collabEnabled: true,
|
||||
flatrateActive: true,
|
||||
flatratePriceCents: 500,
|
||||
flatrateAssetLimit: 1,
|
||||
});
|
||||
const { usageService } = createServices();
|
||||
|
||||
const collabIntent = await usageService.createNewUsage({ ...newInput(editorialId), collab: true });
|
||||
expect(collabIntent.priceCents).toBe(0);
|
||||
|
||||
// The single flatrate slot is still free after the collab usage.
|
||||
const flatrateIntent = await usageService.createNewUsage(newInput(editorialId));
|
||||
expect(flatrateIntent.priceCents).toBe(0);
|
||||
|
||||
// Limit exhausted: the next regular usage costs the individual price.
|
||||
const paidIntent = await usageService.createNewUsage(newInput(editorialId));
|
||||
expect(paidIntent.priceCents).toBe(1_500);
|
||||
});
|
||||
|
||||
async function markDelivered(downloadId: string): Promise<void> {
|
||||
const deliveredAt = new Date();
|
||||
await database
|
||||
|
||||
Vendored
+1
@@ -23,6 +23,7 @@ export const reportFixture: BillingReportSnapshot = {
|
||||
purpose: "Print Nutzung",
|
||||
reference: "REF-001",
|
||||
priceCents: 6_000,
|
||||
collab: false,
|
||||
createdAt: new Date("2026-03-15T10:00:00.000Z"),
|
||||
},
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user