@open-mercato/sync-akeneo 0.10.1-develop.7635.1.03de276351 → 0.10.1-develop.7641.1.db279a693e
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.
|
@@ -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: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;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,SAA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,cAAc;AAAA,MACrE;AAEA,UAAI,WAAW,WAAW,aAAa;AACrC,cAAM,IAAI,MAAM,GAAG,UAAU,qBAAqB;AAAA,MACpD;AAEA,YAAM,MAAM,IAAI;AAAA,IAClB;AAEA,UAAM,gBAAgB;AAAA,MACpB;AAAA,MACA;AAAA,QACE,YAAY,mBAAmB;AAAA,QAC/B,gBAAgB,YAAY;AAAA,QAC5B,MAAM,kBAAkB;AAAA,UACtB,aAAa;AAAA,UACb,cAAc,IAAI;AAAA,UAClB,yBAAyB,IAAI,iBAAiB;AAAA,UAC9C,kBAAkB;AAAA,UAClB,2BAA2B;AAAA,UAC3B,0BAA0B;AAAA,UAC1B,sBAAsB;AAAA,QACxB,CAAC;AAAA,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/sync-akeneo",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.7641.1.db279a693e",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,18 +53,18 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@open-mercato/core": "0.10.1-develop.
|
|
57
|
-
"@open-mercato/ui": "0.10.1-develop.
|
|
56
|
+
"@open-mercato/core": "0.10.1-develop.7641.1.db279a693e",
|
|
57
|
+
"@open-mercato/ui": "0.10.1-develop.7641.1.db279a693e",
|
|
58
58
|
"node-html-markdown": "^2.0.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@mikro-orm/postgresql": "^7.0.14",
|
|
62
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
62
|
+
"@open-mercato/shared": "0.10.1-develop.7641.1.db279a693e",
|
|
63
63
|
"react": "^19.0.0",
|
|
64
64
|
"react-dom": "^19.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
67
|
+
"@open-mercato/shared": "0.10.1-develop.7641.1.db279a693e",
|
|
68
68
|
"@types/jest": "^30.0.0",
|
|
69
69
|
"@types/react": "^19.2.18",
|
|
70
70
|
"@types/react-dom": "^19.2.5",
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { AwilixContainer } from 'awilix'
|
|
2
|
+
import type { startDataSyncRun } from '@open-mercato/core/modules/data_sync/lib/start-run'
|
|
3
|
+
import { runAkeneoFirstImportSequence } from '../lib/first-import'
|
|
4
|
+
|
|
5
|
+
const mockStartDataSyncRun = jest.fn()
|
|
6
|
+
const mockEnqueue = jest.fn()
|
|
7
|
+
|
|
8
|
+
jest.mock('@open-mercato/core/modules/data_sync/lib/queue', () => ({
|
|
9
|
+
getSyncQueue: jest.fn(() => ({ enqueue: mockEnqueue })),
|
|
10
|
+
}))
|
|
11
|
+
|
|
12
|
+
jest.mock('@open-mercato/core/modules/data_sync/lib/start-run', () => {
|
|
13
|
+
const actual = jest.requireActual<typeof import('@open-mercato/core/modules/data_sync/lib/start-run')>(
|
|
14
|
+
'@open-mercato/core/modules/data_sync/lib/start-run',
|
|
15
|
+
)
|
|
16
|
+
return {
|
|
17
|
+
...actual,
|
|
18
|
+
startDataSyncRun: (params: Parameters<typeof startDataSyncRun>[0]) => {
|
|
19
|
+
mockStartDataSyncRun(params)
|
|
20
|
+
return actual.startDataSyncRun(params)
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const scope = { organizationId: 'org-1', tenantId: 'tenant-1', userId: 'user-1' }
|
|
26
|
+
|
|
27
|
+
function buildHarness() {
|
|
28
|
+
const progressService = {
|
|
29
|
+
startJob: jest.fn(async () => undefined),
|
|
30
|
+
createJob: jest.fn(async () => ({ id: 'run-job-1' })),
|
|
31
|
+
updateProgress: jest.fn(async () => undefined),
|
|
32
|
+
completeJob: jest.fn(async () => undefined),
|
|
33
|
+
getJob: jest.fn(async () => ({ totalCount: 1, processedCount: 1, progressPercent: 100 })),
|
|
34
|
+
}
|
|
35
|
+
const syncRunService = {
|
|
36
|
+
findRunningOverlap: jest.fn(async () => null),
|
|
37
|
+
createRun: jest.fn(async (input: { entityType: string; progressJobId: string | null }) => ({
|
|
38
|
+
id: `run-${input.entityType}`,
|
|
39
|
+
status: 'pending',
|
|
40
|
+
progressJobId: input.progressJobId,
|
|
41
|
+
})),
|
|
42
|
+
getRun: jest.fn(async (runId: string) => ({ id: runId, status: 'completed', progressJobId: 'run-job-1' })),
|
|
43
|
+
}
|
|
44
|
+
const services: Record<string, unknown> = {
|
|
45
|
+
em: { clear: jest.fn() },
|
|
46
|
+
progressService,
|
|
47
|
+
dataSyncRunService: syncRunService,
|
|
48
|
+
}
|
|
49
|
+
const container = { resolve: (token: string) => services[token] } as unknown as AwilixContainer
|
|
50
|
+
return { container, progressService, syncRunService }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe('Akeneo first import batch size', () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
jest.clearAllMocks()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('delegates batch size resolution to the shared helper for every step', async () => {
|
|
59
|
+
const { container, progressService, syncRunService } = buildHarness()
|
|
60
|
+
|
|
61
|
+
await runAkeneoFirstImportSequence({ container, progressJobId: 'sequence-job-1', scope })
|
|
62
|
+
|
|
63
|
+
expect(mockStartDataSyncRun).toHaveBeenCalledTimes(3)
|
|
64
|
+
for (const [stepIndex, entityType] of ['categories', 'attributes', 'products'].entries()) {
|
|
65
|
+
const [params] = mockStartDataSyncRun.mock.calls[stepIndex] as [Parameters<typeof startDataSyncRun>[0]]
|
|
66
|
+
expect(params.input).toEqual({
|
|
67
|
+
integrationId: 'sync_akeneo',
|
|
68
|
+
entityType,
|
|
69
|
+
direction: 'import',
|
|
70
|
+
triggeredBy: scope.userId,
|
|
71
|
+
})
|
|
72
|
+
expect(params.scope).toEqual(scope)
|
|
73
|
+
expect(syncRunService.findRunningOverlap).toHaveBeenNthCalledWith(stepIndex + 1, 'sync_akeneo', entityType, 'import', scope)
|
|
74
|
+
expect(mockEnqueue).toHaveBeenNthCalledWith(stepIndex + 1, {
|
|
75
|
+
runId: `run-${entityType}`,
|
|
76
|
+
batchSize: 100,
|
|
77
|
+
scope,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
expect(progressService.completeJob).toHaveBeenCalledWith('sequence-job-1', expect.any(Object), scope)
|
|
81
|
+
})
|
|
82
|
+
})
|