Skip to content

Commit a2cc023

Browse files
authored
Merge pull request #20219 from mozilla/PAY-3578
fix(shared-cms): More than one churn content per product+interval is not allowed
2 parents 4eb5db6 + 2c1aa09 commit a2cc023

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

libs/shared/cms/src/lib/queries/churn-intervention-by-product-id/util.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ describe('ChurnInterventionByProductIdResultUtil', () => {
4242
expect(transformed?.churnInterventionId).toBeDefined();
4343
});
4444

45+
it('should not capture sentry message if no offering is returned', () => {
46+
const result = ChurnInterventionByProductIdRawResultFactory({
47+
offerings: [],
48+
});
49+
const util = new ChurnInterventionByProductIdResultUtil(result);
50+
util.getTransformedChurnInterventionByProductId();
51+
52+
expect(Sentry.captureMessage).toHaveBeenCalledTimes(0);
53+
});
54+
55+
it('should not capture sentry message if one offering is returned', () => {
56+
const result = ChurnInterventionByProductIdRawResultFactory({
57+
offerings: [
58+
ChurnInterventionByProductIdRawResultFactory().offerings[0],
59+
],
60+
});
61+
const util = new ChurnInterventionByProductIdResultUtil(result);
62+
util.getTransformedChurnInterventionByProductId();
63+
64+
expect(Sentry.captureMessage).toHaveBeenCalledTimes(0);
65+
});
66+
4567
it('should capture sentry message if more than one offering is returned', () => {
4668
const result = ChurnInterventionByProductIdRawResultFactory({
4769
offerings: [

libs/shared/cms/src/lib/queries/churn-intervention-by-product-id/util.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export class ChurnInterventionByProductIdResultUtil {
1313
constructor(private rawResult: ChurnInterventionByProductIdRawResult) {}
1414

1515
getTransformedChurnInterventionByProductId() {
16-
if (this.rawResult.offerings.length !== 1) {
16+
if (this.rawResult.offerings.length === 0) {
17+
return [];
18+
}
19+
if (this.rawResult.offerings.length > 1) {
1720
Sentry.captureMessage(
1821
'Unexpected number of offerings found for product and interval',
1922
{ extra: { offeringsCount: this.rawResult.offerings.length } }

0 commit comments

Comments
 (0)