77 lines
2.0 KiB
TypeScript
77 lines
2.0 KiB
TypeScript
import { beforeAll, describe, test } from "bun:test";
|
|
import { LegacyVersion } from "@autumn/shared";
|
|
import { TestFeature } from "@tests/setup/v2Features.js";
|
|
import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js";
|
|
import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js";
|
|
import ctx from "@tests/utils/testInitUtils/createTestContext.js";
|
|
import chalk from "chalk";
|
|
import { AutumnInt } from "@/external/autumn/autumnCli.js";
|
|
import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js";
|
|
import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js";
|
|
import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js";
|
|
import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js";
|
|
|
|
const testCase = "aentity1";
|
|
|
|
const pro = constructProduct({
|
|
items: [
|
|
constructArrearItem({
|
|
featureId: TestFeature.Words,
|
|
includedUsage: 1500,
|
|
}),
|
|
],
|
|
type: "pro",
|
|
});
|
|
|
|
describe(`${chalk.yellowBright(`attach/${testCase}: Testing attach to entity via checkout`)}`, () => {
|
|
const customerId = testCase;
|
|
const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 });
|
|
|
|
beforeAll(async () => {
|
|
await initCustomerV3({
|
|
ctx,
|
|
customerId,
|
|
withTestClock: true,
|
|
});
|
|
|
|
await initProductsV0({
|
|
ctx,
|
|
products: [pro],
|
|
prefix: testCase,
|
|
});
|
|
});
|
|
|
|
const newEntities = [
|
|
{
|
|
id: "1",
|
|
name: "Entity 1",
|
|
feature_id: TestFeature.Users,
|
|
},
|
|
];
|
|
|
|
test("should attach pro product to entity 1", async () => {
|
|
await autumn.entities.create(customerId, newEntities);
|
|
const entityId = newEntities[0].id;
|
|
|
|
await attachAndExpectCorrect({
|
|
autumn,
|
|
customerId,
|
|
product: pro,
|
|
stripeCli: ctx.stripeCli,
|
|
db: ctx.db,
|
|
org: ctx.org,
|
|
env: ctx.env,
|
|
entityId,
|
|
});
|
|
|
|
const customer = await autumn.customers.get(customerId);
|
|
// console.log("customer products:", customer.products);
|
|
|
|
expectProductAttached({
|
|
customer,
|
|
product: pro,
|
|
entityId,
|
|
});
|
|
});
|
|
});
|