feat: add public product catalog boundary

This commit is contained in:
2026-09-08 18:20:04 -04:00
parent f29629c712
commit 43f4f69894
11 changed files with 233 additions and 9 deletions
@@ -0,0 +1,42 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createPublicProductService } from '../../src/modules/products/services/public-product-service.js';
test('returns only a publicly visible product', async () => {
const service = createPublicProductService({
productRepository: {
async findPublicBySlug(slug) {
assert.equal(slug, 'pikachu-plush');
return {
id: 'product-1',
sellerId: 'private-seller-id',
categoryId: 'category-1',
name: 'Pikachu Plush',
slug,
description: 'A friendly plush.',
};
},
},
});
assert.deepEqual(await service.getBySlug('pikachu-plush'), {
id: 'product-1',
sellerId: 'private-seller-id',
categoryId: 'category-1',
name: 'Pikachu Plush',
slug: 'pikachu-plush',
description: 'A friendly plush.',
});
});
test('returns a not-found application error for non-public products', async () => {
const service = createPublicProductService({
productRepository: { async findPublicBySlug() { return null; } },
});
await assert.rejects(
() => service.getBySlug('hidden-product'),
(error) => error.code === 'PRODUCT_NOT_FOUND' && error.statusCode === 404,
);
});