fix: carrying usge from main -> add on disabled
This commit is contained in:
@@ -34,7 +34,8 @@
|
||||
"db:pull": "bun scripts/db/pull.ts",
|
||||
"db:push": " bun -F @autumn/shared db:push",
|
||||
"db:generate": "bun -F @autumn/shared db:generate",
|
||||
"db:migrate": " bun -F @autumn/shared db:migrate"
|
||||
"db:migrate": " bun -F @autumn/shared db:migrate",
|
||||
"kill-ports": "lsof -ti:8080 -ti:3000 | xargs kill -9"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wooorm/starry-night": "^3.8.0",
|
||||
|
||||
@@ -263,6 +263,8 @@ export const getExistingCusProduct = async ({
|
||||
internalEntityId,
|
||||
});
|
||||
|
||||
if (product.is_add_on) return undefined;
|
||||
|
||||
return curMainProduct;
|
||||
};
|
||||
|
||||
@@ -323,7 +325,6 @@ export const createFullCusProduct = async ({
|
||||
product,
|
||||
internalCustomerId: customer.internal_id,
|
||||
internalEntityId: attachParams.internalEntityId,
|
||||
// processorType,
|
||||
});
|
||||
|
||||
freeTrial = disableFreeTrial ? null : freeTrial;
|
||||
|
||||
@@ -121,8 +121,10 @@ export const getCustomerSub = async ({
|
||||
|
||||
cusProducts.sort((a, b) => {
|
||||
if (targetSubId) {
|
||||
if (a.subscription_ids && a.subscription_ids.includes(targetSubId)) return -1;
|
||||
if (b.subscription_ids && b.subscription_ids.includes(targetSubId)) return 1;
|
||||
if (a.subscription_ids && a.subscription_ids.includes(targetSubId))
|
||||
return -1;
|
||||
if (b.subscription_ids && b.subscription_ids.includes(targetSubId))
|
||||
return 1;
|
||||
}
|
||||
// 1. Check same group
|
||||
const aGroupMatches = a.product.group === targetGroup;
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import { beforeAll, describe, it } from "bun:test";
|
||||
import { ApiVersion } from "@autumn/shared";
|
||||
import { TestFeature } from "@tests/setup/v2Features.js";
|
||||
import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached";
|
||||
import ctx from "@tests/utils/testInitUtils/createTestContext.js";
|
||||
import chalk from "chalk";
|
||||
import { AutumnInt } from "@/external/autumn/autumnCli.js";
|
||||
import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js";
|
||||
import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js";
|
||||
import { AutumnCliV2 } from "@/external/autumn/autumnCliV2";
|
||||
import { timeout } from "@/utils/genUtils";
|
||||
import {
|
||||
constructFeatureItem,
|
||||
constructPrepaidItem,
|
||||
} from "@/utils/scriptUtils/constructItem.js";
|
||||
import {
|
||||
constructProduct,
|
||||
constructRawProduct,
|
||||
} from "@/utils/scriptUtils/createTestProducts.js";
|
||||
import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js";
|
||||
import { attachAuthenticatePaymentMethod } from "../../src/external/stripe/stripeCusUtils";
|
||||
import { CusService } from "../../src/internal/customers/CusService";
|
||||
@@ -15,17 +24,21 @@ const pro = constructProduct({
|
||||
type: "pro",
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage: 100,
|
||||
featureId: TestFeature.Users,
|
||||
includedUsage: 1,
|
||||
}),
|
||||
],
|
||||
});
|
||||
const oneOffCredits = constructProduct({
|
||||
type: "one_off",
|
||||
|
||||
export const addOn = constructRawProduct({
|
||||
id: "addOn",
|
||||
isAddOn: true,
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
featureId: TestFeature.Credits,
|
||||
includedUsage: 100,
|
||||
constructPrepaidItem({
|
||||
featureId: TestFeature.Users,
|
||||
includedUsage: 0,
|
||||
billingUnits: 1,
|
||||
price: 10,
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -46,27 +59,35 @@ describe(`${chalk.yellowBright("temp: one off credits test")}`, () => {
|
||||
|
||||
await initProductsV0({
|
||||
ctx,
|
||||
products: [pro, oneOffCredits],
|
||||
products: [pro, addOn],
|
||||
prefix: testCase,
|
||||
});
|
||||
});
|
||||
|
||||
it("should attach one off credits product", async () => {
|
||||
await autumnV1.attach({
|
||||
customer_id: customerId,
|
||||
product_id: oneOffCredits.id,
|
||||
product_id: pro.id,
|
||||
});
|
||||
|
||||
const customer = await CusService.get({
|
||||
db: ctx.db,
|
||||
idOrInternalId: customerId,
|
||||
orgId: ctx.org.id,
|
||||
env: ctx.env,
|
||||
await autumnV1.track({
|
||||
customer_id: customerId,
|
||||
feature_id: TestFeature.Users,
|
||||
value: 1,
|
||||
});
|
||||
|
||||
await attachAuthenticatePaymentMethod({
|
||||
ctx,
|
||||
customerId,
|
||||
await timeout(4000);
|
||||
|
||||
await autumnV1.attach({
|
||||
customer_id: customerId,
|
||||
product_id: addOn.id,
|
||||
options: [
|
||||
{
|
||||
feature_id: TestFeature.Users,
|
||||
quantity: 3,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const customer = await autumnV1.customers.get(customerId);
|
||||
console.log("Customer:", customer);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -139,7 +139,7 @@ export const completeInvoiceCheckout = async ({
|
||||
);
|
||||
if (postalInput) {
|
||||
await postalInput.click();
|
||||
await postalInput.type("SW59SX");
|
||||
await postalInput.type("94107");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Could not find postal code input:", error);
|
||||
|
||||
Reference in New Issue
Block a user