Files
cfw-autumn/server/tests/_temp/temp.test.ts

108 lines
2.5 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 {
constructArrearItem,
constructFeatureItem,
constructPrepaidItem,
} 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";
import { CusService } from "../../src/internal/customers/CusService";
const freeProd = constructProduct({
type: "free",
isDefault: true,
items: [
constructFeatureItem({
featureId: TestFeature.Messages,
includedUsage: 500,
}),
],
});
const proProd = constructProduct({
type: "pro",
isDefault: false,
items: [
constructFeatureItem({
featureId: TestFeature.Messages,
includedUsage: 300,
}),
],
});
const proWithUsage = constructProduct({
type: "pro",
id: "pro-with-usage",
isDefault: false,
items: [
constructArrearItem({
featureId: TestFeature.Messages,
includedUsage: 0,
billingUnits: 1,
price: 0.5,
}),
],
});
const proWithPrepaid = constructProduct({
type: "pro",
id: "pro-with-prepaid",
isDefault: false,
items: [
constructPrepaidItem({
featureId: TestFeature.Messages,
billingUnits: 100,
price: 10,
includedUsage: 100,
}),
],
});
const testCase = "temp";
describe(`${chalk.yellowBright("temp: temporary script for testing")}`, () => {
const customerId = "temp";
const autumnV0: AutumnInt = new AutumnInt({ version: ApiVersion.V0_2 });
const autumnV1: AutumnInt = new AutumnInt({ version: ApiVersion.V1_2 });
beforeAll(async () => {
await CusService.deleteByOrgId({
db: ctx.db,
orgId: ctx.org.id,
env: ctx.env,
});
await initCustomerV3({
ctx,
customerId,
withTestClock: false,
attachPm: "success",
});
await initProductsV0({
ctx,
products: [freeProd, proProd, proWithUsage, proWithPrepaid],
// prefix: testCase,
});
});
return;
test("should have correct v1 response", async () => {
await autumnV1.track({
customer_id: customerId,
feature_id: TestFeature.Users,
value: 4,
});
await autumnV1.track({
customer_id: customerId,
feature_id: TestFeature.Users,
value: -2,
});
});
});