chore: cubic comments
This commit is contained in:
@@ -39,8 +39,14 @@ export const mergeEntityAndCustomerSubjectRows = ({
|
||||
}): SubjectQueryRow => {
|
||||
if (!customerRow) return entityRow;
|
||||
|
||||
// The entityScopedOnly query matches on internal_entity_id alone (adding the
|
||||
// customer predicate degrades its plan), so enforce the customer match here.
|
||||
// Dependent rows of any dropped product are filtered transitively below.
|
||||
const customerProducts = [
|
||||
...entityRow.customer_products,
|
||||
...entityRow.customer_products.filter(
|
||||
(product) =>
|
||||
product.internal_customer_id === entityRow.customer.internal_id,
|
||||
),
|
||||
...customerRow.customer_products,
|
||||
].slice(0, CUSTOMER_PRODUCT_LIMIT);
|
||||
|
||||
|
||||
@@ -14,17 +14,20 @@ import { mergeEntityAndCustomerSubjectRows } from "@/internal/customers/repos/ge
|
||||
const createCustomerProduct = ({
|
||||
id,
|
||||
internalProductId = `prod_internal_${id}`,
|
||||
internalCustomerId = "cus_internal_1",
|
||||
freeTrialId = null,
|
||||
subscriptionIds = [],
|
||||
}: {
|
||||
id: string;
|
||||
internalProductId?: string;
|
||||
internalCustomerId?: string;
|
||||
freeTrialId?: string | null;
|
||||
subscriptionIds?: string[];
|
||||
}) =>
|
||||
({
|
||||
id,
|
||||
internal_product_id: internalProductId,
|
||||
internal_customer_id: internalCustomerId,
|
||||
free_trial_id: freeTrialId,
|
||||
subscription_ids: subscriptionIds,
|
||||
}) as DbCustomerProduct;
|
||||
@@ -90,6 +93,28 @@ describe("mergeEntityAndCustomerSubjectRows", () => {
|
||||
expect(merged).toBe(entityRow);
|
||||
});
|
||||
|
||||
test("drops entity-scoped products belonging to a different customer", () => {
|
||||
const entityRow = createRow({
|
||||
customer_products: [
|
||||
createCustomerProduct({ id: "cp_ours" }),
|
||||
createCustomerProduct({
|
||||
id: "cp_other_customer",
|
||||
internalCustomerId: "cus_internal_other",
|
||||
}),
|
||||
],
|
||||
});
|
||||
const customerRow = createRow();
|
||||
|
||||
const merged = mergeEntityAndCustomerSubjectRows({
|
||||
entityRow,
|
||||
customerRow,
|
||||
});
|
||||
|
||||
expect(merged.customer_products.map((product) => product.id)).toEqual([
|
||||
"cp_ours",
|
||||
]);
|
||||
});
|
||||
|
||||
test("orders entity-scoped rows before customer-level rows", () => {
|
||||
const entityRow = createRow({
|
||||
customer_products: [
|
||||
|
||||
Reference in New Issue
Block a user