113 lines
2.7 KiB
TypeScript
113 lines
2.7 KiB
TypeScript
import { beforeAll, describe, test } from "bun:test";
|
|
import { ApiVersion } from "@autumn/shared";
|
|
import { TestFeature } from "@tests/setup/v2Features.js";
|
|
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 { attachAuthenticatePaymentMethod } from "../../src/external/stripe/stripeCusUtils.js";
|
|
import { initCustomerV3 } from "../../src/utils/scriptUtils/testUtils/initCustomerV3.js";
|
|
import { initProductsV0 } from "../../src/utils/scriptUtils/testUtils/initProductsV0.js";
|
|
import { expectProductAttached } from "../utils/expectUtils/expectProductAttached.js";
|
|
import { expectSubItemsCorrect } from "../utils/expectUtils/expectSubUtils.js";
|
|
import { completeInvoiceConfirmation } from "../utils/stripeUtils/completeInvoiceConfirmation.js";
|
|
|
|
// UNCOMMENT FROM HERE
|
|
const pro = constructProduct({
|
|
type: "pro",
|
|
isDefault: false,
|
|
|
|
items: [
|
|
constructFeatureItem({
|
|
featureId: TestFeature.Credits,
|
|
includedUsage: 200,
|
|
// unlimited: true,
|
|
}),
|
|
],
|
|
});
|
|
|
|
const premium = constructProduct({
|
|
type: "premium",
|
|
items: [
|
|
constructFeatureItem({
|
|
featureId: TestFeature.Messages,
|
|
includedUsage: 100,
|
|
}),
|
|
],
|
|
});
|
|
|
|
describe(`${chalk.yellowBright("temp: Testing add ons")}`, () => {
|
|
const customerId = "temp";
|
|
const autumn: AutumnInt = new AutumnInt({ version: ApiVersion.V1_2 });
|
|
|
|
beforeAll(async () => {
|
|
await initCustomerV3({
|
|
ctx,
|
|
customerId,
|
|
customerData: {},
|
|
attachPm: "success",
|
|
withTestClock: true,
|
|
});
|
|
|
|
await initProductsV0({
|
|
ctx,
|
|
products: [pro, premium],
|
|
prefix: customerId,
|
|
});
|
|
});
|
|
|
|
test("should attach pro product", async () => {
|
|
await autumn.attach({
|
|
customer_id: customerId,
|
|
product_id: pro.id,
|
|
});
|
|
|
|
await attachAuthenticatePaymentMethod({
|
|
ctx,
|
|
customerId,
|
|
});
|
|
|
|
const res = await autumn.attach({
|
|
customer_id: customerId,
|
|
product_id: premium.id,
|
|
});
|
|
|
|
const customer = await autumn.customers.get(customerId);
|
|
expectProductAttached({
|
|
customer,
|
|
product: pro,
|
|
});
|
|
|
|
await expectSubItemsCorrect({
|
|
customerId,
|
|
product: pro,
|
|
stripeCli: ctx.stripeCli,
|
|
db: ctx.db,
|
|
org: ctx.org,
|
|
env: ctx.env,
|
|
});
|
|
|
|
await completeInvoiceConfirmation({
|
|
url: res.checkout_url,
|
|
});
|
|
});
|
|
|
|
test("should have premium product attached", async () => {
|
|
const customer = await autumn.customers.get(customerId);
|
|
expectProductAttached({
|
|
customer,
|
|
product: premium,
|
|
});
|
|
|
|
await expectSubItemsCorrect({
|
|
customerId,
|
|
product: premium,
|
|
stripeCli: ctx.stripeCli,
|
|
db: ctx.db,
|
|
org: ctx.org,
|
|
env: ctx.env,
|
|
});
|
|
});
|
|
});
|