Includes MFA-capable authentication, session and CSRF security, password recovery, listing lifecycle and ownership rules, inventory image metadata, local ImageStorage, migrations, tests, and implementation status documentation. Verification: npm test (62 passing) and integration suite (14 passing).
34 lines
956 B
JavaScript
34 lines
956 B
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { createProductService } from '../../src/modules/products/services/product-service.js';
|
|
|
|
test('creates seller-scoped slugs and increments duplicate names', async () => {
|
|
const createdProducts = [];
|
|
const productService = createProductService({
|
|
productRepository: {
|
|
async create(product) {
|
|
createdProducts.push(product);
|
|
return product;
|
|
},
|
|
async findBySellerIdAndSlug(sellerId, slug) {
|
|
return (
|
|
createdProducts.find(
|
|
(product) => product.sellerId === sellerId && product.slug === slug,
|
|
) ?? null
|
|
);
|
|
},
|
|
},
|
|
});
|
|
|
|
const input = {
|
|
name: 'Pikachu Plush',
|
|
categoryId: 'category-id',
|
|
sellerId: 'seller-id',
|
|
};
|
|
|
|
await productService.create(input);
|
|
const secondProduct = await productService.create(input);
|
|
|
|
assert.equal(secondProduct.slug, 'pikachu-plush-2');
|
|
}); |