chore: ran biome format
This commit is contained in:
@@ -20,167 +20,167 @@ import { runMigrationTest } from "./runMigrationTest.js";
|
||||
import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js";
|
||||
|
||||
let messagesItem = constructFeatureItem({
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage: 500,
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage: 500,
|
||||
}) as LimitedItem;
|
||||
|
||||
let wordsItem = constructFeatureItem({
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: 100,
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: 100,
|
||||
}) as LimitedItem;
|
||||
|
||||
export let free = constructProduct({
|
||||
items: [messagesItem, wordsItem],
|
||||
type: "free",
|
||||
isDefault: false,
|
||||
items: [messagesItem, wordsItem],
|
||||
type: "free",
|
||||
isDefault: false,
|
||||
});
|
||||
|
||||
const testCase = "migrations1";
|
||||
|
||||
describe(`${chalk.yellowBright(`${testCase}: Testing migration for free product`)}`, () => {
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: defaultApiVersion });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: defaultApiVersion });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
|
||||
let curUnix = new Date().getTime();
|
||||
let curUnix = new Date().getTime();
|
||||
|
||||
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;
|
||||
|
||||
addPrefixToProducts({
|
||||
products: [free],
|
||||
prefix: testCase,
|
||||
});
|
||||
addPrefixToProducts({
|
||||
products: [free],
|
||||
prefix: testCase,
|
||||
});
|
||||
|
||||
await createProducts({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
autumn,
|
||||
products: [free],
|
||||
customerId,
|
||||
});
|
||||
await createProducts({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
autumn,
|
||||
products: [free],
|
||||
customerId,
|
||||
});
|
||||
|
||||
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",
|
||||
});
|
||||
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
|
||||
it("should attach free product", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: free,
|
||||
stripeCli,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
skipSubCheck: true,
|
||||
});
|
||||
});
|
||||
it("should attach free product", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: free,
|
||||
stripeCli,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
skipSubCheck: true,
|
||||
});
|
||||
});
|
||||
|
||||
let newFree: ProductV2;
|
||||
let increaseMessagesBy = 100;
|
||||
let reduceWordsBy = 50;
|
||||
it("should update product to new version", async function () {
|
||||
newFree = structuredClone(free);
|
||||
let newFree: ProductV2;
|
||||
let increaseMessagesBy = 100;
|
||||
let reduceWordsBy = 50;
|
||||
it("should update product to new version", async function () {
|
||||
newFree = structuredClone(free);
|
||||
|
||||
let newItems = replaceItems({
|
||||
items: free.items,
|
||||
featureId: TestFeature.Messages,
|
||||
newItem: constructFeatureItem({
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage:
|
||||
(messagesItem.included_usage as number) + increaseMessagesBy,
|
||||
}),
|
||||
});
|
||||
let newItems = replaceItems({
|
||||
items: free.items,
|
||||
featureId: TestFeature.Messages,
|
||||
newItem: constructFeatureItem({
|
||||
featureId: TestFeature.Messages,
|
||||
includedUsage:
|
||||
(messagesItem.included_usage as number) + increaseMessagesBy,
|
||||
}),
|
||||
});
|
||||
|
||||
newItems = replaceItems({
|
||||
items: newItems,
|
||||
featureId: TestFeature.Words,
|
||||
newItem: constructFeatureItem({
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: (wordsItem.included_usage as number) - reduceWordsBy,
|
||||
}),
|
||||
});
|
||||
newItems = replaceItems({
|
||||
items: newItems,
|
||||
featureId: TestFeature.Words,
|
||||
newItem: constructFeatureItem({
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: (wordsItem.included_usage as number) - reduceWordsBy,
|
||||
}),
|
||||
});
|
||||
|
||||
newFree.items = newItems;
|
||||
newFree.items = newItems;
|
||||
|
||||
await autumn.products.update(free.id, {
|
||||
items: newItems,
|
||||
});
|
||||
});
|
||||
await autumn.products.update(free.id, {
|
||||
items: newItems,
|
||||
});
|
||||
});
|
||||
|
||||
it("should attach track usage and get correct balance", async function () {
|
||||
let wordsUsage = 25;
|
||||
let messagesUsage = 20;
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: wordsUsage,
|
||||
feature_id: TestFeature.Words,
|
||||
});
|
||||
it("should attach track usage and get correct balance", async function () {
|
||||
let wordsUsage = 25;
|
||||
let messagesUsage = 20;
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: wordsUsage,
|
||||
feature_id: TestFeature.Words,
|
||||
});
|
||||
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: messagesUsage,
|
||||
feature_id: TestFeature.Messages,
|
||||
});
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: messagesUsage,
|
||||
feature_id: TestFeature.Messages,
|
||||
});
|
||||
|
||||
await advanceTestClock({
|
||||
stripeCli,
|
||||
testClockId,
|
||||
advanceTo: addWeeks(Date.now(), 1).getTime(),
|
||||
waitForSeconds: 30,
|
||||
});
|
||||
await advanceTestClock({
|
||||
stripeCli,
|
||||
testClockId,
|
||||
advanceTo: addWeeks(Date.now(), 1).getTime(),
|
||||
waitForSeconds: 30,
|
||||
});
|
||||
|
||||
let customer = await autumn.customers.get(customerId);
|
||||
let customer = await autumn.customers.get(customerId);
|
||||
|
||||
await autumn.migrate({
|
||||
from_product_id: free.id,
|
||||
to_product_id: newFree.id,
|
||||
from_version: 1,
|
||||
to_version: 2,
|
||||
});
|
||||
await autumn.migrate({
|
||||
from_product_id: free.id,
|
||||
to_product_id: newFree.id,
|
||||
from_version: 1,
|
||||
to_version: 2,
|
||||
});
|
||||
|
||||
await timeout(4000);
|
||||
await timeout(4000);
|
||||
|
||||
// 1. Get features
|
||||
customer = await autumn.customers.get(customerId);
|
||||
// 1. Get features
|
||||
customer = await autumn.customers.get(customerId);
|
||||
|
||||
await runMigrationTest({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct: free,
|
||||
toProduct: newFree,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage: [
|
||||
{
|
||||
featureId: TestFeature.Words,
|
||||
value: wordsUsage,
|
||||
},
|
||||
{
|
||||
featureId: TestFeature.Messages,
|
||||
value: messagesUsage,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
await runMigrationTest({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct: free,
|
||||
toProduct: newFree,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage: [
|
||||
{
|
||||
featureId: TestFeature.Words,
|
||||
value: wordsUsage,
|
||||
},
|
||||
{
|
||||
featureId: TestFeature.Messages,
|
||||
value: messagesUsage,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { AutumnInt } from "@/external/autumn/autumnCli.js";
|
||||
import { initCustomer } from "@/utils/scriptUtils/initCustomer.js";
|
||||
import {
|
||||
AppEnv,
|
||||
BillingInterval,
|
||||
Organization,
|
||||
ProductItemInterval,
|
||||
ProductV2,
|
||||
AppEnv,
|
||||
BillingInterval,
|
||||
Organization,
|
||||
ProductItemInterval,
|
||||
ProductV2,
|
||||
} from "@autumn/shared";
|
||||
import chalk from "chalk";
|
||||
import Stripe from "stripe";
|
||||
@@ -25,140 +25,140 @@ import { runMigrationTest } from "./runMigrationTest.js";
|
||||
import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js";
|
||||
|
||||
let wordsItem = constructArrearItem({
|
||||
featureId: TestFeature.Words,
|
||||
featureId: TestFeature.Words,
|
||||
});
|
||||
|
||||
export let pro = constructProduct({
|
||||
items: [wordsItem],
|
||||
type: "pro",
|
||||
isDefault: false,
|
||||
items: [wordsItem],
|
||||
type: "pro",
|
||||
isDefault: false,
|
||||
});
|
||||
|
||||
const testCase = "migrations2";
|
||||
|
||||
describe(`${chalk.yellowBright(`${testCase}: Testing migration for pro usage product`)}`, () => {
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: defaultApiVersion });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: defaultApiVersion });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
|
||||
let curUnix = new Date().getTime();
|
||||
let curUnix = new Date().getTime();
|
||||
|
||||
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;
|
||||
|
||||
addPrefixToProducts({
|
||||
products: [pro],
|
||||
prefix: testCase,
|
||||
});
|
||||
addPrefixToProducts({
|
||||
products: [pro],
|
||||
prefix: testCase,
|
||||
});
|
||||
|
||||
await createProducts({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
autumn,
|
||||
products: [pro],
|
||||
customerId,
|
||||
});
|
||||
await createProducts({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
autumn,
|
||||
products: [pro],
|
||||
customerId,
|
||||
});
|
||||
|
||||
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",
|
||||
});
|
||||
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
|
||||
it("should attach free product", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: pro,
|
||||
stripeCli,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
});
|
||||
it("should attach free product", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: pro,
|
||||
stripeCli,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
});
|
||||
|
||||
let newPro: ProductV2;
|
||||
let increaseWordsBy = 1500;
|
||||
it("should update product to new version", async function () {
|
||||
newPro = structuredClone(pro);
|
||||
let newPro: ProductV2;
|
||||
let increaseWordsBy = 1500;
|
||||
it("should update product to new version", async function () {
|
||||
newPro = structuredClone(pro);
|
||||
|
||||
let newItems = replaceItems({
|
||||
items: pro.items,
|
||||
featureId: TestFeature.Words,
|
||||
newItem: constructArrearItem({
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: (wordsItem.included_usage as number) + increaseWordsBy,
|
||||
}),
|
||||
});
|
||||
let newItems = replaceItems({
|
||||
items: pro.items,
|
||||
featureId: TestFeature.Words,
|
||||
newItem: constructArrearItem({
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: (wordsItem.included_usage as number) + increaseWordsBy,
|
||||
}),
|
||||
});
|
||||
|
||||
newItems = replaceItems({
|
||||
items: newItems,
|
||||
interval: BillingInterval.Month,
|
||||
newItem: {
|
||||
price: 50,
|
||||
interval: ProductItemInterval.Month,
|
||||
},
|
||||
});
|
||||
newItems = replaceItems({
|
||||
items: newItems,
|
||||
interval: BillingInterval.Month,
|
||||
newItem: {
|
||||
price: 50,
|
||||
interval: ProductItemInterval.Month,
|
||||
},
|
||||
});
|
||||
|
||||
newPro.items = newItems;
|
||||
await autumn.products.update(pro.id, {
|
||||
items: newItems,
|
||||
});
|
||||
});
|
||||
newPro.items = newItems;
|
||||
await autumn.products.update(pro.id, {
|
||||
items: newItems,
|
||||
});
|
||||
});
|
||||
|
||||
it("should attach track usage and get correct balance", async function () {
|
||||
let wordsUsage = 120000;
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: wordsUsage,
|
||||
feature_id: TestFeature.Words,
|
||||
});
|
||||
it("should attach track usage and get correct balance", async function () {
|
||||
let wordsUsage = 120000;
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: wordsUsage,
|
||||
feature_id: TestFeature.Words,
|
||||
});
|
||||
|
||||
await advanceTestClock({
|
||||
stripeCli,
|
||||
testClockId,
|
||||
advanceTo: addWeeks(Date.now(), 1).getTime(),
|
||||
});
|
||||
await advanceTestClock({
|
||||
stripeCli,
|
||||
testClockId,
|
||||
advanceTo: addWeeks(Date.now(), 1).getTime(),
|
||||
});
|
||||
|
||||
await autumn.migrate({
|
||||
from_product_id: pro.id,
|
||||
to_product_id: newPro.id,
|
||||
from_version: 1,
|
||||
to_version: 2,
|
||||
});
|
||||
await autumn.migrate({
|
||||
from_product_id: pro.id,
|
||||
to_product_id: newPro.id,
|
||||
from_version: 1,
|
||||
to_version: 2,
|
||||
});
|
||||
|
||||
await timeout(4000);
|
||||
await timeout(4000);
|
||||
|
||||
await runMigrationTest({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct: pro,
|
||||
toProduct: newPro,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage: [
|
||||
{
|
||||
featureId: TestFeature.Words,
|
||||
value: wordsUsage,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
await runMigrationTest({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct: pro,
|
||||
toProduct: newPro,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage: [
|
||||
{
|
||||
featureId: TestFeature.Words,
|
||||
value: wordsUsage,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { AutumnInt } from "@/external/autumn/autumnCli.js";
|
||||
import { initCustomer } from "@/utils/scriptUtils/initCustomer.js";
|
||||
import {
|
||||
AppEnv,
|
||||
BillingInterval,
|
||||
Organization,
|
||||
ProductItemInterval,
|
||||
ProductV2,
|
||||
AppEnv,
|
||||
BillingInterval,
|
||||
Organization,
|
||||
ProductItemInterval,
|
||||
ProductV2,
|
||||
} from "@autumn/shared";
|
||||
import chalk from "chalk";
|
||||
import Stripe from "stripe";
|
||||
@@ -26,135 +26,135 @@ import { addDays } from "date-fns";
|
||||
import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js";
|
||||
|
||||
let wordsItem = constructArrearItem({
|
||||
featureId: TestFeature.Words,
|
||||
featureId: TestFeature.Words,
|
||||
});
|
||||
|
||||
export let pro = constructProduct({
|
||||
items: [wordsItem],
|
||||
type: "pro",
|
||||
isDefault: false,
|
||||
trial: true,
|
||||
items: [wordsItem],
|
||||
type: "pro",
|
||||
isDefault: false,
|
||||
trial: true,
|
||||
});
|
||||
|
||||
const testCase = "migrations3";
|
||||
|
||||
describe(`${chalk.yellowBright(`${testCase}: Testing migration for pro with trial`)}`, () => {
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: defaultApiVersion });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: defaultApiVersion });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
|
||||
let curUnix = new Date().getTime();
|
||||
let curUnix = new Date().getTime();
|
||||
|
||||
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;
|
||||
|
||||
addPrefixToProducts({
|
||||
products: [pro],
|
||||
prefix: testCase,
|
||||
});
|
||||
addPrefixToProducts({
|
||||
products: [pro],
|
||||
prefix: testCase,
|
||||
});
|
||||
|
||||
await createProducts({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
autumn,
|
||||
products: [pro],
|
||||
customerId,
|
||||
});
|
||||
await createProducts({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
autumn,
|
||||
products: [pro],
|
||||
customerId,
|
||||
});
|
||||
|
||||
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",
|
||||
});
|
||||
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
|
||||
it("should attach free product", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: pro,
|
||||
stripeCli,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
});
|
||||
it("should attach free product", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: pro,
|
||||
stripeCli,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
});
|
||||
|
||||
let newPro: ProductV2;
|
||||
let increaseWordsBy = 1500;
|
||||
it("should update product to new version", async function () {
|
||||
newPro = structuredClone(pro);
|
||||
let newPro: ProductV2;
|
||||
let increaseWordsBy = 1500;
|
||||
it("should update product to new version", async function () {
|
||||
newPro = structuredClone(pro);
|
||||
|
||||
let newItems = replaceItems({
|
||||
items: pro.items,
|
||||
featureId: TestFeature.Words,
|
||||
newItem: constructArrearItem({
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: (wordsItem.included_usage as number) + increaseWordsBy,
|
||||
}),
|
||||
});
|
||||
let newItems = replaceItems({
|
||||
items: pro.items,
|
||||
featureId: TestFeature.Words,
|
||||
newItem: constructArrearItem({
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: (wordsItem.included_usage as number) + increaseWordsBy,
|
||||
}),
|
||||
});
|
||||
|
||||
newItems = replaceItems({
|
||||
items: newItems,
|
||||
interval: BillingInterval.Month,
|
||||
newItem: {
|
||||
price: 50,
|
||||
interval: ProductItemInterval.Month,
|
||||
},
|
||||
});
|
||||
newItems = replaceItems({
|
||||
items: newItems,
|
||||
interval: BillingInterval.Month,
|
||||
newItem: {
|
||||
price: 50,
|
||||
interval: ProductItemInterval.Month,
|
||||
},
|
||||
});
|
||||
|
||||
newPro.items = newItems;
|
||||
newPro.version = 2;
|
||||
await autumn.products.update(pro.id, {
|
||||
items: newItems,
|
||||
});
|
||||
});
|
||||
newPro.items = newItems;
|
||||
newPro.version = 2;
|
||||
await autumn.products.update(pro.id, {
|
||||
items: newItems,
|
||||
});
|
||||
});
|
||||
|
||||
it("should attach track usage and get correct balance", async function () {
|
||||
let wordsUsage = 120000;
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: wordsUsage,
|
||||
feature_id: TestFeature.Words,
|
||||
});
|
||||
it("should attach track usage and get correct balance", async function () {
|
||||
let wordsUsage = 120000;
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: wordsUsage,
|
||||
feature_id: TestFeature.Words,
|
||||
});
|
||||
|
||||
await advanceTestClock({
|
||||
stripeCli,
|
||||
testClockId,
|
||||
advanceTo: addDays(Date.now(), 4).getTime(),
|
||||
});
|
||||
await advanceTestClock({
|
||||
stripeCli,
|
||||
testClockId,
|
||||
advanceTo: addDays(Date.now(), 4).getTime(),
|
||||
});
|
||||
|
||||
// await timeout(5000);
|
||||
// await timeout(5000);
|
||||
|
||||
await runMigrationTest({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct: pro,
|
||||
toProduct: newPro,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage: [
|
||||
{
|
||||
featureId: TestFeature.Words,
|
||||
value: wordsUsage,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
await runMigrationTest({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct: pro,
|
||||
toProduct: newPro,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage: [
|
||||
{
|
||||
featureId: TestFeature.Words,
|
||||
value: wordsUsage,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,121 +16,121 @@ import { timeout } from "@/utils/genUtils.js";
|
||||
import { expect } from "chai";
|
||||
import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js";
|
||||
let wordsItem = constructArrearItem({
|
||||
featureId: TestFeature.Words,
|
||||
featureId: TestFeature.Words,
|
||||
});
|
||||
|
||||
export let pro = constructProduct({
|
||||
items: [wordsItem],
|
||||
type: "pro",
|
||||
isDefault: false,
|
||||
items: [wordsItem],
|
||||
type: "pro",
|
||||
isDefault: false,
|
||||
});
|
||||
|
||||
let newWordsItem = constructArrearItem({
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: 120100,
|
||||
featureId: TestFeature.Words,
|
||||
includedUsage: 120100,
|
||||
});
|
||||
|
||||
let proWithTrial = constructProduct({
|
||||
items: [newWordsItem],
|
||||
type: "pro",
|
||||
isDefault: false,
|
||||
trial: true,
|
||||
items: [newWordsItem],
|
||||
type: "pro",
|
||||
isDefault: false,
|
||||
trial: true,
|
||||
});
|
||||
|
||||
const testCase = "migrations4";
|
||||
|
||||
describe(`${chalk.yellowBright(`${testCase}: Testing migration for pro -> pro with trial (should not start trial)`)}`, () => {
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: defaultApiVersion });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
let customerId = testCase;
|
||||
let autumn: AutumnInt = new AutumnInt({ version: defaultApiVersion });
|
||||
let testClockId: string;
|
||||
let db: DrizzleCli, org: Organization, env: AppEnv;
|
||||
let stripeCli: Stripe;
|
||||
|
||||
let curUnix = new Date().getTime();
|
||||
let curUnix = new Date().getTime();
|
||||
|
||||
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;
|
||||
|
||||
addPrefixToProducts({
|
||||
products: [pro, proWithTrial],
|
||||
prefix: testCase,
|
||||
});
|
||||
addPrefixToProducts({
|
||||
products: [pro, proWithTrial],
|
||||
prefix: testCase,
|
||||
});
|
||||
|
||||
await createProducts({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
autumn,
|
||||
products: [pro],
|
||||
customerId,
|
||||
});
|
||||
await createProducts({
|
||||
db,
|
||||
orgId: org.id,
|
||||
env,
|
||||
autumn,
|
||||
products: [pro],
|
||||
customerId,
|
||||
});
|
||||
|
||||
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",
|
||||
});
|
||||
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
testClockId = testClockId1!;
|
||||
});
|
||||
|
||||
it("should attach pro product", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: pro,
|
||||
stripeCli,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
});
|
||||
it("should attach pro product", async function () {
|
||||
await attachAndExpectCorrect({
|
||||
autumn,
|
||||
customerId,
|
||||
product: pro,
|
||||
stripeCli,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
});
|
||||
|
||||
it("should update product to new version", async function () {
|
||||
proWithTrial.version = 2;
|
||||
await autumn.products.update(pro.id, {
|
||||
items: proWithTrial.items,
|
||||
free_trial: proWithTrial.free_trial,
|
||||
});
|
||||
});
|
||||
it("should update product to new version", async function () {
|
||||
proWithTrial.version = 2;
|
||||
await autumn.products.update(pro.id, {
|
||||
items: proWithTrial.items,
|
||||
free_trial: proWithTrial.free_trial,
|
||||
});
|
||||
});
|
||||
|
||||
it("should attach track usage and get correct balance", async function () {
|
||||
let wordsUsage = 120000;
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: wordsUsage,
|
||||
feature_id: TestFeature.Words,
|
||||
});
|
||||
it("should attach track usage and get correct balance", async function () {
|
||||
let wordsUsage = 120000;
|
||||
await autumn.track({
|
||||
customer_id: customerId,
|
||||
value: wordsUsage,
|
||||
feature_id: TestFeature.Words,
|
||||
});
|
||||
|
||||
await timeout(4000);
|
||||
await timeout(4000);
|
||||
|
||||
const { stripeSubs, cusProduct } = await runMigrationTest({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct: pro,
|
||||
toProduct: proWithTrial,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage: [
|
||||
{
|
||||
featureId: TestFeature.Words,
|
||||
value: wordsUsage,
|
||||
},
|
||||
],
|
||||
});
|
||||
const { stripeSubs, cusProduct } = await runMigrationTest({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct: pro,
|
||||
toProduct: proWithTrial,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage: [
|
||||
{
|
||||
featureId: TestFeature.Words,
|
||||
value: wordsUsage,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(stripeSubs[0].trial_end).to.equal(null);
|
||||
expect(cusProduct?.free_trial).to.equal(null);
|
||||
});
|
||||
expect(stripeSubs[0].trial_end).to.equal(null);
|
||||
expect(cusProduct?.free_trial).to.equal(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,8 +3,8 @@ import { AutumnInt } from "@/external/autumn/autumnCli.js";
|
||||
import { ProductV2, Organization } from "@autumn/shared";
|
||||
import { AppEnv } from "autumn-js";
|
||||
import {
|
||||
expectSubItemsCorrect,
|
||||
getSubsFromCusId,
|
||||
expectSubItemsCorrect,
|
||||
getSubsFromCusId,
|
||||
} from "tests/utils/expectUtils/expectSubUtils.js";
|
||||
import Stripe from "stripe";
|
||||
import { expect } from "chai";
|
||||
@@ -17,116 +17,116 @@ import { subToPeriodStartEnd } from "@/external/stripe/stripeSubUtils/convertSub
|
||||
import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js";
|
||||
|
||||
export const expectSubsSame = ({
|
||||
subsBefore,
|
||||
subsAfter,
|
||||
subsBefore,
|
||||
subsAfter,
|
||||
}: {
|
||||
subsBefore: Stripe.Subscription[];
|
||||
subsAfter: Stripe.Subscription[];
|
||||
subsBefore: Stripe.Subscription[];
|
||||
subsAfter: Stripe.Subscription[];
|
||||
}) => {
|
||||
// let invoicesBefore = subsBefore.map((sub) => sub.latest_invoice);
|
||||
// let invoicesAfter = subsAfter.map((sub) => sub.latest_invoice);
|
||||
let subIdsBefore = subsBefore.map((sub) => sub.id);
|
||||
let subIdsAfter = subsAfter.map((sub) => sub.id);
|
||||
const periodsBefore = subsBefore.map((sub) => subToPeriodStartEnd({ sub }));
|
||||
const periodsAfter = subsAfter.map((sub) => subToPeriodStartEnd({ sub }));
|
||||
// let invoicesBefore = subsBefore.map((sub) => sub.latest_invoice);
|
||||
// let invoicesAfter = subsAfter.map((sub) => sub.latest_invoice);
|
||||
let subIdsBefore = subsBefore.map((sub) => sub.id);
|
||||
let subIdsAfter = subsAfter.map((sub) => sub.id);
|
||||
const periodsBefore = subsBefore.map((sub) => subToPeriodStartEnd({ sub }));
|
||||
const periodsAfter = subsAfter.map((sub) => subToPeriodStartEnd({ sub }));
|
||||
|
||||
// expect(invoicesAfter).to.deep.equal(invoicesBefore);
|
||||
expect(subIdsAfter).to.deep.equal(subIdsBefore);
|
||||
expect(periodsBefore).to.deep.equal(periodsAfter);
|
||||
// expect(invoicesAfter).to.deep.equal(invoicesBefore);
|
||||
expect(subIdsAfter).to.deep.equal(subIdsBefore);
|
||||
expect(periodsBefore).to.deep.equal(periodsAfter);
|
||||
};
|
||||
|
||||
export const runMigrationTest = async ({
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct,
|
||||
toProduct,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage,
|
||||
numInvoices = 1,
|
||||
autumn,
|
||||
stripeCli,
|
||||
customerId,
|
||||
fromProduct,
|
||||
toProduct,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
usage,
|
||||
numInvoices = 1,
|
||||
}: {
|
||||
autumn: AutumnInt;
|
||||
stripeCli: Stripe;
|
||||
customerId: string;
|
||||
fromProduct: ProductV2;
|
||||
toProduct: ProductV2;
|
||||
db: DrizzleCli;
|
||||
org: Organization;
|
||||
env: AppEnv;
|
||||
usage?: {
|
||||
featureId: string;
|
||||
value: number;
|
||||
}[];
|
||||
numInvoices?: number;
|
||||
autumn: AutumnInt;
|
||||
stripeCli: Stripe;
|
||||
customerId: string;
|
||||
fromProduct: ProductV2;
|
||||
toProduct: ProductV2;
|
||||
db: DrizzleCli;
|
||||
org: Organization;
|
||||
env: AppEnv;
|
||||
usage?: {
|
||||
featureId: string;
|
||||
value: number;
|
||||
}[];
|
||||
numInvoices?: number;
|
||||
}) => {
|
||||
const { subs: subsBefore } = await getSubsFromCusId({
|
||||
stripeCli,
|
||||
customerId,
|
||||
productId: fromProduct.id,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
const { subs: subsBefore } = await getSubsFromCusId({
|
||||
stripeCli,
|
||||
customerId,
|
||||
productId: fromProduct.id,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
|
||||
const cusBefore = await autumn.customers.get(customerId);
|
||||
const cusBefore = await autumn.customers.get(customerId);
|
||||
|
||||
await autumn.migrate({
|
||||
from_product_id: fromProduct.id,
|
||||
to_product_id: toProduct.id,
|
||||
from_version: fromProduct.version,
|
||||
to_version: toProduct.version,
|
||||
});
|
||||
await autumn.migrate({
|
||||
from_product_id: fromProduct.id,
|
||||
to_product_id: toProduct.id,
|
||||
from_version: fromProduct.version,
|
||||
to_version: toProduct.version,
|
||||
});
|
||||
|
||||
await timeout(10000);
|
||||
await timeout(10000);
|
||||
|
||||
const { subs: subsAfter } = await getSubsFromCusId({
|
||||
stripeCli,
|
||||
customerId,
|
||||
productId: toProduct.id,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
const { subs: subsAfter } = await getSubsFromCusId({
|
||||
stripeCli,
|
||||
customerId,
|
||||
productId: toProduct.id,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
|
||||
expectSubsSame({ subsBefore, subsAfter });
|
||||
expectSubsSame({ subsBefore, subsAfter });
|
||||
|
||||
const cusAfter = await autumn.customers.get(customerId);
|
||||
const cusAfter = await autumn.customers.get(customerId);
|
||||
|
||||
expectFeaturesCorrect({
|
||||
customer: cusAfter,
|
||||
product: toProduct,
|
||||
usage,
|
||||
});
|
||||
expectFeaturesCorrect({
|
||||
customer: cusAfter,
|
||||
product: toProduct,
|
||||
usage,
|
||||
});
|
||||
|
||||
expectResetAtCorrect({ cusBefore, cusAfter });
|
||||
expectTrialEndsAtCorrect({ cusBefore, cusAfter });
|
||||
expectResetAtCorrect({ cusBefore, cusAfter });
|
||||
expectTrialEndsAtCorrect({ cusBefore, cusAfter });
|
||||
|
||||
const { cusProduct } = await expectSubItemsCorrect({
|
||||
stripeCli,
|
||||
customerId,
|
||||
product: toProduct,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
const { cusProduct } = await expectSubItemsCorrect({
|
||||
stripeCli,
|
||||
customerId,
|
||||
product: toProduct,
|
||||
db,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
|
||||
if (!isFreeProductV2({ product: toProduct })) {
|
||||
await expectSubToBeCorrect({
|
||||
db,
|
||||
customerId,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
}
|
||||
if (!isFreeProductV2({ product: toProduct })) {
|
||||
await expectSubToBeCorrect({
|
||||
db,
|
||||
customerId,
|
||||
org,
|
||||
env,
|
||||
});
|
||||
}
|
||||
|
||||
// if (!isFreeProductV2({ product: toProduct })) {
|
||||
// expect(cusAfter.invoices.length).to.equal(numInvoices);
|
||||
// }
|
||||
// if (!isFreeProductV2({ product: toProduct })) {
|
||||
// expect(cusAfter.invoices.length).to.equal(numInvoices);
|
||||
// }
|
||||
|
||||
return {
|
||||
stripeSubs: subsAfter,
|
||||
cusProduct,
|
||||
};
|
||||
return {
|
||||
stripeSubs: subsAfter,
|
||||
cusProduct,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user