This commit is contained in:
seb
2026-10-04 21:22:05 +02:00
parent 0268583ae3
commit 4718cb5726
48 changed files with 758 additions and 758 deletions

View File

@@ -35,65 +35,65 @@ async function run() {
const art1 = await store.article.createUnderParent({
googleAuthId,
parentId: company.rootCategoryId,
name: 'Root Father Shirt',
name: 'Root Parent Shirt',
});
const art1Res = await store.article.getBySku(googleAuthId, art1.sku);
assert.equal(art1Res.article.slug, 'root-father-shirt', `Expected slug 'root-father-shirt', got '${art1Res.article.slug}'`);
assert.equal(art1Res.article.slug, 'root-parent-shirt', `Expected slug 'root-parent-shirt', got '${art1Res.article.slug}'`);
const art2 = await store.article.createUnderParent({
googleAuthId,
parentId: company.rootCategoryId,
name: 'Root Father Shirt',
name: 'Root Parent Shirt',
});
const art2Res = await store.article.getBySku(googleAuthId, art2.sku);
assert.equal(art2Res.article.slug, 'root-father-shirt-2', `Expected slug 'root-father-shirt-2', got '${art2Res.article.slug}'`);
assert.equal(art2Res.article.slug, 'root-parent-shirt-2', `Expected slug 'root-parent-shirt-2', got '${art2Res.article.slug}'`);
const art3 = await store.article.createUnderParent({
googleAuthId,
parentId: company.rootCategoryId,
name: 'Root Father Shirt',
name: 'Root Parent Shirt',
});
const art3Res = await store.article.getBySku(googleAuthId, art3.sku);
assert.equal(art3Res.article.slug, 'root-father-shirt-3', `Expected slug 'root-father-shirt-3', got '${art3Res.article.slug}'`);
assert.equal(art3Res.article.slug, 'root-parent-shirt-3', `Expected slug 'root-parent-shirt-3', got '${art3Res.article.slug}'`);
console.log('2. Testing updateBySku self-collision and renaming...');
// Update art2 without changing name
await store.article.updateBySku(googleAuthId, art2.sku, { unitamount: 2 });
let updated2 = await store.article.getBySku(googleAuthId, art2.sku);
assert.equal(updated2.article.slug, 'root-father-shirt-2', `Expected unchanged slug, got '${updated2.article.slug}'`);
assert.equal(updated2.article.slug, 'root-parent-shirt-2', `Expected unchanged slug, got '${updated2.article.slug}'`);
// Update art2 with same name
await store.article.updateBySku(googleAuthId, art2.sku, { name: 'Root Father Shirt' });
await store.article.updateBySku(googleAuthId, art2.sku, { name: 'Root Parent Shirt' });
updated2 = await store.article.getBySku(googleAuthId, art2.sku);
assert.equal(updated2.article.slug, 'root-father-shirt-2', `Expected slug to remain 'root-father-shirt-2', got '${updated2.article.slug}'`);
assert.equal(updated2.article.slug, 'root-parent-shirt-2', `Expected slug to remain 'root-parent-shirt-2', got '${updated2.article.slug}'`);
// Rename art2 to something else
await store.article.updateBySku(googleAuthId, art2.sku, { name: 'Unique Shirt' });
updated2 = await store.article.getBySku(googleAuthId, art2.sku);
assert.equal(updated2.article.slug, 'unique-shirt', `Expected slug 'unique-shirt', got '${updated2.article.slug}'`);
// Rename art3 to 'Root Father Shirt' again: should take root-father-shirt-2 now that it is free
await store.article.updateBySku(googleAuthId, art3.sku, { name: 'Root Father Shirt' });
// Rename art3 to 'Root Parent Shirt' again: should take root-parent-shirt-2 now that it is free
await store.article.updateBySku(googleAuthId, art3.sku, { name: 'Root Parent Shirt' });
const updated3 = await store.article.getBySku(googleAuthId, art3.sku);
assert.equal(updated3.article.slug, 'root-father-shirt-2', `Expected slug to fill gap 'root-father-shirt-2', got '${updated3.article.slug}'`);
assert.equal(updated3.article.slug, 'root-parent-shirt-2', `Expected slug to fill gap 'root-parent-shirt-2', got '${updated3.article.slug}'`);
console.log('3. Testing addChild duplicate slugs...');
const attrName = await store.attributename.create(googleAuthId, { name: 'Größe' });
await store.article.toggleFather(googleAuthId, art1.sku, {
isFather: true,
await store.article.toggleParent(googleAuthId, art1.sku, {
isParent: true,
attributeNameId: attrName.id,
});
const child1 = await store.article.addChild(googleAuthId, art1.sku, {
value: 'M',
});
assert.equal(child1.article.slug, 'root-father-shirt-m', `Expected child slug 'root-father-shirt-m', got '${child1.article.slug}'`);
assert.equal(child1.article.slug, 'root-parent-shirt-m', `Expected child slug 'root-parent-shirt-m', got '${child1.article.slug}'`);
// Add another child with name that yields same slug
const child2 = await store.article.addChild(googleAuthId, art1.sku, {
value: 'L',
name: 'Root Father Shirt - M',
name: 'Root Parent Shirt - M',
});
assert.equal(child2.article.slug, 'root-father-shirt-m-2', `Expected child slug 'root-father-shirt-m-2', got '${child2.article.slug}'`);
assert.equal(child2.article.slug, 'root-parent-shirt-m-2', `Expected child slug 'root-parent-shirt-m-2', got '${child2.article.slug}'`);
console.log('4. Testing importRows duplicate slugs in same batch...');
const importRes = await store.article.importRows({
@@ -128,10 +128,10 @@ async function run() {
const artCompany2 = await store.article.createUnderParent({
googleAuthId,
parentId: company2.rootCategoryId,
name: 'Root Father Shirt',
name: 'Root Parent Shirt',
});
const artCompany2Detail = await store.article.getBySku(googleAuthId, artCompany2.sku);
assert.equal(artCompany2Detail.article.slug, 'root-father-shirt', `Expected 'root-father-shirt' in company 2, got '${artCompany2Detail.article.slug}'`);
assert.equal(artCompany2Detail.article.slug, 'root-parent-shirt', `Expected 'root-parent-shirt' in company 2, got '${artCompany2Detail.article.slug}'`);
console.log('✅ ALL SLUG TESTS PASSED');
} finally {