const getParcelPickups = (parcels) => { return Promise.all( parcels.map((parcel) => { const [warehouse] = cacheContainer.warehousesByMerchantId.get(Number(parcel.merchantId)) || []; const pickupRegion = cacheContainer.pickupRegionsByGeoId.get(warehouse.geoId); return getPickupFromParcel({ warehouse, pickupRegion }); })) };
test('getParcelPickups', () => { const mockParcels = [ { merchantId: 1 }, { merchantId: 2 }, { merchantId: 3 }, ]; const mockWarehouses = [ { geoId: 1 }, { geoId: 2 }, { geoId: 3 }, ]; const mockPickupRegions = [ { geoId: 1 }, { geoId: 2 }, { geoId: 3 }, ]; cacheContainer.warehousesByMerchantId = new Map([ [1, [mockWarehouses[0]]], [2, [mockWarehouses[1]]], [3, [mockWarehouses[2]]], ]); cacheContainer.pickupRegionsByGeoId = new Map([ [1, mockPickupRegions[0]], [2, mockPickupRegions[1]], [3, mockPickupRegions[2]], ]); const