@adtrackify/at-service-common 5.1.2 → 5.1.4
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/cjs/__tests__/clients/acuity-client.spec.js +20 -21
- package/dist/cjs/__tests__/clients/acuity-client.spec.js.map +1 -1
- package/dist/cjs/__tests__/clients/cross-platform-compression.spec.js +86 -97
- package/dist/cjs/__tests__/clients/cross-platform-compression.spec.js.map +1 -1
- package/dist/cjs/__tests__/clients/dynamodb-client.spec.js +95 -94
- package/dist/cjs/__tests__/clients/dynamodb-client.spec.js.map +1 -1
- package/dist/cjs/__tests__/clients/event-collector-client.spec.js +58 -58
- package/dist/cjs/__tests__/clients/event-collector-client.spec.js.map +1 -1
- package/dist/cjs/__tests__/clients/liveintent-client.spec.js +37 -0
- package/dist/cjs/__tests__/clients/liveintent-client.spec.js.map +1 -0
- package/dist/cjs/__tests__/clients/open-exchange-rates-client.spec.js +17 -18
- package/dist/cjs/__tests__/clients/open-exchange-rates-client.spec.js.map +1 -1
- package/dist/cjs/__tests__/clients/sqs-bundled-client.spec.js +255 -273
- package/dist/cjs/__tests__/clients/sqs-bundled-client.spec.js.map +1 -1
- package/dist/cjs/__tests__/clients/sqs-bundling-contracts.spec.js +125 -137
- package/dist/cjs/__tests__/clients/sqs-bundling-contracts.spec.js.map +1 -1
- package/dist/cjs/__tests__/clients/sqs-client.spec.js +77 -78
- package/dist/cjs/__tests__/clients/sqs-client.spec.js.map +1 -1
- package/dist/cjs/__tests__/clients/sqs-unbundle.spec.js +430 -431
- package/dist/cjs/__tests__/clients/sqs-unbundle.spec.js.map +1 -1
- package/dist/cjs/__tests__/db/contact-enrichments-db-service.spec.js +29 -30
- package/dist/cjs/__tests__/db/contact-enrichments-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/db/destinations-db-service.spec.js +47 -45
- package/dist/cjs/__tests__/db/destinations-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/db/products-db-service.spec.js +40 -41
- package/dist/cjs/__tests__/db/products-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/db/shared-read-db-services.spec.js +26 -27
- package/dist/cjs/__tests__/db/shared-read-db-services.spec.js.map +1 -1
- package/dist/cjs/__tests__/db/shopify-app-installs-db-service.spec.js +37 -38
- package/dist/cjs/__tests__/db/shopify-app-installs-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/db/subscriptions-db-service.spec.js +35 -36
- package/dist/cjs/__tests__/db/subscriptions-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/db/user-accounts-db-service.spec.js +27 -28
- package/dist/cjs/__tests__/db/user-accounts-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/helpers/account-users-helper.spec.js +64 -65
- package/dist/cjs/__tests__/helpers/account-users-helper.spec.js.map +1 -1
- package/dist/cjs/__tests__/helpers/acuity-helper.spec.js +18 -19
- package/dist/cjs/__tests__/helpers/acuity-helper.spec.js.map +1 -1
- package/dist/cjs/__tests__/helpers/api-key-auth-helper.spec.js +23 -24
- package/dist/cjs/__tests__/helpers/api-key-auth-helper.spec.js.map +1 -1
- package/dist/cjs/__tests__/helpers/cognito-auth-helper.spec.js +16 -17
- package/dist/cjs/__tests__/helpers/cognito-auth-helper.spec.js.map +1 -1
- package/dist/cjs/__tests__/helpers/order-calculation-helper.spec.js +42 -43
- package/dist/cjs/__tests__/helpers/order-calculation-helper.spec.js.map +1 -1
- package/dist/cjs/__tests__/helpers/public-api-response-helper.spec.js +23 -24
- package/dist/cjs/__tests__/helpers/public-api-response-helper.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/helpers.spec.js +114 -115
- package/dist/cjs/__tests__/identity-cache/helpers.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-alias-write.spec.js +29 -30
- package/dist/cjs/__tests__/identity-cache/identity-cache-alias-write.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.js +19 -20
- package/dist/cjs/__tests__/identity-cache/identity-cache-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.js +200 -223
- package/dist/cjs/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-cache-tier-routing.spec.js +114 -123
- package/dist/cjs/__tests__/identity-cache/identity-cache-tier-routing.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-client.spec.js +107 -110
- package/dist/cjs/__tests__/identity-cache/identity-client.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-cache-hit.spec.js +31 -32
- package/dist/cjs/__tests__/identity-cache/identity-gateway-cache-hit.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-cache-miss.spec.js +47 -60
- package/dist/cjs/__tests__/identity-cache/identity-gateway-cache-miss.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-constructor.spec.js +15 -16
- package/dist/cjs/__tests__/identity-cache/identity-gateway-constructor.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-edge-cases.spec.js +28 -35
- package/dist/cjs/__tests__/identity-cache/identity-gateway-edge-cases.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-enqueue-async.spec.js +27 -28
- package/dist/cjs/__tests__/identity-cache/identity-gateway-enqueue-async.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-stale-cache.spec.js +52 -74
- package/dist/cjs/__tests__/identity-cache/identity-gateway-stale-cache.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/identity-gateway-test-setup.d.ts +18 -14
- package/dist/cjs/__tests__/identity-cache/identity-gateway-test-setup.js +30 -37
- package/dist/cjs/__tests__/identity-cache/identity-gateway-test-setup.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/trait-merging-and-staleness.spec.js +424 -403
- package/dist/cjs/__tests__/identity-cache/trait-merging-and-staleness.spec.js.map +1 -1
- package/dist/cjs/__tests__/identity-cache/volatile-traits-optimization.spec.js +218 -219
- package/dist/cjs/__tests__/identity-cache/volatile-traits-optimization.spec.js.map +1 -1
- package/dist/cjs/__tests__/integration/sqs-bundling-roundtrip.spec.js +117 -118
- package/dist/cjs/__tests__/integration/sqs-bundling-roundtrip.spec.js.map +1 -1
- package/dist/cjs/__tests__/libs/compress-decompress.spec.js +7 -8
- package/dist/cjs/__tests__/libs/compress-decompress.spec.js.map +1 -1
- package/dist/cjs/__tests__/libs/contacts.spec.js +101 -102
- package/dist/cjs/__tests__/libs/contacts.spec.js.map +1 -1
- package/dist/cjs/__tests__/libs/currency.spec.js +56 -57
- package/dist/cjs/__tests__/libs/currency.spec.js.map +1 -1
- package/dist/cjs/__tests__/libs/dates.spec.js +94 -82
- package/dist/cjs/__tests__/libs/dates.spec.js.map +1 -1
- package/dist/cjs/__tests__/libs/domain.spec.js +68 -69
- package/dist/cjs/__tests__/libs/domain.spec.js.map +1 -1
- package/dist/cjs/__tests__/libs/numbers.spec.js +249 -250
- package/dist/cjs/__tests__/libs/numbers.spec.js.map +1 -1
- package/dist/cjs/__tests__/s3-client/s3-client.spec.js +16 -15
- package/dist/cjs/__tests__/s3-client/s3-client.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/acuity-api-service.spec.js +32 -35
- package/dist/cjs/__tests__/services/acuity-api-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.js +14 -15
- package/dist/cjs/__tests__/services/cost/cost-calculation-types.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/cost/cost-calculator-service.spec.js +949 -1187
- package/dist/cjs/__tests__/services/cost/cost-calculator-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/cost/cost-currency-service.spec.js +39 -40
- package/dist/cjs/__tests__/services/cost/cost-currency-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/cost/cost-filter-service.spec.js +204 -201
- package/dist/cjs/__tests__/services/cost/cost-filter-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js +174 -299
- package/dist/cjs/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/email-verification/contact-email-verification-service.spec.js +39 -41
- package/dist/cjs/__tests__/services/email-verification/contact-email-verification-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/email-verification/email-verification-service.spec.js +22 -27
- package/dist/cjs/__tests__/services/email-verification/email-verification-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/events/collect-queue-tracking-service.spec.js +64 -67
- package/dist/cjs/__tests__/services/events/collect-queue-tracking-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/events/tracking-event-sqs-service.spec.js +51 -54
- package/dist/cjs/__tests__/services/events/tracking-event-sqs-service.spec.js.map +1 -1
- package/dist/cjs/__tests__/services/liveintent-api-service.spec.js +67 -0
- package/dist/cjs/__tests__/services/liveintent-api-service.spec.js.map +1 -0
- package/dist/cjs/__tests__/shopify/shopify-graphql-transformer.spec.js +9 -10
- package/dist/cjs/__tests__/shopify/shopify-graphql-transformer.spec.js.map +1 -1
- package/dist/cjs/__tests__/unit/libs/api-router/public-api-router.spec.js +58 -69
- package/dist/cjs/__tests__/unit/libs/api-router/public-api-router.spec.js.map +1 -1
- package/dist/cjs/__tests__/unit/libs/api-router/route-matcher.spec.js +31 -32
- package/dist/cjs/__tests__/unit/libs/api-router/route-matcher.spec.js.map +1 -1
- package/dist/cjs/__tests__/utils/custom-measure-formula-utils.spec.js +64 -65
- package/dist/cjs/__tests__/utils/custom-measure-formula-utils.spec.js.map +1 -1
- package/dist/cjs/clients/generic/cognito-client.js +14 -14
- package/dist/cjs/clients/generic/cognito-client.js.map +1 -1
- package/dist/cjs/clients/generic/dynamodb-client.js +9 -9
- package/dist/cjs/clients/generic/dynamodb-client.js.map +1 -1
- package/dist/cjs/clients/generic/eventbridge-client.js +2 -2
- package/dist/cjs/clients/generic/eventbridge-client.js.map +1 -1
- package/dist/cjs/clients/generic/http-client.js +5 -5
- package/dist/cjs/clients/generic/http-client.js.map +1 -1
- package/dist/cjs/clients/generic/lambda-invoke-client.js.map +1 -1
- package/dist/cjs/clients/generic/location-client.js +2 -2
- package/dist/cjs/clients/generic/location-client.js.map +1 -1
- package/dist/cjs/clients/generic/redis-client.js +2 -13
- package/dist/cjs/clients/generic/redis-client.js.map +1 -1
- package/dist/cjs/clients/generic/s3-client.d.ts +1 -0
- package/dist/cjs/clients/generic/s3-client.js +19 -19
- package/dist/cjs/clients/generic/s3-client.js.map +1 -1
- package/dist/cjs/clients/generic/singlestore-db-client.d.ts +2 -2
- package/dist/cjs/clients/generic/singlestore-db-client.js +8 -18
- package/dist/cjs/clients/generic/singlestore-db-client.js.map +1 -1
- package/dist/cjs/clients/generic/sqs-bundled-client.js +2 -2
- package/dist/cjs/clients/generic/sqs-bundled-client.js.map +1 -1
- package/dist/cjs/clients/generic/sqs-bundled-client.types.js +1 -1
- package/dist/cjs/clients/generic/sqs-bundled-client.types.js.map +1 -1
- package/dist/cjs/clients/generic/sqs-client.d.ts +1 -1
- package/dist/cjs/clients/generic/sqs-client.js +2 -2
- package/dist/cjs/clients/generic/sqs-client.js.map +1 -1
- package/dist/cjs/clients/generic/sqs-unbundle.js +7 -6
- package/dist/cjs/clients/generic/sqs-unbundle.js.map +1 -1
- package/dist/cjs/clients/internal-api/accounts-client.js +14 -14
- package/dist/cjs/clients/internal-api/accounts-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/cache-lambda-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/db-management-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/destinations-client.d.ts +2 -1
- package/dist/cjs/clients/internal-api/destinations-client.js +15 -8
- package/dist/cjs/clients/internal-api/destinations-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/event-collector-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/identity-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/shopify-app-install-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/subscriptions-client.js.map +1 -1
- package/dist/cjs/clients/internal-api/users-auth-client.js +11 -11
- package/dist/cjs/clients/internal-api/users-auth-client.js.map +1 -1
- package/dist/cjs/clients/third-party/acuity-client.js.map +1 -1
- package/dist/cjs/clients/third-party/emailable-client.js.map +1 -1
- package/dist/cjs/clients/third-party/index.d.ts +1 -0
- package/dist/cjs/clients/third-party/index.js +1 -0
- package/dist/cjs/clients/third-party/index.js.map +1 -1
- package/dist/cjs/clients/third-party/liveintent-client.d.ts +11 -0
- package/dist/cjs/clients/third-party/liveintent-client.js +25 -0
- package/dist/cjs/clients/third-party/liveintent-client.js.map +1 -0
- package/dist/cjs/clients/third-party/loops-client.js.map +1 -1
- package/dist/cjs/clients/third-party/open-exchange-rates-client.js.map +1 -1
- package/dist/cjs/clients/third-party/shopify/shopify-graphql-client.js.map +1 -1
- package/dist/cjs/clients/third-party/shopify-client.js +15 -15
- package/dist/cjs/clients/third-party/shopify-client.js.map +1 -1
- package/dist/cjs/constants/sqs.js +5 -5
- package/dist/cjs/constants/sqs.js.map +1 -1
- package/dist/cjs/helpers/account-users-helper.js.map +1 -1
- package/dist/cjs/helpers/acuity-helper.js.map +1 -1
- package/dist/cjs/helpers/api-key-auth-helper.d.ts +1 -2
- package/dist/cjs/helpers/api-key-auth-helper.js.map +1 -1
- package/dist/cjs/helpers/api-key-authorizer-helper.js.map +1 -1
- package/dist/cjs/helpers/cognito-auth-helper.d.ts +1 -2
- package/dist/cjs/helpers/cognito-auth-helper.js.map +1 -1
- package/dist/cjs/helpers/input-validation-helper.d.ts +1 -1
- package/dist/cjs/helpers/input-validation-helper.js.map +1 -1
- package/dist/cjs/helpers/logging-helper.d.ts +5 -5
- package/dist/cjs/helpers/logging-helper.js +7 -17
- package/dist/cjs/helpers/logging-helper.js.map +1 -1
- package/dist/cjs/helpers/order-calculation-helper.js.map +1 -1
- package/dist/cjs/helpers/public-api-response-helper.js.map +1 -1
- package/dist/cjs/helpers/response-helper.js.map +1 -1
- package/dist/cjs/helpers/shopify-helper.js.map +1 -1
- package/dist/cjs/helpers/sqs-utils.js +4 -8
- package/dist/cjs/helpers/sqs-utils.js.map +1 -1
- package/dist/cjs/libs/api-router/public-api-router.d.ts +2 -2
- package/dist/cjs/libs/api-router/public-api-router.js.map +1 -1
- package/dist/cjs/libs/api-router/route-matcher.js.map +1 -1
- package/dist/cjs/libs/click-id-parser.js +1 -1
- package/dist/cjs/libs/click-id-parser.js.map +1 -1
- package/dist/cjs/libs/compression.d.ts +1 -1
- package/dist/cjs/libs/compression.js.map +1 -1
- package/dist/cjs/libs/contacts.js.map +1 -1
- package/dist/cjs/libs/cookie.js +1 -1
- package/dist/cjs/libs/cookie.js.map +1 -1
- package/dist/cjs/libs/crypto.js.map +1 -1
- package/dist/cjs/libs/csv.js.map +1 -1
- package/dist/cjs/libs/currency.js.map +1 -1
- package/dist/cjs/libs/dates.d.ts +1 -0
- package/dist/cjs/libs/dates.js +18 -1
- package/dist/cjs/libs/dates.js.map +1 -1
- package/dist/cjs/libs/domain.js.map +1 -1
- package/dist/cjs/libs/emails.js.map +1 -1
- package/dist/cjs/libs/http-error.js.map +1 -1
- package/dist/cjs/libs/http-status-codes.js +1 -1
- package/dist/cjs/libs/http-status-codes.js.map +1 -1
- package/dist/cjs/libs/numbers.js.map +1 -1
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.d.ts +1 -0
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.js +2 -2
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.js.map +1 -1
- package/dist/cjs/libs/strings.js.map +1 -1
- package/dist/cjs/libs/traits.js.map +1 -1
- package/dist/cjs/libs/url.js.map +1 -1
- package/dist/cjs/services/acuity-api-service.js.map +1 -1
- package/dist/cjs/services/cache/product-cache-service.js.map +1 -1
- package/dist/cjs/services/cost/cost-calculation-types.js +2 -1
- package/dist/cjs/services/cost/cost-calculation-types.js.map +1 -1
- package/dist/cjs/services/cost/cost-calculator-service.js +10 -43
- package/dist/cjs/services/cost/cost-calculator-service.js.map +1 -1
- package/dist/cjs/services/cost/cost-currency-service.js.map +1 -1
- package/dist/cjs/services/cost/cost-filter-service.js +7 -16
- package/dist/cjs/services/cost/cost-filter-service.js.map +1 -1
- package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.js +9 -24
- package/dist/cjs/services/cost/order-cost/order-cost-resolution-service.js.map +1 -1
- package/dist/cjs/services/db/accounts-db-service.js.map +1 -1
- package/dist/cjs/services/db/api-keys-db-service.js.map +1 -1
- package/dist/cjs/services/db/contact-enrichments-db-service.js.map +1 -1
- package/dist/cjs/services/db/custom-measures-db-service.js.map +1 -1
- package/dist/cjs/services/db/destinations-db-service.js.map +1 -1
- package/dist/cjs/services/db/identity-cache-db-service.d.ts +1 -1
- package/dist/cjs/services/db/identity-cache-db-service.js.map +1 -1
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.js +1 -5
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.js.map +1 -1
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-gateway-service.js +7 -21
- package/dist/cjs/services/db/identity-cache-dynamodb-service/identity-gateway-service.js.map +1 -1
- package/dist/cjs/services/db/identity-cache-dynamodb-service/key-builders.js +7 -7
- package/dist/cjs/services/db/identity-cache-dynamodb-service/key-builders.js.map +1 -1
- package/dist/cjs/services/db/identity-cache-dynamodb-service/types.js +3 -3
- package/dist/cjs/services/db/identity-cache-dynamodb-service/types.js.map +1 -1
- package/dist/cjs/services/db/index.d.ts +0 -1
- package/dist/cjs/services/db/index.js +0 -1
- package/dist/cjs/services/db/index.js.map +1 -1
- package/dist/cjs/services/db/log-events-db-service.js.map +1 -1
- package/dist/cjs/services/db/pixels-db-service.js.map +1 -1
- package/dist/cjs/services/db/products-db-service.js +16 -45
- package/dist/cjs/services/db/products-db-service.js.map +1 -1
- package/dist/cjs/services/db/purchasable-contacts-db-service.js.map +1 -1
- package/dist/cjs/services/db/purchased-contacts/purchased-contacts-db-service.js.map +1 -1
- package/dist/cjs/services/db/shopify-app-installs-db-service.js.map +1 -1
- package/dist/cjs/services/db/shopify-products-cache-db-service.js.map +1 -1
- package/dist/cjs/services/db/subscriptions-db-service.js.map +1 -1
- package/dist/cjs/services/db/tracking-events-db-service.js.map +1 -1
- package/dist/cjs/services/db/user-accounts-db-service.js.map +1 -1
- package/dist/cjs/services/email-verification/contact-email-verification-service.js.map +1 -1
- package/dist/cjs/services/email-verification/email-verification-service.js.map +1 -1
- package/dist/cjs/services/eventbridge-integration-service.js.map +1 -1
- package/dist/cjs/services/events/build-collect-queue-tracking-event.js +2 -2
- package/dist/cjs/services/events/build-collect-queue-tracking-event.js.map +1 -1
- package/dist/cjs/services/events/collect-queue-tracking-service.js.map +1 -1
- package/dist/cjs/services/events/log-event-service.js.map +1 -1
- package/dist/cjs/services/events/metric-event-service.js.map +1 -1
- package/dist/cjs/services/events/tracking-event-sqs-service.js.map +1 -1
- package/dist/cjs/services/generic-cache-service.js.map +1 -1
- package/dist/cjs/services/index.d.ts +1 -1
- package/dist/cjs/services/index.js +1 -1
- package/dist/cjs/services/index.js.map +1 -1
- package/dist/cjs/services/ipdata-lookup-service.d.ts +1 -1
- package/dist/cjs/services/ipdata-lookup-service.js.map +1 -1
- package/dist/cjs/services/liveintent-api-service.d.ts +15 -0
- package/dist/cjs/services/liveintent-api-service.js +59 -0
- package/dist/cjs/services/liveintent-api-service.js.map +1 -0
- package/dist/cjs/services/shopify/products/shopify-products-serviceV2.js.map +1 -1
- package/dist/cjs/services/shopify/shopify-graphql-transformer.js +1 -1
- package/dist/cjs/services/shopify/shopify-graphql-transformer.js.map +1 -1
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.js +8 -17
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/internal-events/event-detail-types.js +4 -4
- package/dist/cjs/types/internal-events/event-detail-types.js.map +1 -1
- package/dist/cjs/types/liveintent-types.d.ts +8 -0
- package/dist/cjs/types/liveintent-types.js +3 -0
- package/dist/cjs/types/liveintent-types.js.map +1 -0
- package/dist/cjs/types/public-api-types.js +1 -1
- package/dist/cjs/types/public-api-types.js.map +1 -1
- package/dist/cjs/types/shopify-graphql-types/admin.types.js +491 -491
- package/dist/cjs/types/shopify-graphql-types/admin.types.js.map +1 -1
- package/dist/cjs/types/shopify-rest-types.d.ts +1 -1
- package/dist/cjs/utils/compression.d.ts +2 -0
- package/dist/cjs/utils/compression.js +11 -11
- package/dist/cjs/utils/compression.js.map +1 -1
- package/dist/cjs/utils/custom-measure-formula-utils.js.map +1 -1
- package/dist/cjs/utils/retry-envelope.js +4 -3
- package/dist/cjs/utils/retry-envelope.js.map +1 -1
- package/dist/cjs/utils/size.js +3 -2
- package/dist/cjs/utils/size.js.map +1 -1
- package/dist/esm/__tests__/clients/acuity-client.spec.js +5 -6
- package/dist/esm/__tests__/clients/acuity-client.spec.js.map +1 -1
- package/dist/esm/__tests__/clients/cross-platform-compression.spec.js +0 -1
- package/dist/esm/__tests__/clients/cross-platform-compression.spec.js.map +1 -1
- package/dist/esm/__tests__/clients/dynamodb-client.spec.js +42 -41
- package/dist/esm/__tests__/clients/dynamodb-client.spec.js.map +1 -1
- package/dist/esm/__tests__/clients/event-collector-client.spec.js +18 -18
- package/dist/esm/__tests__/clients/event-collector-client.spec.js.map +1 -1
- package/dist/esm/__tests__/clients/liveintent-client.spec.js +35 -0
- package/dist/esm/__tests__/clients/liveintent-client.spec.js.map +1 -0
- package/dist/esm/__tests__/clients/open-exchange-rates-client.spec.js +3 -4
- package/dist/esm/__tests__/clients/open-exchange-rates-client.spec.js.map +1 -1
- package/dist/esm/__tests__/clients/sqs-bundled-client.spec.js +47 -55
- package/dist/esm/__tests__/clients/sqs-bundled-client.spec.js.map +1 -1
- package/dist/esm/__tests__/clients/sqs-bundling-contracts.spec.js +1 -3
- package/dist/esm/__tests__/clients/sqs-bundling-contracts.spec.js.map +1 -1
- package/dist/esm/__tests__/clients/sqs-client.spec.js +21 -22
- package/dist/esm/__tests__/clients/sqs-client.spec.js.map +1 -1
- package/dist/esm/__tests__/clients/sqs-unbundle.spec.js +8 -9
- package/dist/esm/__tests__/clients/sqs-unbundle.spec.js.map +1 -1
- package/dist/esm/__tests__/db/contact-enrichments-db-service.spec.js +5 -6
- package/dist/esm/__tests__/db/contact-enrichments-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/db/destinations-db-service.spec.js +11 -9
- package/dist/esm/__tests__/db/destinations-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/db/products-db-service.spec.js +8 -9
- package/dist/esm/__tests__/db/products-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/db/shared-read-db-services.spec.js +6 -7
- package/dist/esm/__tests__/db/shared-read-db-services.spec.js.map +1 -1
- package/dist/esm/__tests__/db/shopify-app-installs-db-service.spec.js +12 -13
- package/dist/esm/__tests__/db/shopify-app-installs-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/db/subscriptions-db-service.spec.js +11 -12
- package/dist/esm/__tests__/db/subscriptions-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/db/user-accounts-db-service.spec.js +6 -7
- package/dist/esm/__tests__/db/user-accounts-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/helpers/account-users-helper.spec.js +3 -4
- package/dist/esm/__tests__/helpers/account-users-helper.spec.js.map +1 -1
- package/dist/esm/__tests__/helpers/acuity-helper.spec.js +0 -1
- package/dist/esm/__tests__/helpers/acuity-helper.spec.js.map +1 -1
- package/dist/esm/__tests__/helpers/api-key-auth-helper.spec.js +3 -4
- package/dist/esm/__tests__/helpers/api-key-auth-helper.spec.js.map +1 -1
- package/dist/esm/__tests__/helpers/cognito-auth-helper.spec.js +1 -2
- package/dist/esm/__tests__/helpers/cognito-auth-helper.spec.js.map +1 -1
- package/dist/esm/__tests__/helpers/order-calculation-helper.spec.js +4 -5
- package/dist/esm/__tests__/helpers/order-calculation-helper.spec.js.map +1 -1
- package/dist/esm/__tests__/helpers/public-api-response-helper.spec.js +1 -2
- package/dist/esm/__tests__/helpers/public-api-response-helper.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/helpers.spec.js +1 -2
- package/dist/esm/__tests__/identity-cache/helpers.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-cache-alias-write.spec.js +15 -16
- package/dist/esm/__tests__/identity-cache/identity-cache-alias-write.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.js +1 -2
- package/dist/esm/__tests__/identity-cache/identity-cache-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.js +29 -52
- package/dist/esm/__tests__/identity-cache/identity-cache-dynamodb-db-service.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-cache-tier-routing.spec.js +31 -40
- package/dist/esm/__tests__/identity-cache/identity-cache-tier-routing.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-client.spec.js +21 -24
- package/dist/esm/__tests__/identity-cache/identity-client.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-cache-hit.spec.js +0 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-cache-hit.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-cache-miss.spec.js +4 -17
- package/dist/esm/__tests__/identity-cache/identity-gateway-cache-miss.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-constructor.spec.js +0 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-constructor.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-edge-cases.spec.js +2 -9
- package/dist/esm/__tests__/identity-cache/identity-gateway-edge-cases.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-enqueue-async.spec.js +0 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-enqueue-async.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-stale-cache.spec.js +7 -29
- package/dist/esm/__tests__/identity-cache/identity-gateway-stale-cache.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/identity-gateway-test-setup.d.ts +18 -14
- package/dist/esm/__tests__/identity-cache/identity-gateway-test-setup.js +30 -37
- package/dist/esm/__tests__/identity-cache/identity-gateway-test-setup.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/trait-merging-and-staleness.spec.js +37 -16
- package/dist/esm/__tests__/identity-cache/trait-merging-and-staleness.spec.js.map +1 -1
- package/dist/esm/__tests__/identity-cache/volatile-traits-optimization.spec.js +5 -6
- package/dist/esm/__tests__/identity-cache/volatile-traits-optimization.spec.js.map +1 -1
- package/dist/esm/__tests__/integration/sqs-bundling-roundtrip.spec.js +9 -10
- package/dist/esm/__tests__/integration/sqs-bundling-roundtrip.spec.js.map +1 -1
- package/dist/esm/__tests__/libs/compress-decompress.spec.js +1 -2
- package/dist/esm/__tests__/libs/compress-decompress.spec.js.map +1 -1
- package/dist/esm/__tests__/libs/contacts.spec.js +0 -1
- package/dist/esm/__tests__/libs/contacts.spec.js.map +1 -1
- package/dist/esm/__tests__/libs/currency.spec.js +3 -4
- package/dist/esm/__tests__/libs/currency.spec.js.map +1 -1
- package/dist/esm/__tests__/libs/dates.spec.js +23 -11
- package/dist/esm/__tests__/libs/dates.spec.js.map +1 -1
- package/dist/esm/__tests__/libs/domain.spec.js +0 -1
- package/dist/esm/__tests__/libs/domain.spec.js.map +1 -1
- package/dist/esm/__tests__/libs/numbers.spec.js +0 -1
- package/dist/esm/__tests__/libs/numbers.spec.js.map +1 -1
- package/dist/esm/__tests__/s3-client/s3-client.spec.js +7 -6
- package/dist/esm/__tests__/s3-client/s3-client.spec.js.map +1 -1
- package/dist/esm/__tests__/services/acuity-api-service.spec.js +10 -13
- package/dist/esm/__tests__/services/acuity-api-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.js +0 -1
- package/dist/esm/__tests__/services/cost/cost-calculation-types.spec.js.map +1 -1
- package/dist/esm/__tests__/services/cost/cost-calculator-service.spec.js +280 -518
- package/dist/esm/__tests__/services/cost/cost-calculator-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/cost/cost-currency-service.spec.js +3 -4
- package/dist/esm/__tests__/services/cost/cost-currency-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/cost/cost-filter-service.spec.js +22 -19
- package/dist/esm/__tests__/services/cost/cost-filter-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js +41 -133
- package/dist/esm/__tests__/services/cost/order-cost/order-cost-resolution-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/email-verification/contact-email-verification-service.spec.js +6 -8
- package/dist/esm/__tests__/services/email-verification/contact-email-verification-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/email-verification/email-verification-service.spec.js +5 -10
- package/dist/esm/__tests__/services/email-verification/email-verification-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/events/collect-queue-tracking-service.spec.js +14 -17
- package/dist/esm/__tests__/services/events/collect-queue-tracking-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/events/tracking-event-sqs-service.spec.js +16 -19
- package/dist/esm/__tests__/services/events/tracking-event-sqs-service.spec.js.map +1 -1
- package/dist/esm/__tests__/services/liveintent-api-service.spec.js +65 -0
- package/dist/esm/__tests__/services/liveintent-api-service.spec.js.map +1 -0
- package/dist/esm/__tests__/shopify/shopify-graphql-transformer.spec.js +1 -2
- package/dist/esm/__tests__/shopify/shopify-graphql-transformer.spec.js.map +1 -1
- package/dist/esm/__tests__/unit/libs/api-router/public-api-router.spec.js +14 -15
- package/dist/esm/__tests__/unit/libs/api-router/public-api-router.spec.js.map +1 -1
- package/dist/esm/__tests__/unit/libs/api-router/route-matcher.spec.js +1 -2
- package/dist/esm/__tests__/unit/libs/api-router/route-matcher.spec.js.map +1 -1
- package/dist/esm/__tests__/utils/custom-measure-formula-utils.spec.js +0 -1
- package/dist/esm/__tests__/utils/custom-measure-formula-utils.spec.js.map +1 -1
- package/dist/esm/clients/generic/cognito-client.js +2 -2
- package/dist/esm/clients/generic/cognito-client.js.map +1 -1
- package/dist/esm/clients/generic/dynamodb-client.js +9 -9
- package/dist/esm/clients/generic/dynamodb-client.js.map +1 -1
- package/dist/esm/clients/generic/eventbridge-client.js +1 -1
- package/dist/esm/clients/generic/eventbridge-client.js.map +1 -1
- package/dist/esm/clients/generic/http-client.js +5 -5
- package/dist/esm/clients/generic/http-client.js.map +1 -1
- package/dist/esm/clients/generic/lambda-invoke-client.js.map +1 -1
- package/dist/esm/clients/generic/location-client.js +1 -1
- package/dist/esm/clients/generic/location-client.js.map +1 -1
- package/dist/esm/clients/generic/redis-client.js +2 -13
- package/dist/esm/clients/generic/redis-client.js.map +1 -1
- package/dist/esm/clients/generic/s3-client.d.ts +1 -0
- package/dist/esm/clients/generic/s3-client.js +1 -1
- package/dist/esm/clients/generic/s3-client.js.map +1 -1
- package/dist/esm/clients/generic/singlestore-db-client.d.ts +2 -2
- package/dist/esm/clients/generic/singlestore-db-client.js +1 -1
- package/dist/esm/clients/generic/singlestore-db-client.js.map +1 -1
- package/dist/esm/clients/generic/sqs-bundled-client.js +2 -2
- package/dist/esm/clients/generic/sqs-bundled-client.js.map +1 -1
- package/dist/esm/clients/generic/sqs-client.d.ts +1 -1
- package/dist/esm/clients/generic/sqs-client.js +2 -2
- package/dist/esm/clients/generic/sqs-client.js.map +1 -1
- package/dist/esm/clients/generic/sqs-unbundle.js +2 -2
- package/dist/esm/clients/generic/sqs-unbundle.js.map +1 -1
- package/dist/esm/clients/internal-api/accounts-client.js +1 -1
- package/dist/esm/clients/internal-api/accounts-client.js.map +1 -1
- package/dist/esm/clients/internal-api/cache-lambda-client.js.map +1 -1
- package/dist/esm/clients/internal-api/destinations-client.d.ts +2 -1
- package/dist/esm/clients/internal-api/destinations-client.js +8 -1
- package/dist/esm/clients/internal-api/destinations-client.js.map +1 -1
- package/dist/esm/clients/internal-api/event-collector-client.js.map +1 -1
- package/dist/esm/clients/internal-api/identity-client.js.map +1 -1
- package/dist/esm/clients/internal-api/users-auth-client.js +1 -1
- package/dist/esm/clients/internal-api/users-auth-client.js.map +1 -1
- package/dist/esm/clients/third-party/emailable-client.js.map +1 -1
- package/dist/esm/clients/third-party/index.d.ts +1 -0
- package/dist/esm/clients/third-party/index.js +1 -0
- package/dist/esm/clients/third-party/index.js.map +1 -1
- package/dist/esm/clients/third-party/liveintent-client.d.ts +11 -0
- package/dist/esm/clients/third-party/liveintent-client.js +21 -0
- package/dist/esm/clients/third-party/liveintent-client.js.map +1 -0
- package/dist/esm/clients/third-party/loops-client.js.map +1 -1
- package/dist/esm/clients/third-party/open-exchange-rates-client.js.map +1 -1
- package/dist/esm/clients/third-party/shopify/shopify-graphql-client.js +1 -1
- package/dist/esm/clients/third-party/shopify/shopify-graphql-client.js.map +1 -1
- package/dist/esm/clients/third-party/shopify-client.js +1 -1
- package/dist/esm/clients/third-party/shopify-client.js.map +1 -1
- package/dist/esm/constants/sqs.js +3 -3
- package/dist/esm/constants/sqs.js.map +1 -1
- package/dist/esm/helpers/account-users-helper.js.map +1 -1
- package/dist/esm/helpers/acuity-helper.js.map +1 -1
- package/dist/esm/helpers/api-key-auth-helper.d.ts +1 -2
- package/dist/esm/helpers/api-key-auth-helper.js.map +1 -1
- package/dist/esm/helpers/api-key-authorizer-helper.js.map +1 -1
- package/dist/esm/helpers/cognito-auth-helper.d.ts +1 -2
- package/dist/esm/helpers/cognito-auth-helper.js.map +1 -1
- package/dist/esm/helpers/input-validation-helper.d.ts +1 -1
- package/dist/esm/helpers/input-validation-helper.js.map +1 -1
- package/dist/esm/helpers/logging-helper.d.ts +5 -5
- package/dist/esm/helpers/logging-helper.js.map +1 -1
- package/dist/esm/helpers/order-calculation-helper.js.map +1 -1
- package/dist/esm/helpers/public-api-response-helper.js.map +1 -1
- package/dist/esm/helpers/response-helper.js.map +1 -1
- package/dist/esm/helpers/shopify-helper.js.map +1 -1
- package/dist/esm/helpers/sqs-utils.js +1 -6
- package/dist/esm/helpers/sqs-utils.js.map +1 -1
- package/dist/esm/libs/api-router/public-api-router.d.ts +2 -2
- package/dist/esm/libs/api-router/public-api-router.js.map +1 -1
- package/dist/esm/libs/api-router/route-matcher.js.map +1 -1
- package/dist/esm/libs/click-id-parser.js.map +1 -1
- package/dist/esm/libs/compression.d.ts +1 -1
- package/dist/esm/libs/compression.js.map +1 -1
- package/dist/esm/libs/contacts.js.map +1 -1
- package/dist/esm/libs/cookie.js.map +1 -1
- package/dist/esm/libs/csv.js.map +1 -1
- package/dist/esm/libs/currency.js.map +1 -1
- package/dist/esm/libs/dates.d.ts +1 -0
- package/dist/esm/libs/dates.js +16 -0
- package/dist/esm/libs/dates.js.map +1 -1
- package/dist/esm/libs/domain.js.map +1 -1
- package/dist/esm/libs/emails.js.map +1 -1
- package/dist/esm/libs/http-error.js.map +1 -1
- package/dist/esm/libs/numbers.js.map +1 -1
- package/dist/esm/libs/referrer-parser/referrer-parser-util.d.ts +1 -0
- package/dist/esm/libs/referrer-parser/referrer-parser-util.js +2 -2
- package/dist/esm/libs/referrer-parser/referrer-parser-util.js.map +1 -1
- package/dist/esm/libs/strings.js.map +1 -1
- package/dist/esm/libs/traits.js.map +1 -1
- package/dist/esm/services/acuity-api-service.js.map +1 -1
- package/dist/esm/services/cache/product-cache-service.js.map +1 -1
- package/dist/esm/services/cost/cost-calculation-types.js.map +1 -1
- package/dist/esm/services/cost/cost-calculator-service.js +10 -43
- package/dist/esm/services/cost/cost-calculator-service.js.map +1 -1
- package/dist/esm/services/cost/cost-currency-service.js.map +1 -1
- package/dist/esm/services/cost/cost-filter-service.js +7 -16
- package/dist/esm/services/cost/cost-filter-service.js.map +1 -1
- package/dist/esm/services/cost/order-cost/order-cost-resolution-service.js +9 -24
- package/dist/esm/services/cost/order-cost/order-cost-resolution-service.js.map +1 -1
- package/dist/esm/services/db/accounts-db-service.js.map +1 -1
- package/dist/esm/services/db/api-keys-db-service.js.map +1 -1
- package/dist/esm/services/db/contact-enrichments-db-service.js.map +1 -1
- package/dist/esm/services/db/custom-measures-db-service.js.map +1 -1
- package/dist/esm/services/db/identity-cache-db-service.d.ts +1 -1
- package/dist/esm/services/db/identity-cache-db-service.js.map +1 -1
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.js +2 -6
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-cache-dynamodb-db-service.js.map +1 -1
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-gateway-service.js +8 -22
- package/dist/esm/services/db/identity-cache-dynamodb-service/identity-gateway-service.js.map +1 -1
- package/dist/esm/services/db/identity-cache-dynamodb-service/types.js.map +1 -1
- package/dist/esm/services/db/index.d.ts +0 -1
- package/dist/esm/services/db/index.js +0 -1
- package/dist/esm/services/db/index.js.map +1 -1
- package/dist/esm/services/db/log-events-db-service.js.map +1 -1
- package/dist/esm/services/db/products-db-service.js +16 -45
- package/dist/esm/services/db/products-db-service.js.map +1 -1
- package/dist/esm/services/db/purchasable-contacts-db-service.js.map +1 -1
- package/dist/esm/services/db/purchased-contacts/purchased-contacts-db-service.js.map +1 -1
- package/dist/esm/services/db/shopify-app-installs-db-service.js.map +1 -1
- package/dist/esm/services/db/shopify-products-cache-db-service.js.map +1 -1
- package/dist/esm/services/db/subscriptions-db-service.js.map +1 -1
- package/dist/esm/services/db/tracking-events-db-service.js.map +1 -1
- package/dist/esm/services/email-verification/contact-email-verification-service.js.map +1 -1
- package/dist/esm/services/email-verification/email-verification-service.js.map +1 -1
- package/dist/esm/services/events/build-collect-queue-tracking-event.js.map +1 -1
- package/dist/esm/services/events/collect-queue-tracking-service.js +1 -1
- package/dist/esm/services/events/collect-queue-tracking-service.js.map +1 -1
- package/dist/esm/services/events/log-event-service.js.map +1 -1
- package/dist/esm/services/events/metric-event-service.js.map +1 -1
- package/dist/esm/services/events/tracking-event-sqs-service.js.map +1 -1
- package/dist/esm/services/generic-cache-service.js.map +1 -1
- package/dist/esm/services/index.d.ts +1 -1
- package/dist/esm/services/index.js +1 -1
- package/dist/esm/services/index.js.map +1 -1
- package/dist/esm/services/ipdata-lookup-service.d.ts +1 -1
- package/dist/esm/services/ipdata-lookup-service.js.map +1 -1
- package/dist/esm/services/liveintent-api-service.d.ts +15 -0
- package/dist/esm/services/liveintent-api-service.js +55 -0
- package/dist/esm/services/liveintent-api-service.js.map +1 -0
- package/dist/esm/services/shopify/products/shopify-products-serviceV2.js.map +1 -1
- package/dist/esm/services/shopify/shopify-graphql-transformer.js +1 -1
- package/dist/esm/services/shopify/shopify-graphql-transformer.js.map +1 -1
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/liveintent-types.d.ts +8 -0
- package/dist/esm/types/liveintent-types.js +2 -0
- package/dist/esm/types/liveintent-types.js.map +1 -0
- package/dist/esm/types/shopify-rest-types.d.ts +1 -1
- package/dist/esm/utils/compression.d.ts +2 -0
- package/dist/esm/utils/compression.js +3 -3
- package/dist/esm/utils/compression.js.map +1 -1
- package/dist/esm/utils/custom-measure-formula-utils.js.map +1 -1
- package/dist/esm/utils/retry-envelope.js.map +1 -1
- package/dist/esm/utils/size.js.map +1 -1
- package/package.json +136 -139
- package/dist/cjs/__tests__/clients/client-timeout-inventory.spec.js +0 -21
- package/dist/cjs/__tests__/clients/client-timeout-inventory.spec.js.map +0 -1
- package/dist/cjs/__tests__/clients/redis-client.spec.js +0 -79
- package/dist/cjs/__tests__/clients/redis-client.spec.js.map +0 -1
- package/dist/cjs/__tests__/services/currency-exchange-rate-lookup-service.spec.js +0 -40
- package/dist/cjs/__tests__/services/currency-exchange-rate-lookup-service.spec.js.map +0 -1
- package/dist/cjs/clients/third-party/exchange-rate-api-client.d.ts +0 -17
- package/dist/cjs/clients/third-party/exchange-rate-api-client.js +0 -20
- package/dist/cjs/clients/third-party/exchange-rate-api-client.js.map +0 -1
- package/dist/cjs/services/currency-exchange-rate-lookup-service.d.ts +0 -12
- package/dist/cjs/services/currency-exchange-rate-lookup-service.js +0 -98
- package/dist/cjs/services/currency-exchange-rate-lookup-service.js.map +0 -1
- package/dist/cjs/services/db/currency-exchange-rates-db-service.d.ts +0 -21
- package/dist/cjs/services/db/currency-exchange-rates-db-service.js +0 -40
- package/dist/cjs/services/db/currency-exchange-rates-db-service.js.map +0 -1
- package/dist/esm/__tests__/clients/client-timeout-inventory.spec.js +0 -19
- package/dist/esm/__tests__/clients/client-timeout-inventory.spec.js.map +0 -1
- package/dist/esm/__tests__/clients/redis-client.spec.d.ts +0 -1
- package/dist/esm/__tests__/clients/redis-client.spec.js +0 -77
- package/dist/esm/__tests__/clients/redis-client.spec.js.map +0 -1
- package/dist/esm/__tests__/services/currency-exchange-rate-lookup-service.spec.d.ts +0 -1
- package/dist/esm/__tests__/services/currency-exchange-rate-lookup-service.spec.js +0 -38
- package/dist/esm/__tests__/services/currency-exchange-rate-lookup-service.spec.js.map +0 -1
- package/dist/esm/clients/third-party/exchange-rate-api-client.d.ts +0 -17
- package/dist/esm/clients/third-party/exchange-rate-api-client.js +0 -16
- package/dist/esm/clients/third-party/exchange-rate-api-client.js.map +0 -1
- package/dist/esm/services/currency-exchange-rate-lookup-service.d.ts +0 -12
- package/dist/esm/services/currency-exchange-rate-lookup-service.js +0 -94
- package/dist/esm/services/currency-exchange-rate-lookup-service.js.map +0 -1
- package/dist/esm/services/db/currency-exchange-rates-db-service.d.ts +0 -21
- package/dist/esm/services/db/currency-exchange-rates-db-service.js +0 -36
- package/dist/esm/services/db/currency-exchange-rates-db-service.js.map +0 -1
- /package/dist/cjs/__tests__/clients/{client-timeout-inventory.spec.d.ts → liveintent-client.spec.d.ts} +0 -0
- /package/dist/cjs/__tests__/{clients/redis-client.spec.d.ts → services/liveintent-api-service.spec.d.ts} +0 -0
- /package/dist/{cjs/__tests__/services/currency-exchange-rate-lookup-service.spec.d.ts → esm/__tests__/clients/liveintent-client.spec.d.ts} +0 -0
- /package/dist/esm/__tests__/{clients/client-timeout-inventory.spec.d.ts → services/liveintent-api-service.spec.d.ts} +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
1
|
import { ORDER_COST_ENTRY_TYPE, SHIPPING_METHOD, SHIPPING_RATE_TYPE, WEIGHT_UNIT, COST_FILTER_MODE, } from '@adtrackify/at-tracking-event-types';
|
|
3
2
|
import { CostCalculatorService } from '../../../services/cost/cost-calculator-service';
|
|
4
|
-
|
|
5
|
-
Logger: { debug:
|
|
3
|
+
jest.mock('../../../helpers/logging-helper', () => ({
|
|
4
|
+
Logger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() },
|
|
6
5
|
}));
|
|
7
6
|
const emptyRatesMap = {};
|
|
8
7
|
const createLineItem = (overrides = {}) => ({
|
|
@@ -241,9 +240,7 @@ describe('CostCalculatorService', () => {
|
|
|
241
240
|
it('should return 0 when no matching gateway', () => {
|
|
242
241
|
const configs = createConfigs({
|
|
243
242
|
gateway: {
|
|
244
|
-
entries: [
|
|
245
|
-
{ gatewayName: 'paypal', flatAmount: 0.3, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
246
|
-
],
|
|
243
|
+
entries: [{ gatewayName: 'paypal', flatAmount: 0.30, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' }],
|
|
247
244
|
},
|
|
248
245
|
});
|
|
249
246
|
expect(CostCalculatorService.calculateGatewayCost(configs, ['stripe'], 100, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap)).toBe(0);
|
|
@@ -251,20 +248,16 @@ describe('CostCalculatorService', () => {
|
|
|
251
248
|
it('should calculate flat + percent for matching gateway', () => {
|
|
252
249
|
const configs = createConfigs({
|
|
253
250
|
gateway: {
|
|
254
|
-
entries: [
|
|
255
|
-
{ gatewayName: 'stripe', flatAmount: 0.3, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
256
|
-
],
|
|
251
|
+
entries: [{ gatewayName: 'stripe', flatAmount: 0.30, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' }],
|
|
257
252
|
},
|
|
258
253
|
});
|
|
259
254
|
const result = CostCalculatorService.calculateGatewayCost(configs, ['stripe'], 100, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap);
|
|
260
|
-
expect(result).toBeCloseTo(3.
|
|
255
|
+
expect(result).toBeCloseTo(3.20);
|
|
261
256
|
});
|
|
262
257
|
it('should be case-insensitive for gateway name', () => {
|
|
263
258
|
const configs = createConfigs({
|
|
264
259
|
gateway: {
|
|
265
|
-
entries: [
|
|
266
|
-
{ gatewayName: 'Stripe', flatAmount: 1, percentRate: 0, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
267
|
-
],
|
|
260
|
+
entries: [{ gatewayName: 'Stripe', flatAmount: 1, percentRate: 0, currency: 'USD', createdAt: '', updatedAt: '' }],
|
|
268
261
|
},
|
|
269
262
|
});
|
|
270
263
|
expect(CostCalculatorService.calculateGatewayCost(configs, ['stripe'], 100, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap)).toBe(1);
|
|
@@ -272,17 +265,10 @@ describe('CostCalculatorService', () => {
|
|
|
272
265
|
it('should respect date range', () => {
|
|
273
266
|
const configs = createConfigs({
|
|
274
267
|
gateway: {
|
|
275
|
-
entries: [
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
percentRate: 0,
|
|
280
|
-
currency: 'USD',
|
|
281
|
-
effectiveFrom: '2025-01-01T00:00:00Z',
|
|
282
|
-
createdAt: '',
|
|
283
|
-
updatedAt: '',
|
|
284
|
-
},
|
|
285
|
-
],
|
|
268
|
+
entries: [{
|
|
269
|
+
gatewayName: 'stripe', flatAmount: 1, percentRate: 0, currency: 'USD',
|
|
270
|
+
effectiveFrom: '2025-01-01T00:00:00Z', createdAt: '', updatedAt: '',
|
|
271
|
+
}],
|
|
286
272
|
},
|
|
287
273
|
});
|
|
288
274
|
expect(CostCalculatorService.calculateGatewayCost(configs, ['stripe'], 100, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap)).toBe(0);
|
|
@@ -290,9 +276,7 @@ describe('CostCalculatorService', () => {
|
|
|
290
276
|
it('should convert flat amount from entry currency', () => {
|
|
291
277
|
const configs = createConfigs({
|
|
292
278
|
gateway: {
|
|
293
|
-
entries: [
|
|
294
|
-
{ gatewayName: 'stripe', flatAmount: 1, percentRate: 0, currency: 'EUR', createdAt: '', updatedAt: '' },
|
|
295
|
-
],
|
|
279
|
+
entries: [{ gatewayName: 'stripe', flatAmount: 1, percentRate: 0, currency: 'EUR', createdAt: '', updatedAt: '' }],
|
|
296
280
|
},
|
|
297
281
|
});
|
|
298
282
|
const rates = { EUR: { USD: 1.1 } };
|
|
@@ -303,28 +287,21 @@ describe('CostCalculatorService', () => {
|
|
|
303
287
|
const configs = createConfigs({
|
|
304
288
|
gateway: {
|
|
305
289
|
entries: [
|
|
306
|
-
{ gatewayName: 'stripe', flatAmount: 0.
|
|
307
|
-
{ gatewayName: 'stripe', flatAmount: 0.
|
|
290
|
+
{ gatewayName: 'stripe', flatAmount: 0.30, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
291
|
+
{ gatewayName: 'stripe', flatAmount: 0.50, percentRate: 3.5, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
308
292
|
],
|
|
309
293
|
},
|
|
310
294
|
});
|
|
311
295
|
const result = CostCalculatorService.calculateGatewayCost(configs, ['stripe'], 100, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap);
|
|
312
|
-
expect(result).toBeCloseTo(3.
|
|
296
|
+
expect(result).toBeCloseTo(3.20);
|
|
313
297
|
});
|
|
314
298
|
it('should respect effectiveTo date on gateway entry', () => {
|
|
315
299
|
const configs = createConfigs({
|
|
316
300
|
gateway: {
|
|
317
|
-
entries: [
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
percentRate: 0,
|
|
322
|
-
currency: 'USD',
|
|
323
|
-
effectiveTo: '2024-01-01T00:00:00Z',
|
|
324
|
-
createdAt: '',
|
|
325
|
-
updatedAt: '',
|
|
326
|
-
},
|
|
327
|
-
],
|
|
301
|
+
entries: [{
|
|
302
|
+
gatewayName: 'stripe', flatAmount: 1, percentRate: 0, currency: 'USD',
|
|
303
|
+
effectiveTo: '2024-01-01T00:00:00Z', createdAt: '', updatedAt: '',
|
|
304
|
+
}],
|
|
328
305
|
},
|
|
329
306
|
});
|
|
330
307
|
expect(CostCalculatorService.calculateGatewayCost(configs, ['stripe'], 100, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap)).toBe(0);
|
|
@@ -332,13 +309,11 @@ describe('CostCalculatorService', () => {
|
|
|
332
309
|
it('should match gateway when order has multiple gateways', () => {
|
|
333
310
|
const configs = createConfigs({
|
|
334
311
|
gateway: {
|
|
335
|
-
entries: [
|
|
336
|
-
{ gatewayName: 'paypal', flatAmount: 0.5, percentRate: 3.0, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
337
|
-
],
|
|
312
|
+
entries: [{ gatewayName: 'paypal', flatAmount: 0.50, percentRate: 3.0, currency: 'USD', createdAt: '', updatedAt: '' }],
|
|
338
313
|
},
|
|
339
314
|
});
|
|
340
315
|
const result = CostCalculatorService.calculateGatewayCost(configs, ['stripe', 'paypal'], 100, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap);
|
|
341
|
-
expect(result).toBeCloseTo(3.
|
|
316
|
+
expect(result).toBeCloseTo(3.50);
|
|
342
317
|
});
|
|
343
318
|
});
|
|
344
319
|
describe('calculateShippingCost', () => {
|
|
@@ -350,7 +325,7 @@ describe('CostCalculatorService', () => {
|
|
|
350
325
|
const configs = createConfigs({
|
|
351
326
|
shipping: { method: SHIPPING_METHOD.SHOPIFY_CHARGES, currency: 'USD' },
|
|
352
327
|
});
|
|
353
|
-
expect(CostCalculatorService.calculateShippingCost(configs, 15.
|
|
328
|
+
expect(CostCalculatorService.calculateShippingCost(configs, 15.50, 'US', 500, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap)).toBe(15.50);
|
|
354
329
|
});
|
|
355
330
|
it('should return fixed rate for FIXED_RATE method', () => {
|
|
356
331
|
const configs = createConfigs({
|
|
@@ -373,26 +348,14 @@ describe('CostCalculatorService', () => {
|
|
|
373
348
|
currency: 'USD',
|
|
374
349
|
profiles: [
|
|
375
350
|
{
|
|
376
|
-
id: 'p1',
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
isDefault: false,
|
|
380
|
-
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
381
|
-
flatAmount: 5,
|
|
382
|
-
currency: 'USD',
|
|
383
|
-
createdAt: '',
|
|
384
|
-
updatedAt: '',
|
|
351
|
+
id: 'p1', name: 'US Profile', countries: ['US'], isDefault: false,
|
|
352
|
+
rateType: SHIPPING_RATE_TYPE.FLAT, flatAmount: 5, currency: 'USD',
|
|
353
|
+
createdAt: '', updatedAt: '',
|
|
385
354
|
},
|
|
386
355
|
{
|
|
387
|
-
id: 'p2',
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
isDefault: true,
|
|
391
|
-
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
392
|
-
flatAmount: 15,
|
|
393
|
-
currency: 'USD',
|
|
394
|
-
createdAt: '',
|
|
395
|
-
updatedAt: '',
|
|
356
|
+
id: 'p2', name: 'Default', countries: [], isDefault: true,
|
|
357
|
+
rateType: SHIPPING_RATE_TYPE.FLAT, flatAmount: 15, currency: 'USD',
|
|
358
|
+
createdAt: '', updatedAt: '',
|
|
396
359
|
},
|
|
397
360
|
],
|
|
398
361
|
},
|
|
@@ -406,26 +369,14 @@ describe('CostCalculatorService', () => {
|
|
|
406
369
|
currency: 'USD',
|
|
407
370
|
profiles: [
|
|
408
371
|
{
|
|
409
|
-
id: 'p1',
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
isDefault: false,
|
|
413
|
-
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
414
|
-
flatAmount: 5,
|
|
415
|
-
currency: 'USD',
|
|
416
|
-
createdAt: '',
|
|
417
|
-
updatedAt: '',
|
|
372
|
+
id: 'p1', name: 'US Profile', countries: ['US'], isDefault: false,
|
|
373
|
+
rateType: SHIPPING_RATE_TYPE.FLAT, flatAmount: 5, currency: 'USD',
|
|
374
|
+
createdAt: '', updatedAt: '',
|
|
418
375
|
},
|
|
419
376
|
{
|
|
420
|
-
id: 'p2',
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
isDefault: true,
|
|
424
|
-
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
425
|
-
flatAmount: 15,
|
|
426
|
-
currency: 'USD',
|
|
427
|
-
createdAt: '',
|
|
428
|
-
updatedAt: '',
|
|
377
|
+
id: 'p2', name: 'Default', countries: [], isDefault: true,
|
|
378
|
+
rateType: SHIPPING_RATE_TYPE.FLAT, flatAmount: 15, currency: 'USD',
|
|
379
|
+
createdAt: '', updatedAt: '',
|
|
429
380
|
},
|
|
430
381
|
],
|
|
431
382
|
},
|
|
@@ -437,23 +388,16 @@ describe('CostCalculatorService', () => {
|
|
|
437
388
|
shipping: {
|
|
438
389
|
method: SHIPPING_METHOD.SHIPPING_PROFILES,
|
|
439
390
|
currency: 'USD',
|
|
440
|
-
profiles: [
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
name: 'Weight',
|
|
444
|
-
countries: ['US'],
|
|
445
|
-
isDefault: false,
|
|
446
|
-
rateType: SHIPPING_RATE_TYPE.WEIGHT_TIERED,
|
|
447
|
-
currency: 'USD',
|
|
391
|
+
profiles: [{
|
|
392
|
+
id: 'p1', name: 'Weight', countries: ['US'], isDefault: false,
|
|
393
|
+
rateType: SHIPPING_RATE_TYPE.WEIGHT_TIERED, currency: 'USD',
|
|
448
394
|
weightUnit: WEIGHT_UNIT.GRAMS,
|
|
449
395
|
weightTiers: [
|
|
450
396
|
{ weightMin: 0, weightMax: 500, flatAmount: 5 },
|
|
451
397
|
{ weightMin: 501, weightMax: null, flatAmount: 10 },
|
|
452
398
|
],
|
|
453
|
-
createdAt: '',
|
|
454
|
-
|
|
455
|
-
},
|
|
456
|
-
],
|
|
399
|
+
createdAt: '', updatedAt: '',
|
|
400
|
+
}],
|
|
457
401
|
},
|
|
458
402
|
});
|
|
459
403
|
expect(CostCalculatorService.calculateShippingCost(configs, 0, 'US', 300, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap)).toBe(5);
|
|
@@ -464,19 +408,11 @@ describe('CostCalculatorService', () => {
|
|
|
464
408
|
shipping: {
|
|
465
409
|
method: SHIPPING_METHOD.SHIPPING_PROFILES,
|
|
466
410
|
currency: 'USD',
|
|
467
|
-
profiles: [
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
isDefault: false,
|
|
473
|
-
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
474
|
-
flatAmount: 5,
|
|
475
|
-
currency: 'USD',
|
|
476
|
-
createdAt: '',
|
|
477
|
-
updatedAt: '',
|
|
478
|
-
},
|
|
479
|
-
],
|
|
411
|
+
profiles: [{
|
|
412
|
+
id: 'p1', name: 'US Only', countries: ['US'], isDefault: false,
|
|
413
|
+
rateType: SHIPPING_RATE_TYPE.FLAT, flatAmount: 5, currency: 'USD',
|
|
414
|
+
createdAt: '', updatedAt: '',
|
|
415
|
+
}],
|
|
480
416
|
},
|
|
481
417
|
});
|
|
482
418
|
expect(CostCalculatorService.calculateShippingCost(configs, 0, 'CA', 500, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap)).toBe(0);
|
|
@@ -488,27 +424,15 @@ describe('CostCalculatorService', () => {
|
|
|
488
424
|
currency: 'USD',
|
|
489
425
|
profiles: [
|
|
490
426
|
{
|
|
491
|
-
id: 'p1',
|
|
492
|
-
|
|
493
|
-
countries: ['US'],
|
|
494
|
-
isDefault: false,
|
|
495
|
-
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
496
|
-
flatAmount: 5,
|
|
497
|
-
currency: 'USD',
|
|
427
|
+
id: 'p1', name: 'US Expired', countries: ['US'], isDefault: false,
|
|
428
|
+
rateType: SHIPPING_RATE_TYPE.FLAT, flatAmount: 5, currency: 'USD',
|
|
498
429
|
effectiveTo: '2024-01-01T00:00:00Z',
|
|
499
|
-
createdAt: '',
|
|
500
|
-
updatedAt: '',
|
|
430
|
+
createdAt: '', updatedAt: '',
|
|
501
431
|
},
|
|
502
432
|
{
|
|
503
|
-
id: 'p2',
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
isDefault: true,
|
|
507
|
-
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
508
|
-
flatAmount: 12,
|
|
509
|
-
currency: 'USD',
|
|
510
|
-
createdAt: '',
|
|
511
|
-
updatedAt: '',
|
|
433
|
+
id: 'p2', name: 'Default', countries: [], isDefault: true,
|
|
434
|
+
rateType: SHIPPING_RATE_TYPE.FLAT, flatAmount: 12, currency: 'USD',
|
|
435
|
+
createdAt: '', updatedAt: '',
|
|
512
436
|
},
|
|
513
437
|
],
|
|
514
438
|
},
|
|
@@ -520,23 +444,16 @@ describe('CostCalculatorService', () => {
|
|
|
520
444
|
shipping: {
|
|
521
445
|
method: SHIPPING_METHOD.SHIPPING_PROFILES,
|
|
522
446
|
currency: 'EUR',
|
|
523
|
-
profiles: [
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
name: 'EU Weight',
|
|
527
|
-
countries: ['DE'],
|
|
528
|
-
isDefault: false,
|
|
529
|
-
rateType: SHIPPING_RATE_TYPE.WEIGHT_TIERED,
|
|
530
|
-
currency: 'EUR',
|
|
447
|
+
profiles: [{
|
|
448
|
+
id: 'p1', name: 'EU Weight', countries: ['DE'], isDefault: false,
|
|
449
|
+
rateType: SHIPPING_RATE_TYPE.WEIGHT_TIERED, currency: 'EUR',
|
|
531
450
|
weightUnit: WEIGHT_UNIT.GRAMS,
|
|
532
451
|
weightTiers: [
|
|
533
452
|
{ weightMin: 0, weightMax: 500, flatAmount: 5 },
|
|
534
453
|
{ weightMin: 501, weightMax: null, flatAmount: 10 },
|
|
535
454
|
],
|
|
536
|
-
createdAt: '',
|
|
537
|
-
|
|
538
|
-
},
|
|
539
|
-
],
|
|
455
|
+
createdAt: '', updatedAt: '',
|
|
456
|
+
}],
|
|
540
457
|
},
|
|
541
458
|
});
|
|
542
459
|
const rates = { EUR: { USD: 1.1 } };
|
|
@@ -547,19 +464,11 @@ describe('CostCalculatorService', () => {
|
|
|
547
464
|
shipping: {
|
|
548
465
|
method: SHIPPING_METHOD.SHIPPING_PROFILES,
|
|
549
466
|
currency: 'USD',
|
|
550
|
-
profiles: [
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
isDefault: false,
|
|
556
|
-
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
557
|
-
flatAmount: 7,
|
|
558
|
-
currency: 'USD',
|
|
559
|
-
createdAt: '',
|
|
560
|
-
updatedAt: '',
|
|
561
|
-
},
|
|
562
|
-
],
|
|
467
|
+
profiles: [{
|
|
468
|
+
id: 'p1', name: 'US', countries: ['us'], isDefault: false,
|
|
469
|
+
rateType: SHIPPING_RATE_TYPE.FLAT, flatAmount: 7, currency: 'USD',
|
|
470
|
+
createdAt: '', updatedAt: '',
|
|
471
|
+
}],
|
|
563
472
|
},
|
|
564
473
|
});
|
|
565
474
|
expect(CostCalculatorService.calculateShippingCost(configs, 0, 'US', 500, '2024-06-15T10:00:00Z', 'USD', emptyRatesMap)).toBe(7);
|
|
@@ -658,7 +567,7 @@ describe('CostCalculatorService', () => {
|
|
|
658
567
|
});
|
|
659
568
|
it('should calculate BY_ORDER_WEIGHT with flat amount and KILOGRAMS unit (converts weight before multiplying)', () => {
|
|
660
569
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_ORDER_WEIGHT, {
|
|
661
|
-
flatAmount: 0.
|
|
570
|
+
flatAmount: 0.50,
|
|
662
571
|
weightUnit: WEIGHT_UNIT.KILOGRAMS,
|
|
663
572
|
});
|
|
664
573
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, createContext({ totalWeight: 2000 }), initLineItemCosts(), 'USD', emptyRatesMap);
|
|
@@ -667,7 +576,7 @@ describe('CostCalculatorService', () => {
|
|
|
667
576
|
});
|
|
668
577
|
it('should calculate BY_ORDER_WEIGHT with flat amount and POUNDS unit (converts weight before multiplying)', () => {
|
|
669
578
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_ORDER_WEIGHT, {
|
|
670
|
-
flatAmount: 2.
|
|
579
|
+
flatAmount: 2.00,
|
|
671
580
|
weightUnit: WEIGHT_UNIT.POUNDS,
|
|
672
581
|
});
|
|
673
582
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, createContext({ totalWeight: 453.592 }), initLineItemCosts(), 'USD', emptyRatesMap);
|
|
@@ -675,7 +584,7 @@ describe('CostCalculatorService', () => {
|
|
|
675
584
|
expect(result.lineItemLevel).toBe(0);
|
|
676
585
|
});
|
|
677
586
|
it('should calculate BY_LINE_ITEM_QUANTITY with flat amount as line-item-level cost', () => {
|
|
678
|
-
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_LINE_ITEM_QUANTITY, { flatAmount: 0.
|
|
587
|
+
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_LINE_ITEM_QUANTITY, { flatAmount: 0.50 });
|
|
679
588
|
const liCosts = initLineItemCosts();
|
|
680
589
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, createContext({ lineItems: [createLineItem({ quantity: 10 })] }), liCosts, 'USD', emptyRatesMap);
|
|
681
590
|
expect(result.orderLevel).toBe(0);
|
|
@@ -722,7 +631,7 @@ describe('CostCalculatorService', () => {
|
|
|
722
631
|
expect(liCosts['2'].totalLineItemOtherCost).toBe(2);
|
|
723
632
|
});
|
|
724
633
|
it('should calculate BY_ORDER_QUANTITY with flat amount as order-level cost', () => {
|
|
725
|
-
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_ORDER_QUANTITY, { flatAmount: 0.
|
|
634
|
+
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_ORDER_QUANTITY, { flatAmount: 0.50 });
|
|
726
635
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, createContext({ totalQuantity: 10 }), initLineItemCosts(), 'USD', emptyRatesMap);
|
|
727
636
|
expect(result.orderLevel).toBe(5);
|
|
728
637
|
expect(result.lineItemLevel).toBe(0);
|
|
@@ -752,7 +661,9 @@ describe('CostCalculatorService', () => {
|
|
|
752
661
|
});
|
|
753
662
|
it('should return 0 for BY_ORDER_QUANTITY when quantity does not match any tier', () => {
|
|
754
663
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_ORDER_QUANTITY, {
|
|
755
|
-
quantityIntervals: [
|
|
664
|
+
quantityIntervals: [
|
|
665
|
+
{ quantityMin: 5, quantityMax: 10, flatAmount: 3 },
|
|
666
|
+
],
|
|
756
667
|
});
|
|
757
668
|
expect(CostCalculatorService.calculateOtherCostEntry(entry, createContext({ totalQuantity: 2 }), initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
758
669
|
});
|
|
@@ -780,16 +691,8 @@ describe('CostCalculatorService', () => {
|
|
|
780
691
|
};
|
|
781
692
|
const context = createContext({
|
|
782
693
|
lineItems: [
|
|
783
|
-
createLineItem({
|
|
784
|
-
|
|
785
|
-
quantity: 4,
|
|
786
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' },
|
|
787
|
-
}),
|
|
788
|
-
createLineItem({
|
|
789
|
-
lineItemId: '2',
|
|
790
|
-
quantity: 6,
|
|
791
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas' },
|
|
792
|
-
}),
|
|
694
|
+
createLineItem({ lineItemId: '1', quantity: 4, filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } }),
|
|
695
|
+
createLineItem({ lineItemId: '2', quantity: 6, filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas' } }),
|
|
793
696
|
],
|
|
794
697
|
});
|
|
795
698
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, context, liCosts, 'USD', emptyRatesMap);
|
|
@@ -822,8 +725,7 @@ describe('CostCalculatorService', () => {
|
|
|
822
725
|
totalQuantity: 10,
|
|
823
726
|
orderFilterContext: { tags: ['retail'], paymentGateways: [], shippingTitles: [] },
|
|
824
727
|
});
|
|
825
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
826
|
-
.orderLevel).toBe(0);
|
|
728
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
827
729
|
});
|
|
828
730
|
it('should calculate PER_REFUND_ORDER when hasRefund as order-level cost', () => {
|
|
829
731
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_REFUND_ORDER, { flatAmount: 5 });
|
|
@@ -952,9 +854,7 @@ describe('CostCalculatorService', () => {
|
|
|
952
854
|
flatAmount: 5,
|
|
953
855
|
filters: { countries: { mode: COST_FILTER_MODE.INCLUDE, values: ['US'] } },
|
|
954
856
|
});
|
|
955
|
-
const context = createContext({
|
|
956
|
-
orderFilterContext: { tags: [], paymentGateways: [], shippingTitles: [], shipCountryCode: 'CA' },
|
|
957
|
-
});
|
|
857
|
+
const context = createContext({ orderFilterContext: { tags: [], paymentGateways: [], shippingTitles: [], shipCountryCode: 'CA' } });
|
|
958
858
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap);
|
|
959
859
|
expect(result.orderLevel).toBe(0);
|
|
960
860
|
});
|
|
@@ -972,8 +872,7 @@ describe('CostCalculatorService', () => {
|
|
|
972
872
|
const context = createContext({
|
|
973
873
|
lineItems: [createLineItem({ filterContext: { productId: 'P100', variantId: 'V1', tags: [] } })],
|
|
974
874
|
});
|
|
975
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
976
|
-
.orderLevel).toBe(0);
|
|
875
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
977
876
|
});
|
|
978
877
|
it('should apply PER_ORDER when product filter matches a line item', () => {
|
|
979
878
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -983,8 +882,7 @@ describe('CostCalculatorService', () => {
|
|
|
983
882
|
const context = createContext({
|
|
984
883
|
lineItems: [createLineItem({ filterContext: { productId: 'P100', variantId: 'V1', tags: [] } })],
|
|
985
884
|
});
|
|
986
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
987
|
-
.orderLevel).toBe(5);
|
|
885
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
988
886
|
});
|
|
989
887
|
it('should apply PER_ORDER when at least one of multiple line items matches product filter', () => {
|
|
990
888
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -993,14 +891,8 @@ describe('CostCalculatorService', () => {
|
|
|
993
891
|
});
|
|
994
892
|
const context = createContext({
|
|
995
893
|
lineItems: [
|
|
996
|
-
createLineItem({
|
|
997
|
-
|
|
998
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' },
|
|
999
|
-
}),
|
|
1000
|
-
createLineItem({
|
|
1001
|
-
lineItemId: '2',
|
|
1002
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Nike' },
|
|
1003
|
-
}),
|
|
894
|
+
createLineItem({ lineItemId: '1', filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } }),
|
|
895
|
+
createLineItem({ lineItemId: '2', filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Nike' } }),
|
|
1004
896
|
],
|
|
1005
897
|
});
|
|
1006
898
|
const liCosts = {
|
|
@@ -1018,8 +910,7 @@ describe('CostCalculatorService', () => {
|
|
|
1018
910
|
totalWeight: 500,
|
|
1019
911
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: ['lightweight'] } })],
|
|
1020
912
|
});
|
|
1021
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1022
|
-
.orderLevel).toBe(0);
|
|
913
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1023
914
|
});
|
|
1024
915
|
it('should apply BY_ORDER_WEIGHT when productTags filter matches a line item', () => {
|
|
1025
916
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_ORDER_WEIGHT, {
|
|
@@ -1030,8 +921,7 @@ describe('CostCalculatorService', () => {
|
|
|
1030
921
|
totalWeight: 500,
|
|
1031
922
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: ['fragile'] } })],
|
|
1032
923
|
});
|
|
1033
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1034
|
-
.orderLevel).toBe(5);
|
|
924
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1035
925
|
});
|
|
1036
926
|
it('should return 0 for BY_LINE_ITEM_QUANTITY when productVendors filter does not match', () => {
|
|
1037
927
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_LINE_ITEM_QUANTITY, {
|
|
@@ -1039,15 +929,9 @@ describe('CostCalculatorService', () => {
|
|
|
1039
929
|
filters: { productVendors: { mode: COST_FILTER_MODE.INCLUDE, values: ['Nike'] } },
|
|
1040
930
|
});
|
|
1041
931
|
const context = createContext({
|
|
1042
|
-
lineItems: [
|
|
1043
|
-
createLineItem({
|
|
1044
|
-
quantity: 10,
|
|
1045
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' },
|
|
1046
|
-
}),
|
|
1047
|
-
],
|
|
932
|
+
lineItems: [createLineItem({ quantity: 10, filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } })],
|
|
1048
933
|
});
|
|
1049
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1050
|
-
.lineItemLevel).toBe(0);
|
|
934
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).lineItemLevel).toBe(0);
|
|
1051
935
|
});
|
|
1052
936
|
it('should apply BY_LINE_ITEM_QUANTITY when productVendors filter matches', () => {
|
|
1053
937
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_LINE_ITEM_QUANTITY, {
|
|
@@ -1055,15 +939,9 @@ describe('CostCalculatorService', () => {
|
|
|
1055
939
|
filters: { productVendors: { mode: COST_FILTER_MODE.INCLUDE, values: ['Nike'] } },
|
|
1056
940
|
});
|
|
1057
941
|
const context = createContext({
|
|
1058
|
-
lineItems: [
|
|
1059
|
-
createLineItem({
|
|
1060
|
-
quantity: 10,
|
|
1061
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' },
|
|
1062
|
-
}),
|
|
1063
|
-
],
|
|
942
|
+
lineItems: [createLineItem({ quantity: 10, filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } })],
|
|
1064
943
|
});
|
|
1065
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1066
|
-
.lineItemLevel).toBe(5);
|
|
944
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).lineItemLevel).toBe(5);
|
|
1067
945
|
});
|
|
1068
946
|
it('should return 0 for PCT_GROSS_SALES when productTypes filter does not match', () => {
|
|
1069
947
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_GROSS_SALES, {
|
|
@@ -1072,12 +950,9 @@ describe('CostCalculatorService', () => {
|
|
|
1072
950
|
});
|
|
1073
951
|
const context = createContext({
|
|
1074
952
|
grossSalePrice: 150,
|
|
1075
|
-
lineItems: [
|
|
1076
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], productType: 'Clothing' } }),
|
|
1077
|
-
],
|
|
953
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], productType: 'Clothing' } })],
|
|
1078
954
|
});
|
|
1079
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1080
|
-
.orderLevel).toBe(0);
|
|
955
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1081
956
|
});
|
|
1082
957
|
it('should apply PCT_GROSS_SALES when productTypes filter matches', () => {
|
|
1083
958
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_GROSS_SALES, {
|
|
@@ -1086,12 +961,9 @@ describe('CostCalculatorService', () => {
|
|
|
1086
961
|
});
|
|
1087
962
|
const context = createContext({
|
|
1088
963
|
grossSalePrice: 150,
|
|
1089
|
-
lineItems: [
|
|
1090
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], productType: 'Electronics' } }),
|
|
1091
|
-
],
|
|
964
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], productType: 'Electronics' } })],
|
|
1092
965
|
});
|
|
1093
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1094
|
-
.orderLevel).toBeCloseTo(4.5);
|
|
966
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBeCloseTo(4.5);
|
|
1095
967
|
});
|
|
1096
968
|
it('should return 0 for PCT_NET_SALES when productCategories filter does not match', () => {
|
|
1097
969
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_NET_SALES, {
|
|
@@ -1100,12 +972,9 @@ describe('CostCalculatorService', () => {
|
|
|
1100
972
|
});
|
|
1101
973
|
const context = createContext({
|
|
1102
974
|
netSalePrice: 80,
|
|
1103
|
-
lineItems: [
|
|
1104
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], category: 'Sports' } }),
|
|
1105
|
-
],
|
|
975
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], category: 'Sports' } })],
|
|
1106
976
|
});
|
|
1107
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1108
|
-
.orderLevel).toBe(0);
|
|
977
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1109
978
|
});
|
|
1110
979
|
it('should return 0 for PCT_TOTAL_SALES when products filter does not match', () => {
|
|
1111
980
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_TOTAL_SALES, {
|
|
@@ -1116,8 +985,7 @@ describe('CostCalculatorService', () => {
|
|
|
1116
985
|
totalPrice: 200,
|
|
1117
986
|
lineItems: [createLineItem({ filterContext: { productId: 'P100', variantId: 'V1', tags: [] } })],
|
|
1118
987
|
});
|
|
1119
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1120
|
-
.orderLevel).toBe(0);
|
|
988
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1121
989
|
});
|
|
1122
990
|
it('should return 0 for PCT_COGS when product filter does not match', () => {
|
|
1123
991
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_COGS, {
|
|
@@ -1126,12 +994,9 @@ describe('CostCalculatorService', () => {
|
|
|
1126
994
|
});
|
|
1127
995
|
const context = createContext({
|
|
1128
996
|
totalProductCost: 50,
|
|
1129
|
-
lineItems: [
|
|
1130
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Samsung' } }),
|
|
1131
|
-
],
|
|
997
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Samsung' } })],
|
|
1132
998
|
});
|
|
1133
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1134
|
-
.orderLevel).toBe(0);
|
|
999
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1135
1000
|
});
|
|
1136
1001
|
it('should return 0 for PCT_SHIPPING when product filter does not match', () => {
|
|
1137
1002
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_SHIPPING, {
|
|
@@ -1142,8 +1007,7 @@ describe('CostCalculatorService', () => {
|
|
|
1142
1007
|
totalShipping: 20,
|
|
1143
1008
|
lineItems: [createLineItem({ filterContext: { productId: 'P100', variantId: 'V1', tags: [] } })],
|
|
1144
1009
|
});
|
|
1145
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1146
|
-
.orderLevel).toBe(0);
|
|
1010
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1147
1011
|
});
|
|
1148
1012
|
it('should return 0 for PER_REFUND_ORDER when product filter does not match', () => {
|
|
1149
1013
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_REFUND_ORDER, {
|
|
@@ -1152,12 +1016,9 @@ describe('CostCalculatorService', () => {
|
|
|
1152
1016
|
});
|
|
1153
1017
|
const context = createContext({
|
|
1154
1018
|
hasRefund: true,
|
|
1155
|
-
lineItems: [
|
|
1156
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } }),
|
|
1157
|
-
],
|
|
1019
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } })],
|
|
1158
1020
|
});
|
|
1159
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1160
|
-
.orderLevel).toBe(0);
|
|
1021
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1161
1022
|
});
|
|
1162
1023
|
it('should apply PER_REFUND_ORDER when product filter matches and hasRefund', () => {
|
|
1163
1024
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_REFUND_ORDER, {
|
|
@@ -1168,8 +1029,7 @@ describe('CostCalculatorService', () => {
|
|
|
1168
1029
|
hasRefund: true,
|
|
1169
1030
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } })],
|
|
1170
1031
|
});
|
|
1171
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1172
|
-
.orderLevel).toBe(5);
|
|
1032
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1173
1033
|
});
|
|
1174
1034
|
it('should only apply PER_LINE_ITEM cost to line items matching product filter', () => {
|
|
1175
1035
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, {
|
|
@@ -1182,16 +1042,8 @@ describe('CostCalculatorService', () => {
|
|
|
1182
1042
|
};
|
|
1183
1043
|
const context = createContext({
|
|
1184
1044
|
lineItems: [
|
|
1185
|
-
createLineItem({
|
|
1186
|
-
|
|
1187
|
-
quantity: 3,
|
|
1188
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' },
|
|
1189
|
-
}),
|
|
1190
|
-
createLineItem({
|
|
1191
|
-
lineItemId: '2',
|
|
1192
|
-
quantity: 2,
|
|
1193
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas' },
|
|
1194
|
-
}),
|
|
1045
|
+
createLineItem({ lineItemId: '1', quantity: 3, filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } }),
|
|
1046
|
+
createLineItem({ lineItemId: '2', quantity: 2, filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas' } }),
|
|
1195
1047
|
],
|
|
1196
1048
|
});
|
|
1197
1049
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, context, liCosts, 'USD', emptyRatesMap);
|
|
@@ -1206,15 +1058,10 @@ describe('CostCalculatorService', () => {
|
|
|
1206
1058
|
});
|
|
1207
1059
|
const context = createContext({
|
|
1208
1060
|
lineItems: [
|
|
1209
|
-
createLineItem({
|
|
1210
|
-
lineItemId: '1',
|
|
1211
|
-
quantity: 3,
|
|
1212
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' },
|
|
1213
|
-
}),
|
|
1061
|
+
createLineItem({ lineItemId: '1', quantity: 3, filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } }),
|
|
1214
1062
|
],
|
|
1215
1063
|
});
|
|
1216
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1217
|
-
.lineItemLevel).toBe(0);
|
|
1064
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).lineItemLevel).toBe(0);
|
|
1218
1065
|
});
|
|
1219
1066
|
it('should only apply PER_REFUND_LINE_ITEM cost to refunded line items matching product filter', () => {
|
|
1220
1067
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_REFUND_LINE_ITEM, {
|
|
@@ -1228,16 +1075,8 @@ describe('CostCalculatorService', () => {
|
|
|
1228
1075
|
const context = createContext({
|
|
1229
1076
|
hasRefund: true,
|
|
1230
1077
|
lineItems: [
|
|
1231
|
-
createLineItem({
|
|
1232
|
-
|
|
1233
|
-
refundedQuantity: 2,
|
|
1234
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [] },
|
|
1235
|
-
}),
|
|
1236
|
-
createLineItem({
|
|
1237
|
-
lineItemId: '2',
|
|
1238
|
-
refundedQuantity: 1,
|
|
1239
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [] },
|
|
1240
|
-
}),
|
|
1078
|
+
createLineItem({ lineItemId: '1', refundedQuantity: 2, filterContext: { productId: 'P1', variantId: 'V1', tags: [] } }),
|
|
1079
|
+
createLineItem({ lineItemId: '2', refundedQuantity: 1, filterContext: { productId: 'P2', variantId: 'V2', tags: [] } }),
|
|
1241
1080
|
],
|
|
1242
1081
|
});
|
|
1243
1082
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, context, liCosts, 'USD', emptyRatesMap);
|
|
@@ -1257,13 +1096,10 @@ describe('CostCalculatorService', () => {
|
|
|
1257
1096
|
orderFilterContext: { tags: [], paymentGateways: [], shippingTitles: [], shipCountryCode: 'US' },
|
|
1258
1097
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } })],
|
|
1259
1098
|
});
|
|
1260
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, contextPass, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1261
|
-
.orderLevel).toBe(5);
|
|
1099
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, contextPass, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1262
1100
|
const contextProductFail = createContext({
|
|
1263
1101
|
orderFilterContext: { tags: [], paymentGateways: [], shippingTitles: [], shipCountryCode: 'US' },
|
|
1264
|
-
lineItems: [
|
|
1265
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } }),
|
|
1266
|
-
],
|
|
1102
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } })],
|
|
1267
1103
|
});
|
|
1268
1104
|
expect(CostCalculatorService.calculateOtherCostEntry(entry, contextProductFail, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1269
1105
|
const contextOrderFail = createContext({
|
|
@@ -1281,8 +1117,7 @@ describe('CostCalculatorService', () => {
|
|
|
1281
1117
|
totalWeight: 500,
|
|
1282
1118
|
orderFilterContext: { tags: [], paymentGateways: [], shippingTitles: [], shipCountryCode: 'CA' },
|
|
1283
1119
|
});
|
|
1284
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1285
|
-
.orderLevel).toBe(0);
|
|
1120
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1286
1121
|
});
|
|
1287
1122
|
it('should return 0 for BY_LINE_ITEM_QUANTITY when orderTags filter does not match', () => {
|
|
1288
1123
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_LINE_ITEM_QUANTITY, {
|
|
@@ -1293,8 +1128,7 @@ describe('CostCalculatorService', () => {
|
|
|
1293
1128
|
lineItems: [createLineItem({ quantity: 10 })],
|
|
1294
1129
|
orderFilterContext: { tags: ['retail'], paymentGateways: [], shippingTitles: [] },
|
|
1295
1130
|
});
|
|
1296
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1297
|
-
.lineItemLevel).toBe(0);
|
|
1131
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).lineItemLevel).toBe(0);
|
|
1298
1132
|
});
|
|
1299
1133
|
it('should return 0 for PCT_GROSS_SALES when orderPaymentGateways filter does not match', () => {
|
|
1300
1134
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_GROSS_SALES, {
|
|
@@ -1305,8 +1139,7 @@ describe('CostCalculatorService', () => {
|
|
|
1305
1139
|
grossSalePrice: 150,
|
|
1306
1140
|
orderFilterContext: { tags: [], paymentGateways: ['paypal'], shippingTitles: [] },
|
|
1307
1141
|
});
|
|
1308
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1309
|
-
.orderLevel).toBe(0);
|
|
1142
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1310
1143
|
});
|
|
1311
1144
|
it('should apply PCT_GROSS_SALES when orderPaymentGateways filter matches', () => {
|
|
1312
1145
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_GROSS_SALES, {
|
|
@@ -1317,8 +1150,7 @@ describe('CostCalculatorService', () => {
|
|
|
1317
1150
|
grossSalePrice: 150,
|
|
1318
1151
|
orderFilterContext: { tags: [], paymentGateways: ['stripe'], shippingTitles: [] },
|
|
1319
1152
|
});
|
|
1320
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1321
|
-
.orderLevel).toBeCloseTo(4.5);
|
|
1153
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBeCloseTo(4.5);
|
|
1322
1154
|
});
|
|
1323
1155
|
it('should return 0 for PER_LINE_ITEM when orderShippingTitles filter does not match', () => {
|
|
1324
1156
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, {
|
|
@@ -1329,8 +1161,7 @@ describe('CostCalculatorService', () => {
|
|
|
1329
1161
|
orderFilterContext: { tags: [], paymentGateways: [], shippingTitles: ['Standard'] },
|
|
1330
1162
|
lineItems: [createLineItem({ quantity: 3 })],
|
|
1331
1163
|
});
|
|
1332
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1333
|
-
.lineItemLevel).toBe(0);
|
|
1164
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).lineItemLevel).toBe(0);
|
|
1334
1165
|
});
|
|
1335
1166
|
it('should return 0 for PCT_COGS when orderSourceNames filter does not match', () => {
|
|
1336
1167
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PCT_COGS, {
|
|
@@ -1341,8 +1172,7 @@ describe('CostCalculatorService', () => {
|
|
|
1341
1172
|
totalProductCost: 50,
|
|
1342
1173
|
orderFilterContext: { tags: [], paymentGateways: [], shippingTitles: [], sourceName: 'pos' },
|
|
1343
1174
|
});
|
|
1344
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1345
|
-
.orderLevel).toBe(0);
|
|
1175
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1346
1176
|
});
|
|
1347
1177
|
it('should apply PER_ORDER when EXCLUDE product filter does not match any line item vendor', () => {
|
|
1348
1178
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1350,12 +1180,9 @@ describe('CostCalculatorService', () => {
|
|
|
1350
1180
|
filters: { productVendors: { mode: COST_FILTER_MODE.EXCLUDE, values: ['Nike'] } },
|
|
1351
1181
|
});
|
|
1352
1182
|
const context = createContext({
|
|
1353
|
-
lineItems: [
|
|
1354
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } }),
|
|
1355
|
-
],
|
|
1183
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } })],
|
|
1356
1184
|
});
|
|
1357
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1358
|
-
.orderLevel).toBe(5);
|
|
1185
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1359
1186
|
});
|
|
1360
1187
|
it('should return 0 for PER_ORDER when EXCLUDE product filter matches all line items', () => {
|
|
1361
1188
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1364,14 +1191,10 @@ describe('CostCalculatorService', () => {
|
|
|
1364
1191
|
});
|
|
1365
1192
|
const context = createContext({
|
|
1366
1193
|
lineItems: [
|
|
1367
|
-
createLineItem({
|
|
1368
|
-
lineItemId: '1',
|
|
1369
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' },
|
|
1370
|
-
}),
|
|
1194
|
+
createLineItem({ lineItemId: '1', filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } }),
|
|
1371
1195
|
],
|
|
1372
1196
|
});
|
|
1373
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1374
|
-
.orderLevel).toBe(0);
|
|
1197
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1375
1198
|
});
|
|
1376
1199
|
it('should apply PER_ORDER when product filter mode is ALL', () => {
|
|
1377
1200
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1379,12 +1202,9 @@ describe('CostCalculatorService', () => {
|
|
|
1379
1202
|
filters: { productVendors: { mode: COST_FILTER_MODE.ALL, values: [] } },
|
|
1380
1203
|
});
|
|
1381
1204
|
const context = createContext({
|
|
1382
|
-
lineItems: [
|
|
1383
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'anything' } }),
|
|
1384
|
-
],
|
|
1205
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'anything' } })],
|
|
1385
1206
|
});
|
|
1386
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1387
|
-
.orderLevel).toBe(5);
|
|
1207
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1388
1208
|
});
|
|
1389
1209
|
it('should return 0 for PER_ORDER when multiple product filters set and no single line item satisfies all', () => {
|
|
1390
1210
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1396,14 +1216,8 @@ describe('CostCalculatorService', () => {
|
|
|
1396
1216
|
});
|
|
1397
1217
|
const context = createContext({
|
|
1398
1218
|
lineItems: [
|
|
1399
|
-
createLineItem({
|
|
1400
|
-
|
|
1401
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike', productType: 'Hats' },
|
|
1402
|
-
}),
|
|
1403
|
-
createLineItem({
|
|
1404
|
-
lineItemId: '2',
|
|
1405
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas', productType: 'Shoes' },
|
|
1406
|
-
}),
|
|
1219
|
+
createLineItem({ lineItemId: '1', filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike', productType: 'Hats' } }),
|
|
1220
|
+
createLineItem({ lineItemId: '2', filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas', productType: 'Shoes' } }),
|
|
1407
1221
|
],
|
|
1408
1222
|
});
|
|
1409
1223
|
const liCosts = {
|
|
@@ -1422,14 +1236,8 @@ describe('CostCalculatorService', () => {
|
|
|
1422
1236
|
});
|
|
1423
1237
|
const context = createContext({
|
|
1424
1238
|
lineItems: [
|
|
1425
|
-
createLineItem({
|
|
1426
|
-
|
|
1427
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas', productType: 'Hats' },
|
|
1428
|
-
}),
|
|
1429
|
-
createLineItem({
|
|
1430
|
-
lineItemId: '2',
|
|
1431
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Nike', productType: 'Shoes' },
|
|
1432
|
-
}),
|
|
1239
|
+
createLineItem({ lineItemId: '1', filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas', productType: 'Hats' } }),
|
|
1240
|
+
createLineItem({ lineItemId: '2', filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Nike', productType: 'Shoes' } }),
|
|
1433
1241
|
],
|
|
1434
1242
|
});
|
|
1435
1243
|
const liCosts = {
|
|
@@ -1446,13 +1254,11 @@ describe('CostCalculatorService', () => {
|
|
|
1446
1254
|
const matchContext = createContext({
|
|
1447
1255
|
lineItems: [createLineItem({ filterContext: { productId: 'P100', variantId: 'V200', tags: [] } })],
|
|
1448
1256
|
});
|
|
1449
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, matchContext, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1450
|
-
.orderLevel).toBe(5);
|
|
1257
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, matchContext, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1451
1258
|
const noMatchContext = createContext({
|
|
1452
1259
|
lineItems: [createLineItem({ filterContext: { productId: 'P100', variantId: 'V999', tags: [] } })],
|
|
1453
1260
|
});
|
|
1454
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, noMatchContext, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1455
|
-
.orderLevel).toBe(0);
|
|
1261
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, noMatchContext, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1456
1262
|
});
|
|
1457
1263
|
it('should convert currency AND evaluate product filters for PER_ORDER', () => {
|
|
1458
1264
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1466,12 +1272,9 @@ describe('CostCalculatorService', () => {
|
|
|
1466
1272
|
});
|
|
1467
1273
|
expect(CostCalculatorService.calculateOtherCostEntry(entry, matchContext, initLineItemCosts(), 'USD', rates).orderLevel).toBeCloseTo(11);
|
|
1468
1274
|
const noMatchContext = createContext({
|
|
1469
|
-
lineItems: [
|
|
1470
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } }),
|
|
1471
|
-
],
|
|
1275
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Adidas' } })],
|
|
1472
1276
|
});
|
|
1473
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, noMatchContext, initLineItemCosts(), 'USD', rates)
|
|
1474
|
-
.orderLevel).toBe(0);
|
|
1277
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, noMatchContext, initLineItemCosts(), 'USD', rates).orderLevel).toBe(0);
|
|
1475
1278
|
});
|
|
1476
1279
|
it('should evaluate weight tiers AND product filters for BY_ORDER_WEIGHT', () => {
|
|
1477
1280
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_ORDER_WEIGHT, {
|
|
@@ -1484,20 +1287,14 @@ describe('CostCalculatorService', () => {
|
|
|
1484
1287
|
});
|
|
1485
1288
|
const matchContext = createContext({
|
|
1486
1289
|
totalWeight: 2000,
|
|
1487
|
-
lineItems: [
|
|
1488
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], category: 'Heavy Items' } }),
|
|
1489
|
-
],
|
|
1290
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], category: 'Heavy Items' } })],
|
|
1490
1291
|
});
|
|
1491
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, matchContext, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1492
|
-
.orderLevel).toBe(3);
|
|
1292
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, matchContext, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(3);
|
|
1493
1293
|
const noMatchContext = createContext({
|
|
1494
1294
|
totalWeight: 2000,
|
|
1495
|
-
lineItems: [
|
|
1496
|
-
createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], category: 'Light Items' } }),
|
|
1497
|
-
],
|
|
1295
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], category: 'Light Items' } })],
|
|
1498
1296
|
});
|
|
1499
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, noMatchContext, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1500
|
-
.orderLevel).toBe(0);
|
|
1297
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, noMatchContext, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1501
1298
|
});
|
|
1502
1299
|
it('should evaluate quantity tiers AND product filters for BY_LINE_ITEM_QUANTITY', () => {
|
|
1503
1300
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.BY_LINE_ITEM_QUANTITY, {
|
|
@@ -1508,19 +1305,13 @@ describe('CostCalculatorService', () => {
|
|
|
1508
1305
|
filters: { productTags: { mode: COST_FILTER_MODE.INCLUDE, values: ['bulk'] } },
|
|
1509
1306
|
});
|
|
1510
1307
|
const matchContext = createContext({
|
|
1511
|
-
lineItems: [
|
|
1512
|
-
createLineItem({ quantity: 5, filterContext: { productId: 'P1', variantId: 'V1', tags: ['bulk'] } }),
|
|
1513
|
-
],
|
|
1308
|
+
lineItems: [createLineItem({ quantity: 5, filterContext: { productId: 'P1', variantId: 'V1', tags: ['bulk'] } })],
|
|
1514
1309
|
});
|
|
1515
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, matchContext, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1516
|
-
.lineItemLevel).toBe(2);
|
|
1310
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, matchContext, initLineItemCosts(), 'USD', emptyRatesMap).lineItemLevel).toBe(2);
|
|
1517
1311
|
const noMatchContext = createContext({
|
|
1518
|
-
lineItems: [
|
|
1519
|
-
createLineItem({ quantity: 5, filterContext: { productId: 'P1', variantId: 'V1', tags: ['single'] } }),
|
|
1520
|
-
],
|
|
1312
|
+
lineItems: [createLineItem({ quantity: 5, filterContext: { productId: 'P1', variantId: 'V1', tags: ['single'] } })],
|
|
1521
1313
|
});
|
|
1522
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, noMatchContext, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1523
|
-
.lineItemLevel).toBe(0);
|
|
1314
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, noMatchContext, initLineItemCosts(), 'USD', emptyRatesMap).lineItemLevel).toBe(0);
|
|
1524
1315
|
});
|
|
1525
1316
|
it('should apply PER_LINE_ITEM to line items NOT matching EXCLUDE product filter', () => {
|
|
1526
1317
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, {
|
|
@@ -1533,16 +1324,8 @@ describe('CostCalculatorService', () => {
|
|
|
1533
1324
|
};
|
|
1534
1325
|
const context = createContext({
|
|
1535
1326
|
lineItems: [
|
|
1536
|
-
createLineItem({
|
|
1537
|
-
|
|
1538
|
-
quantity: 3,
|
|
1539
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' },
|
|
1540
|
-
}),
|
|
1541
|
-
createLineItem({
|
|
1542
|
-
lineItemId: '2',
|
|
1543
|
-
quantity: 2,
|
|
1544
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas' },
|
|
1545
|
-
}),
|
|
1327
|
+
createLineItem({ lineItemId: '1', quantity: 3, filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } }),
|
|
1328
|
+
createLineItem({ lineItemId: '2', quantity: 2, filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas' } }),
|
|
1546
1329
|
],
|
|
1547
1330
|
});
|
|
1548
1331
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, context, liCosts, 'USD', emptyRatesMap);
|
|
@@ -1565,21 +1348,9 @@ describe('CostCalculatorService', () => {
|
|
|
1565
1348
|
};
|
|
1566
1349
|
const context = createContext({
|
|
1567
1350
|
lineItems: [
|
|
1568
|
-
createLineItem({
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike', productType: 'Shoes' },
|
|
1572
|
-
}),
|
|
1573
|
-
createLineItem({
|
|
1574
|
-
lineItemId: '2',
|
|
1575
|
-
quantity: 3,
|
|
1576
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Nike', productType: 'Hats' },
|
|
1577
|
-
}),
|
|
1578
|
-
createLineItem({
|
|
1579
|
-
lineItemId: '3',
|
|
1580
|
-
quantity: 1,
|
|
1581
|
-
filterContext: { productId: 'P3', variantId: 'V3', tags: [], vendor: 'Adidas', productType: 'Shoes' },
|
|
1582
|
-
}),
|
|
1351
|
+
createLineItem({ lineItemId: '1', quantity: 2, filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike', productType: 'Shoes' } }),
|
|
1352
|
+
createLineItem({ lineItemId: '2', quantity: 3, filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Nike', productType: 'Hats' } }),
|
|
1353
|
+
createLineItem({ lineItemId: '3', quantity: 1, filterContext: { productId: 'P3', variantId: 'V3', tags: [], vendor: 'Adidas', productType: 'Shoes' } }),
|
|
1583
1354
|
],
|
|
1584
1355
|
});
|
|
1585
1356
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, context, liCosts, 'USD', emptyRatesMap);
|
|
@@ -1597,8 +1368,7 @@ describe('CostCalculatorService', () => {
|
|
|
1597
1368
|
hasRefund: false,
|
|
1598
1369
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } })],
|
|
1599
1370
|
});
|
|
1600
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1601
|
-
.orderLevel).toBe(0);
|
|
1371
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1602
1372
|
});
|
|
1603
1373
|
it('should apply PER_REFUND_LINE_ITEM only to refunded line items NOT matching EXCLUDE filter', () => {
|
|
1604
1374
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_REFUND_LINE_ITEM, {
|
|
@@ -1612,16 +1382,8 @@ describe('CostCalculatorService', () => {
|
|
|
1612
1382
|
const context = createContext({
|
|
1613
1383
|
hasRefund: true,
|
|
1614
1384
|
lineItems: [
|
|
1615
|
-
createLineItem({
|
|
1616
|
-
|
|
1617
|
-
refundedQuantity: 2,
|
|
1618
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [] },
|
|
1619
|
-
}),
|
|
1620
|
-
createLineItem({
|
|
1621
|
-
lineItemId: '2',
|
|
1622
|
-
refundedQuantity: 1,
|
|
1623
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [] },
|
|
1624
|
-
}),
|
|
1385
|
+
createLineItem({ lineItemId: '1', refundedQuantity: 2, filterContext: { productId: 'P1', variantId: 'V1', tags: [] } }),
|
|
1386
|
+
createLineItem({ lineItemId: '2', refundedQuantity: 1, filterContext: { productId: 'P2', variantId: 'V2', tags: [] } }),
|
|
1625
1387
|
],
|
|
1626
1388
|
});
|
|
1627
1389
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, context, liCosts, 'USD', emptyRatesMap);
|
|
@@ -1637,8 +1399,7 @@ describe('CostCalculatorService', () => {
|
|
|
1637
1399
|
const context = createContext({
|
|
1638
1400
|
orderFilterContext: { tags: ['vip'], paymentGateways: [], shippingTitles: [] },
|
|
1639
1401
|
});
|
|
1640
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1641
|
-
.orderLevel).toBe(5);
|
|
1402
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1642
1403
|
});
|
|
1643
1404
|
it('should return 0 for PER_ORDER when EXCLUDE order filter matches', () => {
|
|
1644
1405
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1648,8 +1409,7 @@ describe('CostCalculatorService', () => {
|
|
|
1648
1409
|
const context = createContext({
|
|
1649
1410
|
orderFilterContext: { tags: ['test'], paymentGateways: [], shippingTitles: [] },
|
|
1650
1411
|
});
|
|
1651
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1652
|
-
.orderLevel).toBe(0);
|
|
1412
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1653
1413
|
});
|
|
1654
1414
|
it('should handle undefined filter context fields (missing vendor, productType, category)', () => {
|
|
1655
1415
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1659,8 +1419,7 @@ describe('CostCalculatorService', () => {
|
|
|
1659
1419
|
const context = createContext({
|
|
1660
1420
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [] } })],
|
|
1661
1421
|
});
|
|
1662
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1663
|
-
.orderLevel).toBe(0);
|
|
1422
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1664
1423
|
});
|
|
1665
1424
|
it('should handle EXCLUDE filter with undefined filter context field (undefined treated as not matching)', () => {
|
|
1666
1425
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1670,8 +1429,7 @@ describe('CostCalculatorService', () => {
|
|
|
1670
1429
|
const context = createContext({
|
|
1671
1430
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [] } })],
|
|
1672
1431
|
});
|
|
1673
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1674
|
-
.orderLevel).toBe(5);
|
|
1432
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1675
1433
|
});
|
|
1676
1434
|
it('should return 0 for PER_ORDER when INCLUDE productTags filter and line item has empty tags', () => {
|
|
1677
1435
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1681,8 +1439,7 @@ describe('CostCalculatorService', () => {
|
|
|
1681
1439
|
const context = createContext({
|
|
1682
1440
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [] } })],
|
|
1683
1441
|
});
|
|
1684
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1685
|
-
.orderLevel).toBe(0);
|
|
1442
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(0);
|
|
1686
1443
|
});
|
|
1687
1444
|
it('should apply PER_ORDER when EXCLUDE productTags filter and line item has empty tags', () => {
|
|
1688
1445
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
@@ -1692,8 +1449,7 @@ describe('CostCalculatorService', () => {
|
|
|
1692
1449
|
const context = createContext({
|
|
1693
1450
|
lineItems: [createLineItem({ filterContext: { productId: 'P1', variantId: 'V1', tags: [] } })],
|
|
1694
1451
|
});
|
|
1695
|
-
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap)
|
|
1696
|
-
.orderLevel).toBe(5);
|
|
1452
|
+
expect(CostCalculatorService.calculateOtherCostEntry(entry, context, initLineItemCosts(), 'USD', emptyRatesMap).orderLevel).toBe(5);
|
|
1697
1453
|
});
|
|
1698
1454
|
it('should apply PER_LINE_ITEM only to line items matching product filter when order filter also passes', () => {
|
|
1699
1455
|
const entry = createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, {
|
|
@@ -1710,16 +1466,8 @@ describe('CostCalculatorService', () => {
|
|
|
1710
1466
|
const context = createContext({
|
|
1711
1467
|
orderFilterContext: { tags: [], paymentGateways: [], shippingTitles: [], shipCountryCode: 'US' },
|
|
1712
1468
|
lineItems: [
|
|
1713
|
-
createLineItem({
|
|
1714
|
-
|
|
1715
|
-
quantity: 3,
|
|
1716
|
-
filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' },
|
|
1717
|
-
}),
|
|
1718
|
-
createLineItem({
|
|
1719
|
-
lineItemId: '2',
|
|
1720
|
-
quantity: 2,
|
|
1721
|
-
filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas' },
|
|
1722
|
-
}),
|
|
1469
|
+
createLineItem({ lineItemId: '1', quantity: 3, filterContext: { productId: 'P1', variantId: 'V1', tags: [], vendor: 'Nike' } }),
|
|
1470
|
+
createLineItem({ lineItemId: '2', quantity: 2, filterContext: { productId: 'P2', variantId: 'V2', tags: [], vendor: 'Adidas' } }),
|
|
1723
1471
|
],
|
|
1724
1472
|
});
|
|
1725
1473
|
const result = CostCalculatorService.calculateOtherCostEntry(entry, context, liCosts, 'USD', emptyRatesMap);
|
|
@@ -1745,9 +1493,7 @@ describe('CostCalculatorService', () => {
|
|
|
1745
1493
|
],
|
|
1746
1494
|
},
|
|
1747
1495
|
});
|
|
1748
|
-
const liCosts = {
|
|
1749
|
-
'1': { totalLineItemHandlingCost: 0, totalLineItemOtherCost: 0 },
|
|
1750
|
-
};
|
|
1496
|
+
const liCosts = { '1': { totalLineItemHandlingCost: 0, totalLineItemOtherCost: 0 } };
|
|
1751
1497
|
const result = CostCalculatorService.calculateOtherCost(configs, createContext(), liCosts, 'USD', emptyRatesMap);
|
|
1752
1498
|
expect(result.total).toBe(5);
|
|
1753
1499
|
expect(result.orderLevel).toBe(5);
|
|
@@ -1791,22 +1537,18 @@ describe('CostCalculatorService', () => {
|
|
|
1791
1537
|
order: {
|
|
1792
1538
|
entries: [
|
|
1793
1539
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
1794
|
-
id: 'e1',
|
|
1795
|
-
flatAmount: 3,
|
|
1540
|
+
id: 'e1', flatAmount: 3,
|
|
1796
1541
|
filters: { productVendors: { mode: COST_FILTER_MODE.INCLUDE, values: ['Nike'] } },
|
|
1797
1542
|
}),
|
|
1798
1543
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
1799
|
-
id: 'e2',
|
|
1800
|
-
flatAmount: 7,
|
|
1544
|
+
id: 'e2', flatAmount: 7,
|
|
1801
1545
|
filters: { products: { mode: COST_FILTER_MODE.INCLUDE, values: ['P999'] } },
|
|
1802
1546
|
}),
|
|
1803
1547
|
createEntry(ORDER_COST_ENTRY_TYPE.PCT_GROSS_SALES, {
|
|
1804
|
-
id: 'e3',
|
|
1805
|
-
percentRate: 2,
|
|
1548
|
+
id: 'e3', percentRate: 2,
|
|
1806
1549
|
}),
|
|
1807
1550
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
1808
|
-
id: 'e4',
|
|
1809
|
-
flatAmount: 10,
|
|
1551
|
+
id: 'e4', flatAmount: 10,
|
|
1810
1552
|
filters: { countries: { mode: COST_FILTER_MODE.INCLUDE, values: ['CA'] } },
|
|
1811
1553
|
}),
|
|
1812
1554
|
],
|
|
@@ -1814,19 +1556,10 @@ describe('CostCalculatorService', () => {
|
|
|
1814
1556
|
});
|
|
1815
1557
|
const context = createContext({
|
|
1816
1558
|
grossSalePrice: 120,
|
|
1817
|
-
orderFilterContext: {
|
|
1818
|
-
|
|
1819
|
-
paymentGateways: ['stripe'],
|
|
1820
|
-
shippingTitles: ['Standard'],
|
|
1821
|
-
shipCountryCode: 'US',
|
|
1822
|
-
},
|
|
1823
|
-
lineItems: [
|
|
1824
|
-
createLineItem({ filterContext: { productId: 'P100', variantId: 'V1', tags: [], vendor: 'Nike' } }),
|
|
1825
|
-
],
|
|
1559
|
+
orderFilterContext: { tags: [], paymentGateways: ['stripe'], shippingTitles: ['Standard'], shipCountryCode: 'US' },
|
|
1560
|
+
lineItems: [createLineItem({ filterContext: { productId: 'P100', variantId: 'V1', tags: [], vendor: 'Nike' } })],
|
|
1826
1561
|
});
|
|
1827
|
-
const liCosts = {
|
|
1828
|
-
'1': { totalLineItemHandlingCost: 0, totalLineItemOtherCost: 0 },
|
|
1829
|
-
};
|
|
1562
|
+
const liCosts = { '1': { totalLineItemHandlingCost: 0, totalLineItemOtherCost: 0 } };
|
|
1830
1563
|
const result = CostCalculatorService.calculateOtherCost(configs, context, liCosts, 'USD', emptyRatesMap);
|
|
1831
1564
|
expect(result.total).toBeCloseTo(5.4);
|
|
1832
1565
|
expect(result.orderLevel).toBeCloseTo(5.4);
|
|
@@ -1841,7 +1574,10 @@ describe('CostCalculatorService', () => {
|
|
|
1841
1574
|
},
|
|
1842
1575
|
});
|
|
1843
1576
|
const context = createContext({
|
|
1844
|
-
lineItems: [
|
|
1577
|
+
lineItems: [
|
|
1578
|
+
createLineItem({ lineItemId: '1', quantity: 3 }),
|
|
1579
|
+
createLineItem({ lineItemId: '2', quantity: 2 }),
|
|
1580
|
+
],
|
|
1845
1581
|
});
|
|
1846
1582
|
const liCosts = {
|
|
1847
1583
|
'1': { totalLineItemHandlingCost: 0, totalLineItemOtherCost: 0 },
|
|
@@ -1862,9 +1598,7 @@ describe('CostCalculatorService', () => {
|
|
|
1862
1598
|
expect(Object.keys(result)).toHaveLength(0);
|
|
1863
1599
|
});
|
|
1864
1600
|
it('should include an explicit 0 override as 0, distinct from having no override', () => {
|
|
1865
|
-
const result = CostCalculatorService.calculateLineItemHandlingCosts([
|
|
1866
|
-
createLineItem({ variantHandlingFee: 0, quantity: 3 }),
|
|
1867
|
-
]);
|
|
1601
|
+
const result = CostCalculatorService.calculateLineItemHandlingCosts([createLineItem({ variantHandlingFee: 0, quantity: 3 })]);
|
|
1868
1602
|
expect(result['1']).toBe(0);
|
|
1869
1603
|
});
|
|
1870
1604
|
it('should multiply handling fee by quantity', () => {
|
|
@@ -1898,9 +1632,7 @@ describe('CostCalculatorService', () => {
|
|
|
1898
1632
|
const configs = createConfigs({
|
|
1899
1633
|
globalProductOverride: { globalHandlingFee: 2 },
|
|
1900
1634
|
gateway: {
|
|
1901
|
-
entries: [
|
|
1902
|
-
{ gatewayName: 'stripe', flatAmount: 0.3, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
1903
|
-
],
|
|
1635
|
+
entries: [{ gatewayName: 'stripe', flatAmount: 0.30, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' }],
|
|
1904
1636
|
},
|
|
1905
1637
|
shipping: { method: SHIPPING_METHOD.SHOPIFY_CHARGES, currency: 'USD' },
|
|
1906
1638
|
order: {
|
|
@@ -1915,7 +1647,7 @@ describe('CostCalculatorService', () => {
|
|
|
1915
1647
|
expect(result.orderLevelHandlingCost).toBe(0);
|
|
1916
1648
|
expect(result.lineItemLevelHandlingCost).toBe(1);
|
|
1917
1649
|
expect(result.totalHandlingCost).toBe(1);
|
|
1918
|
-
expect(result.totalGatewayCost).toBeCloseTo(3.
|
|
1650
|
+
expect(result.totalGatewayCost).toBeCloseTo(3.20);
|
|
1919
1651
|
expect(result.totalShippingCost).toBe(10);
|
|
1920
1652
|
expect(result.totalOtherCost).toBe(1);
|
|
1921
1653
|
expect(result.orderLevelOtherCost).toBe(1);
|
|
@@ -1925,16 +1657,14 @@ describe('CostCalculatorService', () => {
|
|
|
1925
1657
|
it('should handle partial configs', () => {
|
|
1926
1658
|
const configs = createConfigs({
|
|
1927
1659
|
gateway: {
|
|
1928
|
-
entries: [
|
|
1929
|
-
{ gatewayName: 'stripe', flatAmount: 0.3, percentRate: 0, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
1930
|
-
],
|
|
1660
|
+
entries: [{ gatewayName: 'stripe', flatAmount: 0.30, percentRate: 0, currency: 'USD', createdAt: '', updatedAt: '' }],
|
|
1931
1661
|
},
|
|
1932
1662
|
});
|
|
1933
1663
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
1934
1664
|
expect(result.orderLevelHandlingCost).toBe(0);
|
|
1935
1665
|
expect(result.lineItemLevelHandlingCost).toBe(0);
|
|
1936
1666
|
expect(result.totalHandlingCost).toBe(0);
|
|
1937
|
-
expect(result.totalGatewayCost).toBe(0.
|
|
1667
|
+
expect(result.totalGatewayCost).toBe(0.30);
|
|
1938
1668
|
expect(result.totalShippingCost).toBe(0);
|
|
1939
1669
|
expect(result.totalOtherCost).toBe(0);
|
|
1940
1670
|
});
|
|
@@ -1943,13 +1673,11 @@ describe('CostCalculatorService', () => {
|
|
|
1943
1673
|
order: {
|
|
1944
1674
|
entries: [
|
|
1945
1675
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
1946
|
-
id: 'e1',
|
|
1947
|
-
flatAmount: 5,
|
|
1676
|
+
id: 'e1', flatAmount: 5,
|
|
1948
1677
|
filters: { productVendors: { mode: COST_FILTER_MODE.INCLUDE, values: ['Nike'] } },
|
|
1949
1678
|
}),
|
|
1950
1679
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
1951
|
-
id: 'e2',
|
|
1952
|
-
flatAmount: 10,
|
|
1680
|
+
id: 'e2', flatAmount: 10,
|
|
1953
1681
|
filters: { productVendors: { mode: COST_FILTER_MODE.INCLUDE, values: ['Puma'] } },
|
|
1954
1682
|
}),
|
|
1955
1683
|
],
|
|
@@ -1972,9 +1700,7 @@ describe('CostCalculatorService', () => {
|
|
|
1972
1700
|
const configs = createConfigs({
|
|
1973
1701
|
globalProductOverride: { globalHandlingFee: 1, currency: 'USD' },
|
|
1974
1702
|
gateway: {
|
|
1975
|
-
entries: [
|
|
1976
|
-
{ gatewayName: 'stripe', flatAmount: 0.3, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
1977
|
-
],
|
|
1703
|
+
entries: [{ gatewayName: 'stripe', flatAmount: 0.30, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' }],
|
|
1978
1704
|
},
|
|
1979
1705
|
shipping: { method: SHIPPING_METHOD.FIXED_RATE, fixedRateAmount: 5, currency: 'USD' },
|
|
1980
1706
|
order: {
|
|
@@ -1996,7 +1722,7 @@ describe('CostCalculatorService', () => {
|
|
|
1996
1722
|
expect(result.orderLevelHandlingCost).toBe(0);
|
|
1997
1723
|
expect(result.lineItemLevelHandlingCost).toBe(3.5);
|
|
1998
1724
|
expect(result.totalHandlingCost).toBe(3.5);
|
|
1999
|
-
expect(result.totalGatewayCost).toBeCloseTo(6.
|
|
1725
|
+
expect(result.totalGatewayCost).toBeCloseTo(6.10);
|
|
2000
1726
|
expect(result.totalShippingCost).toBe(5);
|
|
2001
1727
|
expect(result.totalOtherCost).toBe(12);
|
|
2002
1728
|
expect(result.orderLevelOtherCost).toBe(7);
|
|
@@ -2009,7 +1735,9 @@ describe('CostCalculatorService', () => {
|
|
|
2009
1735
|
it('should maintain decimal precision with Big.js', () => {
|
|
2010
1736
|
const configs = createConfigs({
|
|
2011
1737
|
order: {
|
|
2012
|
-
entries: [
|
|
1738
|
+
entries: [
|
|
1739
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PCT_TOTAL_SALES, { percentRate: 33.33 }),
|
|
1740
|
+
],
|
|
2013
1741
|
},
|
|
2014
1742
|
});
|
|
2015
1743
|
const context = createContext({ totalPrice: 99.99 });
|
|
@@ -2075,11 +1803,7 @@ describe('CostCalculatorService', () => {
|
|
|
2075
1803
|
const configs = createConfigs({
|
|
2076
1804
|
order: {
|
|
2077
1805
|
entries: [
|
|
2078
|
-
createEntry(ORDER_COST_ENTRY_TYPE.PCT_GROSS_SALES, {
|
|
2079
|
-
id: 'agency1',
|
|
2080
|
-
percentRate: 15,
|
|
2081
|
-
category: 'agency_fees',
|
|
2082
|
-
}),
|
|
1806
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PCT_GROSS_SALES, { id: 'agency1', percentRate: 15, category: 'agency_fees' }),
|
|
2083
1807
|
],
|
|
2084
1808
|
},
|
|
2085
1809
|
});
|
|
@@ -2090,7 +1814,9 @@ describe('CostCalculatorService', () => {
|
|
|
2090
1814
|
it('should route OPEX category costs to opexCost', () => {
|
|
2091
1815
|
const configs = createConfigs({
|
|
2092
1816
|
order: {
|
|
2093
|
-
entries: [
|
|
1817
|
+
entries: [
|
|
1818
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { id: 'opex1', flatAmount: 12, category: 'opex' }),
|
|
1819
|
+
],
|
|
2094
1820
|
},
|
|
2095
1821
|
});
|
|
2096
1822
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2099,7 +1825,9 @@ describe('CostCalculatorService', () => {
|
|
|
2099
1825
|
it('should route OTHER category costs to totalOtherCost', () => {
|
|
2100
1826
|
const configs = createConfigs({
|
|
2101
1827
|
order: {
|
|
2102
|
-
entries: [
|
|
1828
|
+
entries: [
|
|
1829
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { id: 'other1', flatAmount: 7, category: 'other' }),
|
|
1830
|
+
],
|
|
2103
1831
|
},
|
|
2104
1832
|
});
|
|
2105
1833
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2133,11 +1861,7 @@ describe('CostCalculatorService', () => {
|
|
|
2133
1861
|
const configs = createConfigs({
|
|
2134
1862
|
order: {
|
|
2135
1863
|
entries: [
|
|
2136
|
-
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
2137
|
-
id: 'unknown1',
|
|
2138
|
-
flatAmount: 3,
|
|
2139
|
-
category: 'unknown_category_xyz',
|
|
2140
|
-
}),
|
|
1864
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { id: 'unknown1', flatAmount: 3, category: 'unknown_category_xyz' }),
|
|
2141
1865
|
],
|
|
2142
1866
|
},
|
|
2143
1867
|
});
|
|
@@ -2167,7 +1891,10 @@ describe('CostCalculatorService', () => {
|
|
|
2167
1891
|
},
|
|
2168
1892
|
});
|
|
2169
1893
|
const context = createContext({
|
|
2170
|
-
lineItems: [
|
|
1894
|
+
lineItems: [
|
|
1895
|
+
createLineItem({ lineItemId: '1', quantity: 2 }),
|
|
1896
|
+
createLineItem({ lineItemId: '2', quantity: 3 }),
|
|
1897
|
+
],
|
|
2171
1898
|
});
|
|
2172
1899
|
const result = CostCalculatorService.calculateOrderCosts(configs, context, 'USD', emptyRatesMap);
|
|
2173
1900
|
expect(result.categoryCosts.otherFulfillmentCost).toBe(18);
|
|
@@ -2202,16 +1929,15 @@ describe('CostCalculatorService', () => {
|
|
|
2202
1929
|
order: {
|
|
2203
1930
|
entries: [
|
|
2204
1931
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, { id: 'cogs_li', flatAmount: 2, category: 'cogs' }),
|
|
2205
|
-
createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, {
|
|
2206
|
-
id: 'ful_li',
|
|
2207
|
-
flatAmount: 1.5,
|
|
2208
|
-
category: 'fulfillment',
|
|
2209
|
-
}),
|
|
1932
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, { id: 'ful_li', flatAmount: 1.5, category: 'fulfillment' }),
|
|
2210
1933
|
],
|
|
2211
1934
|
},
|
|
2212
1935
|
});
|
|
2213
1936
|
const context = createContext({
|
|
2214
|
-
lineItems: [
|
|
1937
|
+
lineItems: [
|
|
1938
|
+
createLineItem({ lineItemId: '1', quantity: 3 }),
|
|
1939
|
+
createLineItem({ lineItemId: '2', quantity: 2 }),
|
|
1940
|
+
],
|
|
2215
1941
|
});
|
|
2216
1942
|
const result = CostCalculatorService.calculateOrderCosts(configs, context, 'USD', emptyRatesMap);
|
|
2217
1943
|
expect(result.categoryCosts.totalOtherCogs).toBe(10);
|
|
@@ -2220,7 +1946,9 @@ describe('CostCalculatorService', () => {
|
|
|
2220
1946
|
it('should handle PCT_COGS entry type with category routing', () => {
|
|
2221
1947
|
const configs = createConfigs({
|
|
2222
1948
|
order: {
|
|
2223
|
-
entries: [
|
|
1949
|
+
entries: [
|
|
1950
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PCT_COGS, { id: 'pct_cogs', percentRate: 10, category: 'cogs' }),
|
|
1951
|
+
],
|
|
2224
1952
|
},
|
|
2225
1953
|
});
|
|
2226
1954
|
const context = createContext({ totalProductCost: 50 });
|
|
@@ -2231,11 +1959,7 @@ describe('CostCalculatorService', () => {
|
|
|
2231
1959
|
const configs = createConfigs({
|
|
2232
1960
|
order: {
|
|
2233
1961
|
entries: [
|
|
2234
|
-
createEntry(ORDER_COST_ENTRY_TYPE.PCT_SHIPPING, {
|
|
2235
|
-
id: 'pct_ship',
|
|
2236
|
-
percentRate: 20,
|
|
2237
|
-
category: 'fulfillment',
|
|
2238
|
-
}),
|
|
1962
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PCT_SHIPPING, { id: 'pct_ship', percentRate: 20, category: 'fulfillment' }),
|
|
2239
1963
|
],
|
|
2240
1964
|
},
|
|
2241
1965
|
});
|
|
@@ -2381,7 +2105,10 @@ describe('CostCalculatorService', () => {
|
|
|
2381
2105
|
},
|
|
2382
2106
|
});
|
|
2383
2107
|
const context = createContext({
|
|
2384
|
-
lineItems: [
|
|
2108
|
+
lineItems: [
|
|
2109
|
+
createLineItem({ lineItemId: '1', quantity: 4 }),
|
|
2110
|
+
createLineItem({ lineItemId: '2', quantity: 3 }),
|
|
2111
|
+
],
|
|
2385
2112
|
totalQuantity: 7,
|
|
2386
2113
|
});
|
|
2387
2114
|
const result = CostCalculatorService.calculateOrderCosts(configs, context, 'USD', emptyRatesMap);
|
|
@@ -2414,9 +2141,7 @@ describe('CostCalculatorService', () => {
|
|
|
2414
2141
|
const configs = createConfigs({
|
|
2415
2142
|
globalProductOverride: { globalHandlingFee: 1.5, currency: 'USD' },
|
|
2416
2143
|
gateway: {
|
|
2417
|
-
entries: [
|
|
2418
|
-
{ gatewayName: 'stripe', flatAmount: 0.3, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' },
|
|
2419
|
-
],
|
|
2144
|
+
entries: [{ gatewayName: 'stripe', flatAmount: 0.30, percentRate: 2.9, currency: 'USD', createdAt: '', updatedAt: '' }],
|
|
2420
2145
|
},
|
|
2421
2146
|
shipping: { method: SHIPPING_METHOD.FIXED_RATE, fixedRateAmount: 7, currency: 'USD' },
|
|
2422
2147
|
order: {
|
|
@@ -2441,7 +2166,7 @@ describe('CostCalculatorService', () => {
|
|
|
2441
2166
|
const result = CostCalculatorService.calculateOrderCosts(configs, context, 'USD', emptyRatesMap);
|
|
2442
2167
|
expect(result.lineItemLevelHandlingCost).toBe(3.25);
|
|
2443
2168
|
expect(result.totalHandlingCost).toBe(3.25);
|
|
2444
|
-
expect(result.totalGatewayCost).toBeCloseTo(6.
|
|
2169
|
+
expect(result.totalGatewayCost).toBeCloseTo(6.10);
|
|
2445
2170
|
expect(result.totalShippingCost).toBe(7);
|
|
2446
2171
|
expect(result.categoryCosts.totalOtherCogs).toBe(5);
|
|
2447
2172
|
expect(result.categoryCosts.otherFulfillmentCost).toBe(3);
|
|
@@ -2464,7 +2189,10 @@ describe('CostCalculatorService', () => {
|
|
|
2464
2189
|
},
|
|
2465
2190
|
});
|
|
2466
2191
|
const context = createContext({
|
|
2467
|
-
lineItems: [
|
|
2192
|
+
lineItems: [
|
|
2193
|
+
createLineItem({ lineItemId: '1', quantity: 3 }),
|
|
2194
|
+
createLineItem({ lineItemId: '2', quantity: 2 }),
|
|
2195
|
+
],
|
|
2468
2196
|
});
|
|
2469
2197
|
const result = CostCalculatorService.calculateOrderCosts(configs, context, 'USD', emptyRatesMap);
|
|
2470
2198
|
expect(result.orderLevelOtherCost).toBe(15);
|
|
@@ -2522,7 +2250,9 @@ describe('CostCalculatorService', () => {
|
|
|
2522
2250
|
it('should handle entry with undefined flatAmount', () => {
|
|
2523
2251
|
const configs = createConfigs({
|
|
2524
2252
|
order: {
|
|
2525
|
-
entries: [
|
|
2253
|
+
entries: [
|
|
2254
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: undefined, category: 'cogs' }),
|
|
2255
|
+
],
|
|
2526
2256
|
},
|
|
2527
2257
|
});
|
|
2528
2258
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2531,7 +2261,9 @@ describe('CostCalculatorService', () => {
|
|
|
2531
2261
|
it('should handle entry with null flatAmount', () => {
|
|
2532
2262
|
const configs = createConfigs({
|
|
2533
2263
|
order: {
|
|
2534
|
-
entries: [
|
|
2264
|
+
entries: [
|
|
2265
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: null, category: 'cogs' }),
|
|
2266
|
+
],
|
|
2535
2267
|
},
|
|
2536
2268
|
});
|
|
2537
2269
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2540,7 +2272,9 @@ describe('CostCalculatorService', () => {
|
|
|
2540
2272
|
it('should handle entry with NaN flatAmount', () => {
|
|
2541
2273
|
const configs = createConfigs({
|
|
2542
2274
|
order: {
|
|
2543
|
-
entries: [
|
|
2275
|
+
entries: [
|
|
2276
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: NaN, category: 'fulfillment' }),
|
|
2277
|
+
],
|
|
2544
2278
|
},
|
|
2545
2279
|
});
|
|
2546
2280
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2549,7 +2283,9 @@ describe('CostCalculatorService', () => {
|
|
|
2549
2283
|
it('should handle entry with negative flatAmount', () => {
|
|
2550
2284
|
const configs = createConfigs({
|
|
2551
2285
|
order: {
|
|
2552
|
-
entries: [
|
|
2286
|
+
entries: [
|
|
2287
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: -10, category: 'cogs' }),
|
|
2288
|
+
],
|
|
2553
2289
|
},
|
|
2554
2290
|
});
|
|
2555
2291
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2558,7 +2294,9 @@ describe('CostCalculatorService', () => {
|
|
|
2558
2294
|
it('should handle entry with Infinity flatAmount', () => {
|
|
2559
2295
|
const configs = createConfigs({
|
|
2560
2296
|
order: {
|
|
2561
|
-
entries: [
|
|
2297
|
+
entries: [
|
|
2298
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: Infinity, category: 'marketing' }),
|
|
2299
|
+
],
|
|
2562
2300
|
},
|
|
2563
2301
|
});
|
|
2564
2302
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2567,7 +2305,9 @@ describe('CostCalculatorService', () => {
|
|
|
2567
2305
|
it('should handle entry with string flatAmount', () => {
|
|
2568
2306
|
const configs = createConfigs({
|
|
2569
2307
|
order: {
|
|
2570
|
-
entries: [
|
|
2308
|
+
entries: [
|
|
2309
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: '10.50', category: 'opex' }),
|
|
2310
|
+
],
|
|
2571
2311
|
},
|
|
2572
2312
|
});
|
|
2573
2313
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2602,7 +2342,9 @@ describe('CostCalculatorService', () => {
|
|
|
2602
2342
|
it('should handle negative percentRate', () => {
|
|
2603
2343
|
const configs = createConfigs({
|
|
2604
2344
|
order: {
|
|
2605
|
-
entries: [
|
|
2345
|
+
entries: [
|
|
2346
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PCT_NET_SALES, { percentRate: -5, category: 'marketing' }),
|
|
2347
|
+
],
|
|
2606
2348
|
},
|
|
2607
2349
|
});
|
|
2608
2350
|
const context = createContext({ netSalePrice: 100 });
|
|
@@ -2612,7 +2354,9 @@ describe('CostCalculatorService', () => {
|
|
|
2612
2354
|
it('should handle percentRate over 100', () => {
|
|
2613
2355
|
const configs = createConfigs({
|
|
2614
2356
|
order: {
|
|
2615
|
-
entries: [
|
|
2357
|
+
entries: [
|
|
2358
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PCT_COGS, { percentRate: 150, category: 'fulfillment' }),
|
|
2359
|
+
],
|
|
2616
2360
|
},
|
|
2617
2361
|
});
|
|
2618
2362
|
const context = createContext({ totalProductCost: 50 });
|
|
@@ -2624,7 +2368,9 @@ describe('CostCalculatorService', () => {
|
|
|
2624
2368
|
it('should handle zero totalPrice for percent calculations', () => {
|
|
2625
2369
|
const configs = createConfigs({
|
|
2626
2370
|
order: {
|
|
2627
|
-
entries: [
|
|
2371
|
+
entries: [
|
|
2372
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PCT_TOTAL_SALES, { percentRate: 10, category: 'transaction' }),
|
|
2373
|
+
],
|
|
2628
2374
|
},
|
|
2629
2375
|
});
|
|
2630
2376
|
const context = createContext({ totalPrice: 0 });
|
|
@@ -2634,7 +2380,9 @@ describe('CostCalculatorService', () => {
|
|
|
2634
2380
|
it('should handle negative totalPrice', () => {
|
|
2635
2381
|
const configs = createConfigs({
|
|
2636
2382
|
order: {
|
|
2637
|
-
entries: [
|
|
2383
|
+
entries: [
|
|
2384
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PCT_TOTAL_SALES, { percentRate: 10, category: 'cogs' }),
|
|
2385
|
+
],
|
|
2638
2386
|
},
|
|
2639
2387
|
});
|
|
2640
2388
|
const context = createContext({ totalPrice: -100 });
|
|
@@ -2644,7 +2392,9 @@ describe('CostCalculatorService', () => {
|
|
|
2644
2392
|
it('should handle empty lineItems array', () => {
|
|
2645
2393
|
const configs = createConfigs({
|
|
2646
2394
|
order: {
|
|
2647
|
-
entries: [
|
|
2395
|
+
entries: [
|
|
2396
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, { flatAmount: 5, category: 'fulfillment' }),
|
|
2397
|
+
],
|
|
2648
2398
|
},
|
|
2649
2399
|
});
|
|
2650
2400
|
const context = createContext({ lineItems: [] });
|
|
@@ -2655,7 +2405,9 @@ describe('CostCalculatorService', () => {
|
|
|
2655
2405
|
it('should handle lineItems with zero quantity', () => {
|
|
2656
2406
|
const configs = createConfigs({
|
|
2657
2407
|
order: {
|
|
2658
|
-
entries: [
|
|
2408
|
+
entries: [
|
|
2409
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, { flatAmount: 5, category: 'marketing' }),
|
|
2410
|
+
],
|
|
2659
2411
|
},
|
|
2660
2412
|
});
|
|
2661
2413
|
const context = createContext({
|
|
@@ -2702,7 +2454,9 @@ describe('CostCalculatorService', () => {
|
|
|
2702
2454
|
it('should handle empty currency string', () => {
|
|
2703
2455
|
const configs = createConfigs({
|
|
2704
2456
|
order: {
|
|
2705
|
-
entries: [
|
|
2457
|
+
entries: [
|
|
2458
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 10, currency: '', category: 'cogs' }),
|
|
2459
|
+
],
|
|
2706
2460
|
},
|
|
2707
2461
|
});
|
|
2708
2462
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2711,7 +2465,9 @@ describe('CostCalculatorService', () => {
|
|
|
2711
2465
|
it('should handle null order currency', () => {
|
|
2712
2466
|
const configs = createConfigs({
|
|
2713
2467
|
order: {
|
|
2714
|
-
entries: [
|
|
2468
|
+
entries: [
|
|
2469
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 10, category: 'fulfillment' }),
|
|
2470
|
+
],
|
|
2715
2471
|
},
|
|
2716
2472
|
});
|
|
2717
2473
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), null, emptyRatesMap);
|
|
@@ -2721,11 +2477,7 @@ describe('CostCalculatorService', () => {
|
|
|
2721
2477
|
const configs = createConfigs({
|
|
2722
2478
|
order: {
|
|
2723
2479
|
entries: [
|
|
2724
|
-
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
2725
|
-
flatAmount: 10,
|
|
2726
|
-
currency: 'EUR',
|
|
2727
|
-
category: 'transaction',
|
|
2728
|
-
}),
|
|
2480
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 10, currency: 'EUR', category: 'transaction' }),
|
|
2729
2481
|
],
|
|
2730
2482
|
},
|
|
2731
2483
|
});
|
|
@@ -2822,7 +2574,9 @@ describe('CostCalculatorService', () => {
|
|
|
2822
2574
|
it('should handle undefined orderFilterContext', () => {
|
|
2823
2575
|
const configs = createConfigs({
|
|
2824
2576
|
order: {
|
|
2825
|
-
entries: [
|
|
2577
|
+
entries: [
|
|
2578
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 10, category: 'cogs' }),
|
|
2579
|
+
],
|
|
2826
2580
|
},
|
|
2827
2581
|
});
|
|
2828
2582
|
const context = createContext({ orderFilterContext: undefined });
|
|
@@ -2951,7 +2705,9 @@ describe('CostCalculatorService', () => {
|
|
|
2951
2705
|
it('should maintain identity with single order-level COGS entry', () => {
|
|
2952
2706
|
const configs = createConfigs({
|
|
2953
2707
|
order: {
|
|
2954
|
-
entries: [
|
|
2708
|
+
entries: [
|
|
2709
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 25, category: 'cogs' }),
|
|
2710
|
+
],
|
|
2955
2711
|
},
|
|
2956
2712
|
});
|
|
2957
2713
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -2968,7 +2724,9 @@ describe('CostCalculatorService', () => {
|
|
|
2968
2724
|
const context = createContext({ lineItems, totalQuantity: 5 });
|
|
2969
2725
|
const configs = createConfigs({
|
|
2970
2726
|
order: {
|
|
2971
|
-
entries: [
|
|
2727
|
+
entries: [
|
|
2728
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_LINE_ITEM, { flatAmount: 4, category: 'fulfillment' }),
|
|
2729
|
+
],
|
|
2972
2730
|
},
|
|
2973
2731
|
});
|
|
2974
2732
|
const result = CostCalculatorService.calculateOrderCosts(configs, context, 'USD', emptyRatesMap);
|
|
@@ -3167,11 +2925,7 @@ describe('CostCalculatorService', () => {
|
|
|
3167
2925
|
order: {
|
|
3168
2926
|
entries: [
|
|
3169
2927
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 10, category: 'cogs', currency: 'EUR' }),
|
|
3170
|
-
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
3171
|
-
flatAmount: 20,
|
|
3172
|
-
category: 'fulfillment',
|
|
3173
|
-
currency: 'GBP',
|
|
3174
|
-
}),
|
|
2928
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 20, category: 'fulfillment', currency: 'GBP' }),
|
|
3175
2929
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 15, category: 'marketing', currency: 'USD' }),
|
|
3176
2930
|
],
|
|
3177
2931
|
},
|
|
@@ -3287,7 +3041,9 @@ describe('CostCalculatorService', () => {
|
|
|
3287
3041
|
it('should route each entry to exactly one category', () => {
|
|
3288
3042
|
const configs = createConfigs({
|
|
3289
3043
|
order: {
|
|
3290
|
-
entries: [
|
|
3044
|
+
entries: [
|
|
3045
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { id: 'e1', flatAmount: 100, category: 'cogs' }),
|
|
3046
|
+
],
|
|
3291
3047
|
},
|
|
3292
3048
|
});
|
|
3293
3049
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -3345,7 +3101,9 @@ describe('CostCalculatorService', () => {
|
|
|
3345
3101
|
const configs = createConfigs({
|
|
3346
3102
|
globalProductOverride: { globalHandlingFee: 2, currency: 'USD' },
|
|
3347
3103
|
order: {
|
|
3348
|
-
entries: [
|
|
3104
|
+
entries: [
|
|
3105
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 10, category: 'cogs' }),
|
|
3106
|
+
],
|
|
3349
3107
|
},
|
|
3350
3108
|
});
|
|
3351
3109
|
const context = createContext({ lineItems, totalQuantity: 3 });
|
|
@@ -3365,11 +3123,13 @@ describe('CostCalculatorService', () => {
|
|
|
3365
3123
|
const configs = createConfigs({
|
|
3366
3124
|
gateway: {
|
|
3367
3125
|
entries: [
|
|
3368
|
-
{ id: 'g1', name: 'Stripe', gatewayName: 'stripe', flatAmount: 0.
|
|
3126
|
+
{ id: 'g1', name: 'Stripe', gatewayName: 'stripe', flatAmount: 0.30, percentRate: 2.9, currency: 'USD' },
|
|
3369
3127
|
],
|
|
3370
3128
|
},
|
|
3371
3129
|
order: {
|
|
3372
|
-
entries: [
|
|
3130
|
+
entries: [
|
|
3131
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 10, category: 'fulfillment' }),
|
|
3132
|
+
],
|
|
3373
3133
|
},
|
|
3374
3134
|
});
|
|
3375
3135
|
const context = createContext({ totalPrice: 100 });
|
|
@@ -3392,7 +3152,9 @@ describe('CostCalculatorService', () => {
|
|
|
3392
3152
|
currency: 'USD',
|
|
3393
3153
|
},
|
|
3394
3154
|
order: {
|
|
3395
|
-
entries: [
|
|
3155
|
+
entries: [
|
|
3156
|
+
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, { flatAmount: 10, category: 'marketing' }),
|
|
3157
|
+
],
|
|
3396
3158
|
},
|
|
3397
3159
|
});
|
|
3398
3160
|
const result = CostCalculatorService.calculateOrderCosts(configs, createContext(), 'USD', emptyRatesMap);
|
|
@@ -3414,7 +3176,7 @@ describe('CostCalculatorService', () => {
|
|
|
3414
3176
|
lineItemId: 'li-1',
|
|
3415
3177
|
quantity: 5,
|
|
3416
3178
|
refundedQuantity: 0,
|
|
3417
|
-
variantHandlingFee: 1.
|
|
3179
|
+
variantHandlingFee: 1.50,
|
|
3418
3180
|
filterContext: { tags: ['electronics'], productId: '100', variantId: '200', vendor: 'Samsung' },
|
|
3419
3181
|
}),
|
|
3420
3182
|
createLineItem({
|
|
@@ -3428,17 +3190,17 @@ describe('CostCalculatorService', () => {
|
|
|
3428
3190
|
lineItemId: 'li-3',
|
|
3429
3191
|
quantity: 2,
|
|
3430
3192
|
refundedQuantity: 0,
|
|
3431
|
-
variantHandlingFee: 2.
|
|
3193
|
+
variantHandlingFee: 2.00,
|
|
3432
3194
|
filterContext: { tags: ['premium', 'electronics'], productId: '102', variantId: '202', vendor: 'Apple' },
|
|
3433
3195
|
}),
|
|
3434
3196
|
];
|
|
3435
3197
|
const context = createContext({
|
|
3436
3198
|
orderCreatedAt: '2024-06-15T10:00:00Z',
|
|
3437
|
-
totalPrice: 850.
|
|
3438
|
-
grossSalePrice: 920.
|
|
3439
|
-
netSalePrice: 780.
|
|
3440
|
-
totalProductCost: 425.
|
|
3441
|
-
totalShipping: 25.
|
|
3199
|
+
totalPrice: 850.00,
|
|
3200
|
+
grossSalePrice: 920.00,
|
|
3201
|
+
netSalePrice: 780.00,
|
|
3202
|
+
totalProductCost: 425.00,
|
|
3203
|
+
totalShipping: 25.00,
|
|
3442
3204
|
totalWeight: 2500,
|
|
3443
3205
|
totalQuantity: 10,
|
|
3444
3206
|
hasRefund: true,
|
|
@@ -3458,7 +3220,7 @@ describe('CostCalculatorService', () => {
|
|
|
3458
3220
|
};
|
|
3459
3221
|
const configs = createConfigs({
|
|
3460
3222
|
globalProductOverride: {
|
|
3461
|
-
globalHandlingFee: 0.
|
|
3223
|
+
globalHandlingFee: 0.50,
|
|
3462
3224
|
currency: 'USD',
|
|
3463
3225
|
},
|
|
3464
3226
|
gateway: {
|
|
@@ -3467,7 +3229,7 @@ describe('CostCalculatorService', () => {
|
|
|
3467
3229
|
id: 'stripe',
|
|
3468
3230
|
name: 'Stripe',
|
|
3469
3231
|
gatewayName: 'stripe',
|
|
3470
|
-
flatAmount: 0.
|
|
3232
|
+
flatAmount: 0.30,
|
|
3471
3233
|
percentRate: 2.9,
|
|
3472
3234
|
currency: 'USD',
|
|
3473
3235
|
},
|
|
@@ -3482,7 +3244,7 @@ describe('CostCalculatorService', () => {
|
|
|
3482
3244
|
countries: ['US'],
|
|
3483
3245
|
isDefault: false,
|
|
3484
3246
|
rateType: SHIPPING_RATE_TYPE.FLAT,
|
|
3485
|
-
flatAmount: 12.
|
|
3247
|
+
flatAmount: 12.00,
|
|
3486
3248
|
currency: 'USD',
|
|
3487
3249
|
},
|
|
3488
3250
|
{
|
|
@@ -3505,7 +3267,7 @@ describe('CostCalculatorService', () => {
|
|
|
3505
3267
|
entries: [
|
|
3506
3268
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
3507
3269
|
id: 'packaging-base',
|
|
3508
|
-
flatAmount: 2.
|
|
3270
|
+
flatAmount: 2.00,
|
|
3509
3271
|
category: 'cogs',
|
|
3510
3272
|
}),
|
|
3511
3273
|
createEntry(ORDER_COST_ENTRY_TYPE.PCT_COGS, {
|
|
@@ -3535,7 +3297,7 @@ describe('CostCalculatorService', () => {
|
|
|
3535
3297
|
}),
|
|
3536
3298
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_ORDER, {
|
|
3537
3299
|
id: 'agency-retainer-allocation',
|
|
3538
|
-
flatAmount: 8.
|
|
3300
|
+
flatAmount: 8.00,
|
|
3539
3301
|
currency: 'EUR',
|
|
3540
3302
|
category: 'agency_fees',
|
|
3541
3303
|
}),
|
|
@@ -3546,12 +3308,12 @@ describe('CostCalculatorService', () => {
|
|
|
3546
3308
|
}),
|
|
3547
3309
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_REFUND_ORDER, {
|
|
3548
3310
|
id: 'refund-processing',
|
|
3549
|
-
flatAmount: 5.
|
|
3311
|
+
flatAmount: 5.00,
|
|
3550
3312
|
category: 'opex',
|
|
3551
3313
|
}),
|
|
3552
3314
|
createEntry(ORDER_COST_ENTRY_TYPE.PER_REFUND_LINE_ITEM, {
|
|
3553
3315
|
id: 'restocking-fee',
|
|
3554
|
-
flatAmount: 3.
|
|
3316
|
+
flatAmount: 3.00,
|
|
3555
3317
|
category: 'other',
|
|
3556
3318
|
}),
|
|
3557
3319
|
createEntry(ORDER_COST_ENTRY_TYPE.BY_LINE_ITEM_QUANTITY, {
|