51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import type { Prisma } from '../src/generated/prisma/client';
|
|
import { ownReviewView, reviewInclude } from '../src/reviews/review-view';
|
|
|
|
describe('customer review privacy', () => {
|
|
const review = {
|
|
id: 'review',
|
|
variantId: 'variant',
|
|
userId: 'private-user',
|
|
organizationId: 'private-organization',
|
|
verificationId: 'proof',
|
|
rating: 5,
|
|
displayName: 'Chosen alias',
|
|
title: 'Good candle',
|
|
body: 'A lovely candle fragrance',
|
|
createdAt: new Date(),
|
|
requestHash: 'private-hash',
|
|
idempotencyKey: 'private-key',
|
|
verification: { revocation: null },
|
|
events: [],
|
|
} as Prisma.ProductReviewGetPayload<{ include: typeof reviewInclude }>;
|
|
it('shows pending status without leaking account identifiers or verification records', () => {
|
|
const result = ownReviewView(review);
|
|
expect(result).toMatchObject({
|
|
moderationStatus: 'PENDING',
|
|
purchaseVerified: true,
|
|
displayName: 'Chosen alias',
|
|
});
|
|
for (const field of [
|
|
'userId',
|
|
'organizationId',
|
|
'verificationId',
|
|
'verification',
|
|
'events',
|
|
'requestHash',
|
|
'idempotencyKey',
|
|
])
|
|
expect(result).not.toHaveProperty(field);
|
|
});
|
|
it('shows revoked eligibility separately from immutable moderation status', () => {
|
|
const result = ownReviewView({
|
|
...review,
|
|
verification: { revocation: { verificationId: 'proof' } },
|
|
events: [{ kind: 'HIDDEN' } as (typeof review.events)[number]],
|
|
});
|
|
expect(result).toMatchObject({
|
|
moderationStatus: 'HIDDEN',
|
|
purchaseVerified: false,
|
|
});
|
|
});
|
|
});
|