fix: testing fix on cached invoices
This commit is contained in:
@@ -9,7 +9,6 @@ BUN_PARALLEL_COMPACT \
|
||||
'server/tests/attach/downgrade' \
|
||||
'server/tests/attach/free' \
|
||||
'server/tests/attach/addOn' \
|
||||
'server/tests/attach/entities' \
|
||||
'server/tests/attach/checkout' \
|
||||
'server/tests/attach/misc' \
|
||||
--max=6 \
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import "dotenv/config";
|
||||
import { loadLocalEnv } from "./src/utils/envUtils";
|
||||
import Stripe from "stripe";
|
||||
|
||||
loadLocalEnv();
|
||||
|
||||
const main = async () => {
|
||||
const stripe = new Stripe(process.env.STRIPE_SANDBOX_SECRET_KEY || "");
|
||||
|
||||
|
||||
const result = await stripe.webhookEndpoints.create({
|
||||
url: "https://express.dev.useautumn.com/webhooks/connect/sandbox",
|
||||
url: `${process.env.STRIPE_WEBHOOK_URL}/webhooks/connect/sandbox`,
|
||||
enabled_events: [
|
||||
"checkout.session.completed",
|
||||
"customer.subscription.created",
|
||||
|
||||
@@ -33,7 +33,11 @@ export const setCachedApiCustomer = async ({
|
||||
|
||||
const ctxWithExpand = addToExpand({
|
||||
ctx,
|
||||
add: [CusExpand.BalancesFeature, CusExpand.SubscriptionsPlan],
|
||||
add: [
|
||||
CusExpand.BalancesFeature,
|
||||
CusExpand.SubscriptionsPlan,
|
||||
CusExpand.Invoices,
|
||||
],
|
||||
});
|
||||
|
||||
// Build master api customer (customer-level features only)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { DrizzleCli } from "@/db/initDrizzle.js";
|
||||
import { organizations } from "@autumn/shared";
|
||||
import type { DrizzleCli } from "@/db/initDrizzle.js";
|
||||
|
||||
export const getAllOrgs = async (db: DrizzleCli) => {
|
||||
const orgs = [];
|
||||
let offset = 0;
|
||||
const limit = 200;
|
||||
const limit = 1000;
|
||||
|
||||
while (true) {
|
||||
const batch = await db
|
||||
|
||||
@@ -15,7 +15,7 @@ import { initProductsV0 } from "../../src/utils/scriptUtils/testUtils/initProduc
|
||||
|
||||
// UNCOMMENT FROM HERE
|
||||
const pro = constructProduct({
|
||||
type: "free",
|
||||
type: "pro",
|
||||
isDefault: true,
|
||||
|
||||
items: [
|
||||
@@ -59,24 +59,37 @@ describe(`${chalk.yellowBright("temp: Testing add ons")}`, () => {
|
||||
products: [pro, oneOff],
|
||||
prefix: customerId,
|
||||
});
|
||||
|
||||
await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: pro.id,
|
||||
});
|
||||
});
|
||||
|
||||
test("should attach pro product", async () => {
|
||||
await autumn.attach({
|
||||
// await autumn.customers.get(customerId);
|
||||
|
||||
const res = await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: oneOff.id,
|
||||
});
|
||||
await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: oneOff.id,
|
||||
product_id: pro.id,
|
||||
});
|
||||
|
||||
await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: oneOff.id,
|
||||
});
|
||||
await autumn.attach({
|
||||
customer_id: customerId,
|
||||
product_id: oneOff.id,
|
||||
});
|
||||
const customer = await autumn.customers.get(customerId);
|
||||
console.log("Customer:", customer);
|
||||
|
||||
// await autumn.attach({
|
||||
// customer_id: customerId,
|
||||
// product_id: oneOff.id,
|
||||
// });
|
||||
// await autumn.attach({
|
||||
// customer_id: customerId,
|
||||
// product_id: oneOff.id,
|
||||
// });
|
||||
|
||||
// const customer = await autumn.customers.get(customerId);
|
||||
// console.log("Customer:", customer);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import { beforeAll, describe, test } from "bun:test";
|
||||
import { defaultApiVersion } from "@tests/constants.js";
|
||||
import { TestFeature } from "@tests/setup/v2Features.js";
|
||||
import { hoursToFinalizeInvoice } from "@tests/utils/constants.js";
|
||||
import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js";
|
||||
import { expectFeaturesCorrect } from "@tests/utils/expectUtils/expectFeaturesCorrect.js";
|
||||
import { expectInvoiceAfterUsage } from "@tests/utils/expectUtils/expectSingleUse/expectUsageInvoice.js";
|
||||
import { advanceTestClock } from "@tests/utils/stripeUtils.js";
|
||||
import ctx from "@tests/utils/testInitUtils/createTestContext.js";
|
||||
import chalk from "chalk";
|
||||
import { addHours, addMonths } from "date-fns";
|
||||
import { AutumnInt } from "@/external/autumn/autumnCli.js";
|
||||
import { timeout } from "@/utils/genUtils.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";
|
||||
import { advanceToNextInvoice } from "../../utils/testAttachUtils/testAttachUtils";
|
||||
|
||||
const testCase = "aentity2";
|
||||
|
||||
@@ -85,7 +83,6 @@ describe(`${chalk.yellowBright(`attach/${testCase}: Testing attach pro annual to
|
||||
feature_id: TestFeature.Words,
|
||||
value: usage,
|
||||
});
|
||||
await timeout(5000);
|
||||
|
||||
const entity = await autumn.entities.get(customerId, entityId);
|
||||
|
||||
@@ -118,14 +115,9 @@ describe(`${chalk.yellowBright(`attach/${testCase}: Testing attach pro annual to
|
||||
});
|
||||
|
||||
test("should have correct invoice after cycle", async () => {
|
||||
curUnix = await advanceTestClock({
|
||||
curUnix = await advanceToNextInvoice({
|
||||
stripeCli: ctx.stripeCli,
|
||||
testClockId,
|
||||
advanceTo: addHours(
|
||||
addMonths(curUnix, 1),
|
||||
hoursToFinalizeInvoice,
|
||||
).getTime(),
|
||||
waitForSeconds: 30,
|
||||
});
|
||||
|
||||
await expectInvoiceAfterUsage({
|
||||
|
||||
@@ -13,7 +13,7 @@ import { timeout } from "../../../utils/genUtils.js";
|
||||
// UNCOMMENT FROM HERE
|
||||
const pro = constructProduct({
|
||||
type: "free",
|
||||
isDefault: true,
|
||||
isDefault: false,
|
||||
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
|
||||
@@ -13,7 +13,7 @@ import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"
|
||||
// UNCOMMENT FROM HERE
|
||||
const pro = constructProduct({
|
||||
type: "free",
|
||||
isDefault: true,
|
||||
isDefault: false,
|
||||
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
|
||||
@@ -19,7 +19,7 @@ import { timeout } from "../../../utils/genUtils";
|
||||
// UNCOMMENT FROM HERE
|
||||
const pro = constructProduct({
|
||||
type: "free",
|
||||
isDefault: true,
|
||||
isDefault: false,
|
||||
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
|
||||
@@ -13,7 +13,7 @@ import { getCreditCost } from "../../../../src/internal/features/creditSystemUti
|
||||
// UNCOMMENT FROM HERE
|
||||
const pro = constructProduct({
|
||||
type: "free",
|
||||
isDefault: true,
|
||||
isDefault: false,
|
||||
|
||||
items: [
|
||||
constructFeatureItem({
|
||||
|
||||
@@ -26,7 +26,7 @@ export const completeCheckoutForm = async (
|
||||
_isLocal?: boolean,
|
||||
) => {
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
headless: false,
|
||||
executablePath: "/Applications/Chromium.app/Contents/MacOS/Chromium",
|
||||
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
||||
});
|
||||
|
||||
@@ -29,7 +29,10 @@ export const ApiCustomerSchema = z.object({
|
||||
stripe_id: z.string().nullable(),
|
||||
env: z.enum(AppEnv),
|
||||
metadata: z.record(z.any(), z.any()),
|
||||
|
||||
subscriptions: z.array(ApiSubscriptionSchema),
|
||||
// scheduled_subscriptions: z.array(ApiSubscriptionSchema),
|
||||
|
||||
balances: z.record(z.string(), ApiBalanceSchema),
|
||||
...ApiCusExpandSchema.shape,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user