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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user