71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import { Prisma } from '../src/generated/prisma/client';
|
|
import { wishlistView, wishlistInclude } from '../src/wishlist/wishlist-view';
|
|
import {
|
|
wishlistQuerySchema,
|
|
wishlistSaveSchema,
|
|
} from '../src/wishlist/wishlist.schemas';
|
|
|
|
const item: Prisma.WishlistItemGetPayload<{ include: typeof wishlistInclude }> =
|
|
{
|
|
id: 'item',
|
|
userId: 'user',
|
|
organizationId: 'organization',
|
|
variantId: 'variant',
|
|
createdAt: new Date('2026-10-05T00:00:00Z'),
|
|
variant: {
|
|
name: 'Rose',
|
|
sku: 'ROSE',
|
|
price: new Prisma.Decimal('499.10'),
|
|
currency: 'INR',
|
|
active: true,
|
|
product: {
|
|
id: 'product',
|
|
name: 'Candle',
|
|
slug: 'candle',
|
|
status: 'PUBLISHED',
|
|
},
|
|
},
|
|
};
|
|
describe('wishlist presentation and validation', () => {
|
|
it('returns public current catalog details with exact price and no private ownership fields', () => {
|
|
const result = wishlistView(item);
|
|
expect(result.variant?.price).toBe('499.10');
|
|
expect(result).not.toHaveProperty('userId');
|
|
expect(result.variant?.product).not.toHaveProperty('status');
|
|
});
|
|
it('redacts draft, archived and inactive variants while retaining removal identifiers', () => {
|
|
for (const status of ['DRAFT', 'ARCHIVED'] as const) {
|
|
expect(
|
|
wishlistView({
|
|
...item,
|
|
variant: {
|
|
...item.variant,
|
|
product: { ...item.variant.product, status },
|
|
},
|
|
}),
|
|
).toMatchObject({
|
|
variantId: 'variant',
|
|
available: false,
|
|
variant: null,
|
|
});
|
|
}
|
|
expect(
|
|
wishlistView({ ...item, variant: { ...item.variant, active: false } })
|
|
.variant,
|
|
).toBeNull();
|
|
});
|
|
it('bounds pagination and forbids caller-supplied ownership', () => {
|
|
expect(wishlistQuerySchema.parse({})).toEqual({ limit: 25, offset: 0 });
|
|
for (const query of [
|
|
{ limit: 101 },
|
|
{ offset: -1 },
|
|
{ userId: 'another-user' },
|
|
])
|
|
expect(wishlistQuerySchema.safeParse(query).success).toBe(false);
|
|
expect(wishlistSaveSchema.parse(undefined)).toEqual({});
|
|
expect(
|
|
wishlistSaveSchema.safeParse({ userId: 'another-user' }).success,
|
|
).toBe(false);
|
|
});
|
|
});
|