chore: ran biome format
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { AutumnInt } from "@/external/autumn/autumnCli.js";
|
||||
import { initCustomer } from "@/utils/scriptUtils/initCustomer.js";
|
||||
import {
|
||||
APIVersion,
|
||||
AppEnv,
|
||||
CreateFreeTrialSchema,
|
||||
CusProductStatus,
|
||||
FreeTrialDuration,
|
||||
Organization,
|
||||
organizations,
|
||||
APIVersion,
|
||||
AppEnv,
|
||||
CreateFreeTrialSchema,
|
||||
CusProductStatus,
|
||||
FreeTrialDuration,
|
||||
Organization,
|
||||
organizations,
|
||||
} from "@autumn/shared";
|
||||
import chalk from "chalk";
|
||||
import Stripe from "stripe";
|
||||
@@ -27,185 +27,185 @@ import { clearOrgCache } from "@/internal/orgs/orgUtils/clearOrgCache.js";
|
||||
const testCase = "free1";
|
||||
|
||||
let trial1 = CreateFreeTrialSchema.parse({
|
||||
length: 7,
|
||||
duration: FreeTrialDuration.Day,
|
||||
length: 7,
|
||||
duration: FreeTrialDuration.Day,
|
||||
});
|
||||
|
||||
export let free = constructProduct({
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage: 100,
|
||||
}),
|
||||
],
|
||||
isDefault: false,
|
||||
freeTrial: trial1,
|
||||
type: "free",
|
||||
id: "enterprise_trial",
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage: 100,
|
||||
}),
|
||||
],
|
||||
isDefault: false,
|
||||
freeTrial: trial1,
|
||||
type: "free",
|
||||
id: "enterprise_trial",
|
||||
});
|
||||
export let addOn = constructProduct({
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
featureId: TestFeature.Credits,
|
||||
includedUsage: 1000,
|
||||
}),
|
||||
],
|
||||
isDefault: false,
|
||||
type: "free",
|
||||
isAddOn: true,
|
||||
id: "add_on",
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
featureId: TestFeature.Credits,
|
||||
includedUsage: 1000,
|
||||
}),
|
||||
],
|
||||
isDefault: false,
|
||||
type: "free",
|
||||
isAddOn: true,
|
||||
id: "add_on",
|
||||
});
|
||||
|
||||
describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and attaching add on`)}`, () => {
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
|
||||
let curUnix = new Date().getTime();
|
||||
let numUsers = 0;
|
||||
let curUnix = new Date().getTime();
|
||||
let numUsers = 0;
|
||||
|
||||
before(async function () {
|
||||
await setupBefore(this);
|
||||
const { autumnJs } = this;
|
||||
db = this.db;
|
||||
org = this.org;
|
||||
env = this.env;
|
||||
before(async function () {
|
||||
await setupBefore(this);
|
||||
const { autumnJs } = this;
|
||||
db = this.db;
|
||||
org = this.org;
|
||||
env = this.env;
|
||||
|
||||
stripeCli = this.stripeCli;
|
||||
stripeCli = this.stripeCli;
|
||||
|
||||
await db
|
||||
.update(organizations)
|
||||
.set({
|
||||
config: {
|
||||
...this.org.config,
|
||||
multiple_trials: true,
|
||||
},
|
||||
})
|
||||
.where(eq(organizations.id, org.id));
|
||||
await db
|
||||
.update(organizations)
|
||||
.set({
|
||||
config: {
|
||||
...this.org.config,
|
||||
multiple_trials: true,
|
||||
},
|
||||
})
|
||||
.where(eq(organizations.id, org.id));
|
||||
|
||||
await clearOrgCache({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
});
|
||||
await clearOrgCache({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
});
|
||||
|
||||
const { testClockId: testClockId1 } = await initCustomer({
|
||||
autumn: autumnJs,
|
||||
customerId,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
attachPm: "success",
|
||||
});
|
||||
const { testClockId: testClockId1 } = await initCustomer({
|
||||
autumn: autumnJs,
|
||||
customerId,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
attachPm: "success",
|
||||
});
|
||||
|
||||
addPrefixToProducts({
|
||||
products: [free, addOn],
|
||||
prefix: testCase,
|
||||
});
|
||||
addPrefixToProducts({
|
||||
products: [free, addOn],
|
||||
prefix: testCase,
|
||||
});
|
||||
|
||||
await createProducts({
|
||||
autumn,
|
||||
products: [free, addOn],
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
});
|
||||
await createProducts({
|
||||
autumn,
|
||||
products: [free, addOn],
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
});
|
||||
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
|
||||
const approximateDiff = 1000 * 60 * 30; // 30 minutes
|
||||
it("should attach free product with trial", async function () {
|
||||
let attachPreview = await autumn.attachPreview({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
});
|
||||
const approximateDiff = 1000 * 60 * 30; // 30 minutes
|
||||
it("should attach free product with trial", async function () {
|
||||
let attachPreview = await autumn.attachPreview({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
});
|
||||
|
||||
let attach = await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
});
|
||||
let attach = await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
});
|
||||
|
||||
let customer = await autumn.customers.get(customerId);
|
||||
let freeProduct = customer.products.find((p) => p.id === free.id);
|
||||
let customer = await autumn.customers.get(customerId);
|
||||
let freeProduct = customer.products.find((p) => p.id === free.id);
|
||||
|
||||
expect(freeProduct).to.exist;
|
||||
expect(freeProduct?.status).to.equal(CusProductStatus.Trialing);
|
||||
expect(freeProduct?.current_period_end).to.approximately(
|
||||
addDays(Date.now(), trial1.length).getTime(),
|
||||
approximateDiff
|
||||
);
|
||||
});
|
||||
expect(freeProduct).to.exist;
|
||||
expect(freeProduct?.status).to.equal(CusProductStatus.Trialing);
|
||||
expect(freeProduct?.current_period_end).to.approximately(
|
||||
addDays(Date.now(), trial1.length).getTime(),
|
||||
approximateDiff,
|
||||
);
|
||||
});
|
||||
|
||||
const trial2 = CreateFreeTrialSchema.parse({
|
||||
length: 14,
|
||||
duration: FreeTrialDuration.Day,
|
||||
});
|
||||
const trial2 = CreateFreeTrialSchema.parse({
|
||||
length: 14,
|
||||
duration: FreeTrialDuration.Day,
|
||||
});
|
||||
|
||||
it("should update free product's trial end date", async function () {
|
||||
let attachPreview = await autumn.attachPreview({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
free_trial: trial2,
|
||||
is_custom: true,
|
||||
});
|
||||
it("should update free product's trial end date", async function () {
|
||||
let attachPreview = await autumn.attachPreview({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
free_trial: trial2,
|
||||
is_custom: true,
|
||||
});
|
||||
|
||||
let attach = await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
free_trial: trial2,
|
||||
is_custom: true,
|
||||
});
|
||||
let attach = await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
free_trial: trial2,
|
||||
is_custom: true,
|
||||
});
|
||||
|
||||
let customer = await autumn.customers.get(customerId);
|
||||
let freeProduct = customer.products.find((p) => p.id === free.id);
|
||||
let customer = await autumn.customers.get(customerId);
|
||||
let freeProduct = customer.products.find((p) => p.id === free.id);
|
||||
|
||||
expect(freeProduct?.status).to.equal(CusProductStatus.Trialing);
|
||||
expect(freeProduct?.current_period_end).to.approximately(
|
||||
addDays(Date.now(), trial2.length).getTime(),
|
||||
approximateDiff
|
||||
);
|
||||
});
|
||||
expect(freeProduct?.status).to.equal(CusProductStatus.Trialing);
|
||||
expect(freeProduct?.current_period_end).to.approximately(
|
||||
addDays(Date.now(), trial2.length).getTime(),
|
||||
approximateDiff,
|
||||
);
|
||||
});
|
||||
|
||||
it("should attach add on product", async function () {
|
||||
let attachPreview = await autumn.attachPreview({
|
||||
customer_id: customerId,
|
||||
product_id: addOn.id,
|
||||
});
|
||||
it("should attach add on product", async function () {
|
||||
let attachPreview = await autumn.attachPreview({
|
||||
customer_id: customerId,
|
||||
product_id: addOn.id,
|
||||
});
|
||||
|
||||
let attach = await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: addOn.id,
|
||||
});
|
||||
let attach = await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: addOn.id,
|
||||
});
|
||||
|
||||
let customer = await autumn.customers.get(customerId);
|
||||
let addOnProduct = customer.products.find((p) => p.id === addOn.id);
|
||||
let freeProduct = customer.products.find((p) => p.id === free.id);
|
||||
let customer = await autumn.customers.get(customerId);
|
||||
let addOnProduct = customer.products.find((p) => p.id === addOn.id);
|
||||
let freeProduct = customer.products.find((p) => p.id === free.id);
|
||||
|
||||
expect(addOnProduct).to.exist;
|
||||
expect(addOnProduct?.status).to.equal(CusProductStatus.Active);
|
||||
expect(freeProduct?.status).to.equal(CusProductStatus.Trialing);
|
||||
});
|
||||
expect(addOnProduct).to.exist;
|
||||
expect(addOnProduct?.status).to.equal(CusProductStatus.Active);
|
||||
expect(freeProduct?.status).to.equal(CusProductStatus.Trialing);
|
||||
});
|
||||
|
||||
after(async function () {
|
||||
await db
|
||||
.update(organizations)
|
||||
.set({
|
||||
config: {
|
||||
...this.org.config,
|
||||
multiple_trials: false,
|
||||
},
|
||||
})
|
||||
.where(eq(organizations.id, org.id));
|
||||
after(async function () {
|
||||
await db
|
||||
.update(organizations)
|
||||
.set({
|
||||
config: {
|
||||
...this.org.config,
|
||||
multiple_trials: false,
|
||||
},
|
||||
})
|
||||
.where(eq(organizations.id, org.id));
|
||||
|
||||
await clearOrgCache({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
});
|
||||
await clearOrgCache({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
});
|
||||
|
||||
await CacheManager.disconnect();
|
||||
});
|
||||
await CacheManager.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { AutumnInt } from "@/external/autumn/autumnCli.js";
|
||||
import { initCustomer } from "@/utils/scriptUtils/initCustomer.js";
|
||||
import {
|
||||
APIVersion,
|
||||
AppEnv,
|
||||
BillingInterval,
|
||||
Organization,
|
||||
APIVersion,
|
||||
AppEnv,
|
||||
BillingInterval,
|
||||
Organization,
|
||||
} from "@autumn/shared";
|
||||
import chalk from "chalk";
|
||||
import Stripe from "stripe";
|
||||
@@ -21,15 +21,15 @@ import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"
|
||||
import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js";
|
||||
|
||||
export const free = constructProduct({
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage: 100,
|
||||
}),
|
||||
],
|
||||
isDefault: false,
|
||||
type: "free",
|
||||
id: "free",
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage: 100,
|
||||
}),
|
||||
],
|
||||
isDefault: false,
|
||||
type: "free",
|
||||
id: "free",
|
||||
});
|
||||
// export let addOn = constructProduct({
|
||||
// items: [
|
||||
@@ -46,83 +46,83 @@ export const free = constructProduct({
|
||||
const testCase = "free2";
|
||||
|
||||
describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and attaching add on`)}`, () => {
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
|
||||
let curUnix = new Date().getTime();
|
||||
let numUsers = 0;
|
||||
let curUnix = new Date().getTime();
|
||||
let numUsers = 0;
|
||||
|
||||
before(async function () {
|
||||
await setupBefore(this);
|
||||
const { autumnJs } = this;
|
||||
db = this.db;
|
||||
org = this.org;
|
||||
env = this.env;
|
||||
before(async function () {
|
||||
await setupBefore(this);
|
||||
const { autumnJs } = this;
|
||||
db = this.db;
|
||||
org = this.org;
|
||||
env = this.env;
|
||||
|
||||
stripeCli = this.stripeCli;
|
||||
stripeCli = this.stripeCli;
|
||||
|
||||
const { testClockId: testClockId1 } = await initCustomer({
|
||||
autumn: autumnJs,
|
||||
customerId,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
attachPm: "success",
|
||||
});
|
||||
const { testClockId: testClockId1 } = await initCustomer({
|
||||
autumn: autumnJs,
|
||||
customerId,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
attachPm: "success",
|
||||
});
|
||||
|
||||
addPrefixToProducts({
|
||||
products: [free],
|
||||
prefix: testCase,
|
||||
});
|
||||
addPrefixToProducts({
|
||||
products: [free],
|
||||
prefix: testCase,
|
||||
});
|
||||
|
||||
await createProducts({
|
||||
autumn,
|
||||
products: [free],
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
});
|
||||
await createProducts({
|
||||
autumn,
|
||||
products: [free],
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
});
|
||||
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
|
||||
const approximateDiff = 1000 * 60 * 30; // 30 minutes
|
||||
it("should attach free product", async function () {
|
||||
await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
});
|
||||
const approximateDiff = 1000 * 60 * 30; // 30 minutes
|
||||
it("should attach free product", async function () {
|
||||
await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: free.id,
|
||||
});
|
||||
|
||||
const customer = await autumn.customers.get(customerId);
|
||||
expectProductAttached({
|
||||
customer,
|
||||
product: free,
|
||||
});
|
||||
});
|
||||
const customer = await autumn.customers.get(customerId);
|
||||
expectProductAttached({
|
||||
customer,
|
||||
product: free,
|
||||
});
|
||||
});
|
||||
|
||||
const customItems = [
|
||||
...free.items,
|
||||
constructPriceItem({
|
||||
price: 100,
|
||||
interval: BillingInterval.Month,
|
||||
}),
|
||||
];
|
||||
it("should update free product with price", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: free,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
attachParams: {
|
||||
// @ts-ignore
|
||||
is_custom: true,
|
||||
items: customItems,
|
||||
},
|
||||
});
|
||||
});
|
||||
const customItems = [
|
||||
...free.items,
|
||||
constructPriceItem({
|
||||
price: 100,
|
||||
interval: BillingInterval.Month,
|
||||
}),
|
||||
];
|
||||
it("should update free product with price", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: free,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
attachParams: {
|
||||
// @ts-ignore
|
||||
is_custom: true,
|
||||
items: customItems,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user