@vyro-x/pricing-client
Advanced tools
Comparing version 0.4.3 to 0.5.0
import { Product } from './getProductLineItems'; | ||
import { PromoCode } from './promoCodes'; | ||
import { PricingConfigV2 } from './types'; | ||
import { PricingConfigV2, PricingCustomerType } from './types'; | ||
type Args = { | ||
@@ -8,3 +8,4 @@ basePricingConfig: PricingConfigV2; | ||
allProducts: Product[]; | ||
promoCode?: PromoCode; | ||
promoCode?: PromoCode | null; | ||
customerType?: PricingCustomerType | null; | ||
}; | ||
@@ -11,0 +12,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getOrderPricingConfig = void 0; | ||
const filterByCustomerType_1 = require("./filterByCustomerType"); | ||
const getProductLineItems_1 = require("./getProductLineItems"); | ||
@@ -11,11 +12,16 @@ const promoCodes_1 = require("./promoCodes"); | ||
const getOrderPricingConfig = (args) => { | ||
var _a, _b; | ||
const adjusted = (0, recalc_1.recalc)(Object.assign(Object.assign({}, args.basePricingConfig), { lineItems: Object.assign(Object.assign({}, args.basePricingConfig.lineItems), { dutiable: [ | ||
...(((_a = args.basePricingConfig.lineItems) === null || _a === void 0 ? void 0 : _a.dutiable) || []), | ||
...(0, promoCodes_1.getDutiablePromoCodeLineItems)(args.promoCode), | ||
], additional: [ | ||
...(((_b = args.basePricingConfig.lineItems) === null || _b === void 0 ? void 0 : _b.additional) || []), | ||
...(0, getProductLineItems_1.getProductLineItems)(args.additionalProductVariants, args.allProducts), | ||
...(0, promoCodes_1.getAdditionalPromoCodeLineItems)(args.promoCode), | ||
] }) })); | ||
var _a, _b, _c; | ||
const customerType = args.customerType || 'consumer'; | ||
const dutiable = (0, filterByCustomerType_1.filterByCustomerType)([...(((_a = args.basePricingConfig.lineItems) === null || _a === void 0 ? void 0 : _a.dutiable) || []), ...(0, promoCodes_1.getDutiablePromoCodeLineItems)(args.promoCode)], customerType); | ||
const onRoad = (0, filterByCustomerType_1.filterByCustomerType)(((_b = args.basePricingConfig.lineItems) === null || _b === void 0 ? void 0 : _b.onRoad) || [], customerType); | ||
const additional = (0, filterByCustomerType_1.filterByCustomerType)([ | ||
...(((_c = args.basePricingConfig.lineItems) === null || _c === void 0 ? void 0 : _c.additional) || []), | ||
...(0, getProductLineItems_1.getProductLineItems)(args.additionalProductVariants, args.allProducts), | ||
...(0, promoCodes_1.getAdditionalPromoCodeLineItems)(args.promoCode), | ||
], customerType); | ||
const adjusted = (0, recalc_1.recalc)(Object.assign(Object.assign({}, args.basePricingConfig), { lineItems: { | ||
onRoad, | ||
dutiable, | ||
additional, | ||
} })); | ||
return adjusted; | ||
@@ -22,0 +28,0 @@ }; |
@@ -5,4 +5,7 @@ "use strict"; | ||
const getOrderPricingConfig_1 = require("./getOrderPricingConfig"); | ||
test('should calc the pricing config', () => { | ||
const basePricingConfig = { | ||
let basePricingConfig; | ||
let allProducts; | ||
let additionalProductVariants; | ||
beforeEach(() => { | ||
basePricingConfig = { | ||
version: 'v2', | ||
@@ -16,3 +19,3 @@ lineItems: { | ||
}; | ||
const allProducts = [ | ||
allProducts = [ | ||
{ | ||
@@ -29,3 +32,5 @@ name: 'product', | ||
]; | ||
const additionalProductVariants = ['variant-123']; | ||
additionalProductVariants = ['variant-123']; | ||
}); | ||
test('should calc the pricing config', () => { | ||
const result = (0, getOrderPricingConfig_1.getOrderPricingConfig)({ | ||
@@ -46,2 +51,80 @@ basePricingConfig, | ||
}); | ||
test('should filter out consumer pricing items when customer type is commercial', () => { | ||
basePricingConfig = { | ||
version: 'v2', | ||
lineItems: { | ||
dutiable: [{ code: types_1.DutiablePricingCode.VehiclePrice, value: 10000 }], | ||
onRoad: [{ code: types_1.OnRoadPricingCode.Grant, value: 10000, customerType: 'consumer' }], | ||
additional: [], | ||
}, | ||
driveAwayPrice: 20000, | ||
}; | ||
const result = (0, getOrderPricingConfig_1.getOrderPricingConfig)({ | ||
basePricingConfig, | ||
additionalProductVariants: [], | ||
allProducts: [], | ||
promoCode: null, | ||
customerType: 'commercial', | ||
}); | ||
expect(result).toMatchObject({ | ||
lineItems: { | ||
dutiable: [{ code: types_1.DutiablePricingCode.VehiclePrice, value: 10000 }], | ||
onRoad: [], | ||
additional: [], | ||
}, | ||
driveAwayPrice: 10000, | ||
}); | ||
}); | ||
test('should filter out commercial pricing items when customer type is consumer', () => { | ||
basePricingConfig = { | ||
version: 'v2', | ||
lineItems: { | ||
dutiable: [{ code: types_1.DutiablePricingCode.VehiclePrice, value: 10000 }], | ||
onRoad: [{ code: types_1.OnRoadPricingCode.Grant, value: 10000, customerType: 'commercial' }], | ||
additional: [], | ||
}, | ||
driveAwayPrice: 20000, | ||
}; | ||
const result = (0, getOrderPricingConfig_1.getOrderPricingConfig)({ | ||
basePricingConfig, | ||
additionalProductVariants: [], | ||
allProducts: [], | ||
promoCode: null, | ||
customerType: 'consumer', | ||
}); | ||
expect(result).toMatchObject({ | ||
lineItems: { | ||
dutiable: [{ code: types_1.DutiablePricingCode.VehiclePrice, value: 10000 }], | ||
onRoad: [], | ||
additional: [], | ||
}, | ||
driveAwayPrice: 10000, | ||
}); | ||
}); | ||
test('should filter out commercial pricing items when customer type is not set', () => { | ||
basePricingConfig = { | ||
version: 'v2', | ||
lineItems: { | ||
dutiable: [{ code: types_1.DutiablePricingCode.VehiclePrice, value: 10000 }], | ||
onRoad: [{ code: types_1.OnRoadPricingCode.Grant, value: 10000, customerType: 'commercial' }], | ||
additional: [], | ||
}, | ||
driveAwayPrice: 20000, | ||
}; | ||
const result = (0, getOrderPricingConfig_1.getOrderPricingConfig)({ | ||
basePricingConfig, | ||
additionalProductVariants: [], | ||
allProducts: [], | ||
promoCode: null, | ||
customerType: null, | ||
}); | ||
expect(result).toMatchObject({ | ||
lineItems: { | ||
dutiable: [{ code: types_1.DutiablePricingCode.VehiclePrice, value: 10000 }], | ||
onRoad: [], | ||
additional: [], | ||
}, | ||
driveAwayPrice: 10000, | ||
}); | ||
}); | ||
//# sourceMappingURL=getOrderPricingConfig.test.js.map |
@@ -51,2 +51,3 @@ export type PricingConfigV1 = { | ||
export type PricingCode = DutiablePricingCode | OnRoadPricingCode | AdditionalPricingCode; | ||
export type PricingCustomerType = 'consumer' | 'commercial'; | ||
export type PricingLineItem<T> = { | ||
@@ -58,2 +59,3 @@ code: T; | ||
productVariantId?: string; | ||
customerType?: PricingCustomerType; | ||
}; | ||
@@ -60,0 +62,0 @@ export type PricingConfigV2 = { |
{ | ||
"name": "@vyro-x/pricing-client", | ||
"description": "Client methods and type definitions for price-related entities in Vyro", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26175
25
443