feat: add public product catalog boundary
This commit is contained in:
@@ -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,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user