import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type Stripe from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { attachFailedPaymentMethod } from "@/external/stripe/stripeCusUtils.js"; import { CusService } from "@/internal/customers/CusService.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 = "others3"; export const pro = constructProduct({ type: "pro", items: [], }); describe(`${chalk.yellowBright(`${testCase}: Testing attach payment failure`)}`, () => { const customerId = testCase; const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; const curUnix = new Date().getTime(); beforeAll(async () => { await initProductsV0({ ctx, products: [pro], prefix: testCase, }); const { testClockId: testClockId1 } = await initCustomerV3({ ctx, customerId, customerData: {}, attachPm: "success", withTestClock: true, }); testClockId = testClockId1!; }); // Payment failure test("should handle payment failure", async () => { const customer = await CusService.get({ db: ctx.db, idOrInternalId: customerId, orgId: ctx.org.id, env: ctx.env, }); await attachFailedPaymentMethod({ stripeCli: ctx.stripeCli, customer: customer!, }); const res = await autumn.attach({ customer_id: customerId, product_id: pro.id, }); // console.log(res); expect(res.checkout_url).toBeDefined(); }); });