Skip to content

Commit

Permalink
Merge pull request #65 from vtex/fix/packages-length
Browse files Browse the repository at this point in the history
CHK-1924: Fix calculation of packages length not considering SLA estimate
  • Loading branch information
lucasecdb authored Jul 21, 2022
2 parents e608c21 + b8d7c68 commit f10f639
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Calculation of `packagesLength` not considering SLA estimate.

## [0.2.17] - 2022-07-06
### Fixed
Expand Down
6 changes: 5 additions & 1 deletion react/DeliveryPackagesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ function getPackagesLength(chosenPackage) {
flatten(
chosenPackage
.filter(li => isDelivery(li) && (!!li.selectedSla || hasSLAs(li)))
.map(li => li.selectedSla)
.map(li => {
const sla = li.slas.find(sla => sla.id === li.selectedSla)

return sla.id + sla.shippingEstimate
})
)
)

Expand Down
80 changes: 62 additions & 18 deletions react/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { CHEAPEST, DELIVERY } from '../constants'
import {
getOptionsDetails,
getSelectedDeliveryOption,
} from '../leanShipping'
import { getOptionsDetails, getSelectedDeliveryOption } from '../leanShipping'
import { removeAddressValidation } from '../utils'

describe('getOptionDetails', () => {
Expand Down Expand Up @@ -39,6 +36,45 @@ describe('getOptionDetails', () => {

expect(resultDetails).toEqual(expectedResult)
})

it('should account for shipping estimate in packages length count', () => {
const delivery = {
[CHEAPEST]: [
{
selectedDeliveryChannel: DELIVERY,
selectedSla: 'Normal',
slas: [
{
id: 'Normal',
price: 100,
deliveryChannel: DELIVERY,
shippingEstimate: '1d',
},
],
},
{
selectedDeliveryChannel: DELIVERY,
selectedSla: 'Normal',
slas: [
{
id: 'Normal',
price: 100,
deliveryChannel: DELIVERY,
shippingEstimate: '3d',
},
],
},
],
}

const details = getOptionsDetails(delivery)

expect(details).toStrictEqual([
expect.objectContaining({
packagesLength: 2,
}),
])
})
})

describe('getSelectedDeliveryOption', () => {
Expand Down Expand Up @@ -72,35 +108,43 @@ describe('removeAddressValidation', () => {
})

it('should clean simple address object', () => {
expect(removeAddressValidation({
postalCode: {
value: 'abc123',
},
})).toStrictEqual({
expect(
removeAddressValidation({
postalCode: {
value: 'abc123',
},
})
).toStrictEqual({
postalCode: 'abc123',
})
})

it('should not fail when address doesnt have validation', () => {
expect(removeAddressValidation({
postalCode: 'abc123',
})).toStrictEqual({
expect(
removeAddressValidation({
postalCode: 'abc123',
})
).toStrictEqual({
postalCode: 'abc123',
})
})

it('should not fail when field is undefined', () => {
expect(removeAddressValidation({
postalCode: undefined,
})).toStrictEqual({
expect(
removeAddressValidation({
postalCode: undefined,
})
).toStrictEqual({
postalCode: undefined,
})
})

it('should not fail when field value is undefined', () => {
expect(removeAddressValidation({
postalCode: { value: undefined },
})).toStrictEqual({
expect(
removeAddressValidation({
postalCode: { value: undefined },
})
).toStrictEqual({
postalCode: null,
})
})
Expand Down

0 comments on commit f10f639

Please sign in to comment.