@open-mercato/sync-akeneo 0.9.1-develop.7574.1.837288eec1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/sync_akeneo/cli.js +2 -19
- package/dist/modules/sync_akeneo/cli.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/catalog-importer.js +42 -25
- package/dist/modules/sync_akeneo/lib/catalog-importer.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/first-import.js +1 -2
- package/dist/modules/sync_akeneo/lib/first-import.js.map +2 -2
- package/jest.config.cjs +1 -1
- package/package.json +12 -9
- package/src/modules/sync_akeneo/__tests__/catalog-importer.custom-fields.test.ts +419 -0
- package/src/modules/sync_akeneo/__tests__/catalog-importer.media.test.ts +193 -0
- package/src/modules/sync_akeneo/__tests__/catalog-importer.numeric-values.test.ts +292 -0
- package/src/modules/sync_akeneo/__tests__/catalog-importer.prices.test.ts +47 -0
- package/src/modules/sync_akeneo/__tests__/first-import.test.ts +82 -0
- package/src/modules/sync_akeneo/cli.ts +2 -24
- package/src/modules/sync_akeneo/i18n/de.json +10 -0
- package/src/modules/sync_akeneo/i18n/en.json +10 -0
- package/src/modules/sync_akeneo/i18n/es.json +10 -0
- package/src/modules/sync_akeneo/i18n/ko.json +10 -0
- package/src/modules/sync_akeneo/i18n/pl.json +10 -0
- package/src/modules/sync_akeneo/lib/catalog-importer.ts +51 -28
- package/src/modules/sync_akeneo/lib/first-import.ts +0 -1
|
@@ -97,8 +97,7 @@ async function runAkeneoFirstImportSequence(params) {
|
|
|
97
97
|
integrationId: "sync_akeneo",
|
|
98
98
|
entityType,
|
|
99
99
|
direction: "import",
|
|
100
|
-
triggeredBy: scope.userId ?? null
|
|
101
|
-
batchSize: 100
|
|
100
|
+
triggeredBy: scope.userId ?? null
|
|
102
101
|
}
|
|
103
102
|
})).run;
|
|
104
103
|
await progressService.updateProgress(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sync_akeneo/lib/first-import.ts"],
|
|
4
|
-
"sourcesContent": ["import { setTimeout as sleep } from 'node:timers/promises'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { AwilixContainer } from 'awilix'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { ProgressJob } from '@open-mercato/core/modules/progress/data/entities'\nimport type { ProgressService, ProgressServiceContext } from '@open-mercato/core/modules/progress/lib/progressService'\nimport type { SyncRunService } from '@open-mercato/core/modules/data_sync/lib/sync-run-service'\nimport { startDataSyncRun } from '@open-mercato/core/modules/data_sync/lib/start-run'\n\nexport const AKENEO_FIRST_IMPORT_QUEUE = 'sync-akeneo-first-import'\n\nconst FIRST_IMPORT_STEPS = ['categories', 'attributes', 'products'] as const\n\ntype FirstImportStep = (typeof FIRST_IMPORT_STEPS)[number]\n\nexport type AkeneoFirstImportScope = {\n organizationId: string\n tenantId: string\n userId?: string | null\n}\n\nexport type AkeneoFirstImportJobPayload = {\n progressJobId: string\n scope: AkeneoFirstImportScope\n}\n\nexport type FirstImportSequenceStatus = {\n progressJobId: string\n status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled'\n currentStep: FirstImportStep | null\n currentRunId: string | null\n currentRunProgressJobId: string | null\n currentRunStatus: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | null\n progressPercent: number | null\n processedCount: number | null\n totalCount: number | null\n errorMessage: string | null\n}\n\nfunction buildProgressContext(scope: AkeneoFirstImportScope): ProgressServiceContext {\n return {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n userId: scope.userId,\n }\n}\n\nfunction buildSequenceMeta(input?: Partial<{\n currentStep: FirstImportStep | null\n currentRunId: string | null\n currentRunProgressJobId: string | null\n currentRunStatus: string | null\n currentRunProgressPercent: number | null\n currentRunProcessedCount: number | null\n currentRunTotalCount: number | null\n}>): Record<string, unknown> {\n return {\n integrationId: 'sync_akeneo',\n workflow: 'first_import',\n hiddenFromTopBar: true,\n currentStep: input?.currentStep ?? null,\n currentRunId: input?.currentRunId ?? null,\n currentRunProgressJobId: input?.currentRunProgressJobId ?? null,\n currentRunStatus: input?.currentRunStatus ?? null,\n currentRunProgressPercent: input?.currentRunProgressPercent ?? null,\n currentRunProcessedCount: input?.currentRunProcessedCount ?? null,\n currentRunTotalCount: input?.currentRunTotalCount ?? null,\n }\n}\n\nfunction readString(value: unknown): string | null {\n return typeof value === 'string' && value.trim().length > 0 ? value : null\n}\n\nfunction readNumber(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null\n}\n\nfunction buildSequenceStatus(job: ProgressJob): FirstImportSequenceStatus {\n const meta = (job.meta && typeof job.meta === 'object') ? job.meta : null\n const currentStep = readString(meta?.currentStep)\n const currentRunStatus = readString(meta?.currentRunStatus)\n return {\n progressJobId: job.id,\n status: job.status,\n currentStep: currentStep === 'categories' || currentStep === 'attributes' || currentStep === 'products'\n ? currentStep\n : null,\n currentRunId: readString(meta?.currentRunId),\n currentRunProgressJobId: readString(meta?.currentRunProgressJobId),\n currentRunStatus: currentRunStatus === 'pending'\n || currentRunStatus === 'running'\n || currentRunStatus === 'completed'\n || currentRunStatus === 'failed'\n || currentRunStatus === 'cancelled'\n ? currentRunStatus\n : null,\n progressPercent: readNumber(meta?.currentRunProgressPercent),\n processedCount: readNumber(meta?.currentRunProcessedCount),\n totalCount: readNumber(meta?.currentRunTotalCount),\n errorMessage: job.errorMessage ?? null,\n }\n}\n\nexport async function findLatestAkeneoFirstImportJob(\n em: EntityManager,\n scope: Pick<AkeneoFirstImportScope, 'organizationId' | 'tenantId'>,\n): Promise<ProgressJob | null> {\n const [job] = await findWithDecryption(\n em,\n ProgressJob,\n {\n jobType: 'sync_akeneo.first_import',\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n status: { $in: ['pending', 'running', 'failed'] },\n },\n {\n limit: 1,\n orderBy: { createdAt: 'DESC' },\n },\n scope,\n )\n\n return job ?? null\n}\n\nexport async function getAkeneoFirstImportStatus(params: {\n container: AwilixContainer\n scope: Pick<AkeneoFirstImportScope, 'organizationId' | 'tenantId'>\n}): Promise<FirstImportSequenceStatus | null> {\n const em = params.container.resolve('em') as EntityManager\n const job = await findLatestAkeneoFirstImportJob(em, params.scope)\n return job ? buildSequenceStatus(job) : null\n}\n\nexport async function runAkeneoFirstImportSequence(params: {\n container: AwilixContainer\n progressJobId: string\n scope: AkeneoFirstImportScope\n}): Promise<void> {\n const { container, progressJobId, scope } = params\n const em = container.resolve('em') as EntityManager\n const progressService = container.resolve('progressService') as ProgressService\n const syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const progressContext = buildProgressContext(scope)\n\n await progressService.startJob(progressJobId, progressContext)\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: 0,\n meta: buildSequenceMeta(),\n },\n progressContext,\n )\n\n for (const [stepIndex, entityType] of FIRST_IMPORT_STEPS.entries()) {\n const overlap = await syncRunService.findRunningOverlap('sync_akeneo', entityType, 'import', scope)\n const run = overlap ?? (await startDataSyncRun({\n syncRunService,\n progressService,\n scope,\n input: {\n integrationId: 'sync_akeneo',\n entityType,\n direction: 'import',\n triggeredBy: scope.userId ?? null,\n
|
|
5
|
-
"mappings": "AAAA,SAAS,cAAc,aAAa;AAGpC,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAG5B,SAAS,wBAAwB;AAE1B,MAAM,4BAA4B;AAEzC,MAAM,qBAAqB,CAAC,cAAc,cAAc,UAAU;AA4BlE,SAAS,qBAAqB,OAAuD;AACnF,SAAO;AAAA,IACL,UAAU,MAAM;AAAA,IAChB,gBAAgB,MAAM;AAAA,IACtB,QAAQ,MAAM;AAAA,EAChB;AACF;AAEA,SAAS,kBAAkB,OAQE;AAC3B,SAAO;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,IACV,kBAAkB;AAAA,IAClB,aAAa,OAAO,eAAe;AAAA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MAAM;AAAA,MAChB,QAAQ,EAAE,KAAK,CAAC,WAAW,WAAW,QAAQ,EAAE;AAAA,IAClD;AAAA,IACA;AAAA,MACE,OAAO;AAAA,MACP,SAAS,EAAE,WAAW,OAAO;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AAEA,SAAO,OAAO;AAChB;AAEA,eAAsB,2BAA2B,QAGH;AAC5C,QAAM,KAAK,OAAO,UAAU,QAAQ,IAAI;AACxC,QAAM,MAAM,MAAM,+BAA+B,IAAI,OAAO,KAAK;AACjE,SAAO,MAAM,oBAAoB,GAAG,IAAI;AAC1C;AAEA,eAAsB,6BAA6B,QAIjC;AAChB,QAAM,EAAE,WAAW,eAAe,MAAM,IAAI;AAC5C,QAAM,KAAK,UAAU,QAAQ,IAAI;AACjC,QAAM,kBAAkB,UAAU,QAAQ,iBAAiB;AAC3D,QAAM,iBAAiB,UAAU,QAAQ,oBAAoB;AAC7D,QAAM,kBAAkB,qBAAqB,KAAK;AAElD,QAAM,gBAAgB,SAAS,eAAe,eAAe;AAC7D,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,MACE,YAAY,mBAAmB;AAAA,MAC/B,gBAAgB;AAAA,MAChB,MAAM,kBAAkB;AAAA,IAC1B;AAAA,IACA;AAAA,EACF;AAEA,aAAW,CAAC,WAAW,UAAU,KAAK,mBAAmB,QAAQ,GAAG;AAClE,UAAM,UAAU,MAAM,eAAe,mBAAmB,eAAe,YAAY,UAAU,KAAK;AAClG,UAAM,MAAM,YAAY,MAAM,iBAAiB;AAAA,MAC7C;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,QACL,eAAe;AAAA,QACf;AAAA,QACA,WAAW;AAAA,QACX,aAAa,MAAM,UAAU;AAAA,
|
|
4
|
+
"sourcesContent": ["import { setTimeout as sleep } from 'node:timers/promises'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { AwilixContainer } from 'awilix'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { ProgressJob } from '@open-mercato/core/modules/progress/data/entities'\nimport type { ProgressService, ProgressServiceContext } from '@open-mercato/core/modules/progress/lib/progressService'\nimport type { SyncRunService } from '@open-mercato/core/modules/data_sync/lib/sync-run-service'\nimport { startDataSyncRun } from '@open-mercato/core/modules/data_sync/lib/start-run'\n\nexport const AKENEO_FIRST_IMPORT_QUEUE = 'sync-akeneo-first-import'\n\nconst FIRST_IMPORT_STEPS = ['categories', 'attributes', 'products'] as const\n\ntype FirstImportStep = (typeof FIRST_IMPORT_STEPS)[number]\n\nexport type AkeneoFirstImportScope = {\n organizationId: string\n tenantId: string\n userId?: string | null\n}\n\nexport type AkeneoFirstImportJobPayload = {\n progressJobId: string\n scope: AkeneoFirstImportScope\n}\n\nexport type FirstImportSequenceStatus = {\n progressJobId: string\n status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled'\n currentStep: FirstImportStep | null\n currentRunId: string | null\n currentRunProgressJobId: string | null\n currentRunStatus: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | null\n progressPercent: number | null\n processedCount: number | null\n totalCount: number | null\n errorMessage: string | null\n}\n\nfunction buildProgressContext(scope: AkeneoFirstImportScope): ProgressServiceContext {\n return {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n userId: scope.userId,\n }\n}\n\nfunction buildSequenceMeta(input?: Partial<{\n currentStep: FirstImportStep | null\n currentRunId: string | null\n currentRunProgressJobId: string | null\n currentRunStatus: string | null\n currentRunProgressPercent: number | null\n currentRunProcessedCount: number | null\n currentRunTotalCount: number | null\n}>): Record<string, unknown> {\n return {\n integrationId: 'sync_akeneo',\n workflow: 'first_import',\n hiddenFromTopBar: true,\n currentStep: input?.currentStep ?? null,\n currentRunId: input?.currentRunId ?? null,\n currentRunProgressJobId: input?.currentRunProgressJobId ?? null,\n currentRunStatus: input?.currentRunStatus ?? null,\n currentRunProgressPercent: input?.currentRunProgressPercent ?? null,\n currentRunProcessedCount: input?.currentRunProcessedCount ?? null,\n currentRunTotalCount: input?.currentRunTotalCount ?? null,\n }\n}\n\nfunction readString(value: unknown): string | null {\n return typeof value === 'string' && value.trim().length > 0 ? value : null\n}\n\nfunction readNumber(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null\n}\n\nfunction buildSequenceStatus(job: ProgressJob): FirstImportSequenceStatus {\n const meta = (job.meta && typeof job.meta === 'object') ? job.meta : null\n const currentStep = readString(meta?.currentStep)\n const currentRunStatus = readString(meta?.currentRunStatus)\n return {\n progressJobId: job.id,\n status: job.status,\n currentStep: currentStep === 'categories' || currentStep === 'attributes' || currentStep === 'products'\n ? currentStep\n : null,\n currentRunId: readString(meta?.currentRunId),\n currentRunProgressJobId: readString(meta?.currentRunProgressJobId),\n currentRunStatus: currentRunStatus === 'pending'\n || currentRunStatus === 'running'\n || currentRunStatus === 'completed'\n || currentRunStatus === 'failed'\n || currentRunStatus === 'cancelled'\n ? currentRunStatus\n : null,\n progressPercent: readNumber(meta?.currentRunProgressPercent),\n processedCount: readNumber(meta?.currentRunProcessedCount),\n totalCount: readNumber(meta?.currentRunTotalCount),\n errorMessage: job.errorMessage ?? null,\n }\n}\n\nexport async function findLatestAkeneoFirstImportJob(\n em: EntityManager,\n scope: Pick<AkeneoFirstImportScope, 'organizationId' | 'tenantId'>,\n): Promise<ProgressJob | null> {\n const [job] = await findWithDecryption(\n em,\n ProgressJob,\n {\n jobType: 'sync_akeneo.first_import',\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n status: { $in: ['pending', 'running', 'failed'] },\n },\n {\n limit: 1,\n orderBy: { createdAt: 'DESC' },\n },\n scope,\n )\n\n return job ?? null\n}\n\nexport async function getAkeneoFirstImportStatus(params: {\n container: AwilixContainer\n scope: Pick<AkeneoFirstImportScope, 'organizationId' | 'tenantId'>\n}): Promise<FirstImportSequenceStatus | null> {\n const em = params.container.resolve('em') as EntityManager\n const job = await findLatestAkeneoFirstImportJob(em, params.scope)\n return job ? buildSequenceStatus(job) : null\n}\n\nexport async function runAkeneoFirstImportSequence(params: {\n container: AwilixContainer\n progressJobId: string\n scope: AkeneoFirstImportScope\n}): Promise<void> {\n const { container, progressJobId, scope } = params\n const em = container.resolve('em') as EntityManager\n const progressService = container.resolve('progressService') as ProgressService\n const syncRunService = container.resolve('dataSyncRunService') as SyncRunService\n const progressContext = buildProgressContext(scope)\n\n await progressService.startJob(progressJobId, progressContext)\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: 0,\n meta: buildSequenceMeta(),\n },\n progressContext,\n )\n\n for (const [stepIndex, entityType] of FIRST_IMPORT_STEPS.entries()) {\n const overlap = await syncRunService.findRunningOverlap('sync_akeneo', entityType, 'import', scope)\n const run = overlap ?? (await startDataSyncRun({\n syncRunService,\n progressService,\n scope,\n input: {\n integrationId: 'sync_akeneo',\n entityType,\n direction: 'import',\n triggeredBy: scope.userId ?? null,\n },\n })).run\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: run.id,\n currentRunProgressJobId: run.progressJobId ?? null,\n currentRunStatus: run.status,\n currentRunProgressPercent: null,\n currentRunProcessedCount: 0,\n currentRunTotalCount: null,\n }),\n },\n progressContext,\n )\n\n while (true) {\n em.clear()\n const currentRun = await syncRunService.getRun(run.id, scope)\n if (!currentRun) {\n throw new Error(`Sync run ${run.id} could not be loaded`)\n }\n\n const currentRunJob = currentRun.progressJobId\n ? await progressService.getJob(currentRun.progressJobId, progressContext)\n : null\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: currentRun.id,\n currentRunProgressJobId: currentRun.progressJobId ?? null,\n currentRunStatus: currentRun.status,\n currentRunProgressPercent: currentRunJob?.totalCount ? currentRunJob.progressPercent : null,\n currentRunProcessedCount: currentRunJob?.processedCount ?? null,\n currentRunTotalCount: currentRunJob?.totalCount ?? null,\n }),\n },\n progressContext,\n )\n\n if (currentRun.status === 'completed') {\n break\n }\n\n if (currentRun.status === 'failed') {\n throw new Error(currentRun.lastError ?? `${entityType} sync failed`)\n }\n\n if (currentRun.status === 'cancelled') {\n throw new Error(`${entityType} sync was cancelled`)\n }\n\n await sleep(1500)\n }\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: FIRST_IMPORT_STEPS.length,\n processedCount: stepIndex + 1,\n meta: buildSequenceMeta({\n currentStep: entityType,\n currentRunId: run.id,\n currentRunProgressJobId: run.progressJobId ?? null,\n currentRunStatus: 'completed',\n currentRunProgressPercent: 100,\n currentRunProcessedCount: null,\n currentRunTotalCount: null,\n }),\n },\n progressContext,\n )\n }\n\n await progressService.completeJob(\n progressJobId,\n {\n resultSummary: {\n message: 'The first full Akeneo import finished successfully.',\n },\n },\n progressContext,\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc,aAAa;AAGpC,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAG5B,SAAS,wBAAwB;AAE1B,MAAM,4BAA4B;AAEzC,MAAM,qBAAqB,CAAC,cAAc,cAAc,UAAU;AA4BlE,SAAS,qBAAqB,OAAuD;AACnF,SAAO;AAAA,IACL,UAAU,MAAM;AAAA,IAChB,gBAAgB,MAAM;AAAA,IACtB,QAAQ,MAAM;AAAA,EAChB;AACF;AAEA,SAAS,kBAAkB,OAQE;AAC3B,SAAO;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,IACV,kBAAkB;AAAA,IAClB,aAAa,OAAO,eAAe;AAAA,IACnC,cAAc,OAAO,gBAAgB;AAAA,IACrC,yBAAyB,OAAO,2BAA2B;AAAA,IAC3D,kBAAkB,OAAO,oBAAoB;AAAA,IAC7C,2BAA2B,OAAO,6BAA6B;AAAA,IAC/D,0BAA0B,OAAO,4BAA4B;AAAA,IAC7D,sBAAsB,OAAO,wBA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MACH;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,MACE,eAAe;AAAA,QACb,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/jest.config.cjs
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = {
|
|
|
28
28
|
],
|
|
29
29
|
},
|
|
30
30
|
transformIgnorePatterns: [
|
|
31
|
-
'node_modules/(?!(
|
|
31
|
+
'node_modules/(?!(sanitize-html|htmlparser2|domhandler|domutils|dom-serializer|domelementtype|entities|@mikro-orm|kysely|ai|@ai-sdk|ai-sdk-ollama|@workflow|@standard-schema|@tanstack/react-table|@tanstack/table-core|@tanstack/react-store|@tanstack/store)/)',
|
|
32
32
|
],
|
|
33
33
|
testMatch: ['<rootDir>/src/**/__tests__/**/*.test.(ts|tsx)'],
|
|
34
34
|
passWithNoTests: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/sync-akeneo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,26 +53,30 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@open-mercato/core": "0.
|
|
57
|
-
"@open-mercato/ui": "0.
|
|
56
|
+
"@open-mercato/core": "0.10.0",
|
|
57
|
+
"@open-mercato/ui": "0.10.0",
|
|
58
58
|
"node-html-markdown": "^2.0.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@mikro-orm/postgresql": "^7.0.14",
|
|
62
|
-
"@open-mercato/
|
|
62
|
+
"@open-mercato/ai-assistant": "0.10.0",
|
|
63
|
+
"@open-mercato/shared": "0.10.0",
|
|
63
64
|
"react": "^19.0.0",
|
|
64
|
-
"react-dom": "^19.0.0"
|
|
65
|
+
"react-dom": "^19.0.0",
|
|
66
|
+
"react-is": ">=18.0.0"
|
|
65
67
|
},
|
|
66
68
|
"devDependencies": {
|
|
67
|
-
"@open-mercato/
|
|
69
|
+
"@open-mercato/ai-assistant": "0.10.0",
|
|
70
|
+
"@open-mercato/shared": "0.10.0",
|
|
68
71
|
"@types/jest": "^30.0.0",
|
|
69
72
|
"@types/react": "^19.2.18",
|
|
70
73
|
"@types/react-dom": "^19.2.5",
|
|
71
74
|
"esbuild": "^0.28.2",
|
|
72
|
-
"glob": "^
|
|
75
|
+
"glob": "^14.0.6",
|
|
73
76
|
"jest": "^30.4.2",
|
|
74
77
|
"react": "19.2.8",
|
|
75
78
|
"react-dom": "19.2.8",
|
|
79
|
+
"react-is": "^19.2.8",
|
|
76
80
|
"ts-jest": "^29.4.12",
|
|
77
81
|
"typescript": "7.0.2"
|
|
78
82
|
},
|
|
@@ -83,6 +87,5 @@
|
|
|
83
87
|
"type": "git",
|
|
84
88
|
"url": "https://github.com/open-mercato/open-mercato",
|
|
85
89
|
"directory": "packages/sync-akeneo"
|
|
86
|
-
}
|
|
87
|
-
"stableVersion": "0.9.0"
|
|
90
|
+
}
|
|
88
91
|
}
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { MAX_CUSTOM_FIELD_KEYS_PER_RECORD } from '@open-mercato/shared/modules/entities/validation'
|
|
2
|
+
import { createAkeneoImporter } from '../lib/catalog-importer'
|
|
3
|
+
import {
|
|
4
|
+
buildDefaultAkeneoMapping,
|
|
5
|
+
type AkeneoAttribute,
|
|
6
|
+
type AkeneoCustomFieldMapping,
|
|
7
|
+
type AkeneoDataMapping,
|
|
8
|
+
type AkeneoProduct,
|
|
9
|
+
type AkeneoValues,
|
|
10
|
+
} from '../lib/shared'
|
|
11
|
+
|
|
12
|
+
const mockContainerResolve = jest.fn()
|
|
13
|
+
const mockFindOneWithDecryption = jest.fn()
|
|
14
|
+
const mockFindWithDecryption = jest.fn()
|
|
15
|
+
const mockLoadCustomFieldSnapshot = jest.fn()
|
|
16
|
+
|
|
17
|
+
jest.mock('@open-mercato/shared/lib/commands/customFieldSnapshots', () => ({
|
|
18
|
+
loadCustomFieldSnapshot: (...args: unknown[]) => mockLoadCustomFieldSnapshot(...args),
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
jest.mock('@open-mercato/shared/lib/di/container', () => ({
|
|
22
|
+
createRequestContainer: jest.fn(async () => ({
|
|
23
|
+
resolve: mockContainerResolve,
|
|
24
|
+
})),
|
|
25
|
+
}))
|
|
26
|
+
|
|
27
|
+
jest.mock('@open-mercato/shared/lib/encryption/find', () => ({
|
|
28
|
+
findOneWithDecryption: (...args: unknown[]) => mockFindOneWithDecryption(...args),
|
|
29
|
+
findWithDecryption: (...args: unknown[]) => mockFindWithDecryption(...args),
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
jest.mock('@open-mercato/core/modules/entities/lib/field-definitions', () => ({
|
|
33
|
+
ensureCustomFieldDefinitions: jest.fn(async () => undefined),
|
|
34
|
+
}))
|
|
35
|
+
|
|
36
|
+
jest.mock('@open-mercato/core/modules/entities/api/definitions.cache', () => ({
|
|
37
|
+
invalidateDefinitionsCache: jest.fn(async () => undefined),
|
|
38
|
+
}))
|
|
39
|
+
|
|
40
|
+
const scope = { organizationId: 'org-1', tenantId: 'tenant-1' }
|
|
41
|
+
const PRODUCT_ENTITY_ID = 'catalog:catalog_product'
|
|
42
|
+
const VARIANT_ENTITY_ID = 'catalog:catalog_product_variant'
|
|
43
|
+
const MODEL_CODE = 'jacket'
|
|
44
|
+
const FAMILY_CODE = 'outdoor'
|
|
45
|
+
const FAMILY_VARIANT_CODE = 'outdoor_by_batch'
|
|
46
|
+
|
|
47
|
+
const SPEC_CODES = Array.from({ length: MAX_CUSTOM_FIELD_KEYS_PER_RECORD + 2 }, (_, index) => `spec_${index + 1}`)
|
|
48
|
+
|
|
49
|
+
const ATTRIBUTES: Record<string, AkeneoAttribute> = {
|
|
50
|
+
warranty_notes: { code: 'warranty_notes', type: 'pim_catalog_text' },
|
|
51
|
+
certifications: { code: 'certifications', type: 'pim_catalog_multiselect' },
|
|
52
|
+
batch_code: { code: 'batch_code', type: 'pim_catalog_text' },
|
|
53
|
+
internal_memo: { code: 'internal_memo', type: 'pim_catalog_text' },
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type SetCustomFieldsCall = { entityId: string; recordId: string; values: Record<string, unknown> }
|
|
57
|
+
|
|
58
|
+
function createWorld(extraAttributeCodes: string[] = []) {
|
|
59
|
+
const attributes: Record<string, AkeneoAttribute> = {
|
|
60
|
+
...ATTRIBUTES,
|
|
61
|
+
...Object.fromEntries(extraAttributeCodes.map((code) => [code, { code, type: 'pim_catalog_text' }])),
|
|
62
|
+
}
|
|
63
|
+
const products: string[] = []
|
|
64
|
+
const variants: Array<{ id: string; product: string; sku: string; isDefault: boolean }> = []
|
|
65
|
+
const mappings: Array<{ entityType: string; localId: string; externalId: string }> = []
|
|
66
|
+
let sequence = 0
|
|
67
|
+
const nextId = (prefix: string) => {
|
|
68
|
+
sequence += 1
|
|
69
|
+
return `${prefix}-${sequence}`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const commandBus = {
|
|
73
|
+
execute: jest.fn(async (commandId: string, { input }: { input: Record<string, unknown> }) => {
|
|
74
|
+
switch (commandId) {
|
|
75
|
+
case 'catalog.products.create': {
|
|
76
|
+
const id = nextId('product')
|
|
77
|
+
products.push(id)
|
|
78
|
+
return { result: { productId: id } }
|
|
79
|
+
}
|
|
80
|
+
case 'catalog.products.update':
|
|
81
|
+
return { result: { productId: input.id } }
|
|
82
|
+
case 'catalog.variants.create': {
|
|
83
|
+
const id = nextId('variant')
|
|
84
|
+
variants.push({ id, product: String(input.productId), sku: String(input.sku), isDefault: input.isDefault === true })
|
|
85
|
+
return { result: { variantId: id } }
|
|
86
|
+
}
|
|
87
|
+
case 'catalog.variants.update':
|
|
88
|
+
return { result: { variantId: input.id } }
|
|
89
|
+
default:
|
|
90
|
+
throw new Error(`[internal] unexpected command: ${commandId}`)
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const externalIdMappingService = {
|
|
96
|
+
lookupLocalId: jest.fn(async (_integrationId: string, entityType: string, externalId: string) => (
|
|
97
|
+
mappings.find((row) => row.entityType === entityType && row.externalId === externalId)?.localId ?? null
|
|
98
|
+
)),
|
|
99
|
+
lookupExternalId: jest.fn(async (_integrationId: string, entityType: string, localId: string) => (
|
|
100
|
+
mappings.find((row) => row.entityType === entityType && row.localId === localId)?.externalId ?? null
|
|
101
|
+
)),
|
|
102
|
+
storeExternalIdMapping: jest.fn(async (_integrationId: string, entityType: string, localId: string, externalId: string) => {
|
|
103
|
+
const existing = mappings.find((row) => row.entityType === entityType && row.externalId === externalId)
|
|
104
|
+
if (existing) {
|
|
105
|
+
existing.localId = localId
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
mappings.push({ entityType, localId, externalId })
|
|
109
|
+
}),
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const storedValues = new Map<string, Record<string, unknown>>()
|
|
113
|
+
let writesInFlight = 0
|
|
114
|
+
let maxWritesInFlight = 0
|
|
115
|
+
const setCustomFields = jest.fn(async (input: SetCustomFieldsCall) => {
|
|
116
|
+
if (Object.keys(input.values).length > MAX_CUSTOM_FIELD_KEYS_PER_RECORD) {
|
|
117
|
+
throw new Error('[internal] too many custom fields')
|
|
118
|
+
}
|
|
119
|
+
writesInFlight += 1
|
|
120
|
+
maxWritesInFlight = Math.max(maxWritesInFlight, writesInFlight)
|
|
121
|
+
await new Promise((resolve) => setImmediate(resolve))
|
|
122
|
+
const recordKey = `${input.entityId}:${input.recordId}`
|
|
123
|
+
storedValues.set(recordKey, { ...storedValues.get(recordKey), ...input.values })
|
|
124
|
+
writesInFlight -= 1
|
|
125
|
+
})
|
|
126
|
+
mockLoadCustomFieldSnapshot.mockImplementation(async (_em: unknown, options: { entityId: string; recordId: string }) => (
|
|
127
|
+
{ ...storedValues.get(`${options.entityId}:${options.recordId}`) }
|
|
128
|
+
))
|
|
129
|
+
const model: { values: AkeneoValues; available: boolean } = {
|
|
130
|
+
values: { name: text('Jacket') },
|
|
131
|
+
available: true,
|
|
132
|
+
}
|
|
133
|
+
const em = {
|
|
134
|
+
clear: jest.fn(),
|
|
135
|
+
create: jest.fn((_entity: unknown, data: Record<string, unknown>) => ({ ...data })),
|
|
136
|
+
persist: jest.fn(),
|
|
137
|
+
flush: jest.fn(async () => undefined),
|
|
138
|
+
getConnection: () => ({ execute: jest.fn(async () => []) }),
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
mockContainerResolve.mockImplementation((key: string) => {
|
|
142
|
+
if (key === 'em') return em
|
|
143
|
+
if (key === 'commandBus') return commandBus
|
|
144
|
+
if (key === 'dataEngine') return { setCustomFields }
|
|
145
|
+
if (key === 'externalIdMappingService') return externalIdMappingService
|
|
146
|
+
if (key === 'cache') throw new Error('[internal] no cache in test')
|
|
147
|
+
throw new Error(`[internal] unexpected dependency: ${key}`)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
mockFindOneWithDecryption.mockImplementation(async (_em: unknown, _entity: unknown, where: Record<string, unknown>) => {
|
|
151
|
+
if (typeof where.product === 'string') {
|
|
152
|
+
return variants.find((variant) => (
|
|
153
|
+
variant.product === where.product
|
|
154
|
+
&& (where.isDefault === undefined || variant.isDefault === where.isDefault)
|
|
155
|
+
&& (where.sku === undefined || variant.sku === where.sku)
|
|
156
|
+
)) ?? null
|
|
157
|
+
}
|
|
158
|
+
if (typeof where.id === 'string') {
|
|
159
|
+
if (products.includes(where.id)) return { id: where.id }
|
|
160
|
+
return variants.find((variant) => variant.id === where.id) ?? null
|
|
161
|
+
}
|
|
162
|
+
return null
|
|
163
|
+
})
|
|
164
|
+
mockFindWithDecryption.mockImplementation(async () => [])
|
|
165
|
+
|
|
166
|
+
const client = {
|
|
167
|
+
getFamily: jest.fn(async (code: string) => (
|
|
168
|
+
code === FAMILY_CODE
|
|
169
|
+
? { code: FAMILY_CODE, attributes: ['sku', 'name', ...Object.keys(attributes)] }
|
|
170
|
+
: null
|
|
171
|
+
)),
|
|
172
|
+
getFamilyVariant: jest.fn(async (familyCode: string, code: string) => (
|
|
173
|
+
familyCode === FAMILY_CODE && code === FAMILY_VARIANT_CODE
|
|
174
|
+
? { code: FAMILY_VARIANT_CODE, variant_attribute_sets: [{ level: 1, axes: [], attributes: ['sku', 'batch_code'] }] }
|
|
175
|
+
: null
|
|
176
|
+
)),
|
|
177
|
+
getAttribute: jest.fn(async (code: string) => attributes[code] ?? null),
|
|
178
|
+
listAttributeOptions: jest.fn(async () => []),
|
|
179
|
+
getProductModel: jest.fn(async (code: string) => (
|
|
180
|
+
code === MODEL_CODE && model.available
|
|
181
|
+
? {
|
|
182
|
+
code: MODEL_CODE,
|
|
183
|
+
family: FAMILY_CODE,
|
|
184
|
+
family_variant: FAMILY_VARIANT_CODE,
|
|
185
|
+
values: model.values,
|
|
186
|
+
categories: [],
|
|
187
|
+
}
|
|
188
|
+
: null
|
|
189
|
+
)),
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const writesFor = (entityId: string, keys?: string[]): Array<Record<string, unknown>> => setCustomFields.mock.calls
|
|
193
|
+
.map(([input]) => input)
|
|
194
|
+
.filter((input) => input.entityId === entityId)
|
|
195
|
+
.map((input) => (keys
|
|
196
|
+
? Object.fromEntries(Object.entries(input.values).filter(([key]) => keys.includes(key)))
|
|
197
|
+
: input.values))
|
|
198
|
+
|
|
199
|
+
return { client, model, setCustomFields, writesFor, maxWritesInFlight: () => maxWritesInFlight }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function buildMapping(customFieldMappings: AkeneoCustomFieldMapping[]): AkeneoDataMapping {
|
|
203
|
+
const base = buildDefaultAkeneoMapping('products')
|
|
204
|
+
const products = base.settings?.products
|
|
205
|
+
if (!products) throw new Error('[internal] default Akeneo product mapping is missing')
|
|
206
|
+
return {
|
|
207
|
+
...base,
|
|
208
|
+
settings: {
|
|
209
|
+
...base.settings,
|
|
210
|
+
products: {
|
|
211
|
+
...products,
|
|
212
|
+
priceMappings: [],
|
|
213
|
+
mediaMappings: [],
|
|
214
|
+
fieldsetMappings: [],
|
|
215
|
+
customFieldMappings,
|
|
216
|
+
syncAssociations: false,
|
|
217
|
+
createMissingChannels: false,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function text(data: string): AkeneoValues[string] {
|
|
224
|
+
return [{ locale: null, scope: null, data }]
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function buildSimpleProduct(values: AkeneoValues): AkeneoProduct {
|
|
228
|
+
return {
|
|
229
|
+
uuid: 'uuid-simple',
|
|
230
|
+
identifier: 'TENT-1',
|
|
231
|
+
family: FAMILY_CODE,
|
|
232
|
+
parent: null,
|
|
233
|
+
enabled: true,
|
|
234
|
+
values: { sku: text('TENT-1'), name: text('Tent'), ...values },
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function buildVariant(values: AkeneoValues): AkeneoProduct {
|
|
239
|
+
return {
|
|
240
|
+
uuid: 'uuid-variant',
|
|
241
|
+
identifier: 'JACKET-B1',
|
|
242
|
+
family: FAMILY_CODE,
|
|
243
|
+
parent: MODEL_CODE,
|
|
244
|
+
enabled: true,
|
|
245
|
+
values: { sku: text('JACKET-B1'), ...values },
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
describe('akeneo catalog importer custom field values', () => {
|
|
250
|
+
beforeEach(() => {
|
|
251
|
+
mockContainerResolve.mockReset()
|
|
252
|
+
mockFindOneWithDecryption.mockReset()
|
|
253
|
+
mockFindWithDecryption.mockReset()
|
|
254
|
+
mockLoadCustomFieldSnapshot.mockReset()
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('clears a product custom field once its Akeneo value is removed', async () => {
|
|
258
|
+
const world = createWorld()
|
|
259
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
260
|
+
const mapping = buildMapping([
|
|
261
|
+
{ attributeCode: 'warranty_notes', fieldKey: 'warranty_notes', target: 'product' },
|
|
262
|
+
])
|
|
263
|
+
|
|
264
|
+
await importer.upsertProduct(buildSimpleProduct({ warranty_notes: text('Two years') }), mapping)
|
|
265
|
+
await importer.upsertProduct(buildSimpleProduct({}), mapping)
|
|
266
|
+
|
|
267
|
+
const writes = world.writesFor(PRODUCT_ENTITY_ID)
|
|
268
|
+
expect(writes).toHaveLength(2)
|
|
269
|
+
expect(writes[0]).toMatchObject({ warranty_notes: 'Two years' })
|
|
270
|
+
expect(writes[1]).toHaveProperty('warranty_notes', null)
|
|
271
|
+
expect(mockLoadCustomFieldSnapshot).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
|
272
|
+
entityId: PRODUCT_ENTITY_ID,
|
|
273
|
+
tenantId: scope.tenantId,
|
|
274
|
+
organizationId: scope.organizationId,
|
|
275
|
+
}))
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
it('clears a multi-select product custom field once every Akeneo option is removed', async () => {
|
|
279
|
+
const world = createWorld()
|
|
280
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
281
|
+
const mapping = buildMapping([
|
|
282
|
+
{ attributeCode: 'certifications', fieldKey: 'certifications', target: 'product' },
|
|
283
|
+
])
|
|
284
|
+
|
|
285
|
+
await importer.upsertProduct(buildSimpleProduct({
|
|
286
|
+
certifications: [{ locale: null, scope: null, data: ['bluesign', 'oeko_tex'] }],
|
|
287
|
+
}), mapping)
|
|
288
|
+
await importer.upsertProduct(buildSimpleProduct({
|
|
289
|
+
certifications: [{ locale: null, scope: null, data: [] }],
|
|
290
|
+
}), mapping)
|
|
291
|
+
|
|
292
|
+
const writes = world.writesFor(PRODUCT_ENTITY_ID)
|
|
293
|
+
expect(writes).toHaveLength(2)
|
|
294
|
+
expect(writes[0]).toMatchObject({ certifications: ['bluesign', 'oeko_tex'] })
|
|
295
|
+
expect(writes[1]).toHaveProperty('certifications', null)
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('clears a variant custom field once its Akeneo value is removed', async () => {
|
|
299
|
+
const world = createWorld()
|
|
300
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
301
|
+
const mapping = buildMapping([
|
|
302
|
+
{ attributeCode: 'batch_code', fieldKey: 'batch_code', target: 'variant' },
|
|
303
|
+
])
|
|
304
|
+
|
|
305
|
+
await importer.upsertProduct(buildVariant({ batch_code: text('B-2026-11') }), mapping)
|
|
306
|
+
await importer.upsertProduct(buildVariant({}), mapping)
|
|
307
|
+
|
|
308
|
+
const writes = world.writesFor(VARIANT_ENTITY_ID)
|
|
309
|
+
expect(writes).toHaveLength(2)
|
|
310
|
+
expect(writes[0]).toMatchObject({ batch_code: 'B-2026-11' })
|
|
311
|
+
expect(writes[1]).toHaveProperty('batch_code', null)
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('leaves skipped mappings and attributes unknown to Akeneo untouched', async () => {
|
|
315
|
+
const world = createWorld()
|
|
316
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
317
|
+
const syncedMapping = buildMapping([
|
|
318
|
+
{ attributeCode: 'warranty_notes', fieldKey: 'warranty_notes', target: 'product' },
|
|
319
|
+
{ attributeCode: 'internal_memo', fieldKey: 'internal_memo', target: 'product' },
|
|
320
|
+
])
|
|
321
|
+
const mapping = buildMapping([
|
|
322
|
+
{ attributeCode: 'warranty_notes', fieldKey: 'warranty_notes', target: 'product' },
|
|
323
|
+
{ attributeCode: 'internal_memo', fieldKey: 'internal_memo', target: 'product', skip: true },
|
|
324
|
+
{ attributeCode: 'name', fieldKey: 'legacy_name', target: 'product' },
|
|
325
|
+
])
|
|
326
|
+
|
|
327
|
+
await importer.upsertProduct(buildSimpleProduct({ warranty_notes: text('Two years'), internal_memo: text('Fragile') }), syncedMapping)
|
|
328
|
+
await importer.upsertProduct(buildSimpleProduct({}), mapping)
|
|
329
|
+
|
|
330
|
+
const writes = world.writesFor(PRODUCT_ENTITY_ID, ['warranty_notes', 'internal_memo', 'legacy_name'])
|
|
331
|
+
expect(writes).toEqual([{ warranty_notes: 'Two years', internal_memo: 'Fragile' }, { warranty_notes: null }])
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
it('clears a product custom field inherited from the parent model once the model value is removed', async () => {
|
|
335
|
+
const world = createWorld()
|
|
336
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
337
|
+
const mapping = buildMapping([
|
|
338
|
+
{ attributeCode: 'warranty_notes', fieldKey: 'warranty_notes', target: 'product' },
|
|
339
|
+
])
|
|
340
|
+
|
|
341
|
+
world.model.values = { name: text('Jacket'), warranty_notes: text('Lifetime') }
|
|
342
|
+
await importer.upsertProduct(buildVariant({}), mapping)
|
|
343
|
+
const secondImporter = await createAkeneoImporter(world.client as never, scope)
|
|
344
|
+
world.model.values = { name: text('Jacket') }
|
|
345
|
+
await secondImporter.upsertProduct(buildVariant({}), mapping)
|
|
346
|
+
|
|
347
|
+
expect(world.writesFor(PRODUCT_ENTITY_ID, ['warranty_notes'])).toEqual([{ warranty_notes: 'Lifetime' }, { warranty_notes: null }])
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it('does not clear inherited custom fields when the parent model cannot be loaded', async () => {
|
|
351
|
+
const world = createWorld()
|
|
352
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
353
|
+
const mapping = buildMapping([
|
|
354
|
+
{ attributeCode: 'warranty_notes', fieldKey: 'warranty_notes', target: 'variant' },
|
|
355
|
+
{ attributeCode: 'batch_code', fieldKey: 'batch_code', target: 'variant' },
|
|
356
|
+
])
|
|
357
|
+
|
|
358
|
+
world.model.values = { name: text('Jacket'), warranty_notes: text('Lifetime') }
|
|
359
|
+
await importer.upsertProduct(buildVariant({ batch_code: text('B-2026-11') }), mapping)
|
|
360
|
+
const secondImporter = await createAkeneoImporter(world.client as never, scope)
|
|
361
|
+
world.model.available = false
|
|
362
|
+
await secondImporter.upsertProduct(buildVariant({ batch_code: text('B-2026-12') }), mapping)
|
|
363
|
+
|
|
364
|
+
expect(world.writesFor(VARIANT_ENTITY_ID, ['warranty_notes', 'batch_code'])).toEqual([
|
|
365
|
+
{ warranty_notes: 'Lifetime', batch_code: 'B-2026-11' },
|
|
366
|
+
{ batch_code: 'B-2026-12' },
|
|
367
|
+
])
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
it('does not write empty Akeneo values for fields that hold no local value', async () => {
|
|
371
|
+
const world = createWorld()
|
|
372
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
373
|
+
const mapping = buildMapping([
|
|
374
|
+
{ attributeCode: 'warranty_notes', fieldKey: 'warranty_notes', target: 'product' },
|
|
375
|
+
{ attributeCode: 'internal_memo', fieldKey: 'internal_memo', target: 'product' },
|
|
376
|
+
])
|
|
377
|
+
|
|
378
|
+
await importer.upsertProduct(buildSimpleProduct({ warranty_notes: text('Two years') }), mapping)
|
|
379
|
+
await importer.upsertProduct(buildSimpleProduct({ warranty_notes: text('Two years') }), mapping)
|
|
380
|
+
await importer.upsertProduct(buildSimpleProduct({}), mapping)
|
|
381
|
+
await importer.upsertProduct(buildSimpleProduct({}), mapping)
|
|
382
|
+
|
|
383
|
+
expect(world.writesFor(PRODUCT_ENTITY_ID)).toEqual([
|
|
384
|
+
{ warranty_notes: 'Two years' },
|
|
385
|
+
{ warranty_notes: 'Two years' },
|
|
386
|
+
{ warranty_notes: null },
|
|
387
|
+
])
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
it('keeps the write under the per-record custom field limit when most mapped Akeneo values are empty', async () => {
|
|
391
|
+
const world = createWorld(SPEC_CODES)
|
|
392
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
393
|
+
const mapping = buildMapping(SPEC_CODES.map((code) => ({ attributeCode: code, fieldKey: code, target: 'product' as const })))
|
|
394
|
+
|
|
395
|
+
await importer.upsertProduct(buildSimpleProduct({ spec_1: text('Waterproof'), spec_2: text('Breathable') }), mapping)
|
|
396
|
+
await importer.upsertProduct(buildSimpleProduct({ spec_1: text('Waterproof') }), mapping)
|
|
397
|
+
|
|
398
|
+
expect(world.writesFor(PRODUCT_ENTITY_ID)).toEqual([
|
|
399
|
+
{ spec_1: 'Waterproof', spec_2: 'Breathable' },
|
|
400
|
+
{ spec_1: 'Waterproof', spec_2: null },
|
|
401
|
+
])
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
it('writes product and variant custom fields one after the other', async () => {
|
|
405
|
+
const world = createWorld()
|
|
406
|
+
const importer = await createAkeneoImporter(world.client as never, scope)
|
|
407
|
+
const mapping = buildMapping([
|
|
408
|
+
{ attributeCode: 'warranty_notes', fieldKey: 'warranty_notes', target: 'product' },
|
|
409
|
+
{ attributeCode: 'batch_code', fieldKey: 'batch_code', target: 'variant' },
|
|
410
|
+
])
|
|
411
|
+
|
|
412
|
+
world.model.values = { name: text('Jacket'), warranty_notes: text('Lifetime') }
|
|
413
|
+
await importer.upsertProduct(buildVariant({ batch_code: text('B-2026-11') }), mapping)
|
|
414
|
+
|
|
415
|
+
expect(world.writesFor(PRODUCT_ENTITY_ID, ['warranty_notes'])).toEqual([{ warranty_notes: 'Lifetime' }])
|
|
416
|
+
expect(world.writesFor(VARIANT_ENTITY_ID, ['batch_code'])).toEqual([{ batch_code: 'B-2026-11' }])
|
|
417
|
+
expect(world.maxWritesInFlight()).toBe(1)
|
|
418
|
+
})
|
|
419
|
+
})
|