Skip to content

Commit a13b615

Browse files
committed
fix(catalog): dedupe whole-plan removals
1 parent 317092a commit a13b615

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

server/src/internal/catalog/actions/deriveReplaceRemovals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ export const deriveReplacePlanRemovals = ({
5050
.map((planId) => `${planId}:${plan.version}`);
5151
}),
5252
);
53+
const omittedPlanIds = new Set<string>();
5354

5455
return products.flatMap((product): ReplacePlanRemoval[] => {
5556
if (product.archived) return [];
5657
if (!desiredPlanIds.has(product.id)) {
58+
if (omittedPlanIds.has(product.id)) return [];
59+
omittedPlanIds.add(product.id);
5760
return [{ planId: product.id, allVersions: true }];
5861
}
5962
if (

server/tests/integration/crud/catalog/catalog-explicit-version-removal.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,49 @@ test(`${chalk.yellowBright("catalog: update removes every omitted explicit versi
5353
});
5454
expect(versions.map(({ version }) => version)).toEqual([1]);
5555
});
56+
57+
test(`${chalk.yellowBright("catalog: update removes an entirely omitted versioned plan once")}`, async () => {
58+
const suffix = Math.random().toString(36).slice(2, 9);
59+
const planId = `catalog_remove_plan_${suffix}`;
60+
const product = products.pro({ id: planId, items: [] });
61+
const { autumnV2_2, ctx } = await initScenario({
62+
customerId: `catalog-remove-plan-${suffix}`,
63+
setup: [s.products({ list: [product], prefix: "" })],
64+
actions: [],
65+
});
66+
67+
await autumnV2_2.post("/catalog.update", {
68+
plans: [{ plan_id: planId, name: "Version 2", force_version: true }],
69+
});
70+
71+
const productsBefore = await ProductService.listFull({
72+
db: ctx.db,
73+
orgId: ctx.org.id,
74+
env: ctx.env,
75+
returnAll: true,
76+
});
77+
const skipPlanIds = [
78+
...new Set(
79+
productsBefore
80+
.map(({ id }) => id)
81+
.filter((currentPlanId) => currentPlanId !== planId),
82+
),
83+
];
84+
85+
await autumnV2_2.catalog.update({
86+
features: [],
87+
plans: [],
88+
skip_deletions: false,
89+
skip_feature_ids: ctx.features.map(({ id }) => id),
90+
skip_plan_ids: skipPlanIds,
91+
});
92+
93+
const versions = await ProductService.listFull({
94+
db: ctx.db,
95+
orgId: ctx.org.id,
96+
env: ctx.env,
97+
inIds: [planId],
98+
returnAll: true,
99+
});
100+
expect(versions).toHaveLength(0);
101+
});

0 commit comments

Comments
 (0)