u
This commit is contained in:
@@ -6,7 +6,7 @@ import LibDashStore from '../src/index.js';
|
||||
import { BetterSqlite3Provider } from '../src/providers/sqlite3/index.js';
|
||||
|
||||
async function run() {
|
||||
console.log('--- Testing Father History & AttributeValue Shapes ---');
|
||||
console.log('--- Testing Parent History & AttributeValue Shapes ---');
|
||||
|
||||
const tempDir = mkdtempSync(join(tmpdir(), 'test-hist-attr-'));
|
||||
const dbFile = join(tempDir, 'test.db');
|
||||
@@ -31,11 +31,11 @@ async function run() {
|
||||
});
|
||||
await store.google_auth.setSelectedCompany(googleAuthId, company.id);
|
||||
|
||||
console.log('1. Testing setFatherBySku history logging...');
|
||||
const father = await store.article.createUnderParent({
|
||||
console.log('1. Testing setParentBySku history logging...');
|
||||
const parent = await store.article.createUnderParent({
|
||||
googleAuthId,
|
||||
parentId: company.rootCategoryId,
|
||||
name: 'Father Shirt',
|
||||
name: 'Parent Shirt',
|
||||
});
|
||||
const child = await store.article.createUnderParent({
|
||||
googleAuthId,
|
||||
@@ -44,19 +44,19 @@ async function run() {
|
||||
});
|
||||
|
||||
// Check history before linking
|
||||
let fatherHist = await store.article.getHistoryBySku(googleAuthId, father.sku);
|
||||
assert.equal(fatherHist.length, 1);
|
||||
assert.match(fatherHist[0].text, /angelegt/);
|
||||
let parentHist = await store.article.getHistoryBySku(googleAuthId, parent.sku);
|
||||
assert.equal(parentHist.length, 1);
|
||||
assert.match(parentHist[0].text, /angelegt/);
|
||||
|
||||
// Link child to father
|
||||
await store.article.setFatherBySku(googleAuthId, child.sku, father.sku);
|
||||
// Link child to parent
|
||||
await store.article.setParentBySku(googleAuthId, child.sku, parent.sku);
|
||||
|
||||
// Father history must now contain the conversion entry and the child entry!
|
||||
fatherHist = await store.article.getHistoryBySku(googleAuthId, father.sku);
|
||||
const hasConversion = fatherHist.some((h) => h.text.includes('Artikel zu Vaterartikel konvertiert'));
|
||||
const hasVariantAdded = fatherHist.some((h) => h.text.includes('hinzugefügt'));
|
||||
assert.ok(hasConversion, `Father history missing conversion row: ${JSON.stringify(fatherHist)}`);
|
||||
assert.ok(hasVariantAdded, `Father history missing variant added row: ${JSON.stringify(fatherHist)}`);
|
||||
// Parent history must now contain the conversion entry and the child entry!
|
||||
parentHist = await store.article.getHistoryBySku(googleAuthId, parent.sku);
|
||||
const hasConversion = parentHist.some((h) => h.text.includes('Artikel zu Vaterartikel konvertiert'));
|
||||
const hasVariantAdded = parentHist.some((h) => h.text.includes('hinzugefügt'));
|
||||
assert.ok(hasConversion, `Parent history missing conversion row: ${JSON.stringify(parentHist)}`);
|
||||
assert.ok(hasVariantAdded, `Parent history missing variant added row: ${JSON.stringify(parentHist)}`);
|
||||
|
||||
// Child history must contain the assignment entry
|
||||
const childHist = await store.article.getHistoryBySku(googleAuthId, child.sku);
|
||||
@@ -67,15 +67,15 @@ async function run() {
|
||||
const importRes = await store.article.importRows({
|
||||
googleAuthId,
|
||||
rows: [
|
||||
{ sku: 'IMP-FATHER', name: 'Imported Father', parentId: company.rootCategoryId },
|
||||
{ sku: 'IMP-CHILD', name: 'Imported Child', parentId: company.rootCategoryId, fatherSku: 'IMP-FATHER' },
|
||||
{ sku: 'IMP-PARENT', name: 'Imported Parent', parentId: company.rootCategoryId },
|
||||
{ sku: 'IMP-CHILD', name: 'Imported Child', parentId: company.rootCategoryId, parentSku: 'IMP-PARENT' },
|
||||
],
|
||||
});
|
||||
assert.equal(importRes.errors.length, 0);
|
||||
|
||||
const impFatherHist = await store.article.getHistoryBySku(googleAuthId, 'IMP-FATHER');
|
||||
const impHasConversion = impFatherHist.some((h) => h.text.includes('Artikel zu Vaterartikel konvertiert'));
|
||||
assert.ok(impHasConversion, `Imported father missing conversion row: ${JSON.stringify(impFatherHist)}`);
|
||||
const impParentHist = await store.article.getHistoryBySku(googleAuthId, 'IMP-PARENT');
|
||||
const impHasConversion = impParentHist.some((h) => h.text.includes('Artikel zu Vaterartikel konvertiert'));
|
||||
assert.ok(impHasConversion, `Imported parent missing conversion row: ${JSON.stringify(impParentHist)}`);
|
||||
|
||||
console.log('3. Testing flexible attributevalue request shapes in setByArticleSku...');
|
||||
const attrName = await store.attributename.create(googleAuthId, { name: 'Farbe' });
|
||||
|
||||
Reference in New Issue
Block a user