49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { randomUUID } from 'node:crypto';
|
|
import { secondActor, seedProduct } from './commerce';
|
|
import type { IdentityApp } from './identity-app';
|
|
|
|
export const reviewAuth = { type: 'bearer' as const };
|
|
export const reviewInput = (verificationId: string) => ({
|
|
verificationId,
|
|
rating: 5,
|
|
displayName: 'Candle customer',
|
|
title: 'Lovely fragrance',
|
|
body: 'The candle burns evenly and smells wonderful.',
|
|
idempotencyKey: randomUUID(),
|
|
});
|
|
export const moderationInput = (
|
|
decision: 'APPROVED' | 'REJECTED' | 'HIDDEN' = 'APPROVED',
|
|
) => ({
|
|
decision,
|
|
note: 'Review content checked',
|
|
idempotencyKey: randomUUID(),
|
|
});
|
|
|
|
export async function reviewFixture(
|
|
ctx: IdentityApp,
|
|
buyerPermissions: string[] = [],
|
|
) {
|
|
const catalog = await seedProduct(ctx, true);
|
|
const buyer = await secondActor(ctx, true, buyerPermissions);
|
|
const proofInput = {
|
|
userId: buyer.userId,
|
|
variantId: catalog.variant.id as string,
|
|
reference: 'EXTERNAL-' + randomUUID(),
|
|
note: 'External receipt and completed purchase checked',
|
|
idempotencyKey: randomUUID(),
|
|
};
|
|
const proof = await ctx
|
|
.api()
|
|
.post('/api/v1/review-verifications')
|
|
.auth(ctx.token, reviewAuth)
|
|
.send(proofInput)
|
|
.expect(201);
|
|
return {
|
|
...catalog,
|
|
buyer,
|
|
proofInput,
|
|
proof: proof.body as { id: string },
|
|
publicUrl: `/api/v1/storefront/${ctx.owner.organizationId}/products/${catalog.product.id}/reviews`,
|
|
};
|
|
}
|