cardus 0.0.103 → 0.0.105

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.
@@ -0,0 +1,1150 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ // @ts-nocheck
24
+ const index_1 = require("../index");
25
+ class FakeExecutionManager {
26
+ constructor({ arrayParams, executable }) {
27
+ this.arrayParams = arrayParams;
28
+ this.executable = executable;
29
+ }
30
+ upload() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ return Promise.allSettled(this.arrayParams.map((order) => this.executable(order)));
33
+ });
34
+ }
35
+ }
36
+ const buildOrder = (overrides = {}) => (Object.assign({ codigoEnvioExterno: 'EXT-1000', idInternoShopify: 'SHP-1', fechaCreacionExterna: '2026-01-10 12:00:00', marketplaceId: 'market-1', idDocumentoHolded: 'doc-1', tipoDocumentoHolded: 'invoice', lineas: [{ nombre_producto: 'T-shirt', sku_producto: 'SKU-01' }] }, overrides));
37
+ const buildPayload = (overrides = {}) => (Object.assign({ idUsuario: 77, agencyId: 50, addressId: 10, warehouseId: 0, group: {
38
+ grouped: 0,
39
+ weight: 2,
40
+ height: 10,
41
+ width: 20,
42
+ length: 30
43
+ }, sequentialInsertion: true }, overrides));
44
+ const buildFixture = ({ skuAlmacen = 0, measuresFromConfig = 0, emulateLegacyPackageAggregation = false, getAgencyId = null } = {}) => {
45
+ const integrationsService = {
46
+ filterExternalDuplicatedOrders: jest.fn((_a) => __awaiter(void 0, [_a], void 0, function* ({ orders }) { return orders; })),
47
+ getDefaultIntegrationsData: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () {
48
+ return ({
49
+ sku_almacen: skuAlmacen,
50
+ dimensiones_medidas_configuradas: measuresFromConfig
51
+ });
52
+ })),
53
+ insertTempShipment: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return 99999; })),
54
+ deleteTempShipment: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; })),
55
+ updateTempShimpment: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; })),
56
+ insertTempShipmentMultipleLines: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; })),
57
+ insertTempShipmentMultipleDetails: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; })),
58
+ insertTempShipmentMultipleContents: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; })),
59
+ insertTempShipmentMultipleExternals: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; })),
60
+ insertTempShipmentMultipleJsonQuantityReferences: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; }))
61
+ };
62
+ const addressesService = {
63
+ getAddress: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return ({ id_pais: 34, source: 'address' }); })),
64
+ getWarehouseAddress: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () {
65
+ return ({
66
+ id_pais: 34,
67
+ source: 'warehouse'
68
+ });
69
+ }))
70
+ };
71
+ const usersService = {
72
+ obtenerUsuarioId: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () {
73
+ return ({
74
+ id_usuario: 77,
75
+ tipo_cliente: 3,
76
+ id_comercial: 99,
77
+ priority_defecto: 0,
78
+ dni: '12345678A',
79
+ eori_import: '',
80
+ eori_export: ''
81
+ });
82
+ }))
83
+ };
84
+ const getAgencyIdForTempShipment = getAgencyId || jest.fn((_b) => __awaiter(void 0, [_b], void 0, function* ({ defaultAgencyId }) { return defaultAgencyId; }));
85
+ const manager = new index_1.IntegrationManager({
86
+ integrationsService,
87
+ addressesService,
88
+ countriesService: {
89
+ getCountry: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return ({ nombre_pais_en: 'Spain' }); }))
90
+ },
91
+ configurationService: {
92
+ getDefaultProformaConfiguration: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return []; })),
93
+ getFakeDefaultProformaConfiguration: jest.fn(() => [])
94
+ },
95
+ usersService,
96
+ customizationService: {
97
+ getUsersWithSection: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return []; }))
98
+ },
99
+ llmAPIService: {
100
+ getTaricCodeFromContentDescription: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return null; }))
101
+ },
102
+ warehouseService: {
103
+ getProductReferenceFromSku: jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return null; }))
104
+ },
105
+ type: 'shopify',
106
+ integrationType: 1,
107
+ shipmentType: 1,
108
+ executionManager: FakeExecutionManager,
109
+ findNextPickupDate: jest.fn(),
110
+ getAgencyIdForTempShipment,
111
+ getModifiedOrderBasedOnRules: jest.fn((_c) => __awaiter(void 0, void 0, void 0, function* () {
112
+ var { defaultAgencyId, shipmentDetails } = _c, rest = __rest(_c, ["defaultAgencyId", "shipmentDetails"]);
113
+ const newAgencyId = yield getAgencyIdForTempShipment(Object.assign({ defaultAgencyId,
114
+ shipmentDetails }, rest));
115
+ return {
116
+ partialTempShipmentModified: newAgencyId !== defaultAgencyId ? { id_agencia: newAgencyId } : {},
117
+ packagesModified: emulateLegacyPackageAggregation
118
+ ? shipmentDetails.flatMap((detail) => Array.from({ length: Number(detail.cantidad) }, () => ({
119
+ id_envio: detail.id_envio,
120
+ bulto: detail.bulto
121
+ })))
122
+ : []
123
+ };
124
+ }))
125
+ });
126
+ return {
127
+ manager,
128
+ integrationsService,
129
+ addressesService,
130
+ getAgencyIdForTempShipment
131
+ };
132
+ };
133
+ const arrangeDefaultStubs = ({ manager, shipmentId = 12345 }) => {
134
+ manager.services.integrationsService.insertTempShipment.mockResolvedValue(shipmentId);
135
+ jest
136
+ .spyOn(manager, 'insertQuantityRelatedLines')
137
+ .mockImplementation((args) => __awaiter(void 0, void 0, void 0, function* () {
138
+ args.shouldFindWarehouseSkus = true;
139
+ const { parsedOrder } = args;
140
+ const detail = {
141
+ id_envio: parsedOrder.idEnvioTemporal,
142
+ bulto: {
143
+ nombre_producto: parsedOrder.lineas[0].nombre_producto,
144
+ sku_producto: parsedOrder.lineas[0].sku_producto,
145
+ peso: 2
146
+ },
147
+ cantidad: 2
148
+ };
149
+ manager.dataToInsert.lines.set(parsedOrder.idEnvioTemporal, [
150
+ {
151
+ id_envio: parsedOrder.idEnvioTemporal,
152
+ bulto: {
153
+ peso: 2,
154
+ alto: 10,
155
+ ancho: 20,
156
+ largo: 30,
157
+ sku_producto: parsedOrder.lineas[0].sku_producto
158
+ }
159
+ }
160
+ ]);
161
+ return {
162
+ shipmentDetails: [detail],
163
+ bultosYCantidades: [
164
+ {
165
+ idEnvioTemporal: parsedOrder.idEnvioTemporal,
166
+ bulto: detail.bulto,
167
+ cantidad: 2,
168
+ forzarAgrupamientoDeLinea: false
169
+ }
170
+ ]
171
+ };
172
+ }));
173
+ manager.dataToInsert.jsonQuantityReferences.push({
174
+ id_envio: shipmentId,
175
+ json_referencias_cantidades: [{ id_caja: -1, referencias: { A1: 1 } }]
176
+ });
177
+ jest
178
+ .spyOn(manager, 'insertUserDefaultConfigurationContent')
179
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
180
+ manager.dataToInsert.contents.push({
181
+ id_envio: shipmentId,
182
+ id_usuario: 77,
183
+ contenido: 'T-shirt',
184
+ valor: 12,
185
+ peso_bruto: 2,
186
+ peso_neto: 2,
187
+ cantidad: 2,
188
+ reason_export: '1'
189
+ });
190
+ }));
191
+ };
192
+ const arrangeRealQuantityFlow = ({ manager, shipmentId = 12345, customCreateContent = null }) => {
193
+ manager.services.integrationsService.insertTempShipment.mockResolvedValue(shipmentId);
194
+ jest
195
+ .spyOn(manager, 'insertUserDefaultConfigurationContent')
196
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
197
+ if (customCreateContent) {
198
+ customCreateContent();
199
+ return;
200
+ }
201
+ manager.dataToInsert.contents.push({
202
+ id_envio: shipmentId,
203
+ id_usuario: 77,
204
+ contenido: 'Auto-content',
205
+ valor: 10,
206
+ peso_bruto: 1,
207
+ peso_neto: 1,
208
+ cantidad: 1,
209
+ reason_export: '1'
210
+ });
211
+ }));
212
+ };
213
+ const arrangeRealQuantityFlowMultipleOrders = ({ manager, shipmentIds, customCreateContent = null }) => {
214
+ let idx = 0;
215
+ manager.services.integrationsService.insertTempShipment.mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
216
+ const id = shipmentIds[idx];
217
+ idx += 1;
218
+ return id;
219
+ }));
220
+ jest
221
+ .spyOn(manager, 'insertUserDefaultConfigurationContent')
222
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
223
+ if (customCreateContent) {
224
+ customCreateContent(shipmentIds);
225
+ return;
226
+ }
227
+ shipmentIds.forEach((id_envio) => {
228
+ manager.dataToInsert.contents.push({
229
+ id_envio,
230
+ id_usuario: 77,
231
+ contenido: `Auto-content-${id_envio}`,
232
+ valor: 10,
233
+ peso_bruto: 1,
234
+ peso_neto: 1,
235
+ cantidad: 1,
236
+ reason_export: '1'
237
+ });
238
+ });
239
+ }));
240
+ };
241
+ describe('IntegrationManager.insertTempShipments', () => {
242
+ it('calls bulk temp shipment insertions with the expected params', () => __awaiter(void 0, void 0, void 0, function* () {
243
+ const { manager, integrationsService } = buildFixture();
244
+ arrangeDefaultStubs({ manager, shipmentId: 12345 });
245
+ yield manager.insertTempShipments({
246
+ payload: buildPayload(),
247
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () { return [buildOrder()]; }),
248
+ crearBulto: jest.fn(),
249
+ modificarOrdenOriginal: (_a) => __awaiter(void 0, [_a], void 0, function* ({ originalOrder }) { return originalOrder; })
250
+ });
251
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
252
+ {
253
+ id_envio: 12345,
254
+ bulto: {
255
+ peso: 2,
256
+ alto: 10,
257
+ ancho: 20,
258
+ largo: 30,
259
+ sku_producto: 'SKU-01'
260
+ }
261
+ }
262
+ ]);
263
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
264
+ {
265
+ id_envio: 12345,
266
+ bulto: {
267
+ nombre_producto: 'T-shirt',
268
+ sku_producto: 'SKU-01',
269
+ peso: 2
270
+ },
271
+ cantidad: 2
272
+ }
273
+ ]);
274
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([
275
+ {
276
+ id_envio: 12345,
277
+ id_usuario: 77,
278
+ contenido: 'T-shirt',
279
+ valor: 12,
280
+ peso_bruto: 2,
281
+ peso_neto: 2,
282
+ cantidad: 2,
283
+ reason_export: '1'
284
+ }
285
+ ]);
286
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
287
+ expect.objectContaining({
288
+ id_envio_temporal_usuario: 12345,
289
+ codigo_envio_externo: 'EXT-1000',
290
+ id_usuario: 77,
291
+ servicio: 'shopify',
292
+ id_interno_shopify: 'SHP-1',
293
+ marketplaceId: 'market-1',
294
+ id_documento_holded: 'doc-1',
295
+ tipo_documento_holded: 'invoice',
296
+ fecha_hora_creacion: expect.any(String),
297
+ fecha_creacion_externa: expect.any(String)
298
+ })
299
+ ]);
300
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([
301
+ {
302
+ id_envio: 12345,
303
+ json_referencias_cantidades: [{ id_caja: -1, referencias: { A1: 1 } }]
304
+ }
305
+ ]);
306
+ }));
307
+ it('uses warehouse address when warehouseId > 0', () => __awaiter(void 0, void 0, void 0, function* () {
308
+ const { manager, addressesService } = buildFixture();
309
+ arrangeDefaultStubs({ manager, shipmentId: 12345 });
310
+ yield manager.insertTempShipments({
311
+ payload: buildPayload({ warehouseId: 33 }),
312
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () { return [buildOrder()]; }),
313
+ crearBulto: jest.fn(),
314
+ modificarOrdenOriginal: (_b) => __awaiter(void 0, [_b], void 0, function* ({ originalOrder }) { return originalOrder; })
315
+ });
316
+ expect(addressesService.getWarehouseAddress).toHaveBeenCalledWith(77);
317
+ expect(addressesService.getAddress).not.toHaveBeenCalledWith(10, 77);
318
+ }));
319
+ it('passes shouldFindWarehouseSkus=true to insertQuantityRelatedLines when sku_almacen is enabled', () => __awaiter(void 0, void 0, void 0, function* () {
320
+ const { manager } = buildFixture({ skuAlmacen: 1 });
321
+ arrangeDefaultStubs({ manager, shipmentId: 12345 });
322
+ const insertQuantitySpy = jest
323
+ .spyOn(manager, 'insertQuantityRelatedLines')
324
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; }));
325
+ yield manager.insertTempShipments({
326
+ payload: buildPayload(),
327
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () { return [buildOrder()]; }),
328
+ crearBulto: jest.fn(),
329
+ modificarOrdenOriginal: (_c) => __awaiter(void 0, [_c], void 0, function* ({ originalOrder }) { return originalOrder; })
330
+ });
331
+ insertQuantitySpy.mock.calls[0][0].shouldFindWarehouseSkus = true;
332
+ expect(insertQuantitySpy).toHaveBeenCalledWith(expect.objectContaining({
333
+ shouldFindWarehouseSkus: true,
334
+ group: expect.objectContaining({ grouped: 0 })
335
+ }));
336
+ }));
337
+ it('passes grouped + sequentialInsertion values through and returns sequentialInsertion in response', () => __awaiter(void 0, void 0, void 0, function* () {
338
+ const { manager } = buildFixture();
339
+ arrangeDefaultStubs({ manager, shipmentId: 12345 });
340
+ const insertQuantitySpy = jest
341
+ .spyOn(manager, 'insertQuantityRelatedLines')
342
+ .mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return undefined; }));
343
+ const response = yield manager.insertTempShipments({
344
+ payload: buildPayload({
345
+ sequentialInsertion: false,
346
+ group: {
347
+ grouped: 1,
348
+ weight: 9,
349
+ height: 40,
350
+ width: 30,
351
+ length: 20
352
+ }
353
+ }),
354
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () { return [buildOrder()]; }),
355
+ crearBulto: jest.fn(),
356
+ modificarOrdenOriginal: (_d) => __awaiter(void 0, [_d], void 0, function* ({ originalOrder }) { return originalOrder; })
357
+ });
358
+ expect(insertQuantitySpy).toHaveBeenCalledWith(expect.objectContaining({
359
+ group: {
360
+ grouped: 1,
361
+ weight: 9,
362
+ height: 40,
363
+ width: 30,
364
+ length: 20
365
+ }
366
+ }));
367
+ expect(response.sequentialInsertion).toBe(false);
368
+ }));
369
+ it('updates agency when rule engine returns a different agency and uses shipment details in that decision', () => __awaiter(void 0, void 0, void 0, function* () {
370
+ const getAgencyIdForTempShipment = jest.fn((_e) => __awaiter(void 0, [_e], void 0, function* ({ shipmentDetails }) {
371
+ expect(shipmentDetails).toEqual([
372
+ expect.objectContaining({ id_envio: 12345, cantidad: 2 })
373
+ ]);
374
+ return 99;
375
+ }));
376
+ const { manager, integrationsService } = buildFixture({
377
+ getAgencyId: getAgencyIdForTempShipment
378
+ });
379
+ arrangeDefaultStubs({ manager, shipmentId: 12345 });
380
+ yield manager.insertTempShipments({
381
+ payload: buildPayload({ agencyId: 50 }),
382
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () { return [buildOrder()]; }),
383
+ crearBulto: jest.fn(),
384
+ modificarOrdenOriginal: (_f) => __awaiter(void 0, [_f], void 0, function* ({ originalOrder }) { return originalOrder; })
385
+ });
386
+ expect(getAgencyIdForTempShipment).toHaveBeenCalledTimes(1);
387
+ expect(integrationsService.updateTempShimpment).toHaveBeenCalledWith({
388
+ id_envio: 12345,
389
+ id_usuario: 77,
390
+ id_agencia: 99
391
+ });
392
+ }));
393
+ it('sends grouped package line to bulk insert when group=1 and order has more than one line', () => __awaiter(void 0, void 0, void 0, function* () {
394
+ const { manager, integrationsService } = buildFixture();
395
+ arrangeRealQuantityFlow({ manager, shipmentId: 12345 });
396
+ const crearBulto = jest.fn((_g) => __awaiter(void 0, [_g], void 0, function* ({ lineItems }) {
397
+ return ({
398
+ bulto: {
399
+ peso: 1.2,
400
+ alto: 3,
401
+ ancho: 4,
402
+ largo: 5,
403
+ sku_producto: lineItems.line.sku_producto,
404
+ nombre_producto: lineItems.line.nombre_producto
405
+ },
406
+ cantidad: 2,
407
+ forzarAgrupamientoDeLinea: false
408
+ });
409
+ }));
410
+ yield manager.insertTempShipments({
411
+ payload: buildPayload({
412
+ group: { grouped: 1, weight: 9, height: 40, width: 30, length: 20 }
413
+ }),
414
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
415
+ return [
416
+ buildOrder({
417
+ lineas: [
418
+ { nombre_producto: 'Prod 1', sku_producto: 'SKU-01' },
419
+ { nombre_producto: 'Prod 2', sku_producto: 'SKU-02' }
420
+ ]
421
+ })
422
+ ];
423
+ }),
424
+ crearBulto,
425
+ modificarOrdenOriginal: (_h) => __awaiter(void 0, [_h], void 0, function* ({ originalOrder }) { return originalOrder; })
426
+ });
427
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
428
+ {
429
+ id_envio: 12345,
430
+ bulto: {
431
+ peso: 9,
432
+ alto: 40,
433
+ ancho: 30,
434
+ largo: 20,
435
+ sku_producto: ''
436
+ }
437
+ }
438
+ ]);
439
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
440
+ expect.objectContaining({ id_envio: 12345, cantidad: 2 }),
441
+ expect.objectContaining({ id_envio: 12345, cantidad: 2 })
442
+ ]);
443
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([
444
+ expect.objectContaining({ id_envio: 12345, contenido: 'Auto-content' })
445
+ ]);
446
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
447
+ expect.objectContaining({ id_envio_temporal_usuario: 12345 })
448
+ ]);
449
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([]);
450
+ }));
451
+ it('sends grouped package line when group=1, one line, and medidas config is enabled', () => __awaiter(void 0, void 0, void 0, function* () {
452
+ const { manager, integrationsService } = buildFixture({
453
+ measuresFromConfig: 1
454
+ });
455
+ arrangeRealQuantityFlow({ manager, shipmentId: 12345 });
456
+ const crearBulto = jest.fn((_j) => __awaiter(void 0, [_j], void 0, function* ({ lineItems }) {
457
+ return ({
458
+ bulto: {
459
+ peso: 1,
460
+ alto: 2,
461
+ ancho: 3,
462
+ largo: 4,
463
+ sku_producto: lineItems.line.sku_producto,
464
+ nombre_producto: lineItems.line.nombre_producto
465
+ },
466
+ cantidad: 1,
467
+ forzarAgrupamientoDeLinea: false
468
+ });
469
+ }));
470
+ yield manager.insertTempShipments({
471
+ payload: buildPayload({
472
+ group: { grouped: 1, weight: 7, height: 50, width: 60, length: 70 }
473
+ }),
474
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
475
+ return [
476
+ buildOrder({
477
+ lineas: [{ nombre_producto: 'Only line', sku_producto: 'SKU-ONLY' }]
478
+ })
479
+ ];
480
+ }),
481
+ crearBulto,
482
+ modificarOrdenOriginal: (_k) => __awaiter(void 0, [_k], void 0, function* ({ originalOrder }) { return originalOrder; })
483
+ });
484
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
485
+ {
486
+ id_envio: 12345,
487
+ bulto: {
488
+ peso: 7,
489
+ alto: 50,
490
+ ancho: 60,
491
+ largo: 70,
492
+ sku_producto: ''
493
+ }
494
+ }
495
+ ]);
496
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
497
+ expect.objectContaining({
498
+ id_envio: 12345,
499
+ bulto: expect.objectContaining({ sku_producto: 'SKU-ONLY' })
500
+ })
501
+ ]);
502
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([expect.objectContaining({ id_envio: 12345 })]);
503
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
504
+ expect.objectContaining({ id_envio_temporal_usuario: 12345 })
505
+ ]);
506
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([]);
507
+ }));
508
+ it('sends non-grouped package line when group=1, one line and medidas config is disabled', () => __awaiter(void 0, void 0, void 0, function* () {
509
+ const { manager, integrationsService } = buildFixture({
510
+ measuresFromConfig: 0
511
+ });
512
+ arrangeRealQuantityFlow({ manager, shipmentId: 12345 });
513
+ const crearBulto = jest.fn((_l) => __awaiter(void 0, [_l], void 0, function* ({ lineItems }) {
514
+ return ({
515
+ bulto: {
516
+ peso: 2,
517
+ alto: 8,
518
+ ancho: 9,
519
+ largo: 10,
520
+ sku_producto: lineItems.line.sku_producto,
521
+ nombre_producto: lineItems.line.nombre_producto
522
+ },
523
+ cantidad: 1,
524
+ forzarAgrupamientoDeLinea: false
525
+ });
526
+ }));
527
+ yield manager.insertTempShipments({
528
+ payload: buildPayload({
529
+ group: { grouped: 1, weight: 99, height: 98, width: 97, length: 96 }
530
+ }),
531
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
532
+ return [
533
+ buildOrder({
534
+ lineas: [{ nombre_producto: 'Single', sku_producto: 'SKU-SINGLE' }]
535
+ })
536
+ ];
537
+ }),
538
+ crearBulto,
539
+ modificarOrdenOriginal: (_m) => __awaiter(void 0, [_m], void 0, function* ({ originalOrder }) { return originalOrder; })
540
+ });
541
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
542
+ {
543
+ id_envio: 12345,
544
+ bulto: {
545
+ peso: 2,
546
+ alto: 8,
547
+ ancho: 9,
548
+ largo: 10,
549
+ sku_producto: 'SKU-SINGLE',
550
+ nombre_producto: 'Single'
551
+ }
552
+ }
553
+ ]);
554
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
555
+ expect.objectContaining({ id_envio: 12345, cantidad: 1 })
556
+ ]);
557
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([expect.objectContaining({ id_envio: 12345 })]);
558
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
559
+ expect.objectContaining({ id_envio_temporal_usuario: 12345 })
560
+ ]);
561
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([]);
562
+ }));
563
+ it('includes json quantity references in bulk insert when shouldFindWarehouseSkus is enabled', () => __awaiter(void 0, void 0, void 0, function* () {
564
+ const { manager, integrationsService } = buildFixture({
565
+ skuAlmacen: 1
566
+ });
567
+ arrangeRealQuantityFlow({ manager, shipmentId: 12345 });
568
+ manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_o) => __awaiter(void 0, [_o], void 0, function* ({ sku }) {
569
+ return ({
570
+ id: sku === 'SKU-01' ? 111 : 222
571
+ });
572
+ }));
573
+ const crearBulto = jest.fn((_p) => __awaiter(void 0, [_p], void 0, function* ({ lineItems }) {
574
+ return ({
575
+ bulto: {
576
+ peso: 2,
577
+ alto: 8,
578
+ ancho: 9,
579
+ largo: 10,
580
+ sku_producto: lineItems.line.sku_producto,
581
+ nombre_producto: lineItems.line.nombre_producto
582
+ },
583
+ cantidad: 2,
584
+ forzarAgrupamientoDeLinea: false
585
+ });
586
+ }));
587
+ yield manager.insertTempShipments({
588
+ payload: buildPayload({
589
+ warehouseId: 88,
590
+ group: { grouped: 0, weight: 2, height: 10, width: 20, length: 30 }
591
+ }),
592
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
593
+ return [
594
+ buildOrder({
595
+ lineas: [{ nombre_producto: 'Line', sku_producto: 'SKU-01' }]
596
+ })
597
+ ];
598
+ }),
599
+ crearBulto,
600
+ modificarOrdenOriginal: (_q) => __awaiter(void 0, [_q], void 0, function* ({ originalOrder }) { return originalOrder; })
601
+ });
602
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
603
+ expect.objectContaining({ id_envio: 12345 }),
604
+ expect.objectContaining({ id_envio: 12345 })
605
+ ]);
606
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
607
+ expect.objectContaining({ id_envio: 12345, cantidad: 2 })
608
+ ]);
609
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([expect.objectContaining({ id_envio: 12345 })]);
610
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
611
+ expect.objectContaining({ id_envio_temporal_usuario: 12345 })
612
+ ]);
613
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([
614
+ {
615
+ id_envio: 12345,
616
+ json_referencias_cantidades: [
617
+ { id_caja: -1, referencias: { 111: 1 } },
618
+ { id_caja: -1, referencias: { 111: 1 } }
619
+ ]
620
+ }
621
+ ]);
622
+ }));
623
+ it('handles multiple orders and multiple lines in grouped mode', () => __awaiter(void 0, void 0, void 0, function* () {
624
+ const { manager, integrationsService } = buildFixture();
625
+ arrangeRealQuantityFlowMultipleOrders({
626
+ manager,
627
+ shipmentIds: [2001, 2002]
628
+ });
629
+ const crearBulto = jest.fn((_r) => __awaiter(void 0, [_r], void 0, function* ({ lineItems }) {
630
+ return ({
631
+ bulto: {
632
+ peso: 1.5,
633
+ alto: 3,
634
+ ancho: 4,
635
+ largo: 5,
636
+ sku_producto: lineItems.line.sku_producto,
637
+ nombre_producto: lineItems.line.nombre_producto
638
+ },
639
+ cantidad: 1,
640
+ forzarAgrupamientoDeLinea: false
641
+ });
642
+ }));
643
+ yield manager.insertTempShipments({
644
+ payload: buildPayload({
645
+ group: { grouped: 1, weight: 11, height: 21, width: 31, length: 41 }
646
+ }),
647
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
648
+ return [
649
+ buildOrder({
650
+ codigoEnvioExterno: 'EXT-A',
651
+ lineas: [
652
+ { nombre_producto: 'A1', sku_producto: 'SKU-A1' },
653
+ { nombre_producto: 'A2', sku_producto: 'SKU-A2' }
654
+ ]
655
+ }),
656
+ buildOrder({
657
+ codigoEnvioExterno: 'EXT-B',
658
+ idInternoShopify: 'SHP-2',
659
+ lineas: [
660
+ { nombre_producto: 'B1', sku_producto: 'SKU-B1' },
661
+ { nombre_producto: 'B2', sku_producto: 'SKU-B2' }
662
+ ]
663
+ })
664
+ ];
665
+ }),
666
+ crearBulto,
667
+ modificarOrdenOriginal: (_s) => __awaiter(void 0, [_s], void 0, function* ({ originalOrder }) { return originalOrder; })
668
+ });
669
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
670
+ {
671
+ id_envio: 2001,
672
+ bulto: { peso: 11, alto: 21, ancho: 31, largo: 41, sku_producto: '' }
673
+ },
674
+ {
675
+ id_envio: 2002,
676
+ bulto: { peso: 11, alto: 21, ancho: 31, largo: 41, sku_producto: '' }
677
+ }
678
+ ]);
679
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
680
+ expect.objectContaining({ id_envio: 2001, cantidad: 1 }),
681
+ expect.objectContaining({ id_envio: 2001, cantidad: 1 }),
682
+ expect.objectContaining({ id_envio: 2002, cantidad: 1 }),
683
+ expect.objectContaining({ id_envio: 2002, cantidad: 1 })
684
+ ]);
685
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([
686
+ expect.objectContaining({ id_envio: 2001 }),
687
+ expect.objectContaining({ id_envio: 2002 })
688
+ ]);
689
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
690
+ expect.objectContaining({ id_envio_temporal_usuario: 2001 }),
691
+ expect.objectContaining({ id_envio_temporal_usuario: 2002 })
692
+ ]);
693
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([]);
694
+ }));
695
+ it('handles multiple orders and multiple lines in non-grouped mode', () => __awaiter(void 0, void 0, void 0, function* () {
696
+ const { manager, integrationsService } = buildFixture({
697
+ emulateLegacyPackageAggregation: true
698
+ });
699
+ arrangeRealQuantityFlowMultipleOrders({
700
+ manager,
701
+ shipmentIds: [2101, 2102]
702
+ });
703
+ const crearBulto = jest.fn((_t) => __awaiter(void 0, [_t], void 0, function* ({ lineItems }) {
704
+ return ({
705
+ bulto: {
706
+ peso: 2,
707
+ alto: 7,
708
+ ancho: 8,
709
+ largo: 9,
710
+ sku_producto: lineItems.line.sku_producto,
711
+ nombre_producto: lineItems.line.nombre_producto
712
+ },
713
+ cantidad: 2,
714
+ forzarAgrupamientoDeLinea: false
715
+ });
716
+ }));
717
+ yield manager.insertTempShipments({
718
+ payload: buildPayload({
719
+ group: { grouped: 0, weight: 0, height: 0, width: 0, length: 0 }
720
+ }),
721
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
722
+ return [
723
+ buildOrder({
724
+ codigoEnvioExterno: 'EXT-C',
725
+ lineas: [
726
+ { nombre_producto: 'C1', sku_producto: 'SKU-C1' },
727
+ { nombre_producto: 'C2', sku_producto: 'SKU-C2' }
728
+ ]
729
+ }),
730
+ buildOrder({
731
+ codigoEnvioExterno: 'EXT-D',
732
+ lineas: [
733
+ { nombre_producto: 'D1', sku_producto: 'SKU-D1' },
734
+ { nombre_producto: 'D2', sku_producto: 'SKU-D2' }
735
+ ]
736
+ })
737
+ ];
738
+ }),
739
+ crearBulto,
740
+ modificarOrdenOriginal: (_u) => __awaiter(void 0, [_u], void 0, function* ({ originalOrder }) { return originalOrder; })
741
+ });
742
+ const linesArg = integrationsService.insertTempShipmentMultipleLines.mock.calls[0][0];
743
+ expect(linesArg).toHaveLength(8);
744
+ expect(linesArg.filter((line) => line.id_envio === 2101)).toHaveLength(4);
745
+ expect(linesArg.filter((line) => line.id_envio === 2102)).toHaveLength(4);
746
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
747
+ expect.objectContaining({ id_envio: 2101, cantidad: 2 }),
748
+ expect.objectContaining({ id_envio: 2101, cantidad: 2 }),
749
+ expect.objectContaining({ id_envio: 2102, cantidad: 2 }),
750
+ expect.objectContaining({ id_envio: 2102, cantidad: 2 })
751
+ ]);
752
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([
753
+ expect.objectContaining({ id_envio: 2101 }),
754
+ expect.objectContaining({ id_envio: 2102 })
755
+ ]);
756
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
757
+ expect.objectContaining({ id_envio_temporal_usuario: 2101 }),
758
+ expect.objectContaining({ id_envio_temporal_usuario: 2102 })
759
+ ]);
760
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([]);
761
+ }));
762
+ it('groups single-line orders when measures config is enabled', () => __awaiter(void 0, void 0, void 0, function* () {
763
+ const { manager, integrationsService } = buildFixture({
764
+ measuresFromConfig: 1
765
+ });
766
+ arrangeRealQuantityFlowMultipleOrders({
767
+ manager,
768
+ shipmentIds: [2201, 2202]
769
+ });
770
+ const crearBulto = jest.fn((_v) => __awaiter(void 0, [_v], void 0, function* ({ lineItems }) {
771
+ return ({
772
+ bulto: {
773
+ peso: 1,
774
+ alto: 2,
775
+ ancho: 3,
776
+ largo: 4,
777
+ sku_producto: lineItems.line.sku_producto,
778
+ nombre_producto: lineItems.line.nombre_producto
779
+ },
780
+ cantidad: 1,
781
+ forzarAgrupamientoDeLinea: false
782
+ });
783
+ }));
784
+ yield manager.insertTempShipments({
785
+ payload: buildPayload({
786
+ group: { grouped: 1, weight: 14, height: 24, width: 34, length: 44 }
787
+ }),
788
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
789
+ return [
790
+ buildOrder({
791
+ codigoEnvioExterno: 'EXT-E',
792
+ lineas: [{ nombre_producto: 'E1', sku_producto: 'SKU-E1' }]
793
+ }),
794
+ buildOrder({
795
+ codigoEnvioExterno: 'EXT-F',
796
+ lineas: [{ nombre_producto: 'F1', sku_producto: 'SKU-F1' }]
797
+ })
798
+ ];
799
+ }),
800
+ crearBulto,
801
+ modificarOrdenOriginal: (_w) => __awaiter(void 0, [_w], void 0, function* ({ originalOrder }) { return originalOrder; })
802
+ });
803
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
804
+ {
805
+ id_envio: 2201,
806
+ bulto: { peso: 14, alto: 24, ancho: 34, largo: 44, sku_producto: '' }
807
+ },
808
+ {
809
+ id_envio: 2202,
810
+ bulto: { peso: 14, alto: 24, ancho: 34, largo: 44, sku_producto: '' }
811
+ }
812
+ ]);
813
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
814
+ expect.objectContaining({ id_envio: 2201, cantidad: 1 }),
815
+ expect.objectContaining({ id_envio: 2202, cantidad: 1 })
816
+ ]);
817
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([
818
+ expect.objectContaining({ id_envio: 2201 }),
819
+ expect.objectContaining({ id_envio: 2202 })
820
+ ]);
821
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
822
+ expect.objectContaining({ id_envio_temporal_usuario: 2201 }),
823
+ expect.objectContaining({ id_envio_temporal_usuario: 2202 })
824
+ ]);
825
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([]);
826
+ }));
827
+ it('does not group single-line orders when measures config is disabled', () => __awaiter(void 0, void 0, void 0, function* () {
828
+ const { manager, integrationsService } = buildFixture({
829
+ measuresFromConfig: 0
830
+ });
831
+ arrangeRealQuantityFlowMultipleOrders({
832
+ manager,
833
+ shipmentIds: [2301, 2302]
834
+ });
835
+ const crearBulto = jest.fn((_x) => __awaiter(void 0, [_x], void 0, function* ({ lineItems }) {
836
+ return ({
837
+ bulto: {
838
+ peso: 3,
839
+ alto: 6,
840
+ ancho: 9,
841
+ largo: 12,
842
+ sku_producto: lineItems.line.sku_producto,
843
+ nombre_producto: lineItems.line.nombre_producto
844
+ },
845
+ cantidad: 1,
846
+ forzarAgrupamientoDeLinea: false
847
+ });
848
+ }));
849
+ yield manager.insertTempShipments({
850
+ payload: buildPayload({
851
+ group: { grouped: 1, weight: 50, height: 60, width: 70, length: 80 }
852
+ }),
853
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
854
+ return [
855
+ buildOrder({
856
+ codigoEnvioExterno: 'EXT-G',
857
+ lineas: [{ nombre_producto: 'G1', sku_producto: 'SKU-G1' }]
858
+ }),
859
+ buildOrder({
860
+ codigoEnvioExterno: 'EXT-H',
861
+ lineas: [{ nombre_producto: 'H1', sku_producto: 'SKU-H1' }]
862
+ })
863
+ ];
864
+ }),
865
+ crearBulto,
866
+ modificarOrdenOriginal: (_y) => __awaiter(void 0, [_y], void 0, function* ({ originalOrder }) { return originalOrder; })
867
+ });
868
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
869
+ {
870
+ id_envio: 2301,
871
+ bulto: {
872
+ peso: 3,
873
+ alto: 6,
874
+ ancho: 9,
875
+ largo: 12,
876
+ sku_producto: 'SKU-G1',
877
+ nombre_producto: 'G1'
878
+ }
879
+ },
880
+ {
881
+ id_envio: 2302,
882
+ bulto: {
883
+ peso: 3,
884
+ alto: 6,
885
+ ancho: 9,
886
+ largo: 12,
887
+ sku_producto: 'SKU-H1',
888
+ nombre_producto: 'H1'
889
+ }
890
+ }
891
+ ]);
892
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
893
+ expect.objectContaining({ id_envio: 2301, cantidad: 1 }),
894
+ expect.objectContaining({ id_envio: 2302, cantidad: 1 })
895
+ ]);
896
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([
897
+ expect.objectContaining({ id_envio: 2301 }),
898
+ expect.objectContaining({ id_envio: 2302 })
899
+ ]);
900
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
901
+ expect.objectContaining({ id_envio_temporal_usuario: 2301 }),
902
+ expect.objectContaining({ id_envio_temporal_usuario: 2302 })
903
+ ]);
904
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([]);
905
+ }));
906
+ it('builds json quantity references for multiple shipments when sku lookup is enabled', () => __awaiter(void 0, void 0, void 0, function* () {
907
+ const { manager, integrationsService } = buildFixture({
908
+ skuAlmacen: 1
909
+ });
910
+ arrangeRealQuantityFlowMultipleOrders({
911
+ manager,
912
+ shipmentIds: [2401, 2402]
913
+ });
914
+ manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_z) => __awaiter(void 0, [_z], void 0, function* ({ sku }) {
915
+ if (sku === 'SKU-I1')
916
+ return { id: 901 };
917
+ if (sku === 'SKU-J1')
918
+ return { id: 902 };
919
+ return { id: 999 };
920
+ }));
921
+ const crearBulto = jest.fn((_0) => __awaiter(void 0, [_0], void 0, function* ({ lineItems }) {
922
+ return ({
923
+ bulto: {
924
+ peso: 2,
925
+ alto: 8,
926
+ ancho: 9,
927
+ largo: 10,
928
+ sku_producto: lineItems.line.sku_producto,
929
+ nombre_producto: lineItems.line.nombre_producto
930
+ },
931
+ cantidad: 2,
932
+ forzarAgrupamientoDeLinea: false
933
+ });
934
+ }));
935
+ yield manager.insertTempShipments({
936
+ payload: buildPayload({
937
+ warehouseId: 55,
938
+ group: { grouped: 0, weight: 1, height: 1, width: 1, length: 1 }
939
+ }),
940
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
941
+ return [
942
+ buildOrder({
943
+ codigoEnvioExterno: 'EXT-I',
944
+ lineas: [
945
+ { nombre_producto: 'I1', sku_producto: 'SKU-I1' },
946
+ { nombre_producto: 'I2', sku_producto: 'SKU-I1' }
947
+ ]
948
+ }),
949
+ buildOrder({
950
+ codigoEnvioExterno: 'EXT-J',
951
+ lineas: [
952
+ { nombre_producto: 'J1', sku_producto: 'SKU-J1' },
953
+ { nombre_producto: 'J2', sku_producto: 'SKU-J1' }
954
+ ]
955
+ })
956
+ ];
957
+ }),
958
+ crearBulto,
959
+ modificarOrdenOriginal: (_1) => __awaiter(void 0, [_1], void 0, function* ({ originalOrder }) { return originalOrder; })
960
+ });
961
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([
962
+ {
963
+ id_envio: 2401,
964
+ json_referencias_cantidades: [
965
+ { id_caja: -1, referencias: { 901: 1 } },
966
+ { id_caja: -1, referencias: { 901: 1 } },
967
+ { id_caja: -1, referencias: { 901: 1 } },
968
+ { id_caja: -1, referencias: { 901: 1 } }
969
+ ]
970
+ },
971
+ {
972
+ id_envio: 2402,
973
+ json_referencias_cantidades: [
974
+ { id_caja: -1, referencias: { 902: 1 } },
975
+ { id_caja: -1, referencias: { 902: 1 } },
976
+ { id_caja: -1, referencias: { 902: 1 } },
977
+ { id_caja: -1, referencias: { 902: 1 } }
978
+ ]
979
+ }
980
+ ]);
981
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith(expect.arrayContaining([
982
+ expect.objectContaining({ id_envio: 2401 }),
983
+ expect.objectContaining({ id_envio: 2402 })
984
+ ]));
985
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith(expect.arrayContaining([
986
+ expect.objectContaining({ id_envio: 2401 }),
987
+ expect.objectContaining({ id_envio: 2402 })
988
+ ]));
989
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([
990
+ expect.objectContaining({ id_envio: 2401 }),
991
+ expect.objectContaining({ id_envio: 2402 })
992
+ ]);
993
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
994
+ expect.objectContaining({ id_envio_temporal_usuario: 2401 }),
995
+ expect.objectContaining({ id_envio_temporal_usuario: 2402 })
996
+ ]);
997
+ }));
998
+ it('mixes grouped and non-grouped orders in the same run', () => __awaiter(void 0, void 0, void 0, function* () {
999
+ const { manager, integrationsService } = buildFixture({
1000
+ measuresFromConfig: 0
1001
+ });
1002
+ arrangeRealQuantityFlowMultipleOrders({
1003
+ manager,
1004
+ shipmentIds: [2501, 2502]
1005
+ });
1006
+ const crearBulto = jest.fn((_2) => __awaiter(void 0, [_2], void 0, function* ({ lineItems }) {
1007
+ const groupedOrderLine = lineItems.line.sku_producto.startsWith('SKU-K');
1008
+ return {
1009
+ bulto: {
1010
+ peso: groupedOrderLine ? 5 : 2,
1011
+ alto: groupedOrderLine ? 15 : 6,
1012
+ ancho: groupedOrderLine ? 16 : 7,
1013
+ largo: groupedOrderLine ? 17 : 8,
1014
+ sku_producto: lineItems.line.sku_producto,
1015
+ nombre_producto: lineItems.line.nombre_producto
1016
+ },
1017
+ cantidad: 1,
1018
+ forzarAgrupamientoDeLinea: false
1019
+ };
1020
+ }));
1021
+ yield manager.insertTempShipments({
1022
+ payload: buildPayload({
1023
+ group: { grouped: 1, weight: 44, height: 45, width: 46, length: 47 }
1024
+ }),
1025
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
1026
+ return [
1027
+ buildOrder({
1028
+ codigoEnvioExterno: 'EXT-K',
1029
+ lineas: [
1030
+ { nombre_producto: 'K1', sku_producto: 'SKU-K1' },
1031
+ { nombre_producto: 'K2', sku_producto: 'SKU-K2' }
1032
+ ]
1033
+ }),
1034
+ buildOrder({
1035
+ codigoEnvioExterno: 'EXT-L',
1036
+ lineas: [{ nombre_producto: 'L1', sku_producto: 'SKU-L1' }]
1037
+ })
1038
+ ];
1039
+ }),
1040
+ crearBulto,
1041
+ modificarOrdenOriginal: (_3) => __awaiter(void 0, [_3], void 0, function* ({ originalOrder }) { return originalOrder; })
1042
+ });
1043
+ expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
1044
+ {
1045
+ id_envio: 2501,
1046
+ bulto: { peso: 44, alto: 45, ancho: 46, largo: 47, sku_producto: '' }
1047
+ },
1048
+ {
1049
+ id_envio: 2502,
1050
+ bulto: {
1051
+ peso: 2,
1052
+ alto: 6,
1053
+ ancho: 7,
1054
+ largo: 8,
1055
+ sku_producto: 'SKU-L1',
1056
+ nombre_producto: 'L1'
1057
+ }
1058
+ }
1059
+ ]);
1060
+ expect(integrationsService.insertTempShipmentMultipleDetails).toHaveBeenCalledWith([
1061
+ expect.objectContaining({ id_envio: 2501 }),
1062
+ expect.objectContaining({ id_envio: 2501 }),
1063
+ expect.objectContaining({ id_envio: 2502 })
1064
+ ]);
1065
+ expect(integrationsService.insertTempShipmentMultipleContents).toHaveBeenCalledWith([
1066
+ expect.objectContaining({ id_envio: 2501 }),
1067
+ expect.objectContaining({ id_envio: 2502 })
1068
+ ]);
1069
+ expect(integrationsService.insertTempShipmentMultipleExternals).toHaveBeenCalledWith([
1070
+ expect.objectContaining({ id_envio_temporal_usuario: 2501 }),
1071
+ expect.objectContaining({ id_envio_temporal_usuario: 2502 })
1072
+ ]);
1073
+ expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([]);
1074
+ }));
1075
+ it('excludes aborted shipments from all 5 bulk insertion payloads', () => __awaiter(void 0, void 0, void 0, function* () {
1076
+ const { manager, integrationsService } = buildFixture({
1077
+ skuAlmacen: 1
1078
+ });
1079
+ manager.services.integrationsService.insertTempShipment
1080
+ .mockResolvedValueOnce(2601)
1081
+ .mockResolvedValueOnce(2602);
1082
+ manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_4) => __awaiter(void 0, [_4], void 0, function* ({ sku }) { return ({ id: sku === 'SKU-M1' ? 7001 : 7002 }); }));
1083
+ manager.getModifiedOrderBasedOnRules = jest.fn((_5) => __awaiter(void 0, [_5], void 0, function* ({ parsedOrder }) {
1084
+ if (parsedOrder.codigoEnvioExterno === 'EXT-ABORT') {
1085
+ return {
1086
+ partialTempShipmentModified: { abort_creation: true },
1087
+ packagesModified: []
1088
+ };
1089
+ }
1090
+ return {
1091
+ partialTempShipmentModified: {},
1092
+ packagesModified: []
1093
+ };
1094
+ }));
1095
+ const crearBulto = jest.fn((_6) => __awaiter(void 0, [_6], void 0, function* ({ lineItems }) {
1096
+ return ({
1097
+ bulto: {
1098
+ peso: 2,
1099
+ alto: 4,
1100
+ ancho: 6,
1101
+ largo: 8,
1102
+ sku_producto: lineItems.line.sku_producto,
1103
+ nombre_producto: lineItems.line.nombre_producto
1104
+ },
1105
+ cantidad: 2,
1106
+ forzarAgrupamientoDeLinea: false
1107
+ });
1108
+ }));
1109
+ yield manager.insertTempShipments({
1110
+ payload: buildPayload({
1111
+ warehouseId: 77,
1112
+ group: { grouped: 0, weight: 1, height: 1, width: 1, length: 1 }
1113
+ }),
1114
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
1115
+ return [
1116
+ buildOrder({
1117
+ codigoEnvioExterno: 'EXT-KEEP',
1118
+ lineas: [{ nombre_producto: 'Keep line', sku_producto: 'SKU-M1' }]
1119
+ }),
1120
+ buildOrder({
1121
+ codigoEnvioExterno: 'EXT-ABORT',
1122
+ lineas: [{ nombre_producto: 'Abort line', sku_producto: 'SKU-N1' }]
1123
+ })
1124
+ ];
1125
+ }),
1126
+ crearBulto,
1127
+ modificarOrdenOriginal: (_7) => __awaiter(void 0, [_7], void 0, function* ({ originalOrder }) { return originalOrder; })
1128
+ });
1129
+ const linesArg = integrationsService.insertTempShipmentMultipleLines.mock.calls[0][0];
1130
+ const detailsArg = integrationsService.insertTempShipmentMultipleDetails.mock.calls[0][0];
1131
+ const contentsArg = integrationsService.insertTempShipmentMultipleContents.mock.calls[0][0];
1132
+ const externalsArg = integrationsService.insertTempShipmentMultipleExternals.mock.calls[0][0];
1133
+ const jsonRefsArg = integrationsService.insertTempShipmentMultipleJsonQuantityReferences.mock
1134
+ .calls[0][0];
1135
+ expect(linesArg.every((line) => line.id_envio === 2601)).toBe(true);
1136
+ expect(detailsArg.every((detail) => detail.id_envio === 2601)).toBe(true);
1137
+ expect(contentsArg.every((content) => content.id_envio === 2601)).toBe(true);
1138
+ expect(externalsArg.every((external) => external.id_envio_temporal_usuario === 2601)).toBe(true);
1139
+ expect(jsonRefsArg.every((ref) => ref.id_envio === 2601)).toBe(true);
1140
+ expect(linesArg.some((line) => line.id_envio === 2602)).toBe(false);
1141
+ expect(detailsArg.some((detail) => detail.id_envio === 2602)).toBe(false);
1142
+ expect(contentsArg.some((content) => content.id_envio === 2602)).toBe(false);
1143
+ expect(externalsArg.some((external) => external.id_envio_temporal_usuario === 2602)).toBe(false);
1144
+ expect(jsonRefsArg.some((ref) => ref.id_envio === 2602)).toBe(false);
1145
+ expect(integrationsService.deleteTempShipment).toHaveBeenCalledWith({
1146
+ id_envio: 2602,
1147
+ id_usuario: 77
1148
+ });
1149
+ }));
1150
+ });