Skip to content

Commit

Permalink
bug(plan) make sure groupBy is undefined if not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol committed Feb 20, 2024
1 parent b1d9d7d commit e1c756c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions src/core/serializers/__tests__/serializePlanInput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ describe('serializePlanInput()', () => {
},
],
graduatedPercentageRanges: undefined,
groupedBy: undefined,
packageSize: undefined,
perTransactionMinAmount: undefined,
perTransactionMaxAmount: undefined,
Expand Down Expand Up @@ -224,6 +225,7 @@ describe('serializePlanInput()', () => {
},
],
graduatedRanges: undefined,
groupedBy: undefined,
packageSize: undefined,
perTransactionMinAmount: undefined,
perTransactionMaxAmount: undefined,
Expand Down Expand Up @@ -288,6 +290,7 @@ describe('serializePlanInput()', () => {
freeUnitsPerTotalAggregation: '1',
graduatedRanges: undefined,
graduatedPercentageRanges: undefined,
groupedBy: undefined,
packageSize: 12,
perTransactionMinAmount: undefined,
perTransactionMaxAmount: undefined,
Expand Down Expand Up @@ -352,6 +355,7 @@ describe('serializePlanInput()', () => {
freeUnitsPerEvents: undefined,
freeUnitsPerTotalAggregation: '1',
graduatedRanges: undefined,
groupedBy: undefined,
graduatedPercentageRanges: undefined,
packageSize: undefined,
perTransactionMinAmount: '1',
Expand Down Expand Up @@ -436,6 +440,67 @@ describe('serializePlanInput()', () => {
taxCodes: [],
})
})

it('formats correctly the groupedBy', () => {
const plan = serializePlanInput({
amountCents: '1',
amountCurrency: CurrencyEnum.Eur,
billChargesMonthly: true,
charges: [
{
chargeModel: ChargeModelEnum.Standard,
billableMetric: {
id: '1234',
name: 'simpleBM',
code: 'simple-bm',
recurring: false,
aggregationType: AggregationTypeEnum.CountAgg,
},
// @ts-ignore
properties: { groupedBy: 'one,two' },
taxCodes: [],
},
],
code: 'my-plan',
interval: PlanInterval.Monthly,
name: 'My plan',
payInAdvance: true,
trialPeriod: 1,
taxCodes: [],
})

expect(plan).toStrictEqual({
amountCents: 100,
amountCurrency: 'EUR',
billChargesMonthly: true,
charges: [
{
billableMetricId: '1234',
chargeModel: 'standard',
minAmountCents: 0,
groupProperties: [],
properties: {
amount: undefined,
freeUnits: undefined,
graduatedRanges: undefined,
groupedBy: ['one', 'two'],
graduatedPercentageRanges: undefined,
packageSize: undefined,
perTransactionMinAmount: undefined,
perTransactionMaxAmount: undefined,
volumeRanges: undefined,
},
taxCodes: [],
},
],
code: 'my-plan',
interval: 'monthly',
name: 'My plan',
payInAdvance: true,
trialPeriod: 1,
taxCodes: [],
})
})
})

describe('a plan with volume charge', () => {
Expand Down Expand Up @@ -484,6 +549,7 @@ describe('serializePlanInput()', () => {
freeUnitsPerTotalAggregation: '1',
graduatedRanges: undefined,
graduatedPercentageRanges: undefined,
groupedBy: undefined,
packageSize: undefined,
perTransactionMinAmount: undefined,
perTransactionMaxAmount: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/core/serializers/serializePlanInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const serializeProperties = (properties: Properties, chargeModel: ChargeModelEnu
...([ChargeModelEnum.Standard].includes(chargeModel)
? // @ts-ignore EDIT: groupedBy is a string at this stage. need to send string[] to BE
{ groupedBy: !!properties?.groupedBy ? properties?.groupedBy.split(',') : undefined }
: {}),
: { groupedBy: undefined }),
...([ChargeModelEnum.Package, ChargeModelEnum.Standard].includes(chargeModel)
? { amount: !!properties?.amount ? String(properties?.amount) : undefined }
: {}),
Expand Down

0 comments on commit e1c756c

Please sign in to comment.