diff --git a/bun.lock b/bun.lock index c5cdb35e4..939d383a8 100644 --- a/bun.lock +++ b/bun.lock @@ -47,6 +47,7 @@ "@react-email/components": "^0.0.42", "@sentry/node": "^9.30.0", "@supabase/supabase-js": "^2.46.2", + "@types/semver": "^7.7.1", "@upstash/redis": "^1.35.1", "ai": "^4.3.10", "autumn-js": "^0.1.8", @@ -88,6 +89,7 @@ "react": "^18.2.0", "recaseai": "^0.0.37", "resend": "^4.1.1", + "semver": "^7.7.2", "stripe": "^18.4.0", "svix": "^1.45.1", "tsc-alias": "^1.8.16", @@ -1187,6 +1189,8 @@ "@types/recharts": ["@types/recharts@2.0.1", "", { "dependencies": { "recharts": "*" } }, "sha512-/cFs7oiafzByUwBSWA1IzE6FW+ppPwQAWsDTadSgVOwzveY9MESpyLHyyHY0SfPPKLW4+4qVNYHPXd0rFiC8vg=="], + "@types/semver": ["@types/semver@7.7.1", "", {}, "sha512-FmgJfu+MOcQ370SD0ev7EI8TlCAfKYU+B4m5T3yXc1CiRN94g/SZPtsCkk506aUDtlMnFZvasDwHHUcZUEaYuA=="], + "@types/send": ["@types/send@0.17.5", "", { "dependencies": { "@types/mime": "^1", "@types/node": "*" } }, "sha512-z6F2D3cOStZvuk2SaP6YrwkNO65iTZcwA2ZkSABegdkAh/lf+Aa/YQndZVfmEXT5vgAp6zv06VQ3ejSVjAny4w=="], "@types/serve-static": ["@types/serve-static@1.15.8", "", { "dependencies": { "@types/http-errors": "*", "@types/node": "*", "@types/send": "*" } }, "sha512-roei0UY3LhpOJvjbIP6ZZFngyLKl5dskOtDhxY5THRSpO+ZI+nzJ+m5yUMzGrp89YRa7lvknKkMYjqQFGwA7Sg=="], diff --git a/server/package.json b/server/package.json index 9197e28c5..304d038fb 100644 --- a/server/package.json +++ b/server/package.json @@ -10,7 +10,6 @@ "dev": "cross-env NODE_ENV=development bunx nodemon --exec bun src/index.ts --ignore scripts --ignore tests", "workers:dev": "cross-env NODE_ENV=development bunx nodemon --exec bun src/workers.ts --watch src/workers.ts --watch src/queue --ignore scripts --ignore tests", "workers": "bun src/workers.ts", - "cron": "bun src/cron.ts", "check": "bun src/check.ts", "build": "bun build ./src/index.ts ./src/workers.ts ./src/cron.ts --outdir dist --target bun", @@ -50,6 +49,7 @@ "@react-email/components": "^0.0.42", "@sentry/node": "^9.30.0", "@supabase/supabase-js": "^2.46.2", + "@types/semver": "^7.7.1", "@upstash/redis": "^1.35.1", "ai": "^4.3.10", "autumn-js": "^0.1.8", @@ -91,6 +91,7 @@ "react": "^18.2.0", "recaseai": "^0.0.37", "resend": "^4.1.1", + "semver": "^7.7.2", "stripe": "^18.4.0", "svix": "^1.45.1", "tsc-alias": "^1.8.16", diff --git a/server/src/external/autumn/autumnCli.ts b/server/src/external/autumn/autumnCli.ts index 1af382567..6d5d94375 100644 --- a/server/src/external/autumn/autumnCli.ts +++ b/server/src/external/autumn/autumnCli.ts @@ -4,13 +4,13 @@ import dotenv from "dotenv"; dotenv.config(); import { - type APIVersion, type AttachBody, type CreateEntity, type CreateRewardProgram, CusExpand, EntityExpand, ErrCode, + type LegacyVersion, type OrgConfig, type RewardRedemption, } from "@autumn/shared"; @@ -56,7 +56,7 @@ export class AutumnInt { apiKey?: string; secretKey?: string; baseUrl?: string; - version?: string | APIVersion; + version?: string | LegacyVersion; orgConfig?: Partial; liveUrl?: boolean; } = {}) { diff --git a/server/src/external/stripe/priceToStripeItem/priceToStripeItem.ts b/server/src/external/stripe/priceToStripeItem/priceToStripeItem.ts index 67eb0ed44..68c10ac28 100644 --- a/server/src/external/stripe/priceToStripeItem/priceToStripeItem.ts +++ b/server/src/external/stripe/priceToStripeItem/priceToStripeItem.ts @@ -1,5 +1,4 @@ import { - APIVersion, BillingType, type EntitlementWithFeature, ErrCode, @@ -7,6 +6,7 @@ import { type FixedPriceConfig, type FullProduct, InternalError, + LegacyVersion, type Organization, type Price, type ProductOptions, @@ -69,7 +69,7 @@ export const priceToStripeItem = ({ existingUsage: number; withEntity: boolean; isCheckout: boolean; - apiVersion?: APIVersion; + apiVersion?: LegacyVersion; productOptions?: ProductOptions | undefined; }) => { // TODO: Implement this @@ -140,7 +140,7 @@ export const priceToStripeItem = ({ }; } - if (apiVersion === APIVersion.v1_4 && !isCheckout) { + if (apiVersion === LegacyVersion.v1_4 && !isCheckout) { return { lineItem: { // lineItem: getEmptyPriceItem({ price, org }), diff --git a/server/src/external/stripe/stripeSubUtils/getStripeSubItems.ts b/server/src/external/stripe/stripeSubUtils/getStripeSubItems.ts index 1ee64188d..54061c9a1 100644 --- a/server/src/external/stripe/stripeSubUtils/getStripeSubItems.ts +++ b/server/src/external/stripe/stripeSubUtils/getStripeSubItems.ts @@ -1,5 +1,4 @@ import { - type APIVersion, type AttachConfig, type AttachReplaceable, BillingInterval, @@ -10,6 +9,7 @@ import { type FullProduct, InternalError, isUsagePrice, + type LegacyVersion, type Organization, type Price, type ProductOptions, @@ -79,7 +79,7 @@ export const getStripeSubItems = async ({ internalEntityId?: string; cusProducts?: FullCusProduct[]; entities: Entity[]; - apiVersion?: APIVersion; + apiVersion?: LegacyVersion; replaceables: AttachReplaceable[]; }; isCheckout?: boolean; diff --git a/server/src/external/stripe/webhookHandlers/handleCheckoutCompleted/handleCheckoutSub.ts b/server/src/external/stripe/webhookHandlers/handleCheckoutCompleted/handleCheckoutSub.ts index 0c4799c31..3a9029e8a 100644 --- a/server/src/external/stripe/webhookHandlers/handleCheckoutCompleted/handleCheckoutSub.ts +++ b/server/src/external/stripe/webhookHandlers/handleCheckoutCompleted/handleCheckoutSub.ts @@ -1,16 +1,19 @@ -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { APIVersion, BillingType, UsagePriceConfig } from "@autumn/shared"; -import Stripe from "stripe"; -import { SubService } from "@/internal/subscriptions/SubService.js"; -import { constructSub } from "@/internal/subscriptions/subUtils.js"; -import { AttachParams } from "@/internal/customers/cusProducts/AttachParams.js"; +import { + BillingType, + LegacyVersion, + type UsagePriceConfig, +} from "@autumn/shared"; +import type Stripe from "stripe"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import type { AttachParams } from "@/internal/customers/cusProducts/AttachParams.js"; import { findPriceFromPlaceholderId, findPriceFromStripeId, } from "@/internal/products/prices/priceUtils/findPriceUtils.js"; -import { getArrearItems } from "../../stripeSubUtils/getStripeSubItems/getArrearItems.js"; -import { subToPeriodStartEnd } from "../../stripeSubUtils/convertSubUtils.js"; +import { SubService } from "@/internal/subscriptions/SubService.js"; +import { constructSub } from "@/internal/subscriptions/subUtils.js"; import { getEmptyPriceItem } from "../../priceToStripeItem/priceToStripeItem.js"; +import { subToPeriodStartEnd } from "../../stripeSubUtils/convertSubUtils.js"; export const handleCheckoutSub = async ({ stripeCli, @@ -44,12 +47,12 @@ export const handleCheckoutSub = async ({ }); const curSubItems = subscription.items.data; - let itemsUpdate = []; + const itemsUpdate = []; for (const item of curSubItems) { - let stripePriceId = item.price.id; + const stripePriceId = item.price.id; - let arrearProratedPrice = findPriceFromPlaceholderId({ + const arrearProratedPrice = findPriceFromPlaceholderId({ prices: attachParams.prices, placeholderId: stripePriceId, }); @@ -67,7 +70,7 @@ export const handleCheckoutSub = async ({ continue; } - let arrearPrice = findPriceFromStripeId({ + const arrearPrice = findPriceFromStripeId({ prices: attachParams.prices, stripePriceId, billingType: BillingType.UsageInArrear, @@ -76,7 +79,7 @@ export const handleCheckoutSub = async ({ if ( arrearPrice && (attachParams.internalEntityId || - attachParams.apiVersion == APIVersion.v1_4) + attachParams.apiVersion == LegacyVersion.v1_4) ) { itemsUpdate.push({ id: item.id, diff --git a/server/src/external/stripe/webhookHandlers/handleCheckoutCompleted/handleRemainingSets.ts b/server/src/external/stripe/webhookHandlers/handleCheckoutCompleted/handleRemainingSets.ts index 0007604e5..8053dc576 100644 --- a/server/src/external/stripe/webhookHandlers/handleCheckoutCompleted/handleRemainingSets.ts +++ b/server/src/external/stripe/webhookHandlers/handleCheckoutCompleted/handleRemainingSets.ts @@ -1,4 +1,4 @@ -import { APIVersion, isUsagePrice, type Organization } from "@autumn/shared"; +import { isUsagePrice, LegacyVersion, type Organization } from "@autumn/shared"; import type Stripe from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import type { AttachParams } from "@/internal/customers/cusProducts/AttachParams.js"; @@ -38,7 +38,7 @@ export const handleRemainingSets = async ({ if ( attachParams.internalEntityId || - attachParams.apiVersion === APIVersion.v1_4 + attachParams.apiVersion === LegacyVersion.v1_4 ) { const replaceIndex = remainingItems.findIndex( (item) => item.price === config.stripe_price_id, diff --git a/server/src/external/stripe/webhookHandlers/handleInvoiceCreated/handleUsagePrices.ts b/server/src/external/stripe/webhookHandlers/handleInvoiceCreated/handleUsagePrices.ts index 3e25337f6..2ac60222e 100644 --- a/server/src/external/stripe/webhookHandlers/handleInvoiceCreated/handleUsagePrices.ts +++ b/server/src/external/stripe/webhookHandlers/handleInvoiceCreated/handleUsagePrices.ts @@ -1,27 +1,25 @@ -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { CusEntService } from "@/internal/customers/cusProducts/cusEnts/CusEntitlementService.js"; -import { getResetBalancesUpdate } from "@/internal/customers/cusProducts/cusEnts/groupByUtils.js"; import { - FullCustomerEntitlement, - Price, - FullCusProduct, - UsagePriceConfig, + type Customer, EntInterval, - Customer, - APIVersion, - RolloverConfig, - Organization, + type FullCusProduct, + type FullCustomerEntitlement, + LegacyVersion, + type Organization, + type Price, + type UsagePriceConfig, } from "@autumn/shared"; import { differenceInMinutes, subDays } from "date-fns"; +import type Stripe from "stripe"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { CusEntService } from "@/internal/customers/cusProducts/cusEnts/CusEntitlementService.js"; +import { RolloverService } from "@/internal/customers/cusProducts/cusEnts/cusRollovers/RolloverService.js"; +import { getRolloverUpdates } from "@/internal/customers/cusProducts/cusEnts/cusRollovers/rolloverUtils.js"; +import { getResetBalancesUpdate } from "@/internal/customers/cusProducts/cusEnts/groupByUtils.js"; +import { getCusPriceUsage } from "@/internal/customers/cusProducts/cusPrices/cusPriceUtils.js"; import { submitUsageToStripe } from "../../stripeMeterUtils.js"; import { getInvoiceItemForUsage } from "../../stripePriceUtils.js"; -import { getCusPriceUsage } from "@/internal/customers/cusProducts/cusPrices/cusPriceUtils.js"; -import { findStripeItemForPrice } from "../../stripeSubUtils/stripeSubItemUtils.js"; -import { getRolloverUpdates } from "@/internal/customers/cusProducts/cusEnts/cusRollovers/rolloverUtils.js"; -import { RolloverService } from "@/internal/customers/cusProducts/cusEnts/cusRollovers/RolloverService.js"; -import { notNullish } from "@/utils/genUtils.js"; import { subToPeriodStartEnd } from "../../stripeSubUtils/convertSubUtils.js"; +import { findStripeItemForPrice } from "../../stripeSubUtils/stripeSubItemUtils.js"; export const handleUsagePrices = async ({ db, @@ -46,7 +44,7 @@ export const handleUsagePrices = async ({ logger: any; activeProduct: FullCusProduct; }) => { - let invoiceCreatedRecently = + const invoiceCreatedRecently = Math.abs( differenceInMinutes( new Date(activeProduct.created_at), @@ -54,7 +52,7 @@ export const handleUsagePrices = async ({ ), ) < 10; - let invoiceFromUpgrade = + const invoiceFromUpgrade = invoice.billing_reason == "subscription_update" || invoice.billing_reason == "manual"; @@ -71,7 +69,7 @@ export const handleUsagePrices = async ({ logger.info(`✨ Handling usage prices for ${customer.name || customer.id}`); logger.info(`✨ org: ${org.slug}, product: ${activeProduct.product.id}`); - let config = price.config as UsagePriceConfig; + const config = price.config as UsagePriceConfig; // If relatedCusEnt's balance > 0 and next_reset_at is null, skip... if (relatedCusEnt.balance! > 0 && !relatedCusEnt.next_reset_at) { @@ -86,10 +84,10 @@ export const handleUsagePrices = async ({ const isNewUsageMethod = activeProduct.internal_entity_id || - activeProduct.api_version === APIVersion.v1_4; + activeProduct.api_version === LegacyVersion.v1_4; if (isNewUsageMethod) { - let invoiceItem = getInvoiceItemForUsage({ + const invoiceItem = getInvoiceItemForUsage({ stripeInvoiceId: invoice.id!, price, customer, @@ -136,9 +134,9 @@ export const handleUsagePrices = async ({ return; } - let ent = relatedCusEnt.entitlement; + const ent = relatedCusEnt.entitlement; - let resetBalancesUpdate = getResetBalancesUpdate({ + const resetBalancesUpdate = getResetBalancesUpdate({ cusEnt: relatedCusEnt, allowance: ent.interval == EntInterval.Lifetime ? 0 : ent.allowance!, }); @@ -154,7 +152,7 @@ export const handleUsagePrices = async ({ }, }); - let rolloverUpdate = getRolloverUpdates({ + const rolloverUpdate = getRolloverUpdates({ cusEnt: relatedCusEnt, nextResetAt: end * 1000, }); diff --git a/server/src/external/stripe/webhookHandlers/handleSubDeleted/handleCusProductDeleted.ts b/server/src/external/stripe/webhookHandlers/handleSubDeleted/handleCusProductDeleted.ts index 032895c41..a6b115030 100644 --- a/server/src/external/stripe/webhookHandlers/handleSubDeleted/handleCusProductDeleted.ts +++ b/server/src/external/stripe/webhookHandlers/handleSubDeleted/handleCusProductDeleted.ts @@ -1,10 +1,10 @@ import { - APIVersion, AttachScenario, BillingType, CusProductStatus, cusProductToPrices, type FullCusProduct, + LegacyVersion, } from "@autumn/shared"; import type Stripe from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; @@ -53,7 +53,7 @@ export const handleCusProductDeleted = async ({ stripeId: fullCus.processor?.id, }); - const isV4Usage = cusProduct.api_version === APIVersion.v1_4; + const isV4Usage = cusProduct.api_version === LegacyVersion.v1_4; // refer to handleUpgradeFlow.ts, when cancel immediately through API / dashboard, this happens...? const isAutumnCancel = diff --git a/server/src/honoMiddlewares/apiVersionMiddleware.ts b/server/src/honoMiddlewares/apiVersionMiddleware.ts index 6753c943b..62fd0360d 100644 --- a/server/src/honoMiddlewares/apiVersionMiddleware.ts +++ b/server/src/honoMiddlewares/apiVersionMiddleware.ts @@ -1,9 +1,9 @@ import { ErrCode } from "@autumn/shared"; import type { Context, Next } from "hono"; +import semver, { type SemVer } from "semver"; import type { HonoEnv } from "@/honoUtils/HonoEnv.js"; import RecaseError from "@/utils/errorUtils.js"; -import { floatToVersion } from "@/utils/versionUtils.js"; - +import { floatToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; /** * Middleware to verify and set API version from x-api-version header */ @@ -24,7 +24,9 @@ export const apiVersionMiddleware = async (c: Context, next: Next) => { } // Store in context - ctx.apiVersion = apiVersion.toString(); + // ctx.apiVersion = apiVersion.toString(); + ctx.apiVersion = semver.parse(version) as SemVer; + // ctx.apiVersion. } await next(); diff --git a/server/src/honoUtils/HonoEnv.ts b/server/src/honoUtils/HonoEnv.ts index 17ab0eeb1..241271b5d 100644 --- a/server/src/honoUtils/HonoEnv.ts +++ b/server/src/honoUtils/HonoEnv.ts @@ -1,5 +1,6 @@ import type { AppEnv, AuthType, Feature, Organization } from "@autumn/shared"; import type { ClickHouseClient } from "@clickhouse/client"; +import type { SemVer } from "semver"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import type { Logger } from "@/external/logtail/logtailUtils.js"; @@ -19,7 +20,7 @@ export type RequestContext = { id: string; isPublic: boolean; authType: AuthType; - apiVersion: string; + apiVersion: SemVer; timestamp: number; }; diff --git a/server/src/index.ts b/server/src/index.ts index ff9fc5388..bae9b29b8 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,3 +1,13 @@ +// Suppress BullMQ eviction policy warnings BEFORE any imports +const originalWarn = console.warn; +console.warn = (...args: any[]) => { + const msg = args.join(" "); + if (msg.includes("Eviction policy")) { + return; + } + originalWarn.apply(console, args); +}; + import { config } from "dotenv"; config(); diff --git a/server/src/internal/api/entities/getEntityUtils.ts b/server/src/internal/api/entities/getEntityUtils.ts index fb1884784..1a78091e0 100644 --- a/server/src/internal/api/entities/getEntityUtils.ts +++ b/server/src/internal/api/entities/getEntityUtils.ts @@ -1,6 +1,5 @@ import { type APICusProduct, - APIVersion, type AppEnv, type Entity, type EntityExpand, @@ -9,6 +8,7 @@ import { type Feature, type FullCusProduct, type FullCustomer, + LegacyVersion, notNullish, type Organization, type Subscription, @@ -37,7 +37,7 @@ export const getSingleEntityResponse = async ({ features: Feature[]; withAutumnId?: boolean; }) => { - const apiVersion = APIVersion.v1_2; + const apiVersion = LegacyVersion.v1_2; if (!entity) { throw new RecaseError({ @@ -74,7 +74,7 @@ export const getSingleEntityResponse = async ({ entity, subs: entitySubs, org, - apiVersion: APIVersion.v1_2, + apiVersion: LegacyVersion.v1_2, features, }); diff --git a/server/src/internal/api/entities/handlers/handleGetEntity.ts b/server/src/internal/api/entities/handlers/handleGetEntity.ts index f149afa86..66721be5d 100644 --- a/server/src/internal/api/entities/handlers/handleGetEntity.ts +++ b/server/src/internal/api/entities/handlers/handleGetEntity.ts @@ -1,10 +1,14 @@ -import { routeHandler } from "@/utils/routerUtils.js"; -import { APIVersion, EntityExpand, EntityResponseSchema } from "@autumn/shared"; +import { + EntityExpand, + EntityResponseSchema, + LegacyVersion, +} from "@autumn/shared"; +import { invoicesToResponse } from "@/internal/invoices/invoiceUtils.js"; import { OrgService } from "@/internal/orgs/OrgService.js"; +import { routeHandler } from "@/utils/routerUtils.js"; +import { orgToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; import { parseEntityExpand } from "../entityUtils.js"; import { getEntityResponse } from "../getEntityUtils.js"; -import { invoicesToResponse } from "@/internal/invoices/invoiceUtils.js"; -import { orgToVersion } from "@/utils/versionUtils.js"; export const handleGetEntity = async (req: any, res: any) => routeHandler({ @@ -16,17 +20,19 @@ export const handleGetEntity = async (req: any, res: any) => const customerId = req.params.customer_id as string; const expand = parseEntityExpand(req.query.expand); - let { orgId, env, db, logger, features } = req; + const { orgId, env, db, logger, features } = req; - let org = await OrgService.getFromReq(req); - let apiVersion = orgToVersion({ + const org = await OrgService.getFromReq(req); + const apiVersion = orgToVersion({ org, reqApiVersion: - req.apiVersion >= APIVersion.v1_1 ? req.apiVersion : APIVersion.v1_2, + req.apiVersion >= LegacyVersion.v1_1 + ? req.apiVersion + : LegacyVersion.v1_2, }); // const start = performance.now(); - let { entities, customer, fullEntities, invoices } = + const { entities, customer, fullEntities, invoices } = await getEntityResponse({ db, entityIds: [entityId], @@ -40,8 +46,8 @@ export const handleGetEntity = async (req: any, res: any) => logger, }); - let entity = entities[0]; - let withInvoices = expand.includes(EntityExpand.Invoices); + const entity = entities[0]; + const withInvoices = expand.includes(EntityExpand.Invoices); res.status(200).json( EntityResponseSchema.parse({ diff --git a/server/src/internal/api/entitled/checkRouter.ts b/server/src/internal/api/entitled/checkRouter.ts index 3baf40a6e..d56dc28b3 100644 --- a/server/src/internal/api/entitled/checkRouter.ts +++ b/server/src/internal/api/entitled/checkRouter.ts @@ -1,9 +1,14 @@ -import { APIVersion, ErrCode, type Feature, FeatureType } from "@autumn/shared"; +import { + ErrCode, + type Feature, + FeatureType, + LegacyVersion, +} from "@autumn/shared"; import { Router } from "express"; import { StatusCodes } from "http-status-codes"; import RecaseError, { handleRequestError } from "@/utils/errorUtils.js"; import { notNullish } from "@/utils/genUtils.js"; -import { orgToVersion } from "@/utils/versionUtils.js"; +import { orgToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; import { handleEventSent } from "../events/eventRouter.js"; import { getCheckData } from "./checkUtils/getCheckData.js"; import { getV1CheckResponse } from "./checkUtils/getV1CheckResponse.js"; @@ -185,7 +190,7 @@ checkRouter.post("", async (req: any, res: any) => { } } - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { res.status(200).json({ ...v2Response, preview, diff --git a/server/src/internal/api/entitled/checkUtils.ts b/server/src/internal/api/entitled/checkUtils.ts index 4527c951c..ce375cf8e 100644 --- a/server/src/internal/api/entitled/checkUtils.ts +++ b/server/src/internal/api/entitled/checkUtils.ts @@ -1,8 +1,4 @@ -import { itemToPriceOrTiers } from "@/internal/products/product-items/productItemUtils.js"; -import { isFeaturePriceItem } from "@/internal/products/product-items/productItemUtils/getItemType.js"; - import { - APIVersion, BillingInterval, type Feature, type FreeTrial, @@ -10,23 +6,20 @@ import { type FullCustomer, type FullCustomerEntitlement, isTrialing, + LegacyVersion, type ProductItem, SuccessCode, UsageModel, } from "@autumn/shared"; -import { getCheckPreview } from "./getCheckPreview.js"; - -import type { DrizzleCli } from "@/db/initDrizzle.js"; -import { getProration } from "@/internal/invoices/previewItemUtils/getItemsForNewProduct.js"; -import { - formatUnixToDate, - formatUnixToDateTime, - notNullish, -} from "@/utils/genUtils.js"; -import { featureToCusPrice } from "@/internal/customers/cusProducts/cusPrices/convertCusPriceUtils.js"; -import { priceToInvoiceAmount } from "@/internal/products/prices/priceUtils/priceToInvoiceAmount.js"; import { Decimal } from "decimal.js"; -import { isOneOffPrice } from "@/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { featureToCusPrice } from "@/internal/customers/cusProducts/cusPrices/convertCusPriceUtils.js"; +import { getProration } from "@/internal/invoices/previewItemUtils/getItemsForNewProduct.js"; +import { priceToInvoiceAmount } from "@/internal/products/prices/priceUtils/priceToInvoiceAmount.js"; +import { isFeaturePriceItem } from "@/internal/products/product-items/productItemUtils/getItemType.js"; +import { itemToPriceOrTiers } from "@/internal/products/product-items/productItemUtils.js"; +import { notNullish } from "@/utils/genUtils.js"; +import { getCheckPreview } from "./getCheckPreview.js"; export const getBooleanEntitledResult = async ({ db, @@ -50,20 +43,20 @@ export const getBooleanEntitledResult = async ({ allFeatures: Feature[]; }) => { const allowed = cusEnts.some((cusEnt) => { - let featureMatch = cusEnt.internal_feature_id === feature.internal_id; + const featureMatch = cusEnt.internal_feature_id === feature.internal_id; - let entityFeatureId = cusEnt.entitlement.entity_feature_id; - let compareEntity = + const entityFeatureId = cusEnt.entitlement.entity_feature_id; + const compareEntity = notNullish(entityFeatureId) && notNullish(fullCus.entity); - let entityMatch = compareEntity + const entityMatch = compareEntity ? entityFeatureId === fullCus.entity!.feature_id : true; return featureMatch && entityMatch; }); - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { return res.status(200).json({ customer_id: fullCus.id, feature_id: feature.id, @@ -136,7 +129,7 @@ export const getOptions = ({ proration: finalProration, }); - let actualPrice = itemToPriceOrTiers({ + const actualPrice = itemToPriceOrTiers({ item: i, }); diff --git a/server/src/internal/api/events/eventRouter.ts b/server/src/internal/api/events/eventRouter.ts index 52e99aa9e..c7b42a4de 100644 --- a/server/src/internal/api/events/eventRouter.ts +++ b/server/src/internal/api/events/eventRouter.ts @@ -1,5 +1,4 @@ import { - APIVersion, type AppEnv, CreateEventSchema, CusProductStatus, @@ -9,6 +8,7 @@ import { type Feature, FeatureType, type FullCustomer, + LegacyVersion, type Organization, } from "@autumn/shared"; import { Router } from "express"; @@ -23,7 +23,7 @@ import { addTaskToQueue } from "@/queue/queueUtils.js"; import RecaseError, { handleRequestError } from "@/utils/errorUtils.js"; import { generateId, notNullish } from "@/utils/genUtils.js"; import type { ExtendedRequest } from "@/utils/models/Request.js"; -import { orgToVersion } from "@/utils/versionUtils.js"; +import { orgToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; import { EventService } from "./EventService.js"; import { getEventTimestamp } from "./eventUtils.js"; import { handleUsageEvent } from "./usageRouter.js"; @@ -259,7 +259,7 @@ eventsRouter.post("", async (req: any, res: any) => { response.event_name = event.event_name; } - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { res.status(200).json(response); } else { res.status(200).json({ success: true }); diff --git a/server/src/internal/customers/add-product/createFullCusProduct.ts b/server/src/internal/customers/add-product/createFullCusProduct.ts index 8c9f59f8f..5d7b0c0ca 100644 --- a/server/src/internal/customers/add-product/createFullCusProduct.ts +++ b/server/src/internal/customers/add-product/createFullCusProduct.ts @@ -1,5 +1,4 @@ import { - type APIVersion, CollectionMethod, type CusProduct, CusProductStatus, @@ -11,6 +10,7 @@ import { type FullCusProduct, type FullProduct, type InsertReplaceable, + type LegacyVersion, type Price, ProcessorType, type ProductOptions, @@ -98,7 +98,7 @@ export const initCusProduct = ({ isCustom?: boolean; entityId?: string; internalEntityId?: string; - apiVersion?: APIVersion; + apiVersion?: LegacyVersion; quantity?: number; }) => { const isFuture = startsAt && startsAt > Date.now(); diff --git a/server/src/internal/customers/add-product/handleCreateCheckout.ts b/server/src/internal/customers/add-product/handleCreateCheckout.ts index bac676590..61b80593b 100644 --- a/server/src/internal/customers/add-product/handleCreateCheckout.ts +++ b/server/src/internal/customers/add-product/handleCreateCheckout.ts @@ -1,6 +1,6 @@ import { - APIVersion, type AttachConfig, + LegacyVersion, RecaseError, SuccessCode, } from "@autumn/shared"; @@ -188,8 +188,8 @@ export const handleCreateCheckout = async ({ return checkout; } - const apiVersion = attachParams.apiVersion || APIVersion.v1; - if (apiVersion >= APIVersion.v1_1) { + const apiVersion = attachParams.apiVersion || LegacyVersion.v1; + if (apiVersion >= LegacyVersion.v1_1) { res.status(200).json( AttachResultSchema.parse({ checkout_url: checkout.url, diff --git a/server/src/internal/customers/attach/attachFunctions/addProductFlow/handleAddProduct.ts b/server/src/internal/customers/attach/attachFunctions/addProductFlow/handleAddProduct.ts index a05b23ede..215939ab8 100644 --- a/server/src/internal/customers/attach/attachFunctions/addProductFlow/handleAddProduct.ts +++ b/server/src/internal/customers/attach/attachFunctions/addProductFlow/handleAddProduct.ts @@ -1,7 +1,7 @@ import { - APIVersion, AttachBranch, type AttachConfig, + LegacyVersion, SuccessCode, } from "@autumn/shared"; import { subToPeriodStartEnd } from "@/external/stripe/stripeSubUtils/convertSubUtils.js"; @@ -89,10 +89,10 @@ export const handleAddProduct = async ({ logger.info("Successfully created full cus product"); if (res) { - const apiVersion = attachParams.org.api_version || APIVersion.v1; + const apiVersion = attachParams.org.api_version || LegacyVersion.v1; const productNames = products.map((p) => p.name).join(", "); const customerName = customer.name || customer.email || customer.id; - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { res.status(200).json( AttachResultSchema.parse({ success: true, diff --git a/server/src/internal/customers/attach/attachFunctions/addProductFlow/handlePaidProduct.ts b/server/src/internal/customers/attach/attachFunctions/addProductFlow/handlePaidProduct.ts index 8d7ec666d..e75f45987 100644 --- a/server/src/internal/customers/attach/attachFunctions/addProductFlow/handlePaidProduct.ts +++ b/server/src/internal/customers/attach/attachFunctions/addProductFlow/handlePaidProduct.ts @@ -1,9 +1,9 @@ import { - APIVersion, type AttachConfig, AttachScenario, ErrCode, isTrialing, + LegacyVersion, SuccessCode, } from "@autumn/shared"; import type Stripe from "stripe"; @@ -249,10 +249,10 @@ export const handlePaidProduct = async ({ await Promise.all(batchInsert); if (res) { - const apiVersion = attachParams.apiVersion || APIVersion.v1; + const apiVersion = attachParams.apiVersion || LegacyVersion.v1; const productNames = products.map((p) => p.name).join(", "); const customerName = customer.name || customer.email || customer.id; - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { res.status(200).json( AttachResultSchema.parse({ message: `Successfully created subscriptions and attached ${productNames} to ${customerName}`, diff --git a/server/src/internal/customers/attach/attachFunctions/scheduleFlow/handleScheduleFlow2.ts b/server/src/internal/customers/attach/attachFunctions/scheduleFlow/handleScheduleFlow2.ts index f04ec62c0..5e4f0131c 100644 --- a/server/src/internal/customers/attach/attachFunctions/scheduleFlow/handleScheduleFlow2.ts +++ b/server/src/internal/customers/attach/attachFunctions/scheduleFlow/handleScheduleFlow2.ts @@ -1,8 +1,8 @@ import { - APIVersion, type AttachConfig, AttachScenario, ErrCode, + LegacyVersion, SuccessCode, } from "@autumn/shared"; import { StatusCodes } from "http-status-codes"; @@ -208,10 +208,10 @@ export const handleScheduleFunction2 = async ({ } } - const apiVersion = attachParams.apiVersion || APIVersion.v1; + const apiVersion = attachParams.apiVersion || LegacyVersion.v1; if (res) { - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { res.status(200).json( AttachResultSchema.parse({ code: SuccessCode.DowngradeScheduled, diff --git a/server/src/internal/customers/attach/attachFunctions/upgradeFlow/handleUpgradeFlow.ts b/server/src/internal/customers/attach/attachFunctions/upgradeFlow/handleUpgradeFlow.ts index a6c6d0a08..04383ff97 100644 --- a/server/src/internal/customers/attach/attachFunctions/upgradeFlow/handleUpgradeFlow.ts +++ b/server/src/internal/customers/attach/attachFunctions/upgradeFlow/handleUpgradeFlow.ts @@ -1,10 +1,10 @@ import { - APIVersion, AttachBranch, type AttachConfig, AttachScenario, CusProductStatus, cusProductToProduct, + LegacyVersion, ProrationBehavior, } from "@autumn/shared"; import type Stripe from "stripe"; @@ -229,8 +229,8 @@ export const handleUpgradeFlow = async ({ } if (res) { - const apiVersion = attachParams.org.api_version || APIVersion.v1; - if (apiVersion >= APIVersion.v1_1) { + const apiVersion = attachParams.org.api_version || LegacyVersion.v1; + if (apiVersion >= LegacyVersion.v1_1) { res.status(200).json( AttachResultSchema.parse({ customer_id: attachParams.customer.id, diff --git a/server/src/internal/customers/attach/attachUtils/attachParams/checkToAttachParams.ts b/server/src/internal/customers/attach/attachUtils/attachParams/checkToAttachParams.ts index 4f64f6afd..ab0e1cff9 100644 --- a/server/src/internal/customers/attach/attachUtils/attachParams/checkToAttachParams.ts +++ b/server/src/internal/customers/attach/attachUtils/attachParams/checkToAttachParams.ts @@ -1,16 +1,14 @@ -import { createStripeCli } from "@/external/stripe/utils.js"; -import { AttachParams } from "@/internal/customers/cusProducts/AttachParams.js"; -import { ExtendedRequest } from "@/utils/models/Request.js"; import { - APIVersion, - Feature, - FullCusProduct, - FullCustomer, - FullProduct, + type FullCustomer, + type FullProduct, + LegacyVersion, } from "@autumn/shared"; -import { getStripeCusData } from "./attachParamsUtils/getStripeCusData.js"; +import { createStripeCli } from "@/external/stripe/utils.js"; +import type { AttachParams } from "@/internal/customers/cusProducts/AttachParams.js"; import { getFreeTrialAfterFingerprint } from "@/internal/products/free-trials/freeTrialUtils.js"; -import { orgToVersion } from "@/utils/versionUtils.js"; +import type { ExtendedRequest } from "@/utils/models/Request.js"; +import { orgToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; +import { getStripeCusData } from "./attachParamsUtils/getStripeCusData.js"; export const checkToAttachParams = async ({ req, @@ -29,10 +27,10 @@ export const checkToAttachParams = async ({ orgToVersion({ org, reqApiVersion: req.apiVersion, - }) || APIVersion.v1; + }) || LegacyVersion.v1; const stripeCli = createStripeCli({ org, env }); - let stripeCusData = await getStripeCusData({ + const stripeCusData = await getStripeCusData({ stripeCli, db, org, @@ -42,7 +40,7 @@ export const checkToAttachParams = async ({ allowNoStripe: true, }); - let freeTrial = await getFreeTrialAfterFingerprint({ + const freeTrial = await getFreeTrialAfterFingerprint({ db, freeTrial: product.free_trial, fingerprint: customer.fingerprint, diff --git a/server/src/internal/customers/attach/attachUtils/attachParams/getAttachParams.ts b/server/src/internal/customers/attach/attachUtils/attachParams/getAttachParams.ts index f6e7852f1..f03bf9e29 100644 --- a/server/src/internal/customers/attach/attachUtils/attachParams/getAttachParams.ts +++ b/server/src/internal/customers/attach/attachUtils/attachParams/getAttachParams.ts @@ -1,7 +1,7 @@ -import { APIVersion, type AttachBody } from "@autumn/shared"; +import { type AttachBody, LegacyVersion } from "@autumn/shared"; import { nullish } from "@/utils/genUtils.js"; import type { ExtendedRequest } from "@/utils/models/Request.js"; -import { orgToVersion } from "@/utils/versionUtils.js"; +import { orgToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; import type { AttachParams } from "../../../cusProducts/AttachParams.js"; import { processAttachBody } from "./processAttachBody.js"; @@ -34,7 +34,7 @@ export const getAttachParams = async ({ orgToVersion({ org, reqApiVersion: req.apiVersion, - }) || APIVersion.v1; + }) || LegacyVersion.v1; const entityId = attachBody.entity_id; const internalEntityId = entityId ? customer.entity?.internal_id : undefined; diff --git a/server/src/internal/customers/cusProducts/AttachParams.ts b/server/src/internal/customers/cusProducts/AttachParams.ts index d8cc66869..762a34aef 100644 --- a/server/src/internal/customers/cusProducts/AttachParams.ts +++ b/server/src/internal/customers/cusProducts/AttachParams.ts @@ -1,5 +1,4 @@ import type { - APIVersion, AttachReplaceable, AttachScenario, Customer, @@ -11,6 +10,7 @@ import type { FullCusProduct, FullCustomer, FullProduct, + LegacyVersion, Organization, Price, ProductOptions, @@ -109,7 +109,7 @@ export type InsertCusProductParams = { entityId?: string; internalEntityId?: string; fromMigration?: boolean; - apiVersion?: APIVersion; + apiVersion?: LegacyVersion; finalizeInvoice?: boolean; }; diff --git a/server/src/internal/customers/cusProducts/cusProductUtils.ts b/server/src/internal/customers/cusProducts/cusProductUtils.ts index a60102045..4dcffbc56 100644 --- a/server/src/internal/customers/cusProducts/cusProductUtils.ts +++ b/server/src/internal/customers/cusProducts/cusProductUtils.ts @@ -1,7 +1,6 @@ import { ACTIVE_STATUSES, APICusProductSchema, - APIVersion, type AppEnv, AttachScenario, CusProductStatus, @@ -11,6 +10,7 @@ import { type FullCusProduct, type FullCustomer, type FullProduct, + LegacyVersion, type Organization, PriceType, type Subscription, @@ -507,7 +507,7 @@ export const processFullCusProduct = ({ }; } - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { if ((!subIds || subIds.length === 0) && trialing) { stripeSubData = { current_period_start: cusProduct.starts_at, diff --git a/server/src/internal/customers/cusRouter.ts b/server/src/internal/customers/cusRouter.ts index e1ae573cc..565591ac6 100644 --- a/server/src/internal/customers/cusRouter.ts +++ b/server/src/internal/customers/cusRouter.ts @@ -1,28 +1,24 @@ -import RecaseError, { handleRequestError } from "@/utils/errorUtils.js"; - -import { APIVersion } from "@autumn/shared"; -import { ErrCode } from "@autumn/shared"; - +import { ErrCode, LegacyVersion } from "@autumn/shared"; import { Router } from "express"; import { StatusCodes } from "http-status-codes"; -import { CusService } from "./CusService.js"; -import { OrgService } from "@/internal/orgs/OrgService.js"; - -import { createStripeCli } from "@/external/stripe/utils.js"; -import { handleDeleteCustomer } from "./handlers/handleDeleteCustomer.js"; -import { handleUpdateBalances } from "./handlers/handleUpdateBalances.js"; -import { handleUpdateEntitlement } from "./handlers/handleUpdateEntitlement.js"; -import { handleAddCouponToCus } from "./handlers/handleAddCouponToCus.js"; -import { handlePostCustomerRequest } from "./handlers/handlePostCustomer.js"; -import { entityRouter } from "../api/entities/entityRouter.js"; -import { handleUpdateCustomer } from "./handlers/handleUpdateCustomer.js"; -import { handleCreateBillingPortal } from "./handlers/handleCreateBillingPortal.js"; -import { handleGetCustomer } from "./handlers/handleGetCustomer.js"; -import { CusSearchService } from "@/internal/customers/CusSearchService.js"; import { createStripeCusIfNotExists } from "@/external/stripe/stripeCusUtils.js"; -import { handleTransferProduct } from "./handlers/handleTransferProduct.js"; +import { createStripeCli } from "@/external/stripe/utils.js"; +import { CusSearchService } from "@/internal/customers/CusSearchService.js"; +import { OrgService } from "@/internal/orgs/OrgService.js"; +import RecaseError, { handleRequestError } from "@/utils/errorUtils.js"; import { handleBatchCustomers } from "../api/batch/handlers/handleBatchCustomers.js"; +import { entityRouter } from "../api/entities/entityRouter.js"; import { toSuccessUrl } from "../orgs/orgUtils/convertOrgUtils.js"; +import { CusService } from "./CusService.js"; +import { handleAddCouponToCus } from "./handlers/handleAddCouponToCus.js"; +import { handleCreateBillingPortal } from "./handlers/handleCreateBillingPortal.js"; +import { handleDeleteCustomer } from "./handlers/handleDeleteCustomer.js"; +import { handleGetCustomer } from "./handlers/handleGetCustomer.js"; +import { handlePostCustomerRequest } from "./handlers/handlePostCustomer.js"; +import { handleTransferProduct } from "./handlers/handleTransferProduct.js"; +import { handleUpdateBalances } from "./handlers/handleUpdateBalances.js"; +import { handleUpdateCustomer } from "./handlers/handleUpdateCustomer.js"; +import { handleUpdateEntitlement } from "./handlers/handleUpdateEntitlement.js"; export const cusRouter: Router = Router(); @@ -72,7 +68,7 @@ cusRouter.post("/:customer_id/balances", handleUpdateBalances); cusRouter.get("/:customer_id/billing_portal", async (req: any, res: any) => { try { - let returnUrl = req.query.return_url; + const returnUrl = req.query.return_url; const customerId = req.params.customer_id; @@ -126,7 +122,7 @@ cusRouter.get("/:customer_id/billing_portal", async (req: any, res: any) => { return_url: returnUrl || toSuccessUrl({ org, env: req.env }), }); - if (org.api_version >= APIVersion.v1_1) { + if (org.api_version >= LegacyVersion.v1_1) { return res.status(200).json({ customer_id: customer.id, url: portal.url, @@ -144,7 +140,7 @@ cusRouter.get("/:customer_id/billing_portal", async (req: any, res: any) => { return_url: returnUrl || toSuccessUrl({ org, env: req.env }), }); - if (org.api_version >= APIVersion.v1_1) { + if (org.api_version >= LegacyVersion.v1_1) { res.status(200).json({ customer_id: customer.id, url: portal.url, diff --git a/server/src/internal/customers/cusUtils/cusFeatureResponseUtils/getCusBalances.ts b/server/src/internal/customers/cusUtils/cusFeatureResponseUtils/getCusBalances.ts index 0376cefa9..2733613b5 100644 --- a/server/src/internal/customers/cusUtils/cusFeatureResponseUtils/getCusBalances.ts +++ b/server/src/internal/customers/cusUtils/cusFeatureResponseUtils/getCusBalances.ts @@ -1,25 +1,24 @@ import { - APIVersion, - EntInterval, - EntitlementWithFeature, - Entity, + type EntInterval, + type EntitlementWithFeature, + type Entity, FeatureType, - FullCusProduct, - FullCustomerEntitlement, - FullCustomerPrice, - Organization, + type FullCusProduct, + type FullCustomerEntitlement, + type FullCustomerPrice, + getCusEntBalance, + LegacyVersion, + type Organization, } from "@autumn/shared"; import { getEntOptions } from "@/internal/products/prices/priceUtils.js"; -import { notNullish, notNullOrUndefined } from "@/utils/genUtils.js"; - import { BREAK_API_VERSION } from "@/utils/constants.js"; +import { notNullish, notNullOrUndefined } from "@/utils/genUtils.js"; import { getRelatedCusPrice, getResetBalance, getUnlimitedAndUsageAllowed, } from "../../cusProducts/cusEnts/cusEntUtils.js"; -import { getCusEntBalance } from "@autumn/shared"; export interface CusFeatureBalance { feature_id: string; @@ -48,7 +47,7 @@ export const getV1EntitlementsRes = ({ unlimited: boolean; ent: EntitlementWithFeature; }) => { - let res: any = { + const res: any = { feature_id: ent.feature.id, unlimited: isBoolean ? undefined : unlimited, interval: isBoolean || unlimited ? null : ent.interval || undefined, @@ -76,12 +75,12 @@ export const getRolloverFields = ({ cusEnt: FullCustomerEntitlement; entityId?: string; }) => { - let hasRollover = notNullish(cusEnt.entitlement.rollover); + const hasRollover = notNullish(cusEnt.entitlement.rollover); if (!hasRollover) { return null; } - let rollovers = cusEnt.rollovers || []; + const rollovers = cusEnt.rollovers || []; if (cusEnt.entitlement.entity_feature_id) { if (entityId) { @@ -204,10 +203,10 @@ export const getCusBalances = async ({ const cusProduct = cusEnt.customer_product; const feature = cusEnt.entitlement.feature; const ent: EntitlementWithFeature = cusEnt.entitlement; - let key = `${ent.interval || "no-interval"}-${ent.interval_count || 1}-${feature.id}`; + const key = `${ent.interval || "no-interval"}-${ent.interval_count || 1}-${feature.id}`; // 1. Handle boolean - let isBoolean = feature.type == FeatureType.Boolean; + const isBoolean = feature.type == FeatureType.Boolean; const { unlimited, usageAllowed } = getUnlimitedAndUsageAllowed({ cusEnts: cusEntsWithCusProduct, @@ -215,7 +214,7 @@ export const getCusBalances = async ({ }); // 1. Initialize balance object - if (!data[key] && apiVersion == APIVersion.v1) { + if (!data[key] && apiVersion == LegacyVersion.v1) { data[key] = getV1EntitlementsRes({ org, cusEnt, @@ -266,7 +265,7 @@ export const getCusBalances = async ({ continue; } - let { balance, adjustment, count, unused } = getCusEntBalance({ + const { balance, adjustment, count, unused } = getCusEntBalance({ cusEnt, entityId: entity?.id, }); @@ -274,7 +273,7 @@ export const getCusBalances = async ({ data[key].balance += balance || 0; data[key].adjustment += adjustment || 0; - let total = + const total = (getResetBalance({ entitlement: ent, options: getEntOptions(cusProduct.options, ent), @@ -285,7 +284,7 @@ export const getCusBalances = async ({ data[key].total += total; data[key].unused += unused || 0; - let rollover = getRolloverFields({ + const rollover = getRolloverFields({ cusEnt, entityId: entity?.id, }); @@ -313,7 +312,7 @@ export const getCusBalances = async ({ data[key].allowance += (resetBalance || 0) * count; - let usageLimit = ent.usage_limit; + const usageLimit = ent.usage_limit; if (notNullish(usageLimit)) { data[key].usage_limit += usageLimit; @@ -343,10 +342,10 @@ export const getCusBalances = async ({ } // Sort balances - if (org.api_version == APIVersion.v1) { + if (org.api_version == LegacyVersion.v1) { balances.sort((a: any, b: any) => { - let featureA = features.find((f) => f.id == a.feature_id); - let featureB = features.find((f) => f.id == b.feature_id); + const featureA = features.find((f) => f.id == a.feature_id); + const featureB = features.find((f) => f.id == b.feature_id); if ( featureA?.type == FeatureType.Boolean && @@ -370,7 +369,7 @@ export const getCusBalances = async ({ }); } - // if (org.api_version == APIVersion.v1) { + // if (org.api_version == LegacyVersion.v1) { // } diff --git a/server/src/internal/customers/cusUtils/cusFeatureResponseUtils/getCusFeaturesResponse.ts b/server/src/internal/customers/cusUtils/cusFeatureResponseUtils/getCusFeaturesResponse.ts index f20a2628b..a55a6974b 100644 --- a/server/src/internal/customers/cusUtils/cusFeatureResponseUtils/getCusFeaturesResponse.ts +++ b/server/src/internal/customers/cusUtils/cusFeatureResponseUtils/getCusFeaturesResponse.ts @@ -1,11 +1,12 @@ -import { balancesToFeatureResponse } from "./balancesToFeatureResponse.js"; import { - FullCusProduct, - Organization, - Entity, - APIVersion, + cusProductsToCusEnts, + cusProductsToCusPrices, + type Entity, + type FullCusProduct, + type LegacyVersion, + type Organization, } from "@autumn/shared"; -import { cusProductsToCusEnts, cusProductsToCusPrices } from "@autumn/shared"; +import { balancesToFeatureResponse } from "./balancesToFeatureResponse.js"; import { getCusBalances } from "./getCusBalances.js"; export const getCusFeaturesResponse = async ({ @@ -17,9 +18,9 @@ export const getCusFeaturesResponse = async ({ cusProducts: FullCusProduct[]; org: Organization; entity?: Entity; - apiVersion: APIVersion; + apiVersion: LegacyVersion; }) => { - let cusEnts = cusProductsToCusEnts({ cusProducts }) as any; + const cusEnts = cusProductsToCusEnts({ cusProducts }) as any; const balances = await getCusBalances({ cusEntsWithCusProduct: cusEnts, diff --git a/server/src/internal/customers/cusUtils/cusProductResponseUtils/getCusProductResponse.ts b/server/src/internal/customers/cusUtils/cusProductResponseUtils/getCusProductResponse.ts index f659e5fad..b84ed8e09 100644 --- a/server/src/internal/customers/cusUtils/cusProductResponseUtils/getCusProductResponse.ts +++ b/server/src/internal/customers/cusUtils/cusProductResponseUtils/getCusProductResponse.ts @@ -1,11 +1,11 @@ import { APICusProductSchema, - APIVersion, CusProductStatus, type Entity, type Feature, type FixedPriceConfig, type FullCusProduct, + LegacyVersion, type Organization, PriceType, type Subscription, @@ -137,7 +137,7 @@ export const getCusProductResponse = async ({ }; } - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { if ((!subIds || subIds.length === 0) && trialing) { stripeSubData = { current_period_start: cusProduct.starts_at, diff --git a/server/src/internal/customers/cusUtils/cusProductResponseUtils/processFullCusProducts.ts b/server/src/internal/customers/cusUtils/cusProductResponseUtils/processFullCusProducts.ts index acdb2e0ca..d2d8eb153 100644 --- a/server/src/internal/customers/cusUtils/cusProductResponseUtils/processFullCusProducts.ts +++ b/server/src/internal/customers/cusUtils/cusProductResponseUtils/processFullCusProducts.ts @@ -1,10 +1,10 @@ import { ACTIVE_STATUSES, type APICusProduct, - APIVersion, type CusProductStatus, type Entity, type Feature, + LegacyVersion, type Organization, } from "@autumn/shared"; import { getCusProductResponse } from "./getCusProductResponse.js"; @@ -81,7 +81,7 @@ export const processFullCusProducts = async ({ } } - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { main = mergeCusProductResponses({ cusProductResponses: main as APICusProduct[], }); diff --git a/server/src/internal/customers/cusUtils/getCustomerDetails.ts b/server/src/internal/customers/cusUtils/getCustomerDetails.ts index 2e71eaafc..537675df8 100644 --- a/server/src/internal/customers/cusUtils/getCustomerDetails.ts +++ b/server/src/internal/customers/cusUtils/getCustomerDetails.ts @@ -1,6 +1,5 @@ import { APICustomerSchema, - APIVersion, type AppEnv, CusEntResponseSchema, CusExpand, @@ -13,13 +12,14 @@ import { FeatureType, type FullCusProduct, type FullCustomer, + LegacyVersion, type Organization, type RewardResponse, } from "@autumn/shared"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { invoicesToResponse } from "@/internal/invoices/invoiceUtils.js"; import { BREAK_API_VERSION } from "@/utils/constants.js"; -import { orgToVersion } from "@/utils/versionUtils.js"; +import { orgToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; import { featuresToObject } from "./cusFeatureResponseUtils/balancesToFeatureResponse.js"; import { getCusBalances } from "./cusFeatureResponseUtils/getCusBalances.js"; import { processFullCusProducts } from "./cusProductResponseUtils/processFullCusProducts.js"; @@ -85,7 +85,7 @@ export const getCustomerDetails = async ({ features, }); - if (apiVersion >= APIVersion.v1_1) { + if (apiVersion >= LegacyVersion.v1_1) { let entList: any = balances.map((b) => { const isBoolean = features.find((f: Feature) => f.id === b.feature_id)?.type === @@ -103,7 +103,7 @@ export const getCustomerDetails = async ({ const products: any = [...main, ...addOns]; - if (apiVersion >= APIVersion.v1_2) { + if (apiVersion >= LegacyVersion.v1_2) { entList = featuresToObject({ features, entList, diff --git a/server/src/internal/customers/handlers/handleGetCustomer.ts b/server/src/internal/customers/handlers/handleGetCustomer.ts index 88a148061..2f0028fab 100644 --- a/server/src/internal/customers/handlers/handleGetCustomer.ts +++ b/server/src/internal/customers/handlers/handleGetCustomer.ts @@ -1,7 +1,7 @@ -import { APIVersion, CusExpand, ErrCode } from "@autumn/shared"; +import { CusExpand, ErrCode, LegacyVersion } from "@autumn/shared"; import { StatusCodes } from "http-status-codes"; import { routeHandler } from "@/utils/routerUtils.js"; -import { orgToVersion } from "@/utils/versionUtils.js"; +import { orgToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; import { getCusWithCache } from "../cusCache/getCusWithCache.js"; import { parseCusExpand } from "../cusUtils/cusUtils.js"; import { getCustomerDetails } from "../cusUtils/getCustomerDetails.js"; @@ -23,7 +23,7 @@ export const handleGetCustomer = async (req: any, res: any) => reqApiVersion: req.apiVersion, }); - const getInvoices = apiVersion < APIVersion.v1_1; + const getInvoices = apiVersion < LegacyVersion.v1_1; if (getInvoices) expandArray.push(CusExpand.Invoices); logger.info(`getting customer ${customerId} for org ${org.slug}`); diff --git a/server/src/internal/dev/ApiKeyService.ts b/server/src/internal/dev/ApiKeyService.ts index a0a71451b..bc7ab8415 100644 --- a/server/src/internal/dev/ApiKeyService.ts +++ b/server/src/internal/dev/ApiKeyService.ts @@ -11,7 +11,7 @@ import { and, desc, eq } from "drizzle-orm"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { CacheManager } from "@/external/caching/CacheManager.js"; import { CacheType } from "@/external/caching/cacheActions.js"; -import { getApiVersion } from "@/utils/versionUtils.js"; +import { getApiVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; export class ApiKeyService { static async verifyAndFetch({ diff --git a/server/src/internal/entities/handlers/handleCreateEntity/handleCreateEntity.ts b/server/src/internal/entities/handlers/handleCreateEntity/handleCreateEntity.ts index 64b895e45..ef0ca2024 100644 --- a/server/src/internal/entities/handlers/handleCreateEntity/handleCreateEntity.ts +++ b/server/src/internal/entities/handlers/handleCreateEntity/handleCreateEntity.ts @@ -1,12 +1,17 @@ -import { EntityService } from "../../../api/entities/EntityService.js"; -import { APIVersion, CreateEntity, CustomerData, Entity } from "@autumn/shared"; -import { getEntityResponse } from "../../../api/entities/getEntityUtils.js"; -import { orgToVersion } from "@/utils/versionUtils.js"; +import { + type CreateEntity, + type CustomerData, + type Entity, + LegacyVersion, +} from "@autumn/shared"; +import type { ExtendedRequest } from "@/utils/models/Request.js"; import { routeHandler } from "@/utils/routerUtils.js"; -import { ExtendedRequest } from "@/utils/models/Request.js"; +import { orgToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; +import { EntityService } from "../../../api/entities/EntityService.js"; +import { getEntityResponse } from "../../../api/entities/getEntityUtils.js"; import { constructEntity } from "../../entityUtils/entityUtils.js"; -import { validateAndGetInputEntities } from "./getInputEntities.js"; import { createEntityForCusProduct } from "./createEntityForCusProduct.js"; +import { validateAndGetInputEntities } from "./getInputEntities.js"; export const createEntities = async ({ req, @@ -24,7 +29,7 @@ export const createEntities = async ({ customerId: string; createEntityData: CreateEntity[] | CreateEntity; withAutumnId?: boolean; - apiVersion?: APIVersion; + apiVersion?: LegacyVersion; fromAutoCreate?: boolean; }) => { const { db, org, env, features } = req; @@ -59,9 +64,9 @@ export const createEntities = async ({ }), ); - let newEntities: Entity[] = []; + const newEntities: Entity[] = []; if (existingEntities.some((e: any) => e.id === null)) { - let updatedEntity = await EntityService.update({ + const updatedEntity = await EntityService.update({ db, internalId: existingEntities.find((e: any) => e.id === null)!.internal_id, update: { @@ -74,7 +79,7 @@ export const createEntities = async ({ newEntities.push(updatedEntity); } - let insertedEntities = await EntityService.insert({ + const insertedEntities = await EntityService.insert({ db, data, }); @@ -85,7 +90,7 @@ export const createEntities = async ({ return newEntities; } - let { entities } = await getEntityResponse({ + const { entities } = await getEntityResponse({ db, entityIds: newEntities.map((e: any) => e.id || e.internal_id), org, @@ -109,12 +114,12 @@ export const handlePostEntityRequest = async (req: any, res: any) => handler: async (req: any, res: any) => { const { logtail: logger, org } = req; - let apiVersion = orgToVersion({ + const apiVersion = orgToVersion({ org, reqApiVersion: req.apiVersion, }); - let customerData = + const customerData = Array.isArray(req.body) && req.body.length > 0 ? req.body[0].customer_data : req.body.customer_data; @@ -131,7 +136,7 @@ export const handlePostEntityRequest = async (req: any, res: any) => logger.info(` Created / replaced entities!`); - if (apiVersion < APIVersion.v1_2) { + if (apiVersion < LegacyVersion.v1_2) { res.status(200).json({ success: true, }); diff --git a/server/src/internal/migrations/migrationUtils/migrationToAttachParams.ts b/server/src/internal/migrations/migrationUtils/migrationToAttachParams.ts index 67e2bad3f..7ef371a7a 100644 --- a/server/src/internal/migrations/migrationUtils/migrationToAttachParams.ts +++ b/server/src/internal/migrations/migrationUtils/migrationToAttachParams.ts @@ -1,13 +1,13 @@ -import { getStripeCusData } from "@/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getStripeCusData.js"; -import { AttachParams } from "@/internal/customers/cusProducts/AttachParams.js"; -import { ExtendedRequest } from "@/utils/models/Request.js"; import { - APIVersion, - FullCusProduct, - FullCustomer, - FullProduct, + type FullCusProduct, + type FullCustomer, + type FullProduct, + LegacyVersion, } from "@autumn/shared"; -import Stripe from "stripe"; +import type Stripe from "stripe"; +import { getStripeCusData } from "@/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getStripeCusData.js"; +import type { AttachParams } from "@/internal/customers/cusProducts/AttachParams.js"; +import type { ExtendedRequest } from "@/utils/models/Request.js"; export const migrationToAttachParams = async ({ req, @@ -24,7 +24,7 @@ export const migrationToAttachParams = async ({ }): Promise => { const { org } = req; - const apiVersion = org.config.api_version || APIVersion.v1; + const apiVersion = org.config.api_version || LegacyVersion.v1; const internalEntityId = cusProduct.internal_entity_id || undefined; const { stripeCus, paymentMethod, now } = await getStripeCusData({ diff --git a/server/src/internal/orgs/OrgService.ts b/server/src/internal/orgs/OrgService.ts index 1729301a6..5eba6a6cd 100644 --- a/server/src/internal/orgs/OrgService.ts +++ b/server/src/internal/orgs/OrgService.ts @@ -1,28 +1,28 @@ -import RecaseError from "@/utils/errorUtils.js"; -import { and, eq, sql, inArray } from "drizzle-orm"; import { AppEnv, + apiKeys, ErrCode, - Feature, + type Feature, features, invitation, member, - Organization, + type Organization, OrgConfigSchema, + organizations, user, } from "@autumn/shared"; - -import { getApiVersion } from "@/utils/versionUtils.js"; +import { and, eq, sql } from "drizzle-orm"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import RecaseError from "@/utils/errorUtils.js"; +import { getApiVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; import { clearOrgCache } from "./orgUtils/clearOrgCache.js"; -import { organizations, apiKeys } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; export class OrgService { static async getFromReq(req: any) { if (req.org) { - let org = structuredClone(req.org); - let config = org.config || {}; - let apiVersion = getApiVersion({ + const org = structuredClone(req.org); + const config = org.config || {}; + const apiVersion = getApiVersion({ createdAt: org.created_at, }); return { @@ -32,7 +32,7 @@ export class OrgService { }; } - return await this.get({ db: req.db, orgId: req.orgId }); + return await OrgService.get({ db: req.db, orgId: req.orgId }); } static async getMembers({ db, orgId }: { db: DrizzleCli; orgId: string }) { @@ -200,7 +200,7 @@ export class OrgService { }); } - let org = structuredClone(result); + const org = structuredClone(result); delete (org as any).features; return { org: { @@ -223,7 +223,7 @@ export class OrgService { pkey: string; env: AppEnv; }) { - let org = await db.query.organizations.findFirst({ + const org = await db.query.organizations.findFirst({ where: env === AppEnv.Sandbox ? eq(organizations.test_pkey, pkey) @@ -270,7 +270,7 @@ export class OrgService { updates: any; }) { try { - let result = await db + const result = await db .update(organizations) .set(updates) .where(eq(organizations.id, orgId)) diff --git a/server/src/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.ts b/server/src/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.ts index 927f9e8a1..4e9a6ba17 100644 --- a/server/src/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.ts +++ b/server/src/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.ts @@ -1,8 +1,8 @@ import { - APIVersion, BillingInterval, BillingType, type FullCusProduct, + LegacyVersion, OnDecrease, OnIncrease, type Price, @@ -75,7 +75,7 @@ export const isV4Usage = ({ return ( billingType === BillingType.UsageInArrear && - (cusProduct.api_version === APIVersion.v1_4 || + (cusProduct.api_version === LegacyVersion.v1_4 || notNullish(cusProduct.internal_entity_id)) ); }; diff --git a/server/src/middleware/apiAuthMiddleware.ts b/server/src/middleware/apiAuthMiddleware.ts index cef61e26d..ba1071d07 100644 --- a/server/src/middleware/apiAuthMiddleware.ts +++ b/server/src/middleware/apiAuthMiddleware.ts @@ -2,7 +2,7 @@ import { AuthType, ErrCode } from "@autumn/shared"; import { verifyKey } from "@/internal/dev/api-keys/apiKeyUtils.js"; import { dashboardOrigins } from "@/utils/constants.js"; import RecaseError from "@/utils/errorUtils.js"; -import { floatToVersion } from "@/utils/versionUtils.js"; +import { floatToVersion } from "@/utils/versionUtils/legacyVersionUtils.js"; import { withOrgAuth } from "./authMiddleware.js"; import { verifyBearerPublishableKey } from "./publicAuthMiddleware.js"; import { trmnlAuthMiddleware, trmnlExclusions } from "./trmnlAuthMiddleware.js"; diff --git a/server/src/trigger/handleThresholdReached.ts b/server/src/trigger/handleThresholdReached.ts index 35f1f587e..97695efe0 100644 --- a/server/src/trigger/handleThresholdReached.ts +++ b/server/src/trigger/handleThresholdReached.ts @@ -1,20 +1,19 @@ -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { + type AppEnv, + type Feature, + type FullCusEntWithFullCusProduct, + type FullCusProduct, + type FullCustomer, + LegacyVersion, + type Organization, + WebhookEventType, +} from "@autumn/shared"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; import { sendSvixEvent } from "@/external/svix/svixHelpers.js"; -import { EntityService } from "@/internal/api/entities/EntityService.js"; import { getSingleEntityResponse } from "@/internal/api/entities/getEntityUtils.js"; import { getV2CheckResponse } from "@/internal/api/entitled/checkUtils/getV2CheckResponse.js"; import { getCustomerDetails } from "@/internal/customers/cusUtils/getCustomerDetails.js"; import { toAPIFeature } from "@/internal/features/utils/mapFeatureUtils.js"; -import { - FullCusEntWithFullCusProduct, - Feature, - FullCustomer, - Organization, - AppEnv, - FullCusProduct, - APIVersion, - WebhookEventType, -} from "@autumn/shared"; export const mergeNewCusEntsIntoCusProducts = ({ cusProducts, @@ -25,7 +24,7 @@ export const mergeNewCusEntsIntoCusProducts = ({ }) => { for (const cusProduct of cusProducts) { for (let i = 0; i < cusProduct.customer_entitlements.length; i++) { - let correspondingCusEnt = newCusEnts.find( + const correspondingCusEnt = newCusEnts.find( (cusEnt) => cusEnt.id == cusProduct.customer_entitlements[i].id, ); @@ -135,7 +134,7 @@ export const handleAllowanceUsed = async ({ feature, org, cusProducts: fullCus.customer_products, - apiVersion: APIVersion.v1_2, + apiVersion: LegacyVersion.v1_2, }); const v2CheckResponse = await getV2CheckResponse({ @@ -145,7 +144,7 @@ export const handleAllowanceUsed = async ({ feature, org, cusProducts: fullCus.customer_products, - apiVersion: APIVersion.v1_2, + apiVersion: LegacyVersion.v1_2, }); // console.log(`Handling allowance used for feature: ${feature.id}`); @@ -207,7 +206,7 @@ export const handleThresholdReached = async ({ feature, org, cusProducts: fullCus.customer_products, - apiVersion: APIVersion.v1_2, + apiVersion: LegacyVersion.v1_2, }); const v2CheckResponse = await getV2CheckResponse({ @@ -217,7 +216,7 @@ export const handleThresholdReached = async ({ feature, org, cusProducts: newCusProducts, - apiVersion: APIVersion.v1_2, + apiVersion: LegacyVersion.v1_2, }); if ( diff --git a/server/src/utils/versionUtils.ts b/server/src/utils/versionUtils/legacyVersionUtils.ts similarity index 51% rename from server/src/utils/versionUtils.ts rename to server/src/utils/versionUtils/legacyVersionUtils.ts index f15dce48d..d6b529234 100644 --- a/server/src/utils/versionUtils.ts +++ b/server/src/utils/versionUtils/legacyVersionUtils.ts @@ -1,7 +1,7 @@ -import { Organization, APIVersion } from "@autumn/shared"; +import { LegacyVersion, type Organization } from "@autumn/shared"; export const floatToVersion = (version: number) => { - if (Object.values(APIVersion).includes(version)) { + if (Object.values(LegacyVersion).includes(version)) { return version; } @@ -12,21 +12,21 @@ export const getApiVersion = ({ createdAt, }: { createdAt: number; -}): APIVersion => { +}): LegacyVersion => { // v1.1 -- 17 April - let v1_2 = new Date("2025-05-05"); - let v1_1 = new Date("2025-04-17"); + const v1_2 = new Date("2025-05-05"); + const v1_1 = new Date("2025-04-17"); if (createdAt >= v1_2.getTime()) { - return APIVersion.v1_2; + return LegacyVersion.v1_2; } if (createdAt >= v1_1.getTime()) { - return APIVersion.v1_1; + return LegacyVersion.v1_1; } - return APIVersion.v1; + return LegacyVersion.v1; }; export const orgToVersion = ({ @@ -36,5 +36,5 @@ export const orgToVersion = ({ org: Organization; reqApiVersion?: number; }) => { - return reqApiVersion || org.api_version || APIVersion.v1; + return reqApiVersion || org.api_version || LegacyVersion.v1; }; diff --git a/server/src/workers.ts b/server/src/workers.ts index 6e8a46768..d6fcbef05 100644 --- a/server/src/workers.ts +++ b/server/src/workers.ts @@ -1,5 +1,15 @@ -import { initWorkers } from "./queue/workersInit.js"; +// Suppress BullMQ eviction policy warnings BEFORE any imports +const originalWarn = console.warn; +console.warn = (...args: any[]) => { + const msg = args.join(" "); + if (msg.includes("Eviction policy")) { + return; + } + originalWarn.apply(console, args); +}; + import { QueueManager } from "./queue/QueueManager.js"; +import { initWorkers } from "./queue/workersInit.js"; const init = async () => { await QueueManager.getInstance(); // initialize the queue manager diff --git a/server/tests/advanced/advancedOthers/advancedOthers1.ts b/server/tests/advanced/advancedOthers/advancedOthers1.ts index 52a567361..19b89088c 100644 --- a/server/tests/advanced/advancedOthers/advancedOthers1.ts +++ b/server/tests/advanced/advancedOthers/advancedOthers1.ts @@ -1,31 +1,31 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { cusProductToSub } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { getMainCusProduct } from "tests/utils/cusProductUtils/cusProductUtils.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { cusProductToSub } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; import { timeout } from "@/utils/genUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // UNCOMMENT FROM HERE -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); describe(`${chalk.yellowBright("advancedOthers1: Testing convert collection method from send_invoice")}`, () => { - let customerId = "advancedOthers1"; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = "advancedOthers1"; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -69,7 +69,7 @@ describe(`${chalk.yellowBright("advancedOthers1: Testing convert collection meth testClockId = testClockId1!; }); - it("should attach pro product and pay for it", async function () { + it("should attach pro product and pay for it", async () => { const res = await autumn.attach({ customer_id: customerId, product_id: pro.id, @@ -90,7 +90,7 @@ describe(`${chalk.yellowBright("advancedOthers1: Testing convert collection meth await stripeCli.invoices.pay(invoiceStripeId); }); - it("should have collection method charge automatically", async function () { + it("should have collection method charge automatically", async () => { await timeout(5000); const cusProduct = await getMainCusProduct({ diff --git a/server/tests/advanced/check/check1.ts b/server/tests/advanced/check/check1.ts index 18457c87a..9124c6750 100644 --- a/server/tests/advanced/check/check1.ts +++ b/server/tests/advanced/check/check1.ts @@ -1,20 +1,20 @@ -import chalk from "chalk"; -import Stripe from "stripe"; +import { type Customer, LegacyVersion, type LimitedItem } from "@autumn/shared"; import { expect } from "chai"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { APIVersion, Customer, LimitedItem } from "@autumn/shared"; -import { setupBefore } from "tests/before.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { createProducts } from "tests/utils/productUtils.js"; +import chalk from "chalk"; import { Decimal } from "decimal.js"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const creditCost = 0.2; -let freeProduct = constructProduct({ +const freeProduct = constructProduct({ id: "free", items: [constructFeatureItem({ featureId: TestFeature.Action1 })], type: "free", @@ -24,7 +24,7 @@ let freeProduct = constructProduct({ const creditFeatureItem = constructFeatureItem({ featureId: TestFeature.Credits, }) as LimitedItem; -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [creditFeatureItem], type: "pro", @@ -36,7 +36,7 @@ describe(`${chalk.yellowBright("check1: Checking credit systems")}`, () => { let testClockId: string; let customer: Customer; let stripeCli: Stripe; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); before(async function () { await setupBefore(this); @@ -68,18 +68,18 @@ describe(`${chalk.yellowBright("check1: Checking credit systems")}`, () => { testClockId = testClockId_; }); - it("should attach free product and check action1 allowed", async function () { + it("should attach free product and check action1 allowed", async () => { await autumn.attach({ customer_id: customerId, product_id: freeProduct.id, }); - let actionCheck = await autumn.check({ + const actionCheck = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Action1, }); - let creditsCheck = await autumn.check({ + const creditsCheck = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Credits, }); @@ -88,18 +88,18 @@ describe(`${chalk.yellowBright("check1: Checking credit systems")}`, () => { expect(creditsCheck.allowed).to.be.false; }); - it("should attach pro product and check allowed", async function () { + it("should attach pro product and check allowed", async () => { await autumn.attach({ customer_id: customerId, product_id: pro.id, }); - let creditsCheck = await autumn.check({ + const creditsCheck = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Credits, }); - let actionCheck = await autumn.check({ + const actionCheck = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Action1, }); @@ -108,11 +108,11 @@ describe(`${chalk.yellowBright("check1: Checking credit systems")}`, () => { expect(creditsCheck.allowed).to.be.true; }); - it("should use up credits and have correct check response", async function () { - let usage = 50; - let creditUsage = new Decimal(creditCost).mul(usage).toNumber(); + it("should use up credits and have correct check response", async () => { + const usage = 50; + const creditUsage = new Decimal(creditCost).mul(usage).toNumber(); - let creditBalance = new Decimal(creditFeatureItem.included_usage) + const creditBalance = new Decimal(creditFeatureItem.included_usage) .sub(creditUsage) .toNumber(); @@ -124,7 +124,7 @@ describe(`${chalk.yellowBright("check1: Checking credit systems")}`, () => { await timeout(3000); - let creditsCheck = await autumn.check({ + const creditsCheck = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Credits, }); diff --git a/server/tests/advanced/coupons/coupon1.ts b/server/tests/advanced/coupons/coupon1.ts index 6b8c94be6..2e97e1924 100644 --- a/server/tests/advanced/coupons/coupon1.ts +++ b/server/tests/advanced/coupons/coupon1.ts @@ -1,7 +1,7 @@ import { - APIVersion, type AppEnv, type Customer, + LegacyVersion, type Organization, } from "@autumn/shared"; import { expect } from "chai"; @@ -128,7 +128,7 @@ describe( let org: Organization; let env: AppEnv; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let couponAmount = rewards.rolloverAll.discount_config.discount_value; let curUnix = new Date().getTime(); diff --git a/server/tests/advanced/coupons/coupon2.ts b/server/tests/advanced/coupons/coupon2.ts index 84f961913..fca812a3e 100644 --- a/server/tests/advanced/coupons/coupon2.ts +++ b/server/tests/advanced/coupons/coupon2.ts @@ -1,8 +1,8 @@ import { - APIVersion, type AppEnv, CouponDurationType, type CreateReward, + LegacyVersion, type Organization, RewardType, } from "@autumn/shared"; @@ -62,7 +62,7 @@ describe( let stripeCli: Stripe; let testClockId: string; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let org: Organization; let env: AppEnv; let db: DrizzleCli; diff --git a/server/tests/advanced/coupons/coupon3.ts b/server/tests/advanced/coupons/coupon3.ts index 7f09238b4..ce9c002c5 100644 --- a/server/tests/advanced/coupons/coupon3.ts +++ b/server/tests/advanced/coupons/coupon3.ts @@ -1,33 +1,30 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - -import { expect } from "chai"; - import { - APIVersion, - AppEnv, + type AppEnv, CouponDurationType, - CreateReward, - Organization, + type CreateReward, + LegacyVersion, + type Organization, RewardType, } from "@autumn/shared"; - -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { expect } from "chai"; +import chalk from "chalk"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { - constructArrearItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts, createReward } from "tests/utils/productUtils.js"; import { addPrefixToProducts, getBasePrice, } from "tests/utils/testProductUtils/testProductUtils.js"; -import { createProducts, createReward } from "tests/utils/productUtils.js"; -import { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { + constructArrearItem, + constructFeatureItem, +} from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const pro = constructProduct({ type: "pro", @@ -64,16 +61,16 @@ const reward: CreateReward = { const testCase = "coupon3"; describe(chalk.yellow(`${testCase} - Testing attach coupon`), () => { - let customerId = testCase; + const customerId = testCase; let stripeCli: Stripe; let testClockId: string; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let org: Organization; let env: AppEnv; let db: DrizzleCli; - let couponAmount = reward.discount_config!.discount_value; + const couponAmount = reward.discount_config!.discount_value; before(async function () { await setupBefore(this); @@ -132,7 +129,7 @@ describe(chalk.yellow(`${testCase} - Testing attach coupon`), () => { }); const invoice = customer.invoices![0]; - let basePrice = getBasePrice({ product: pro }); + const basePrice = getBasePrice({ product: pro }); expect(invoice.total).to.equal(basePrice - couponAmount); }); @@ -150,7 +147,7 @@ describe(chalk.yellow(`${testCase} - Testing attach coupon`), () => { }); const invoice = customer.invoices![0]; - let basePrice = getBasePrice({ product: oneOff }); + const basePrice = getBasePrice({ product: oneOff }); expect(invoice.total).to.equal(basePrice - couponAmount); expect(invoice.product_ids).to.include(oneOff.id); }); @@ -169,9 +166,9 @@ describe(chalk.yellow(`${testCase} - Testing attach coupon`), () => { }); expect(customer.invoices!.length).to.equal(3); - let basePrice = getBasePrice({ product: oneOff }); + const basePrice = getBasePrice({ product: oneOff }); for (let i = 0; i < 2; i++) { - let invoice = customer.invoices![i]; + const invoice = customer.invoices![i]; expect(invoice.total).to.equal(basePrice - couponAmount); expect(invoice.product_ids).to.include(oneOff.id); } diff --git a/server/tests/advanced/customInterval/customInterval1.ts b/server/tests/advanced/customInterval/customInterval1.ts index 6759b1870..c864b9417 100644 --- a/server/tests/advanced/customInterval/customInterval1.ts +++ b/server/tests/advanced/customInterval/customInterval1.ts @@ -1,27 +1,25 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addHours, addMonths } from "date-fns"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const testCase = "customInterval1"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Words, @@ -33,7 +31,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Words, @@ -50,8 +48,8 @@ export let premium = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing custom interval and interval count`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -90,7 +88,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom interval and interva testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -102,8 +100,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom interval and interva }); }); - let usage = 100012; - it("should upgrade to premium product and have correct invoice next cycle", async function () { + const usage = 100012; + it("should upgrade to premium product and have correct invoice next cycle", async () => { const curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -141,7 +139,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom interval and interva expect(invoices[0].total).to.equal(getBasePrice({ product: premium })); const wordsFeature = customer2.features[TestFeature.Words]; - // @ts-ignore + // @ts-expect-error expect(wordsFeature.interval_count).to.equal(2); }); }); diff --git a/server/tests/advanced/customInterval/customInterval2.ts b/server/tests/advanced/customInterval/customInterval2.ts index dae9d1c8d..9cf54f547 100644 --- a/server/tests/advanced/customInterval/customInterval2.ts +++ b/server/tests/advanced/customInterval/customInterval2.ts @@ -1,28 +1,25 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructRawProduct } from "@/utils/scriptUtils/createTestProducts.js"; - -import { addPrefixToProducts } from "tests/attach/utils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addHours, addMonths } from "date-fns"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructRawProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const testCase = "customInterval2"; -export let pro = constructRawProduct({ +export const pro = constructRawProduct({ id: "pro", items: [ constructArrearItem({ @@ -34,8 +31,8 @@ export let pro = constructRawProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing custom interval on arrear prorated price`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -74,7 +71,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom interval on arrear p testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -86,8 +83,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom interval on arrear p }); }); - let usage = 100012; - it("should upgrade to premium product and have correct invoice next cycle", async function () { + const usage = 100012; + it("should upgrade to premium product and have correct invoice next cycle", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Words, diff --git a/server/tests/advanced/customInterval/customInterval3.ts b/server/tests/advanced/customInterval/customInterval3.ts index 389014764..424ab4ead 100644 --- a/server/tests/advanced/customInterval/customInterval3.ts +++ b/server/tests/advanced/customInterval/customInterval3.ts @@ -1,45 +1,31 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { - APIVersion, - AppEnv, - BillingInterval, - LimitedItem, - Organization, - Product, -} from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { addDays, addMonths } from "date-fns"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { createProducts } from "tests/utils/productUtils.js"; - +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { calculateProrationAmount } from "@/internal/invoices/prorationUtils.js"; import { - constructArrearItem, constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; - -import { addPrefixToProducts } from "tests/attach/utils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addDays, addHours, addMonths } from "date-fns"; -import { expect } from "chai"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { calculateProrationAmount } from "@/internal/invoices/prorationUtils.js"; -import { getProration } from "@/internal/invoices/previewItemUtils/getItemsForNewProduct.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const testCase = "customInterval3"; -export let pro = constructProduct({ +export const pro = constructProduct({ type: "pro", items: [ constructFeatureItem({ @@ -65,8 +51,8 @@ export const addOn = constructRawProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing custom interval on add on merged product`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -105,7 +91,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom interval on add on m testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -117,7 +103,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom interval on add on m }); }); - it("should upgrade to attached add on and have correct invoice next cycle", async function () { + it("should upgrade to attached add on and have correct invoice next cycle", async () => { const curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -151,7 +137,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom interval on add on m product: addOn, }); - let expectedPrice = wordsBillingUnits * prepaidWordsItem.price!; + const expectedPrice = wordsBillingUnits * prepaidWordsItem.price!; const proratedPrice = calculateProrationAmount({ amount: expectedPrice, periodStart: new Date().getTime(), diff --git a/server/tests/advanced/customInterval/customInterval4.ts b/server/tests/advanced/customInterval/customInterval4.ts index c428aba75..b68f29764 100644 --- a/server/tests/advanced/customInterval/customInterval4.ts +++ b/server/tests/advanced/customInterval/customInterval4.ts @@ -1,30 +1,27 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; - -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; - -import { addPrefixToProducts } from "tests/attach/utils.js"; - -import { addMonths } from "date-fns"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import { addMonths } from "date-fns"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectDowngradeCorrect, expectNextCycleCorrect, } from "tests/utils/expectUtils/expectScheduleUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const testCase = "customInterval4"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Words, @@ -35,7 +32,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ id: "premium", items: [ constructFeatureItem({ @@ -48,8 +45,8 @@ export let premium = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing downgrades for custom intervals`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -88,7 +85,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrades for custom inter testClockId = testClockId1!; }); - it("should attach premium product", async function () { + it("should attach premium product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -100,13 +97,13 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrades for custom inter }); }); - it("should have correct next cycle at on checkout", async function () { + it("should have correct next cycle at on checkout", async () => { const checkout = await autumn.checkout({ customer_id: customerId, product_id: pro.id, }); - let expectedNextCycle = addMonths(new Date(), 2); + const expectedNextCycle = addMonths(new Date(), 2); expect(checkout.next_cycle?.starts_at).to.be.approximately( expectedNextCycle.getTime(), 1000 * 60 * 60 * 24, @@ -116,7 +113,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrades for custom inter }); let preview: any; - it("should downgrade to pro", async function () { + it("should downgrade to pro", async () => { const { preview: preview_ } = await expectDowngradeCorrect({ autumn, customerId, @@ -131,7 +128,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrades for custom inter preview = preview_; }); - it("should have pro attached on next cycle", async function () { + it("should have pro attached on next cycle", async () => { await expectNextCycleCorrect({ preview: preview!, autumn, diff --git a/server/tests/advanced/customInterval/customInterval5.ts b/server/tests/advanced/customInterval/customInterval5.ts index 92e99b87f..1820e928b 100644 --- a/server/tests/advanced/customInterval/customInterval5.ts +++ b/server/tests/advanced/customInterval/customInterval5.ts @@ -1,21 +1,19 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, FullCustomer, Organization } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import type { Customer } from "autumn-js"; import { expect } from "chai"; -import { Customer } from "autumn-js"; -import { timeout } from "@/utils/genUtils.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const testCase = "customInterval5"; @@ -31,7 +29,7 @@ const biMonthlyWords = constructFeatureItem({ includedUsage, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [monthlyWords, biMonthlyWords], intervalCount: 2, type: "pro", @@ -45,15 +43,15 @@ const getBreakdown = ({ intervalCount: number; }) => { const wordsFeature = customer.features[TestFeature.Words]; - // @ts-ignore + // @ts-expect-error return wordsFeature.breakdown?.find( (b: any) => b.interval_count == intervalCount, ); }; describe(`${chalk.yellowBright(`${testCase}: Testing multi interval features with custom intervals`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -92,7 +90,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing multi interval features wit testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -105,7 +103,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing multi interval features wit const customer = await autumn.customers.get(customerId); const wordsFeature = customer.features[TestFeature.Words]; - // @ts-ignore + // @ts-expect-error expect(wordsFeature.interval_count).to.equal(null); expect(wordsFeature.breakdown?.length).to.equal(2); @@ -122,7 +120,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing multi interval features wit }); const trackVal = 300; - it("should have correct breakdown after usage", async function () { + it("should have correct breakdown after usage", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Words, diff --git a/server/tests/advanced/defaultTrial/defaultTrial1.test.ts b/server/tests/advanced/defaultTrial/defaultTrial1.test.ts index 0c4aa7354..58318f1b6 100644 --- a/server/tests/advanced/defaultTrial/defaultTrial1.test.ts +++ b/server/tests/advanced/defaultTrial/defaultTrial1.test.ts @@ -1,23 +1,23 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; // Manual customer creation - not using initCustomer to control test clock properly import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; import { defaultTrialFree, defaultTrialPro, setupDefaultTrialBefore, } from "./defaultTrialBefore.test.js"; -import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; // Case 1: ✅ // Pro product with default trial exists alongside a free default product @@ -31,13 +31,13 @@ import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; const testCase = "defaultTrial1"; describe(`${chalk.yellowBright(`advanced/${testCase}: ensure default trials are attached when creating a customer`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockID: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = Math.floor(new Date().getTime() / 1000); + const curUnix = Math.floor(new Date().getTime() / 1000); before(async function () { await setupBefore(this); @@ -59,8 +59,8 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure default trials are testClockID = res.testClockId; }); - it("should create a customer with the paid default trial", async function () { - let customer = await autumn.customers.get(customerId); + it("should create a customer with the paid default trial", async () => { + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, @@ -70,7 +70,7 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure default trials are }); describe("ensure trials automatically cancel if no payment method is provided", () => { - it("should expire after 7 days", async function () { + it("should expire after 7 days", async () => { await advanceTestClock({ stripeCli, testClockId: testClockID, @@ -78,7 +78,7 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure default trials are waitForSeconds: 10, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, diff --git a/server/tests/advanced/defaultTrial/defaultTrial2.test.ts b/server/tests/advanced/defaultTrial/defaultTrial2.test.ts index bd3386ef8..688ac774f 100644 --- a/server/tests/advanced/defaultTrial/defaultTrial2.test.ts +++ b/server/tests/advanced/defaultTrial/defaultTrial2.test.ts @@ -1,25 +1,24 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; // Manual customer creation - not using initCustomer to control test clock properly import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { addDays, addHours } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; +import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { advanceTestClock } from "tests/utils/stripeUtils.js"; - +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; import { defaultTrialPro, setupDefaultTrialBefore, } from "./defaultTrialBefore.test.js"; -import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; -import { addDays, addHours } from "date-fns"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; // 2.2: // -> Creating a new customer with a payment method should attach the pro product with default trial @@ -28,13 +27,13 @@ import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; const testCase = "defaultTrial2"; describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trial transitions into full product if payment method is valid`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockID: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = Math.floor(new Date().getTime() / 1000); + const curUnix = Math.floor(new Date().getTime() / 1000); before(async function () { await setupBefore(this); @@ -57,8 +56,8 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trial transitions i testClockID = res.testClockId; }); - it("should create a customer with the paid default trial", async function () { - let customer = await autumn.customers.get(customerId); + it("should create a customer with the paid default trial", async () => { + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, @@ -66,7 +65,7 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trial transitions i }); }); - it("should be active after 7 days", async function () { + it("should be active after 7 days", async () => { await advanceTestClock({ stripeCli, testClockId: testClockID, @@ -77,7 +76,7 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trial transitions i waitForSeconds: 10, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, diff --git a/server/tests/advanced/defaultTrial/defaultTrial3.test.ts b/server/tests/advanced/defaultTrial/defaultTrial3.test.ts index 703472190..527d2d1ee 100644 --- a/server/tests/advanced/defaultTrial/defaultTrial3.test.ts +++ b/server/tests/advanced/defaultTrial/defaultTrial3.test.ts @@ -1,26 +1,24 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; // Manual customer creation - not using initCustomer to control test clock properly import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { addDays, addHours } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; +import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { advanceTestClock } from "tests/utils/stripeUtils.js"; - +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; import { - defaultTrialFree, defaultTrialPro, setupDefaultTrialBefore, } from "./defaultTrialBefore.test.js"; -import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; -import { addDays, addHours } from "date-fns"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; // 2.3: // -> Creating a new customer with a fake payment method should attach the pro product with default trial @@ -29,13 +27,13 @@ import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; const testCase = "defaultTrial3"; describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trials cancel with bad payment method`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockID: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = Math.floor(new Date().getTime() / 1000); + const curUnix = Math.floor(new Date().getTime() / 1000); before(async function () { await setupBefore(this); @@ -58,8 +56,8 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trials cancel with testClockID = res.testClockId; }); - it("should create a customer with the paid default trial", async function () { - let customer = await autumn.customers.get(customerId); + it("should create a customer with the paid default trial", async () => { + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, @@ -67,7 +65,7 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trials cancel with }); }); - it("should cancel after 7 days", async function () { + it("should cancel after 7 days", async () => { await advanceTestClock({ stripeCli, testClockId: testClockID, @@ -78,7 +76,7 @@ describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trials cancel with waitForSeconds: 30, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, diff --git a/server/tests/advanced/defaultTrial/defaultTrialBefore.test.ts b/server/tests/advanced/defaultTrial/defaultTrialBefore.test.ts index e9d01ee70..3ef5195a6 100644 --- a/server/tests/advanced/defaultTrial/defaultTrialBefore.test.ts +++ b/server/tests/advanced/defaultTrial/defaultTrialBefore.test.ts @@ -1,14 +1,14 @@ -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { - APIVersion, FreeTrialDuration, + LegacyVersion, ProductItemInterval, } from "@autumn/shared"; import { TestFeature } from "tests/setup/v2Features.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -export let defaultTrialPro = constructProduct({ +export const defaultTrialPro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Words, @@ -29,7 +29,7 @@ export let defaultTrialPro = constructProduct({ }, }); -export let defaultTrialFree = constructProduct({ +export const defaultTrialFree = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Words, @@ -44,9 +44,9 @@ export let defaultTrialFree = constructProduct({ }); export const setupDefaultTrialBefore = async ({}: {}) => { - const autumn = new AutumnInt({ version: APIVersion.v1_2 }); + const autumn = new AutumnInt({ version: LegacyVersion.v1_2 }); for (const product of [defaultTrialPro, defaultTrialFree]) { - let res = await autumn.products.get(product.id); + const res = await autumn.products.get(product.id); if (res.code === "product_not_found") { try { diff --git a/server/tests/advanced/multiFeature/multiFeature1.ts b/server/tests/advanced/multiFeature/multiFeature1.ts index dcd7409d1..489667e57 100644 --- a/server/tests/advanced/multiFeature/multiFeature1.ts +++ b/server/tests/advanced/multiFeature/multiFeature1.ts @@ -1,26 +1,28 @@ -import { expect } from "chai"; -import chalk from "chalk"; -import { features } from "tests/global.js"; -import { setupBefore } from "tests/before.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, BillingInterval, + LegacyVersion, ProductItemFeatureType, UsageModel, } from "@autumn/shared"; -import { createProducts } from "tests/utils/productUtils.js"; +import { expect } from "chai"; +import chalk from "chalk"; +import { setupBefore } from "tests/before.js"; +import { features } from "tests/global.js"; +import { + getPrepaidCusEnt, + getUsageCusEnt, +} from "tests/utils/cusProductUtils/cusEntSearchUtils.js"; import { getMainCusProduct } from "tests/utils/cusProductUtils/cusProductUtils.js"; -import { getUsageCusEnt } from "tests/utils/cusProductUtils/cusEntSearchUtils.js"; -import { getPrepaidCusEnt } from "tests/utils/cusProductUtils/cusEntSearchUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeaturePriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { timeout } from "@/utils/genUtils.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // Scenario 1: prepaid + pay per use monthly -> prepaid + pay per use monthly -let pro = { +const pro = { id: "multiFeature1Pro", name: "Multi Feature 1 Pro", items: { @@ -43,7 +45,7 @@ let pro = { }, }; -let premium = { +const premium = { id: "multiFeature1Premium", name: "Multi Feature 1 Premium", items: { @@ -82,19 +84,19 @@ export const getPrepaidAndUsageCusEnts = async ({ env: AppEnv; featureId: string; }) => { - let mainCusProduct = await getMainCusProduct({ + const mainCusProduct = await getMainCusProduct({ customerId, db, orgId, env, }); - let prepaidCusEnt = getPrepaidCusEnt({ + const prepaidCusEnt = getPrepaidCusEnt({ cusProduct: mainCusProduct!, featureId, }); - let usageCusEnt = getUsageCusEnt({ + const usageCusEnt = getUsageCusEnt({ cusProduct: mainCusProduct!, featureId, }); @@ -107,17 +109,17 @@ describe(`${chalk.yellowBright( "multiFeature1: Testing prepaid + pay per use -> prepaid + pay per use", )}`, () => { let autumn: AutumnInt = new AutumnInt(); - let autumn2: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); - let customerId = testCase; + const autumn2: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); + const customerId = testCase; - let prepaidQuantity = 10; - let prepaidAllowance = pro.items.prepaid.included_usage + prepaidQuantity; + const prepaidQuantity = 10; + const prepaidAllowance = pro.items.prepaid.included_usage + prepaidQuantity; let totalUsage = 0; - let premiumPrepaidAllowance = + const premiumPrepaidAllowance = premium.items.prepaid.included_usage + prepaidQuantity; - let optionsList = [ + const optionsList = [ { feature_id: features.metered1.id, quantity: prepaidQuantity, @@ -154,7 +156,7 @@ describe(`${chalk.yellowBright( options: optionsList, }); - let { prepaidCusEnt, usageCusEnt } = await getPrepaidAndUsageCusEnts({ + const { prepaidCusEnt, usageCusEnt } = await getPrepaidAndUsageCusEnts({ customerId, db: this.db, orgId: this.org.id, @@ -170,7 +172,7 @@ describe(`${chalk.yellowBright( }); it("should use prepaid allowance first", async function () { - let value = 60; + const value = 60; await autumn.track({ customer_id: customerId, @@ -182,7 +184,7 @@ describe(`${chalk.yellowBright( await timeout(3000); - let { prepaidCusEnt, usageCusEnt } = await getPrepaidAndUsageCusEnts({ + const { prepaidCusEnt, usageCusEnt } = await getPrepaidAndUsageCusEnts({ customerId, db: this.db, orgId: this.org.id, @@ -195,7 +197,7 @@ describe(`${chalk.yellowBright( }); it("should have correct usage / invoice after upgrade", async function () { - let value = 60; + const value = 60; await autumn.track({ customer_id: customerId, value, @@ -206,7 +208,7 @@ describe(`${chalk.yellowBright( await timeout(10000); - let { usageCusEnt } = await getPrepaidAndUsageCusEnts({ + const { usageCusEnt } = await getPrepaidAndUsageCusEnts({ customerId, db: this.db, orgId: this.org.id, @@ -220,7 +222,7 @@ describe(`${chalk.yellowBright( options: optionsList, }); - let { prepaidCusEnt, usageCusEnt: newUsageCusEnt } = + const { prepaidCusEnt, usageCusEnt: newUsageCusEnt } = await getPrepaidAndUsageCusEnts({ customerId, db: this.db, @@ -230,19 +232,19 @@ describe(`${chalk.yellowBright( }); // Check invoice too - let { invoices } = await autumn2.customers.get(customerId); + const { invoices } = await autumn2.customers.get(customerId); - let invoice1Amount = + const invoice1Amount = (premium.items.prepaid.price ?? 0) * prepaidQuantity - (pro.items.prepaid.price ?? 0) * prepaidQuantity; - let invoice0Amount = value * (pro.items.payPerUse.price ?? 0); + const invoice0Amount = value * (pro.items.payPerUse.price ?? 0); - let totalAmount = invoice1Amount + invoice0Amount; + const totalAmount = invoice1Amount + invoice0Amount; expect(invoices![0].total).to.equal(totalAmount); - let leftover = premiumPrepaidAllowance - totalUsage + value; + const leftover = premiumPrepaidAllowance - totalUsage + value; expect(prepaidCusEnt?.balance).to.equal(Math.max(0, leftover)); expect(newUsageCusEnt?.balance).to.equal(0); }); diff --git a/server/tests/advanced/multiFeature/multiFeature2.ts b/server/tests/advanced/multiFeature/multiFeature2.ts index 10ae4afb9..2cb146ae1 100644 --- a/server/tests/advanced/multiFeature/multiFeature2.ts +++ b/server/tests/advanced/multiFeature/multiFeature2.ts @@ -1,34 +1,32 @@ -import { expect } from "chai"; -import chalk from "chalk"; -import { features } from "tests/global.js"; -import { setupBefore } from "tests/before.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, BillingInterval, EntInterval, + LegacyVersion, ProductItemFeatureType, UsageModel, } from "@autumn/shared"; -import { createProduct } from "tests/utils/productUtils.js"; -import { getMainCusProduct } from "tests/utils/cusProductUtils/cusProductUtils.js"; +import { expect } from "chai"; +import chalk from "chalk"; +import { setupBefore } from "tests/before.js"; +import { features } from "tests/global.js"; import { getLifetimeFreeCusEnt, getUsageCusEnt, } from "tests/utils/cusProductUtils/cusEntSearchUtils.js"; - +import { getMainCusProduct } from "tests/utils/cusProductUtils/cusProductUtils.js"; +import { createProduct } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, constructFeaturePriceItem, } from "@/internal/products/product-items/productItemUtils.js"; - import { timeout } from "@/utils/genUtils.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // Scenario 1: prepaid + pay per use monthly -> prepaid + pay per use monthly -let pro = { +const pro = { id: "multiFeature2Pro", name: "Multi Feature 2 Pro", items: { @@ -48,7 +46,7 @@ let pro = { }, }; -let premium = { +const premium = { id: "multiFeature2Premium", name: "Multi Feature 2 Premium", items: { @@ -77,19 +75,19 @@ export const getLifetimeAndUsageCusEnts = async ({ env: AppEnv; featureId: string; }) => { - let mainCusProduct = await getMainCusProduct({ + const mainCusProduct = await getMainCusProduct({ customerId: customerId, db, orgId, env, }); - let lifetimeCusEnt = getLifetimeFreeCusEnt({ + const lifetimeCusEnt = getLifetimeFreeCusEnt({ cusProduct: mainCusProduct!, featureId, }); - let usageCusEnt = getUsageCusEnt({ + const usageCusEnt = getUsageCusEnt({ cusProduct: mainCusProduct!, featureId, }); @@ -102,8 +100,8 @@ describe(`${chalk.yellowBright( "multiFeature2: Testing lifetime + pay per use -> pay per use", )}`, () => { let autumn: AutumnInt = new AutumnInt(); - let autumn2: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); - let customerId = testCase; + const autumn2: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); + const customerId = testCase; let totalUsage = 0; @@ -144,7 +142,7 @@ describe(`${chalk.yellowBright( product_id: pro.id, }); - let { lifetimeCusEnt, usageCusEnt } = await getLifetimeAndUsageCusEnts({ + const { lifetimeCusEnt, usageCusEnt } = await getLifetimeAndUsageCusEnts({ customerId, db: this.db, orgId: this.org.id, @@ -158,7 +156,7 @@ describe(`${chalk.yellowBright( }); it("should use lifetime allowance first", async function () { - let value = pro.items.lifetime.included_usage as number; + const value = pro.items.lifetime.included_usage as number; await autumn.events.send({ customerId, @@ -170,7 +168,7 @@ describe(`${chalk.yellowBright( await timeout(3000); - let { lifetimeCusEnt, usageCusEnt } = await getLifetimeAndUsageCusEnts({ + const { lifetimeCusEnt, usageCusEnt } = await getLifetimeAndUsageCusEnts({ customerId, db: this.db, orgId: this.org.id, @@ -185,7 +183,7 @@ describe(`${chalk.yellowBright( }); it("should have correct usage after upgrade", async function () { - let value = 20; + const value = 20; await autumn.track({ customer_id: customerId, @@ -201,7 +199,7 @@ describe(`${chalk.yellowBright( }); // return; - let { lifetimeCusEnt, usageCusEnt: newUsageCusEnt } = + const { lifetimeCusEnt, usageCusEnt: newUsageCusEnt } = await getLifetimeAndUsageCusEnts({ customerId, db: this.db, @@ -214,10 +212,10 @@ describe(`${chalk.yellowBright( expect(newUsageCusEnt?.balance).to.equal(-50); // Check invoice too - let res = await autumn2.customers.get(customerId); - let invoices = res.invoices; + const res = await autumn2.customers.get(customerId); + const invoices = res.invoices; - let invoice0Amount = value * (pro.items.payPerUse.price ?? 0); + const invoice0Amount = value * (pro.items.payPerUse.price ?? 0); expect(invoices![0].total).to.equal( invoice0Amount, "Invoice 0 should be 0", diff --git a/server/tests/advanced/rollovers/rollover1.ts b/server/tests/advanced/rollovers/rollover1.ts index 9c7ed1e25..9b81e8ecb 100644 --- a/server/tests/advanced/rollovers/rollover1.ts +++ b/server/tests/advanced/rollovers/rollover1.ts @@ -1,31 +1,32 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, - Customer, - LimitedItem, - Organization, + type AppEnv, + type Customer, + LegacyVersion, + type LimitedItem, + type Organization, ProductItemInterval, RolloverDuration, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; - import { expect } from "chai"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { resetAndGetCusEnt } from "./rolloverTestUtils.js"; -let rolloverConfig = { max: 500, length: 1, duration: RolloverDuration.Month }; +const rolloverConfig = { + max: 500, + length: 1, + duration: RolloverDuration.Month, +}; const messagesItem = constructFeatureItem({ featureId: TestFeature.Messages, includedUsage: 400, @@ -33,7 +34,7 @@ const messagesItem = constructFeatureItem({ rolloverConfig, }) as LimitedItem; -export let free = constructProduct({ +export const free = constructProduct({ items: [messagesItem], type: "free", isDefault: false, @@ -43,14 +44,14 @@ const testCase = "rollover1"; // , per entity and regular describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let customer: Customer; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -88,17 +89,17 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item` customer = res.customer; }); - it("should attach free product", async function () { + it("should attach free product", async () => { await autumn.attach({ customer_id: customerId, product_id: free.id, }); }); - let messageUsage = 250; + const messageUsage = 250; let curBalance = messagesItem.included_usage; - it("should create track messages, reset, and have correct rollover", async function () { + it("should create track messages, reset, and have correct rollover", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -114,25 +115,25 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item` featureId: TestFeature.Messages, }); - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; - let expectedRollover = Math.min( + const expectedRollover = Math.min( messagesItem.included_usage - messageUsage, rolloverConfig.max, ); - let expectedBalance = messagesItem.included_usage + expectedRollover; + const expectedBalance = messagesItem.included_usage + expectedRollover; expect(msgesFeature).to.exist; expect(msgesFeature?.balance).to.equal(expectedBalance); - // @ts-ignore + // @ts-expect-error expect(msgesFeature?.rollovers[0].balance).to.equal(expectedRollover); curBalance = expectedBalance; }); // let usage2 = 50; - it("should reset again and have correct rollover", async function () { + it("should reset again and have correct rollover", async () => { await resetAndGetCusEnt({ db, customer, @@ -140,22 +141,22 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item` featureId: TestFeature.Messages, }); - let expectedRollover = Math.min(curBalance, rolloverConfig.max); - let expectedBalance = messagesItem.included_usage + expectedRollover; + const expectedRollover = Math.min(curBalance, rolloverConfig.max); + const expectedBalance = messagesItem.included_usage + expectedRollover; - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; expect(msgesFeature).to.exist; expect(msgesFeature?.balance).to.equal(expectedBalance); - // @ts-ignore (oldest rollover should be 100 (150 - 50)) + // @ts-expect-error (oldest rollover should be 100 (150 - 50)) expect(msgesFeature?.rollovers[0].balance).to.equal(100); - // @ts-ignore (newest rollover should be 400 (msges.included_usage)) + // @ts-expect-error (newest rollover should be 400 (msges.included_usage)) expect(msgesFeature?.rollovers[1].balance).to.equal(400); }); - it("should track messages and deduct from rollovers first", async function () { + it("should track messages and deduct from rollovers first", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -164,19 +165,19 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item` await timeout(3000); - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; - // @ts-ignore - let rollover1 = msgesFeature?.rollovers[0]; - // @ts-ignore - let rollover2 = msgesFeature?.rollovers[1]; + // @ts-expect-error + const rollover1 = msgesFeature?.rollovers[0]; + // @ts-expect-error + const rollover2 = msgesFeature?.rollovers[1]; expect(rollover1.balance).to.equal(0); expect(rollover2.balance).to.equal(350); }); - it("should track and deduct from rollover + original balance", async function () { + it("should track and deduct from rollover + original balance", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -185,11 +186,11 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item` await timeout(3000); - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; - // @ts-ignore - let rollovers = msgesFeature.rollovers; + // @ts-expect-error + const rollovers = msgesFeature.rollovers; expect(rollovers![0].balance).to.equal(0); expect(rollovers![1].balance).to.equal(0); expect(msgesFeature.balance).to.equal(messagesItem.included_usage - 50); diff --git a/server/tests/advanced/rollovers/rollover2.ts b/server/tests/advanced/rollovers/rollover2.ts index 940ec7b6e..bdd212140 100644 --- a/server/tests/advanced/rollovers/rollover2.ts +++ b/server/tests/advanced/rollovers/rollover2.ts @@ -1,34 +1,32 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, - Customer, - LimitedItem, - Organization, + type AppEnv, + type Customer, + LegacyVersion, + type LimitedItem, + type Organization, ProductItemInterval, RolloverDuration, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; - import { expect } from "chai"; -import { getMainCusProduct } from "@/internal/customers/cusProducts/cusProductUtils.js"; -import { cusProductToCusEnt } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; -import { resetCustomerEntitlement } from "@/cron/cronUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { resetAndGetCusEnt } from "./rolloverTestUtils.js"; -let rolloverConfig = { max: 500, length: 1, duration: RolloverDuration.Month }; +const rolloverConfig = { + max: 500, + length: 1, + duration: RolloverDuration.Month, +}; const msgesItem = constructFeatureItem({ featureId: TestFeature.Messages, @@ -38,7 +36,7 @@ const msgesItem = constructFeatureItem({ entityFeatureId: TestFeature.Users, }) as LimitedItem; -export let free = constructProduct({ +export const free = constructProduct({ items: [msgesItem], type: "free", isDefault: false, @@ -48,14 +46,14 @@ const testCase = "rollover2"; // , per entity and regular describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item (per entity)`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let customer: Customer; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -106,7 +104,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item }, ]; - it("should attach pro product", async function () { + it("should attach pro product", async () => { await autumn.attach({ customer_id: customerId, product_id: free.id, @@ -115,12 +113,12 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item await autumn.entities.create(customerId, entities); }); - let entity1Id = entities[0].id; - let entity2Id = entities[1].id; - let newEntity1Balance = 300; - let newEntity2Balance = 200; - let includedUsage = msgesItem.included_usage; - let usages = [ + const entity1Id = entities[0].id; + const entity2Id = entities[1].id; + const newEntity1Balance = 300; + const newEntity2Balance = 200; + const includedUsage = msgesItem.included_usage; + const usages = [ { entityId: entity1Id, usage: includedUsage - newEntity1Balance, @@ -133,7 +131,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item }, ]; - it("should create track messages, reset, and have correct rollover", async function () { + it("should create track messages, reset, and have correct rollover", async () => { for (const usage of usages) { await autumn.track({ customer_id: customerId, @@ -154,9 +152,9 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item }); for (const usage of usages) { - let entity = await autumn.entities.get(customerId, usage.entityId); - let msgesFeature = entity.features[TestFeature.Messages]; - let expectedRollover = Math.min(usage.rollover, rolloverConfig.max); + const entity = await autumn.entities.get(customerId, usage.entityId); + const msgesFeature = entity.features[TestFeature.Messages]; + const expectedRollover = Math.min(usage.rollover, rolloverConfig.max); expect(msgesFeature.rollovers.length).to.equal(1); expect(msgesFeature.balance).to.equal(includedUsage + expectedRollover); @@ -164,7 +162,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item } }); - it("should reset again and have correct rollovers", async function () { + it("should reset again and have correct rollovers", async () => { await resetAndGetCusEnt({ db, customer, @@ -172,22 +170,22 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item featureId: TestFeature.Messages, }); - let entity1 = await autumn.entities.get(customerId, entity1Id); - let entity1Msges = entity1.features[TestFeature.Messages]; + const entity1 = await autumn.entities.get(customerId, entity1Id); + const entity1Msges = entity1.features[TestFeature.Messages]; // 400, 300 -> 400, 100 (max is 500) - let rollovers = entity1Msges.rollovers; + const rollovers = entity1Msges.rollovers; expect(rollovers[0].balance).to.equal(100); expect(rollovers[1].balance).to.equal(400); - let entity2 = await autumn.entities.get(customerId, entity2Id); - let entity2Msges = entity2.features[TestFeature.Messages]; + const entity2 = await autumn.entities.get(customerId, entity2Id); + const entity2Msges = entity2.features[TestFeature.Messages]; // 400, 200 -> 400, 0 (max is 500) - let rollovers2 = entity2Msges.rollovers; + const rollovers2 = entity2Msges.rollovers; expect(rollovers2[0].balance).to.equal(100); expect(rollovers2[1].balance).to.equal(400); }); - it("should track and deduct from oldest rollovers first", async function () { + it("should track and deduct from oldest rollovers first", async () => { for (const entity of entities) { await autumn.track({ customer_id: customerId, @@ -197,16 +195,16 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item }); await timeout(2000); - let entRes = await autumn.entities.get(customerId, entity.id); - let msgesFeature = entRes.features[TestFeature.Messages]; - let rollovers = msgesFeature.rollovers; + const entRes = await autumn.entities.get(customerId, entity.id); + const msgesFeature = entRes.features[TestFeature.Messages]; + const rollovers = msgesFeature.rollovers; expect(rollovers[0].balance).to.equal(0); expect(rollovers[1].balance).to.equal(350); expect(msgesFeature.balance).to.equal(includedUsage + 350); } }); - it("should track past rollovers and deduct from original balance", async function () { + it("should track past rollovers and deduct from original balance", async () => { for (const entity of entities) { await autumn.track({ customer_id: customerId, @@ -216,9 +214,9 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for feature item }); await timeout(2000); - let entRes = await autumn.entities.get(customerId, entity.id); - let msgesFeature = entRes.features[TestFeature.Messages]; - let rollovers = msgesFeature.rollovers; + const entRes = await autumn.entities.get(customerId, entity.id); + const msgesFeature = entRes.features[TestFeature.Messages]; + const rollovers = msgesFeature.rollovers; expect(rollovers[0].balance).to.equal(0); expect(rollovers[1].balance).to.equal(0); expect(msgesFeature.balance).to.equal(includedUsage - 50); diff --git a/server/tests/advanced/rollovers/rollover3.ts b/server/tests/advanced/rollovers/rollover3.ts index 17351ea00..37b0c7590 100644 --- a/server/tests/advanced/rollovers/rollover3.ts +++ b/server/tests/advanced/rollovers/rollover3.ts @@ -1,38 +1,39 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, - Customer, - LimitedItem, - Organization, + type AppEnv, + type Customer, + LegacyVersion, + type LimitedItem, + type Organization, RolloverDuration, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; - import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; +import chalk from "chalk"; import { addMonths } from "date-fns"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; -let rolloverConfig = { max: 500, length: 1, duration: RolloverDuration.Month }; +const rolloverConfig = { + max: 500, + length: 1, + duration: RolloverDuration.Month, +}; const messagesItem = constructArrearProratedItem({ featureId: TestFeature.Messages, includedUsage: 400, rolloverConfig, }) as LimitedItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [messagesItem], type: "pro", isDefault: false, @@ -41,14 +42,14 @@ export let pro = constructProduct({ const testCase = "rollover3"; describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price feature`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let customer: Customer; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -86,17 +87,17 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f customer = res.customer; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await autumn.attach({ customer_id: customerId, product_id: pro.id, }); }); - let rollover = 250; + const rollover = 250; let curBalance = messagesItem.included_usage; - it("should create track messages, reset, and have correct rollover", async function () { + it("should create track messages, reset, and have correct rollover", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -112,14 +113,14 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f waitForSeconds: 20, }); - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; - let expectedBalance = messagesItem.included_usage + rollover; + const expectedBalance = messagesItem.included_usage + rollover; expect(msgesFeature).to.exist; expect(msgesFeature?.balance).to.equal(expectedBalance); - // @ts-ignore + // @ts-expect-error expect(msgesFeature?.rollovers[0].balance).to.equal(rollover); curBalance = expectedBalance; }); diff --git a/server/tests/advanced/rollovers/rollover4.ts b/server/tests/advanced/rollovers/rollover4.ts index 08e0717a3..13e38b224 100644 --- a/server/tests/advanced/rollovers/rollover4.ts +++ b/server/tests/advanced/rollovers/rollover4.ts @@ -1,32 +1,32 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, - Customer, - LimitedItem, - Organization, + type AppEnv, + type Customer, + LegacyVersion, + type LimitedItem, + type Organization, RolloverDuration, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; - import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; +import chalk from "chalk"; import { addMonths } from "date-fns"; -import { resetAndGetCusEnt } from "./rolloverTestUtils.js"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; -let rolloverConfig = { max: 400, length: 1, duration: RolloverDuration.Month }; +const rolloverConfig = { + max: 400, + length: 1, + duration: RolloverDuration.Month, +}; const messagesItem = constructPrepaidItem({ featureId: TestFeature.Messages, includedUsage: 100, @@ -35,7 +35,7 @@ const messagesItem = constructPrepaidItem({ rolloverConfig, }) as LimitedItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [messagesItem], type: "pro", isDefault: false, @@ -44,8 +44,8 @@ export let pro = constructProduct({ const testCase = "rollover4"; describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price feature`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let customer: Customer; @@ -89,8 +89,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f customer = res.customer; }); - let paidQuantity = 300; - let balance = paidQuantity + messagesItem.included_usage; + const paidQuantity = 300; + const balance = paidQuantity + messagesItem.included_usage; const options = [ { feature_id: TestFeature.Messages, @@ -98,7 +98,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f }, ]; - it("should attach pro product", async function () { + it("should attach pro product", async () => { await autumn.attach({ customer_id: customerId, product_id: pro.id, @@ -106,8 +106,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f }); }); - let rollover = 50; - it("should create track messages, reset, and have correct rollover", async function () { + const rollover = 50; + it("should create track messages, reset, and have correct rollover", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -123,11 +123,11 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f waitForSeconds: 20, }); - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; - // @ts-ignore - let rollovers = msgesFeature?.rollovers; + // @ts-expect-error + const rollovers = msgesFeature?.rollovers; expect(msgesFeature).to.exist; expect(msgesFeature?.balance).to.equal(balance + rollover); @@ -135,7 +135,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f }); // let usage2 = 50; - it("should reset again and have correct rollover", async function () { + it("should reset again and have correct rollover", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -143,11 +143,11 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f waitForSeconds: 20, }); - let newRollover = Math.min(balance + rollover, rolloverConfig.max); - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; - // @ts-ignore - let rollovers = msgesFeature?.rollovers; + const newRollover = Math.min(balance + rollover, rolloverConfig.max); + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; + // @ts-expect-error + const rollovers = msgesFeature?.rollovers; expect(msgesFeature).to.exist; expect(msgesFeature?.balance).to.equal(balance + newRollover); diff --git a/server/tests/advanced/rollovers/rollover5.ts b/server/tests/advanced/rollovers/rollover5.ts index 1e5f88ad9..13a77c758 100644 --- a/server/tests/advanced/rollovers/rollover5.ts +++ b/server/tests/advanced/rollovers/rollover5.ts @@ -1,30 +1,27 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, - Customer, - LimitedItem, - Organization, + type AppEnv, + type Customer, + LegacyVersion, + type LimitedItem, + type Organization, RolloverDuration, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; - import { expect } from "chai"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { resetAndGetCusEnt } from "./rolloverTestUtils.js"; -let freeRollover = { max: 1000, length: 1, duration: RolloverDuration.Month }; -let proRollover = { max: 600, length: 1, duration: RolloverDuration.Month }; +const freeRollover = { max: 1000, length: 1, duration: RolloverDuration.Month }; +const proRollover = { max: 600, length: 1, duration: RolloverDuration.Month }; const freeMsges = constructFeatureItem({ featureId: TestFeature.Messages, @@ -52,13 +49,13 @@ const pro = constructProduct({ const testCase = "rollover5"; describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for upgrade`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let customer: Customer; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -96,14 +93,14 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for upgrade`)}`, customer = res.customer; }); - it("should attach free product", async function () { + it("should attach free product", async () => { await autumn.attach({ customer_id: customerId, product_id: free.id, }); }); - it("should create rollovers", async function () { + it("should create rollovers", async () => { await resetAndGetCusEnt({ customer, db, @@ -123,17 +120,17 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for upgrade`)}`, product_id: pro.id, }); - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; - let freeRolloverBalance = freeMsges.included_usage * 2; - let proRolloverBalance = Math.min(proRollover.max, freeRolloverBalance); + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; + const freeRolloverBalance = freeMsges.included_usage * 2; + const proRolloverBalance = Math.min(proRollover.max, freeRolloverBalance); expect(msgesFeature).to.exist; expect(msgesFeature?.balance).to.equal( proMsges.included_usage + proRolloverBalance, ); - // @ts-ignore - let rollovers = msgesFeature?.rollovers; + // @ts-expect-error + const rollovers = msgesFeature?.rollovers; expect(rollovers[0].balance).to.equal(100); expect(rollovers[1].balance).to.equal(500); }); diff --git a/server/tests/advanced/rollovers/rollover6.ts b/server/tests/advanced/rollovers/rollover6.ts index 5452edfda..f7c1051d0 100644 --- a/server/tests/advanced/rollovers/rollover6.ts +++ b/server/tests/advanced/rollovers/rollover6.ts @@ -1,33 +1,30 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, - Customer, - LimitedItem, - Organization, + type AppEnv, + type Customer, + LegacyVersion, + type LimitedItem, + type Organization, RolloverDuration, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; - import { expect } from "chai"; -import { resetAndGetCusEnt } from "./rolloverTestUtils.js"; -import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; +import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; +import { resetAndGetCusEnt } from "./rolloverTestUtils.js"; -let freeRollover = { max: 600, length: 1, duration: RolloverDuration.Month }; -let proRollover = { max: 1000, length: 1, duration: RolloverDuration.Month }; +const freeRollover = { max: 600, length: 1, duration: RolloverDuration.Month }; +const proRollover = { max: 1000, length: 1, duration: RolloverDuration.Month }; const freeMsges = constructFeatureItem({ featureId: TestFeature.Messages, @@ -55,13 +52,13 @@ const pro = constructProduct({ const testCase = "rollover6"; describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for upgrade`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let customer: Customer; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -99,14 +96,14 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for upgrade`)}`, customer = res.customer; }); - it("should attach free product", async function () { + it("should attach free product", async () => { await autumn.attach({ customer_id: customerId, product_id: pro.id, }); }); - it("should create rollovers", async function () { + it("should create rollovers", async () => { await resetAndGetCusEnt({ customer, db, @@ -136,18 +133,18 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for upgrade`)}`, waitForSeconds: 20, }); - let cus = await autumn.customers.get(customerId); - let msgesFeature = cus.features[TestFeature.Messages]; - let proRolloverBalance = proMsges.included_usage * 2; - let freeRolloverBalance = Math.min(freeRollover.max, proRolloverBalance); + const cus = await autumn.customers.get(customerId); + const msgesFeature = cus.features[TestFeature.Messages]; + const proRolloverBalance = proMsges.included_usage * 2; + const freeRolloverBalance = Math.min(freeRollover.max, proRolloverBalance); expect(msgesFeature).to.exist; expect(msgesFeature?.balance).to.equal( freeMsges.included_usage + freeRolloverBalance, ); - // @ts-ignore - let rollovers = msgesFeature?.rollovers; + // @ts-expect-error + const rollovers = msgesFeature?.rollovers; expect(rollovers[0].balance).to.equal(100); expect(rollovers[1].balance).to.equal(500); }); diff --git a/server/tests/advanced/usageLimit/usageLimit1.ts b/server/tests/advanced/usageLimit/usageLimit1.ts index b1d25b8b6..417433e12 100644 --- a/server/tests/advanced/usageLimit/usageLimit1.ts +++ b/server/tests/advanced/usageLimit/usageLimit1.ts @@ -1,19 +1,23 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, ErrCode, Organization } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { + type AppEnv, + ErrCode, + LegacyVersion, + type Organization, +} from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, @@ -22,7 +26,7 @@ const userItem = constructArrearProratedItem({ usageLimit: 2, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -30,13 +34,13 @@ export let pro = constructProduct({ const testCase = "usageLimit1"; describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for entities`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -96,7 +100,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for entities`) }, ]; - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -107,7 +111,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for entities`) env, }); }); - it("should create more entities than the limit and hit error", async function () { + it("should create more entities than the limit and hit error", async () => { await expectAutumnError({ errCode: ErrCode.FeatureLimitReached, func: async () => { @@ -116,7 +120,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for entities`) }); }); - it("should create entities one by one, then hit usage limit", async function () { + it("should create entities one by one, then hit usage limit", async () => { await autumn.entities.create(customerId, entities[0]); await autumn.entities.create(customerId, entities[1]); @@ -128,7 +132,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for entities`) }); }); - it("should have correct check and get customer value", async function () { + it("should have correct check and get customer value", async () => { const check = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Users, @@ -136,10 +140,10 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for entities`) const customer = await autumn.customers.get(customerId); expect(check.balance).to.equal(-2); - // @ts-ignore + // @ts-expect-error expect(check.usage_limit).to.equal(userItem.usage_limit); - // @ts-ignore + // @ts-expect-error expect(customer.features[TestFeature.Users].usage_limit).to.equal( userItem.usage_limit, ); diff --git a/server/tests/advanced/usageLimit/usageLimit2.ts b/server/tests/advanced/usageLimit/usageLimit2.ts index 7289499c0..58e2dc733 100644 --- a/server/tests/advanced/usageLimit/usageLimit2.ts +++ b/server/tests/advanced/usageLimit/usageLimit2.ts @@ -1,22 +1,26 @@ +import { + type AppEnv, + LegacyVersion, + type LimitedItem, + type Organization, +} from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, LimitedItem, Organization } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem, constructFeatureItem, } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; -import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const messageItem = constructArrearItem({ featureId: TestFeature.Messages, @@ -26,7 +30,7 @@ const messageItem = constructArrearItem({ usageLimit: 500, }) as LimitedItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [messageItem], type: "pro", }); @@ -45,13 +49,13 @@ const messageAddOn = constructProduct({ const testCase = "usageLimit2"; describe(`${chalk.yellowBright(`${testCase}: Testing usage limits, usage prices`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -88,7 +92,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits, usage prices` testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -100,10 +104,10 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits, usage prices` }); }); - let initialUsage = + const initialUsage = messageItem.included_usage + messageItem.usage_limit! + 1000; - it("should track more messages than limit and not surpass", async function () { + it("should track more messages than limit and not surpass", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -112,36 +116,37 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits, usage prices` await timeout(2000); - let check = await autumn.check({ + const check = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); - let expectedBalance = messageItem.included_usage - messageItem.usage_limit!; + const expectedBalance = + messageItem.included_usage - messageItem.usage_limit!; expect(check.balance).to.equal(expectedBalance); expect(check.allowed).to.equal(false); - // @ts-ignore + // @ts-expect-error expect(check.usage_limit!).to.equal(messageItem.usage_limit!); - // @ts-ignore + // @ts-expect-error expect(customer.features[TestFeature.Messages].usage_limit).to.equal( messageItem.usage_limit!, ); }); - it("should purchase add ons and have correct check results", async function () { + it("should purchase add ons and have correct check results", async () => { await autumn.attach({ customer_id: customerId, product_id: messageAddOn.id, }); - let check = await autumn.check({ + const check = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, }); - let customer = await autumn.customers.get(customerId); - let expectedBalance = + const customer = await autumn.customers.get(customerId); + const expectedBalance = messageItem.included_usage - messageItem.usage_limit! + addOnMessages.included_usage; @@ -149,17 +154,17 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits, usage prices` expect(check.balance).to.equal(expectedBalance); expect(check.allowed).to.equal(true); - // @ts-ignore + // @ts-expect-error expect(check.usage_limit!).to.equal( messageItem.usage_limit! + addOnMessages.included_usage, ); - // @ts-ignore + // @ts-expect-error expect(customer.features[TestFeature.Messages].usage_limit).to.equal( messageItem.usage_limit! + addOnMessages.included_usage, ); }); - it("should use up all add ons and have correct check results", async function () { + it("should use up all add ons and have correct check results", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -168,20 +173,21 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits, usage prices` await timeout(2000); - let check = await autumn.check({ + const check = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); - let expectedBalance = messageItem.included_usage - messageItem.usage_limit!; + const expectedBalance = + messageItem.included_usage - messageItem.usage_limit!; expect(check.balance).to.equal(expectedBalance); expect(check.allowed).to.equal(false); - // @ts-ignore + // @ts-expect-error expect(check.usage_limit!).to.equal( messageItem.usage_limit! + addOnMessages.included_usage, ); - // @ts-ignore + // @ts-expect-error expect(customer.features[TestFeature.Messages].usage_limit).to.equal( messageItem.usage_limit! + addOnMessages.included_usage, ); diff --git a/server/tests/advanced/usageLimit/usageLimit3.ts b/server/tests/advanced/usageLimit/usageLimit3.ts index d9d86d6a8..fc48ebe43 100644 --- a/server/tests/advanced/usageLimit/usageLimit3.ts +++ b/server/tests/advanced/usageLimit/usageLimit3.ts @@ -1,29 +1,23 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, ErrCode, - LimitedItem, - Organization, + LegacyVersion, + type LimitedItem, + type Organization, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { - constructFeatureItem, - constructPrepaidItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; import { addPrefixToProducts } from "tests/attach/utils.js"; -import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const messageItem = constructPrepaidItem({ featureId: TestFeature.Messages, @@ -33,7 +27,7 @@ const messageItem = constructPrepaidItem({ usageLimit: 500, }) as LimitedItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [messageItem], type: "pro", }); @@ -52,13 +46,13 @@ export let pro = constructProduct({ const testCase = "usageLimit3"; describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for prepaid`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -95,7 +89,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for prepaid`)} testClockId = testClockId1!; }); - it("should attach pro product with quantity exceeding usage limit and get an error", async function () { + it("should attach pro product with quantity exceeding usage limit and get an error", async () => { expectAutumnError({ errCode: ErrCode.InvalidOptions, func: async () => { @@ -117,7 +111,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for prepaid`)} }, }); }); - it("should attach pro product and update quantity with quantity exceeding usage limit and get an error", async function () { + it("should attach pro product and update quantity with quantity exceeding usage limit and get an error", async () => { await autumn.attach({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/advanced/usageLimit/usageLimit4.ts b/server/tests/advanced/usageLimit/usageLimit4.ts index 596058f69..0938b1a32 100644 --- a/server/tests/advanced/usageLimit/usageLimit4.ts +++ b/server/tests/advanced/usageLimit/usageLimit4.ts @@ -1,30 +1,24 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, ErrCode, - LimitedItem, - Organization, + LegacyVersion, + type LimitedItem, + type Organization, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { - constructArrearProratedItem, - constructFeatureItem, - constructPrepaidItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const messageItem = constructArrearProratedItem({ featureId: TestFeature.Users, @@ -33,7 +27,7 @@ const messageItem = constructArrearProratedItem({ usageLimit: 3, }) as LimitedItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [messageItem], type: "pro", }); @@ -41,13 +35,13 @@ export let pro = constructProduct({ const testCase = "usageLimit4"; describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for cont use item`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -84,7 +78,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for cont use i testClockId = testClockId1!; }); - it("should attach pro product with quantity exceeding usage limit and get an error", async function () { + it("should attach pro product with quantity exceeding usage limit and get an error", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -95,7 +89,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing usage limits for cont use i env, }); }); - it("should attach pro product and update quantity with quantity exceeding usage limit and get an error", async function () { + it("should attach pro product and update quantity with quantity exceeding usage limit and get an error", async () => { await expectAutumnError({ errCode: ErrCode.InvalidInputs, func: async () => { diff --git a/server/tests/archives/coupon1 copy.ts b/server/tests/archives/coupon1 copy.ts index f3918c904..bc5792712 100644 --- a/server/tests/archives/coupon1 copy.ts +++ b/server/tests/archives/coupon1 copy.ts @@ -1,38 +1,36 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { APIVersion, Customer } from "@autumn/shared"; -import { createStripeCli } from "@/external/stripe/utils.js"; -import { getOriginalCouponId } from "@/internal/rewards/rewardUtils.js"; -import { getPriceForOverage } from "@/internal/products/prices/priceUtils.js"; +import { type Customer, LegacyVersion } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; -import { features, products, rewards } from "tests/global.js"; -import { getFixedPriceAmount, timeout } from "tests/utils/genUtils.js"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; import { AutumnCli } from "tests/cli/AutumnCli.js"; +import { features, products, rewards } from "tests/global.js"; import { compareMainProduct } from "tests/utils/compare.js"; - +import { getFixedPriceAmount, timeout } from "tests/utils/genUtils.js"; import { advanceClockForInvoice, advanceTestClock, completeCheckoutForm, getDiscount, } from "tests/utils/stripeUtils.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { setupBefore } from "tests/before.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { getPriceForOverage } from "@/internal/products/prices/priceUtils.js"; +import { getOriginalCouponId } from "@/internal/rewards/rewardUtils.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const testCase = "coupon1"; describe( chalk.yellow(`${testCase} -- Testing one-off rollover, apply to all`), () => { - let customerId = "coupon1"; + const customerId = "coupon1"; let stripeCli: Stripe; let customer: Customer; let testClockId: string; let db, org, env; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + let autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let couponAmount = rewards.rolloverAll.discount_config.discount_value; @@ -159,7 +157,7 @@ describe( // CYCLE 2 it("CYCLE 2: should have $0 invoice and correct new coupon amount after 2nd cycle", async () => { await timeout(20000); - let advanceTo = addHours(addMonths(new Date(), 2), 2); + const advanceTo = addHours(addMonths(new Date(), 2), 2); await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/attach/addOn/addOn1.ts b/server/tests/attach/addOn/addOn1.ts index ab8250ae8..16eb67780 100644 --- a/server/tests/attach/addOn/addOn1.ts +++ b/server/tests/attach/addOn/addOn1.ts @@ -1,26 +1,23 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts, replaceItems } from "../utils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; -import { - constructArrearProratedItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expect } from "chai"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts, replaceItems } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -30,7 +27,7 @@ export let pro = constructProduct({ type: "pro", }); -export let addOn = constructRawProduct({ +export const addOn = constructRawProduct({ id: "add_on_1", items: [ constructFeatureItem({ @@ -44,13 +41,13 @@ export let addOn = constructRawProduct({ const testCase = "addOn1"; describe(`${chalk.yellowBright(`${testCase}: Testing free add on, and updating free add on`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -87,7 +84,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free add on, and updating f testClockId = testClockId1!; }); - it("should should attach pro product, then add on product", async function () { + it("should should attach pro product, then add on product", async () => { await attachAndExpectCorrect({ autumn, db, @@ -99,7 +96,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free add on, and updating f }); }); - it("should should attach add on product", async function () { + it("should should attach add on product", async () => { const preview = await autumn.attachPreview({ customer_id: customerId, product_id: addOn.id, @@ -132,7 +129,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free add on, and updating f }), }); - it("should update add on product", async function () { + it("should update add on product", async () => { const preview = await autumn.attachPreview({ customer_id: customerId, product_id: addOn.id, diff --git a/server/tests/attach/addOn/addOn2.test.ts b/server/tests/attach/addOn/addOn2.test.ts index 3ac20052a..8141359a0 100644 --- a/server/tests/attach/addOn/addOn2.test.ts +++ b/server/tests/attach/addOn/addOn2.test.ts @@ -1,24 +1,23 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { addPrefixToProducts } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ type: "pro", items: [], }); @@ -36,8 +35,8 @@ export const addOn = constructRawProduct({ const testCase = "addOn2"; describe(`${chalk.yellowBright(`${testCase}: Testing attach free add on twice (should be treated as one off?)`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -73,7 +72,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach free add on twice (s }); }); - it("should attach pro product and free add on", async function () { + it("should attach pro product and free add on", async () => { await attachAndExpectCorrect({ autumn, customerId, diff --git a/server/tests/attach/basic/basic1.ts b/server/tests/attach/basic/basic1.ts index 556a4b8f9..eb25bf2e8 100644 --- a/server/tests/attach/basic/basic1.ts +++ b/server/tests/attach/basic/basic1.ts @@ -1,20 +1,19 @@ +import { LegacyVersion } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; +import { setupBefore } from "tests/before.js"; +import { AutumnCli } from "tests/cli/AutumnCli.js"; +import { features, products } from "tests/global.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { compareMainProduct } from "tests/utils/compare.js"; +import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { expect } from "chai"; - -import { setupBefore } from "tests/before.js"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { features, products } from "tests/global.js"; -import { compareMainProduct } from "tests/utils/compare.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { APIVersion } from "@autumn/shared"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; const freeProd = constructProduct({ type: "free", @@ -33,8 +32,8 @@ const freeProd = constructProduct({ // UNCOMMENT FROM HERE const testCase = "basic1"; describe(`${chalk.yellowBright("basic1: Testing attach free product")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); let db, org, env; before(async function () { @@ -67,7 +66,7 @@ describe(`${chalk.yellowBright("basic1: Testing attach free product")}`, () => { }); }); - it("should create customer and have default free active", async function () { + it("should create customer and have default free active", async () => { const data = await AutumnCli.getCustomer(customerId); compareMainProduct({ @@ -76,7 +75,7 @@ describe(`${chalk.yellowBright("basic1: Testing attach free product")}`, () => { }); }); - it("should have correct entitlements", async function () { + it("should have correct entitlements", async () => { const expectedEntitlement = products.free.entitlements.metered1; const entitled = (await AutumnCli.entitled( @@ -94,12 +93,12 @@ describe(`${chalk.yellowBright("basic1: Testing attach free product")}`, () => { expect(metered1Balance.unlimited).to.not.exist; }); - it("should have correct boolean1 entitlement", async function () { + it("should have correct boolean1 entitlement", async () => { const entitled = await AutumnCli.entitled(customerId, features.boolean1.id); expect(entitled!.allowed).to.be.false; }); - it("should attach free (with $0 price) and force checkout and succeed", async function () { + it("should attach free (with $0 price) and force checkout and succeed", async () => { await autumn.attach({ customer_id: customerId, product_id: freeProd.id, diff --git a/server/tests/attach/checkout/checkout3.ts b/server/tests/attach/checkout/checkout3.ts index efe3a21ad..c47b55289 100644 --- a/server/tests/attach/checkout/checkout3.ts +++ b/server/tests/attach/checkout/checkout3.ts @@ -1,24 +1,21 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { - constructArrearProratedItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import { timeout } from "@/utils/genUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -41,12 +38,12 @@ export const oneOff = constructProduct({ const testCase = "checkout3"; describe(`${chalk.yellowBright(`${testCase}: Testing multi attach checkout, pro + one off`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -83,7 +80,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing multi attach checkout, pro testClockId = testClockId1!; }); - it("should attach pro and one off product", async function () { + it("should attach pro and one off product", async () => { const res = await autumn.attach({ customer_id: customerId, product_ids: [pro.id, oneOff.id], diff --git a/server/tests/attach/checkout/checkout5.ts b/server/tests/attach/checkout/checkout5.ts index 2ffd5c22e..46f523565 100644 --- a/server/tests/attach/checkout/checkout5.ts +++ b/server/tests/attach/checkout/checkout5.ts @@ -1,24 +1,22 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; -import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -30,12 +28,12 @@ export let pro = constructProduct({ const testCase = "checkout5"; describe(`${chalk.yellowBright(`${testCase}: Testing invoice checkout, no product till paid`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -72,7 +70,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing invoice checkout, no produc testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { const res = await autumn.attach({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/attach/checkout/checkout6.ts b/server/tests/attach/checkout/checkout6.ts index b484e260f..41e9985ae 100644 --- a/server/tests/attach/checkout/checkout6.ts +++ b/server/tests/attach/checkout/checkout6.ts @@ -1,24 +1,23 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -28,7 +27,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -40,12 +39,12 @@ export let premium = constructProduct({ const testCase = "checkout6"; describe(`${chalk.yellowBright(`${testCase}: Testing invoice checkout via checkout endpoint`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -82,7 +81,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing invoice checkout via checko testClockId = testClockId1!; }); - it("should attach pro product via invoice checkout", async function () { + it("should attach pro product via invoice checkout", async () => { const res = await autumn.checkout({ customer_id: customerId, product_id: pro.id, @@ -108,7 +107,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing invoice checkout via checko }); }); - it("should have no URL returned if try to attach premium (with invoice true)", async function () { + it("should have no URL returned if try to attach premium (with invoice true)", async () => { await expectAutumnError({ func: async () => { await autumn.attach({ @@ -128,7 +127,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing invoice checkout via checko expect(res.url).to.not.exist; }); - it("should attach premium product via invoice enable immediately", async function () { + it("should attach premium product via invoice enable immediately", async () => { const res = await autumn.attach({ customer_id: customerId, product_id: premium.id, diff --git a/server/tests/attach/checkout/checkout7.ts b/server/tests/attach/checkout/checkout7.ts index e91038933..14a2df46c 100644 --- a/server/tests/attach/checkout/checkout7.ts +++ b/server/tests/attach/checkout/checkout7.ts @@ -1,28 +1,27 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { - constructProduct, - constructRawProduct, -} from "@/utils/scriptUtils/createTestProducts.js"; +import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; -import { expect } from "chai"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { + constructProduct, + constructRawProduct, +} from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -32,7 +31,7 @@ export let pro = constructProduct({ type: "pro", }); -export let addOn = constructRawProduct({ +export const addOn = constructRawProduct({ id: "addOn", items: [ constructPrepaidItem({ @@ -46,12 +45,12 @@ export let addOn = constructRawProduct({ const testCase = "checkout7"; describe(`${chalk.yellowBright(`${testCase}: Testing invoice checkout with one off product`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -88,7 +87,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing invoice checkout with one o testClockId = testClockId1!; }); - it("should attach pro product, then add on product via invoice checkout", async function () { + it("should attach pro product, then add on product via invoice checkout", async () => { await autumn.attach({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/attach/downgrade/downgrade1.ts b/server/tests/attach/downgrade/downgrade1.ts index 9e6038838..3a3295582 100644 --- a/server/tests/attach/downgrade/downgrade1.ts +++ b/server/tests/attach/downgrade/downgrade1.ts @@ -1,4 +1,4 @@ -import { APIVersion, type AppEnv, type Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; @@ -30,7 +30,7 @@ const premium = constructProduct({ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade from premium -> pro`)}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; diff --git a/server/tests/attach/downgrade/downgrade2.ts b/server/tests/attach/downgrade/downgrade2.ts index 94c608e4e..511c0a8d3 100644 --- a/server/tests/attach/downgrade/downgrade2.ts +++ b/server/tests/attach/downgrade/downgrade2.ts @@ -1,27 +1,25 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectDowngradeCorrect, expectNextCycleCorrect, } from "tests/utils/expectUtils/expectScheduleUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "downgrade2"; -let free = constructProduct({ +const free = constructProduct({ items: [ constructFeatureItem({ feature_id: TestFeature.Words, @@ -32,19 +30,19 @@ let free = constructProduct({ isDefault: false, }); -let premium = constructProduct({ +const premium = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); describe(`${chalk.yellowBright(`${testCase}: Testing downgrade from premium -> free`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -81,7 +79,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade from premium -> f testClockId = testClockId1!; }); - it("should attach premium product", async function () { + it("should attach premium product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -95,7 +93,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade from premium -> f // let nextCycle = Date.now(); let preview = null; - it("should downgrade to free", async function () { + it("should downgrade to free", async () => { const { preview: preview_ } = await expectDowngradeCorrect({ autumn, customerId, @@ -110,7 +108,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade from premium -> f preview = preview_; }); - it("should have pro attached on next cycle", async function () { + it("should have pro attached on next cycle", async () => { await expectNextCycleCorrect({ preview: preview!, autumn, diff --git a/server/tests/attach/downgrade/downgrade3.ts b/server/tests/attach/downgrade/downgrade3.ts index 228b1b86d..6ea933771 100644 --- a/server/tests/attach/downgrade/downgrade3.ts +++ b/server/tests/attach/downgrade/downgrade3.ts @@ -1,24 +1,28 @@ +import { + type AppEnv, + type Customer, + LegacyVersion, + type Organization, +} from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Customer, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; -import { expectDowngradeCorrect } from "tests/utils/expectUtils/expectScheduleUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { expectDowngradeCorrect } from "tests/utils/expectUtils/expectScheduleUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "downgrade3"; -let free = constructProduct({ +const free = constructProduct({ items: [ constructFeatureItem({ feature_id: TestFeature.Words, @@ -29,25 +33,25 @@ let free = constructProduct({ isDefault: false, }); -let pro = constructProduct({ +const pro = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); -let premium = constructProduct({ +const premium = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: premium -> pro -> free -> pro -> premium`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let customer: Customer; let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -86,7 +90,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: premium -> pro - customer = customer_!; }); - it("should attach premium product", async function () { + it("should attach premium product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -100,7 +104,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: premium -> pro - // let nextCycle = Date.now(); let preview = null; - it("should downgrade to pro", async function () { + it("should downgrade to pro", async () => { const { preview: preview_ } = await expectDowngradeCorrect({ autumn, customerId, @@ -115,7 +119,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: premium -> pro - preview = preview_; }); - it("should downgrade to free", async function () { + it("should downgrade to free", async () => { const { preview: preview_ } = await expectDowngradeCorrect({ autumn, customerId, @@ -130,7 +134,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: premium -> pro - preview = preview_; }); - it("should change downgrade to pro", async function () { + it("should change downgrade to pro", async () => { const { preview: preview_ } = await expectDowngradeCorrect({ autumn, customerId, @@ -143,7 +147,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: premium -> pro - }); }); - it("should renew premium", async function () { + it("should renew premium", async () => { await autumn.attach({ customer_id: customerId, product_id: premium.id, diff --git a/server/tests/attach/downgrade/downgrade4.ts b/server/tests/attach/downgrade/downgrade4.ts index 48b64f815..5b956657a 100644 --- a/server/tests/attach/downgrade/downgrade4.ts +++ b/server/tests/attach/downgrade/downgrade4.ts @@ -1,57 +1,56 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, BillingInterval, - Customer, - Organization, + type Customer, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; - -import { addPrefixToProducts } from "../utils.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectDowngradeCorrect, expectNextCycleCorrect, } from "tests/utils/expectUtils/expectScheduleUtils.js"; import { createProducts } from "tests/utils/productUtils.js"; import { advanceMonths } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; + const testCase = "downgrade4"; -let proQuarter = constructProduct({ +const proQuarter = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", interval: BillingInterval.Quarter, }); -let pro = constructProduct({ +const pro = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); -let premium = constructProduct({ +const premium = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: pro-quarter -> premium -> pro`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let customer: Customer; let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -90,7 +89,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: pro-quarter -> p customer = customer_!; }); - it("should attach pro quarterly product", async function () { + it("should attach pro quarterly product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -102,7 +101,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: pro-quarter -> p }); }); - it("should downgrade to premium", async function () { + it("should downgrade to premium", async () => { await expectDowngradeCorrect({ autumn, customerId, @@ -117,7 +116,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: pro-quarter -> p let preview = null; - it("should downgrade to pro", async function () { + it("should downgrade to pro", async () => { const { preview: preview_ } = await expectDowngradeCorrect({ autumn, customerId, @@ -132,7 +131,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing downgrade: pro-quarter -> p preview = preview_; }); - it("should have correct invoice after cycle", async function () { + it("should have correct invoice after cycle", async () => { await advanceMonths({ stripeCli, testClockId, numberOfMonths: 3 }); await timeout(10000); diff --git a/server/tests/attach/entities/entity1.ts b/server/tests/attach/entities/entity1.ts index 923b4c8c0..6f3164213 100644 --- a/server/tests/attach/entities/entity1.ts +++ b/server/tests/attach/entities/entity1.ts @@ -1,4 +1,4 @@ -import { APIVersion, type AppEnv, type Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; @@ -27,7 +27,7 @@ const pro = constructProduct({ describe(`${chalk.yellowBright(`attach/${testCase}: Testing attach to entity via checkout`)}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; diff --git a/server/tests/attach/free/free1.ts b/server/tests/attach/free/free1.ts index e171b1d69..c736eb0ae 100644 --- a/server/tests/attach/free/free1.ts +++ b/server/tests/attach/free/free1.ts @@ -1,37 +1,37 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CreateFreeTrialSchema, CusProductStatus, FreeTrialDuration, - Organization, + LegacyVersion, + type Organization, organizations, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { addDays } from "date-fns"; import { expect } from "chai"; +import chalk from "chalk"; +import { addDays } from "date-fns"; import { eq } from "drizzle-orm"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CacheManager } from "@/external/caching/CacheManager.js"; import { clearOrgCache } from "@/internal/orgs/orgUtils/clearOrgCache.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "free1"; -let trial1 = CreateFreeTrialSchema.parse({ +const trial1 = CreateFreeTrialSchema.parse({ length: 7, duration: FreeTrialDuration.Day, }); -export let free = constructProduct({ +export const free = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -43,7 +43,7 @@ export let free = constructProduct({ type: "free", id: "enterprise_trial", }); -export let addOn = constructProduct({ +export const addOn = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Credits, @@ -57,14 +57,14 @@ export let addOn = constructProduct({ }); 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 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); - let numUsers = 0; + const curUnix = new Date().getTime(); + const numUsers = 0; before(async function () { await setupBefore(this); @@ -117,19 +117,19 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and }); const approximateDiff = 1000 * 60 * 30; // 30 minutes - it("should attach free product with trial", async function () { - let attachPreview = await autumn.attachPreview({ + it("should attach free product with trial", async () => { + const attachPreview = await autumn.attachPreview({ customer_id: customerId, product_id: free.id, }); - let attach = await autumn.attach({ + const 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); + const customer = await autumn.customers.get(customerId); + const freeProduct = customer.products.find((p) => p.id === free.id); expect(freeProduct).to.exist; expect(freeProduct?.status).to.equal(CusProductStatus.Trialing); @@ -144,23 +144,23 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and duration: FreeTrialDuration.Day, }); - it("should update free product's trial end date", async function () { - let attachPreview = await autumn.attachPreview({ + it("should update free product's trial end date", async () => { + const attachPreview = await autumn.attachPreview({ customer_id: customerId, product_id: free.id, free_trial: trial2, is_custom: true, }); - let attach = await autumn.attach({ + const 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); + const customer = await autumn.customers.get(customerId); + const freeProduct = customer.products.find((p) => p.id === free.id); expect(freeProduct?.status).to.equal(CusProductStatus.Trialing); expect(freeProduct?.current_period_end).to.approximately( @@ -169,20 +169,20 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and ); }); - it("should attach add on product", async function () { - let attachPreview = await autumn.attachPreview({ + it("should attach add on product", async () => { + const attachPreview = await autumn.attachPreview({ customer_id: customerId, product_id: addOn.id, }); - let attach = await autumn.attach({ + const 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); + const customer = await autumn.customers.get(customerId); + const addOnProduct = customer.products.find((p) => p.id === addOn.id); + const freeProduct = customer.products.find((p) => p.id === free.id); expect(addOnProduct).to.exist; expect(addOnProduct?.status).to.equal(CusProductStatus.Active); diff --git a/server/tests/attach/free/free2.ts b/server/tests/attach/free/free2.ts index d0e87fdc8..e85805233 100644 --- a/server/tests/attach/free/free2.ts +++ b/server/tests/attach/free/free2.ts @@ -1,24 +1,23 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, BillingInterval, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; - -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; export const free = constructProduct({ items: [ @@ -46,14 +45,14 @@ 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 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); - let numUsers = 0; + const curUnix = new Date().getTime(); + const numUsers = 0; before(async function () { await setupBefore(this); @@ -90,7 +89,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and }); const approximateDiff = 1000 * 60 * 30; // 30 minutes - it("should attach free product", async function () { + it("should attach free product", async () => { await autumn.attach({ customer_id: customerId, product_id: free.id, @@ -110,7 +109,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and interval: BillingInterval.Month, }), ]; - it("should update free product with price", async function () { + it("should update free product with price", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -119,7 +118,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and org, env, attachParams: { - // @ts-ignore + // @ts-expect-error is_custom: true, items: customItems, }, diff --git a/server/tests/attach/newVersion/newVersion1.ts b/server/tests/attach/newVersion/newVersion1.ts index 6dd4de492..711e28d67 100644 --- a/server/tests/attach/newVersion/newVersion1.ts +++ b/server/tests/attach/newVersion/newVersion1.ts @@ -1,32 +1,31 @@ -import { expect } from "chai"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, BillingInterval, - Organization, - ProductV2, + LegacyVersion, + type Organization, + type ProductV2, } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { replaceItems } from "../utils.js"; -import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; -import runUpdateEntsTest from "../updateEnts/expectUpdateEnts.js"; -import { timeout } from "@/utils/genUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { addHours, addMonths, addWeeks } from "date-fns"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -export let pro = constructProduct({ +import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import runUpdateEntsTest from "../updateEnts/expectUpdateEnts.js"; +import { addPrefixToProducts, replaceItems } from "../utils.js"; +export const pro = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); @@ -34,13 +33,13 @@ export let pro = constructProduct({ const testCase = "newVersion1"; describe(`${chalk.yellowBright(`${testCase}: Testing attach with new version`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -77,7 +76,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with new version`)}` testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -89,9 +88,9 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with new version`)}` }); }); - let usage = 50000; + const usage = 50000; let newPro: ProductV2; - it("should update product to new version", async function () { + it("should update product to new version", async () => { newPro = structuredClone(pro); let newItems = replaceItems({ items: pro.items, @@ -119,7 +118,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with new version`)}` }); }); - it("should attach pro v2", async function () { + it("should attach pro v2", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -152,7 +151,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with new version`)}` }); }); - it("should have correct invoice total on next cycle", async function () { + it("should have correct invoice total on next cycle", async () => { const invoiceTotal = await getExpectedInvoiceTotal({ org, env, diff --git a/server/tests/attach/newVersion/newVersion2.ts b/server/tests/attach/newVersion/newVersion2.ts index 08deff395..3ae80e98e 100644 --- a/server/tests/attach/newVersion/newVersion2.ts +++ b/server/tests/attach/newVersion/newVersion2.ts @@ -1,7 +1,7 @@ import { - APIVersion, type AppEnv, BillingInterval, + LegacyVersion, type Organization, type ProductV2, } from "@autumn/shared"; @@ -30,7 +30,7 @@ const testCase = "newVersion2"; describe(`${chalk.yellowBright(`${testCase}: Testing attach new version for trial product`)}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; diff --git a/server/tests/attach/others/others1.ts b/server/tests/attach/others/others1.ts index 67eaf5388..059295f26 100644 --- a/server/tests/attach/others/others1.ts +++ b/server/tests/attach/others/others1.ts @@ -1,47 +1,47 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectDowngradeCorrect, expectNextCycleCorrect, } from "tests/utils/expectUtils/expectScheduleUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "others1"; -export let free = constructProduct({ +export const free = constructProduct({ items: [], type: "free", isDefault: false, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [], type: "pro", trial: true, }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [], type: "premium", trial: true, }); describe(`${chalk.yellowBright(`${testCase}: Testing trials: pro with trial -> premium with trial -> free`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -78,7 +78,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing trials: pro with trial -> p testClockId = testClockId1!; }); - it("should attach pro product (with trial)", async function () { + it("should attach pro product (with trial)", async () => { await attachAndExpectCorrect({ autumn, stripeCli, @@ -90,7 +90,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing trials: pro with trial -> p }); }); - it("should attach premium product (with trial)", async function () { + it("should attach premium product (with trial)", async () => { await attachAndExpectCorrect({ autumn, stripeCli, @@ -102,7 +102,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing trials: pro with trial -> p }); }); - it("should attach free product at the end of the trial", async function () { + it("should attach free product at the end of the trial", async () => { const { preview } = await expectDowngradeCorrect({ autumn, stripeCli, diff --git a/server/tests/attach/others/others2.ts b/server/tests/attach/others/others2.ts index 4ad607286..16f2aa0df 100644 --- a/server/tests/attach/others/others2.ts +++ b/server/tests/attach/others/others2.ts @@ -1,23 +1,23 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +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 { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "others2"; -export let oneOff = constructProduct({ +export const oneOff = constructProduct({ type: "one_off", items: [ constructPrepaidItem({ @@ -30,13 +30,13 @@ export let oneOff = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing one-off`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -80,7 +80,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing one-off`)}`, () => { }, ]; - it("should attach one-off product", async function () { + it("should attach one-off product", async () => { await attachAndExpectCorrect({ autumn, stripeCli, @@ -99,7 +99,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing one-off`)}`, () => { quantity: 750, }, ]; - it("should be able to attach again", async function () { + it("should be able to attach again", async () => { await attachAndExpectCorrect({ autumn, stripeCli, @@ -120,8 +120,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing one-off`)}`, () => { }); // Payment failure - it("should handle payment failure", async function () { - let customer = await CusService.get({ + it("should handle payment failure", async () => { + const customer = await CusService.get({ db, idOrInternalId: customerId, orgId: org.id, diff --git a/server/tests/attach/others/others3.ts b/server/tests/attach/others/others3.ts index cd67e0ef1..257f0322d 100644 --- a/server/tests/attach/others/others3.ts +++ b/server/tests/attach/others/others3.ts @@ -1,32 +1,32 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { expect } from "chai"; +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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "others3"; -export let pro = constructProduct({ +export const pro = constructProduct({ type: "pro", items: [], }); describe(`${chalk.yellowBright(`${testCase}: Testing attach payment failure`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -63,8 +63,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach payment failure`)}`, }); // Payment failure - it("should handle payment failure", async function () { - let customer = await CusService.get({ + it("should handle payment failure", async () => { + const customer = await CusService.get({ db, idOrInternalId: customerId, orgId: org.id, diff --git a/server/tests/attach/others/others6.ts b/server/tests/attach/others/others6.ts index c16b6fe4a..86fc70d14 100644 --- a/server/tests/attach/others/others6.ts +++ b/server/tests/attach/others/others6.ts @@ -1,19 +1,19 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; import { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { addPrefixToProducts } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); @@ -21,8 +21,8 @@ export let pro = constructProduct({ const testCase = "others6"; describe(`${chalk.yellowBright(`${testCase}: Testing attach with customer ID and entity ID null`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -37,7 +37,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with customer ID and stripeCli = this.stripeCli; - let customer = await CusService.getByEmail({ + const customer = await CusService.getByEmail({ db, orgId: org.id, env, @@ -64,10 +64,10 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with customer ID and let internalCustomerId = ""; let internalEntityId = ""; - let entityId = "1"; - it("should attach create customer with no ID", async function () { - let customer = await autumn.customers.create({ - // @ts-ignore + const entityId = "1"; + it("should attach create customer with no ID", async () => { + const customer = await autumn.customers.create({ + // @ts-expect-error id: null, email: `${customerId}@test.com`, name: customerId, @@ -77,8 +77,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with customer ID and internalCustomerId = customer.autumn_id; - let data = await autumn.entities.create(internalCustomerId, { - // @ts-ignore + const data = await autumn.entities.create(internalCustomerId, { + // @ts-expect-error id: null, feature_id: TestFeature.Users, }); @@ -88,7 +88,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with customer ID and expect(internalEntityId, "Entity ID should exist").to.exist; }); - it("should be able to attach pro product, invoice only", async function () { + it("should be able to attach pro product, invoice only", async () => { await autumn.attach({ customer_id: internalCustomerId, entity_id: internalEntityId, @@ -108,15 +108,15 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with customer ID and expect(customer.invoices[0].status).to.equal("draft"); }); - it("should create customer with ID, and attach pro product", async function () { - let customer = await autumn.customers.create({ + it("should create customer with ID, and attach pro product", async () => { + const customer = await autumn.customers.create({ id: customerId, email: `${customerId}@test.com`, }); expect(customer.autumn_id).to.equal(internalCustomerId); - let entity = await autumn.entities.create(customer.autumn_id, { + const entity = await autumn.entities.create(customer.autumn_id, { id: entityId, feature_id: TestFeature.Users, }); diff --git a/server/tests/attach/others/others7.ts b/server/tests/attach/others/others7.ts index 6647bf13b..881110ac7 100644 --- a/server/tests/attach/others/others7.ts +++ b/server/tests/attach/others/others7.ts @@ -1,20 +1,20 @@ -import chalk from "chalk"; -import Stripe from "stripe"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; import { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", trial: true, @@ -23,8 +23,8 @@ export let pro = constructProduct({ const testCase = "others7"; describe(`${chalk.yellowBright(`${testCase}: Testing attach with free_trial=False`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -60,7 +60,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with free_trial=Fals }); }); - it("should attach pro product with free_trial=False", async function () { + it("should attach pro product with free_trial=False", async () => { await autumn.attach({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/attach/others/others8.ts b/server/tests/attach/others/others8.ts index a735d1571..f33d9b75a 100644 --- a/server/tests/attach/others/others8.ts +++ b/server/tests/attach/others/others8.ts @@ -1,24 +1,22 @@ -import chalk from "chalk"; -import Stripe from "stripe"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { - constructArrearItem, constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import { addPrefixToProducts } from "../utils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Words, @@ -37,8 +35,8 @@ export let pro = constructProduct({ const testCase = "others8"; describe(`${chalk.yellowBright(`${testCase}: Testing annual pro with one off prepaid`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -74,7 +72,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing annual pro with one off pre }); }); - it("should attach annual pro product with one off prepaid", async function () { + it("should attach annual pro product with one off prepaid", async () => { const options = [ { feature_id: TestFeature.Users, diff --git a/server/tests/attach/others/others9.ts b/server/tests/attach/others/others9.ts index c542e7408..14edf188c 100644 --- a/server/tests/attach/others/others9.ts +++ b/server/tests/attach/others/others9.ts @@ -1,19 +1,19 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; -export let free = constructProduct({ +export const free = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Words, @@ -31,8 +31,8 @@ export let free = constructProduct({ const testCase = "others9"; describe(`${chalk.yellowBright(`${testCase}: Testing attach free product again`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -68,7 +68,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach free product again`) }); }); - it("should attach free product, then try again and hit error", async function () { + it("should attach free product, then try again and hit error", async () => { await attachAndExpectCorrect({ autumn, customerId, diff --git a/server/tests/attach/prepaid/prepaid1.ts b/server/tests/attach/prepaid/prepaid1.ts index f233f00f8..ceb714e29 100644 --- a/server/tests/attach/prepaid/prepaid1.ts +++ b/server/tests/attach/prepaid/prepaid1.ts @@ -1,7 +1,7 @@ import { - APIVersion, type AppEnv, type Customer, + LegacyVersion, OnDecrease, OnIncrease, type Organization, @@ -45,7 +45,7 @@ export const pro = constructProduct({ describe(`${chalk.yellowBright(`attach/${testCase}: update quantity, no proration downgrade, single use`)}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; diff --git a/server/tests/attach/prepaid/prepaid2.ts b/server/tests/attach/prepaid/prepaid2.ts index c08875124..6f1d241a6 100644 --- a/server/tests/attach/prepaid/prepaid2.ts +++ b/server/tests/attach/prepaid/prepaid2.ts @@ -1,29 +1,29 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { addWeeks } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; -import { addWeeks } from "date-fns"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "prepaid2"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Messages, @@ -40,13 +40,13 @@ export let pro = constructProduct({ }); describe(`${chalk.yellowBright(`attach/${testCase}: upgrade quantity, prorate immediately, single use`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -89,7 +89,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: upgrade quantity, prorate im }, ]; - it("should attach pro product to customer", async function () { + it("should attach pro product to customer", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -101,14 +101,14 @@ describe(`${chalk.yellowBright(`attach/${testCase}: upgrade quantity, prorate im options, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, product: pro, }); }); - it("should increase advance test clock, increase quantity to 400 and have correct sub item quantity + invoice..", async function () { + it("should increase advance test clock, increase quantity to 400 and have correct sub item quantity + invoice..", async () => { const usage = Math.floor(Math.random() * 220); await autumn.track({ customer_id: customerId, diff --git a/server/tests/attach/prepaid/prepaid3.ts b/server/tests/attach/prepaid/prepaid3.ts index 7f619d20c..d14b645de 100644 --- a/server/tests/attach/prepaid/prepaid3.ts +++ b/server/tests/attach/prepaid/prepaid3.ts @@ -1,31 +1,31 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; -import { addHours, addMonths, addWeeks } from "date-fns"; -import { expect } from "chai"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "prepaid3"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Messages, @@ -42,13 +42,13 @@ export let pro = constructProduct({ }); describe(`${chalk.yellowBright(`attach/${testCase}: upgrade quantity, prorate next cycle, single use`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -91,7 +91,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: upgrade quantity, prorate ne }, ]; - it("should attach pro product to customer", async function () { + it("should attach pro product to customer", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -103,14 +103,14 @@ describe(`${chalk.yellowBright(`attach/${testCase}: upgrade quantity, prorate ne options, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, product: pro, }); }); - it("should increase advance test clock, increase quantity to 400", async function () { + it("should increase advance test clock, increase quantity to 400", async () => { const usage = Math.floor(Math.random() * 220); await autumn.track({ customer_id: customerId, @@ -144,7 +144,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: upgrade quantity, prorate ne expect(customer.invoices.length).to.equal(1); }); - it("should advance test clock to end of cycle and have correct invoice", async function () { + it("should advance test clock to end of cycle and have correct invoice", async () => { await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/attach/prepaid/prepaid4.ts b/server/tests/attach/prepaid/prepaid4.ts index 04846b823..9a3ad00c6 100644 --- a/server/tests/attach/prepaid/prepaid4.ts +++ b/server/tests/attach/prepaid/prepaid4.ts @@ -1,32 +1,32 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; -import { expect } from "chai"; -import { addHours, addMonths } from "date-fns"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "prepaid4"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Messages, @@ -43,13 +43,13 @@ export let pro = constructProduct({ }); describe(`${chalk.yellowBright(`attach/${testCase}: Testing prepaid reset`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -92,7 +92,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: Testing prepaid reset`)}`, ( }, ]; - it("should attach pro product to customer", async function () { + it("should attach pro product to customer", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -104,7 +104,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: Testing prepaid reset`)}`, ( options, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, product: pro, @@ -113,7 +113,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: Testing prepaid reset`)}`, ( // return; const usage = 100; - it("should track usage for prepaid and have correct balance", async function () { + it("should track usage for prepaid and have correct balance", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -129,7 +129,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: Testing prepaid reset`)}`, ( ); }); - it("should advance clock to next cycle and have correct balance", async function () { + it("should advance clock to next cycle and have correct balance", async () => { await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/attach/prepaid/prepaid5.ts b/server/tests/attach/prepaid/prepaid5.ts index ec538d738..4c73347e5 100644 --- a/server/tests/attach/prepaid/prepaid5.ts +++ b/server/tests/attach/prepaid/prepaid5.ts @@ -1,38 +1,31 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, - Customer, + type AppEnv, + type Customer, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; -import { addHours, addMonths, addWeeks } from "date-fns"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { expect } from "chai"; -import { getMainCusProduct } from "@/internal/customers/cusProducts/cusProductUtils.js"; -import { CusService } from "@/internal/customers/CusService.js"; -import { CusProductService } from "@/internal/customers/cusProducts/CusProductService.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "prepaid5"; -export let prepaidAddOn = constructProduct({ +export const prepaidAddOn = constructProduct({ type: "pro", excludeBase: true, id: "topup", @@ -50,7 +43,7 @@ export let prepaidAddOn = constructProduct({ isAddOn: true, }); -export let pro = constructProduct({ +export const pro = constructProduct({ type: "pro", items: [ constructFeatureItem({ @@ -59,7 +52,7 @@ export let pro = constructProduct({ }), ], }); -export let premium = constructProduct({ +export const premium = constructProduct({ type: "premium", items: [ constructFeatureItem({ @@ -70,13 +63,13 @@ export let premium = constructProduct({ }); describe(`${chalk.yellowBright(`attach/${testCase}: prepaid add on, with entities`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); let customer: Customer; before(async function () { @@ -130,7 +123,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: prepaid add on, with entitie }, ]; - it("should attach pro product to entity1", async function () { + it("should attach pro product to entity1", async () => { await autumn.entities.create(customerId, entities); await attachAndExpectCorrect({ @@ -165,7 +158,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: prepaid add on, with entitie }); const oldEntity2Quantity = 300; - it("should advance test clock and attach top up to entity2", async function () { + it("should advance test clock and attach top up to entity2", async () => { // await advanceTestClock({ // stripeCli, // testClockId, @@ -205,7 +198,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: prepaid add on, with entitie }); }); - it("should increase prepaid add on quantity for entity1", async function () { + it("should increase prepaid add on quantity for entity1", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -228,7 +221,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: prepaid add on, with entitie }); const newEntity2Quantity = 200; - it("should decrease prepaid add on quantity for entity2", async function () { + it("should decrease prepaid add on quantity for entity2", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -251,7 +244,9 @@ describe(`${chalk.yellowBright(`attach/${testCase}: prepaid add on, with entitie const entity2 = await autumn.entities.get(customerId, entity2Id); expect(entity2.invoices.length).to.equal(2); - let creditProd = entity2.products.find((p: any) => p.id == prepaidAddOn.id); + const creditProd = entity2.products.find( + (p: any) => p.id == prepaidAddOn.id, + ); expect(creditProd).to.exist; const messagesItem = creditProd!.items.find( (i: any) => i.feature_id == TestFeature.Messages, diff --git a/server/tests/attach/prepaid/prepaid6.ts b/server/tests/attach/prepaid/prepaid6.ts index aa4b0e999..cf50e6202 100644 --- a/server/tests/attach/prepaid/prepaid6.ts +++ b/server/tests/attach/prepaid/prepaid6.ts @@ -1,30 +1,29 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, - Customer, + type AppEnv, + type Customer, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; -import { addHours, addMonths } from "date-fns"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { expect } from "chai"; -import { getMainCusProduct } from "@/internal/customers/cusProducts/cusProductUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; +import { addPrefixToProducts } from "../utils.js"; const userItem = constructPrepaidItem({ featureId: TestFeature.Users, @@ -36,7 +35,7 @@ const userItem = constructPrepaidItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], excludeBase: true, type: "pro", @@ -44,13 +43,13 @@ export let pro = constructProduct({ const testCase = "prepaid6"; describe(`${chalk.yellowBright(`attach/${testCase}: update quantity, no proration downgrade, cont use`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); let customer: Customer; before(async function () { @@ -96,7 +95,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: update quantity, no proratio ]; const originalQuantity = 4; - it("should attach pro product to customer", async function () { + it("should attach pro product to customer", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -108,7 +107,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: update quantity, no proratio options, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, product: pro, @@ -117,7 +116,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: update quantity, no proratio const usage = 3; const newQuantity = 3; - it("should use 3 users, then downgrade to 3 seats", async function () { + it("should use 3 users, then downgrade to 3 seats", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Users, @@ -148,7 +147,7 @@ describe(`${chalk.yellowBright(`attach/${testCase}: update quantity, no proratio ], }); }); - it("should have correct balance (0) next cycle", async function () { + it("should have correct balance (0) next cycle", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -162,8 +161,8 @@ describe(`${chalk.yellowBright(`attach/${testCase}: update quantity, no proratio const autumnCus = await autumn.customers.get(customerId); expect(autumnCus.features[TestFeature.Users].balance).to.equal(0); - let product = autumnCus.products.find((p: any) => p.id == pro.id) as any; - let userItem = product.items.find( + const product = autumnCus.products.find((p: any) => p.id == pro.id) as any; + const userItem = product.items.find( (i: any) => i.feature_id == TestFeature.Users, ); diff --git a/server/tests/attach/prepaid/prepaid7.ts b/server/tests/attach/prepaid/prepaid7.ts index f09ce9dcd..651bedf84 100644 --- a/server/tests/attach/prepaid/prepaid7.ts +++ b/server/tests/attach/prepaid/prepaid7.ts @@ -1,7 +1,7 @@ // import { AutumnInt } from "@/external/autumn/autumnCli.js"; // import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // import { -// APIVersion, +// LegacyVersion, // AppEnv, // Customer, // OnDecrease, @@ -56,7 +56,7 @@ // describe(`${chalk.yellowBright(`attach/${testCase}: prepaid add on, with entities`)}`, () => { // let customerId = testCase; -// let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); +// let autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); // let testClockId: string; // let db: DrizzleCli, org: Organization, env: AppEnv; // let stripeCli: Stripe; diff --git a/server/tests/attach/renew/renew1.ts b/server/tests/attach/renew/renew1.ts index 6539aa695..d29b9fc89 100644 --- a/server/tests/attach/renew/renew1.ts +++ b/server/tests/attach/renew/renew1.ts @@ -1,22 +1,27 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, AttachBranch, Organization } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { + type AppEnv, + AttachBranch, + LegacyVersion, + type Organization, +} from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "renew1"; -export let free = constructProduct({ +export const free = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -27,7 +32,7 @@ export let free = constructProduct({ type: "free", }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Credits, @@ -39,8 +44,8 @@ export let pro = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing renew pro, force checkout`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -76,7 +81,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing renew pro, force checkout`) }); }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -88,14 +93,14 @@ describe(`${chalk.yellowBright(`${testCase}: Testing renew pro, force checkout`) }); }); - it("should attach free, then pro with force checkout and renew", async function () { + it("should attach free, then pro with force checkout and renew", async () => { await autumn.attach({ customer_id: customerId, product_id: free.id, }); // 1. Get attach preview - let attachPreview = await autumn.attachPreview({ + const attachPreview = await autumn.attachPreview({ customer_id: customerId, product_id: pro.id, }); @@ -108,7 +113,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing renew pro, force checkout`) force_checkout: true, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, diff --git a/server/tests/attach/updateEnts/expectUpdateEnts.ts b/server/tests/attach/updateEnts/expectUpdateEnts.ts index c86f19f9d..d5fb5f2ef 100644 --- a/server/tests/attach/updateEnts/expectUpdateEnts.ts +++ b/server/tests/attach/updateEnts/expectUpdateEnts.ts @@ -1,21 +1,20 @@ -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { - APIVersion, - AppEnv, + type AppEnv, AttachBranch, - Organization, - ProductItem, - ProductV2, + type Organization, + type ProductItem, + type ProductV2, } from "@autumn/shared"; import { expect } from "chai"; -import Stripe from "stripe"; +import type Stripe from "stripe"; import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; import { expectSubItemsCorrect, getSubsFromCusId, } from "tests/utils/expectUtils/expectSubUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import type { AutumnInt } from "@/external/autumn/autumnCli.js"; const runUpdateEntsTest = async ({ autumn, @@ -87,10 +86,10 @@ const runUpdateEntsTest = async ({ env, }); - 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 invoicesBefore = subsBefore.map((sub) => sub.latest_invoice); + const invoicesAfter = subsAfter.map((sub) => sub.latest_invoice); + const subIdsBefore = subsBefore.map((sub) => sub.id); + const subIdsAfter = subsAfter.map((sub) => sub.id); // let periodEndsBefore = subsBefore.map((sub) => sub.current_period_end); // let periodEndsAfter = subsAfter.map((sub) => sub.current_period_end); diff --git a/server/tests/attach/updateEnts/updateEnts1.ts b/server/tests/attach/updateEnts/updateEnts1.ts index be8360071..c4d037394 100644 --- a/server/tests/attach/updateEnts/updateEnts1.ts +++ b/server/tests/attach/updateEnts/updateEnts1.ts @@ -1,27 +1,27 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts, replaceItems } from "../utils.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addHours, addMonths } from "date-fns"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import runUpdateEntsTest from "./expectUpdateEnts.js"; -import { timeout } from "@/utils/genUtils.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts, replaceItems } from "../utils.js"; +import runUpdateEntsTest from "./expectUpdateEnts.js"; const testCase = "updateEnts1"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructArrearItem({ featureId: TestFeature.Words, @@ -32,14 +32,14 @@ export let pro = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing included usage)`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); - let numUsers = 0; + const curUnix = new Date().getTime(); + const numUsers = 0; before(async function () { await setupBefore(this); @@ -76,7 +76,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing inclu testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -99,10 +99,10 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing inclu newItem, }); - let usage = 50000; - let overage = 50000 - (newItem.included_usage as number); + const usage = 50000; + const overage = 50000 - (newItem.included_usage as number); - it("should update overage item to have new included usage", async function () { + it("should update overage item to have new included usage", async () => { const customProduct = { ...pro, items: customItems, @@ -135,7 +135,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing inclu }); return; - it("should have correct invoice next cycle", async function () { + it("should have correct invoice next cycle", async () => { const invoiceTotal = await getExpectedInvoiceTotal({ org, env, diff --git a/server/tests/attach/updateEnts/updateEnts2.ts b/server/tests/attach/updateEnts/updateEnts2.ts index b62007d41..daca61d5c 100644 --- a/server/tests/attach/updateEnts/updateEnts2.ts +++ b/server/tests/attach/updateEnts/updateEnts2.ts @@ -1,27 +1,27 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts, replaceItems } from "../utils.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addHours, addMonths, addWeeks } from "date-fns"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import { addHours, addMonths, addWeeks } from "date-fns"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import runUpdateEntsTest from "./expectUpdateEnts.js"; -import { timeout } from "@/utils/genUtils.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts, replaceItems } from "../utils.js"; +import runUpdateEntsTest from "./expectUpdateEnts.js"; const testCase = "updateEnts2"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructArrearItem({ featureId: TestFeature.Words, @@ -45,14 +45,14 @@ export let pro = constructProduct({ */ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing included usage) for annual plan`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); - let numUsers = 0; + const curUnix = new Date().getTime(); + const numUsers = 0; before(async function () { await setupBefore(this); @@ -88,7 +88,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing inclu testClockId = testClockId1!; }); - it("should attach pro annual product", async function () { + it("should attach pro annual product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -111,9 +111,9 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing inclu newItem, }); - let usage = 1200500; + const usage = 1200500; - it("should attach custom pro product", async function () { + it("should attach custom pro product", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -152,7 +152,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing inclu }); }); - it("should have correct invoice usage next cycle", async function () { + it("should have correct invoice usage next cycle", async () => { const invoiceTotal = await getExpectedInvoiceTotal({ org, env, diff --git a/server/tests/attach/updateEnts/updateEnts3.ts b/server/tests/attach/updateEnts/updateEnts3.ts index 34b338ec5..b152a7a47 100644 --- a/server/tests/attach/updateEnts/updateEnts3.ts +++ b/server/tests/attach/updateEnts/updateEnts3.ts @@ -1,25 +1,24 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import runUpdateEntsTest from "./expectUpdateEnts.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts, replaceItems } from "../utils.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { addWeeks } from "date-fns"; -import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts, replaceItems } from "../utils.js"; +import runUpdateEntsTest from "./expectUpdateEnts.js"; const testCase = "updateEnts3"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructArrearItem({ featureId: TestFeature.Words, @@ -43,13 +42,13 @@ export let pro = constructProduct({ */ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing feature items)`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -85,7 +84,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing featu testClockId = testClockId1!; }); - it("should attach pro annual product", async function () { + it("should attach pro annual product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -106,7 +105,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing featu const customItems = [...pro.items, newFeatureItem]; - it("should attach custom pro product with new feature item", async function () { + it("should attach custom pro product with new feature item", async () => { const customProduct = { ...pro, items: customItems, @@ -143,8 +142,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing featu }); }); - it("should attach custom pro product with updated feature item", async function () { - let customItems2 = replaceItems({ + it("should attach custom pro product with updated feature item", async () => { + const customItems2 = replaceItems({ items: customItems, featureId: TestFeature.Messages, newItem: constructFeatureItem({ @@ -176,7 +175,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing featu }); }); - it("should attach custom pro product with removed feature item", async function () { + it("should attach custom pro product with removed feature item", async () => { const customItems2 = customItems.filter( (item) => item.feature_id != TestFeature.Messages, ); diff --git a/server/tests/attach/updateEnts/updateEnts4.ts b/server/tests/attach/updateEnts/updateEnts4.ts index 9077918e7..8f77e158c 100644 --- a/server/tests/attach/updateEnts/updateEnts4.ts +++ b/server/tests/attach/updateEnts/updateEnts4.ts @@ -1,30 +1,29 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, AttachBranch, BillingInterval, - Organization, - ProductItemInterval, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { expect } from "chai"; -import { nullish } from "@/utils/genUtils.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; +import { nullish } from "@/utils/genUtils.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "updateEnts4"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructArrearItem({ featureId: TestFeature.Words, @@ -36,13 +35,13 @@ export let pro = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Checking price changes don't result in update ents func`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -78,7 +77,7 @@ describe(`${chalk.yellowBright(`${testCase}: Checking price changes don't result testClockId = testClockId1!; }); - it("should attach pro annual product", async function () { + it("should attach pro annual product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -90,7 +89,7 @@ describe(`${chalk.yellowBright(`${testCase}: Checking price changes don't result }); }); - it("branch should not be same custom ents if base price updated", async function () { + it("branch should not be same custom ents if base price updated", async () => { let customItems = pro.items.filter((item) => !nullish(item.feature_id)); customItems = [ diff --git a/server/tests/attach/updateQuantity/updateQuantity1.ts b/server/tests/attach/updateQuantity/updateQuantity1.ts index a36b48290..8d769f826 100644 --- a/server/tests/attach/updateQuantity/updateQuantity1.ts +++ b/server/tests/attach/updateQuantity/updateQuantity1.ts @@ -1,30 +1,29 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; - import { - APIVersion, - AppEnv, + type AppEnv, AttachErrCode, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { addWeeks } from "date-fns"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { timeout } from "@/utils/genUtils.js"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "updateQuantity1"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Users, @@ -36,14 +35,14 @@ export let pro = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid single use`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; let curUnix = new Date().getTime(); - let numUsers = 0; + const numUsers = 0; before(async function () { await setupBefore(this); @@ -86,7 +85,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid singl }, ]; - it("should attach pro product (arrear prorated)", async function () { + it("should attach pro product (arrear prorated)", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -99,7 +98,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid singl }); }); - it("should throw error if try to attach same options", async function () { + it("should throw error if try to attach same options", async () => { await expectAutumnError({ errCode: AttachErrCode.ProductAlreadyAttached, func: async () => { @@ -119,7 +118,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid singl }, ]; - it("should update quantity to 4 users and have usage stay the same", async function () { + it("should update quantity to 4 users and have usage stay the same", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Users, diff --git a/server/tests/attach/upgrade/upgrade1.ts b/server/tests/attach/upgrade/upgrade1.ts index 2a75540ba..eaf2e3d0d 100644 --- a/server/tests/attach/upgrade/upgrade1.ts +++ b/server/tests/attach/upgrade/upgrade1.ts @@ -1,4 +1,4 @@ -import { APIVersion, type AppEnv, type Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type { Stripe } from "stripe"; @@ -33,7 +33,7 @@ const growth = constructProduct({ describe(`${chalk.yellowBright("upgrade1: Testing usage upgrades")}`, () => { const customerId = "upgrade1"; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; diff --git a/server/tests/attach/upgrade/upgrade2.ts b/server/tests/attach/upgrade/upgrade2.ts index 28aba97f5..d4081eecc 100644 --- a/server/tests/attach/upgrade/upgrade2.ts +++ b/server/tests/attach/upgrade/upgrade2.ts @@ -1,36 +1,35 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; +import { addWeeks } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addWeeks } from "date-fns"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; // Shared products for attach tests const testCase = "upgrade2"; -export let pro = constructProduct({ +export const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); -export let proAnnual = constructProduct({ +export const proAnnual = constructProduct({ id: "pro_annual", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", isAnnual: true, }); -export let premiumAnnual = constructProduct({ +export const premiumAnnual = constructProduct({ id: "premium_annual", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -47,8 +46,8 @@ export let premiumAnnual = constructProduct({ */ describe(`${chalk.yellowBright("upgrade2: Testing usage upgrades with monthly -> annual")}`, () => { - let customerId = "upgrade2"; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = "upgrade2"; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; @@ -90,7 +89,7 @@ describe(`${chalk.yellowBright("upgrade2: Testing usage upgrades with monthly -> testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -102,7 +101,7 @@ describe(`${chalk.yellowBright("upgrade2: Testing usage upgrades with monthly -> }); }); - it("should attach pro annual product", async function () { + it("should attach pro annual product", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Words, @@ -128,7 +127,7 @@ describe(`${chalk.yellowBright("upgrade2: Testing usage upgrades with monthly -> }); return; - it("should attach premium annual product", async function () { + it("should attach premium annual product", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Words, diff --git a/server/tests/attach/upgrade/upgrade3.ts b/server/tests/attach/upgrade/upgrade3.ts index b1de3c2ff..612a065fa 100644 --- a/server/tests/attach/upgrade/upgrade3.ts +++ b/server/tests/attach/upgrade/upgrade3.ts @@ -1,24 +1,23 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; - -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { addWeeks } from "date-fns"; -import { timeout } from "@/utils/genUtils.js"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "upgrade3"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructArrearProratedItem({ featureId: TestFeature.Users, @@ -28,7 +27,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [ constructArrearProratedItem({ featureId: TestFeature.Users, @@ -38,7 +37,7 @@ export let premium = constructProduct({ type: "premium", }); -export let proAnnual = constructProduct({ +export const proAnnual = constructProduct({ items: [ constructArrearProratedItem({ featureId: TestFeature.Users, @@ -61,8 +60,8 @@ export let proAnnual = constructProduct({ */ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with arrear prorated`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -104,9 +103,9 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with arrear prorat testClockId = testClockId1!; }); - it("should attach pro product (arrear prorated)", async function () { + it("should attach pro product (arrear prorated)", async () => { // 1. Create multiple entities - let entities = await autumn.entities.create(customerId, [ + const entities = await autumn.entities.create(customerId, [ { id: "entity1", name: "entity1", @@ -137,7 +136,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with arrear prorat }); }); - it("should create entity, then upgrade to premium product (arrear prorated)", async function () { + it("should create entity, then upgrade to premium product (arrear prorated)", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -173,7 +172,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with arrear prorat }); }); - it("should upgrade to pro-annual product (arrear prorated)", async function () { + it("should upgrade to pro-annual product (arrear prorated)", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/attach/upgrade/upgrade4.ts b/server/tests/attach/upgrade/upgrade4.ts index 3cb14195d..48996f0d4 100644 --- a/server/tests/attach/upgrade/upgrade4.ts +++ b/server/tests/attach/upgrade/upgrade4.ts @@ -1,22 +1,22 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { addWeeks } from "date-fns"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "upgrade4"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Users, @@ -27,7 +27,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Users, @@ -38,7 +38,7 @@ export let premium = constructProduct({ type: "premium", }); -export let proAnnual = constructProduct({ +export const proAnnual = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Users, @@ -62,14 +62,14 @@ export let proAnnual = constructProduct({ */ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid continuous use`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; let curUnix = new Date().getTime(); - let numUsers = 0; + const numUsers = 0; before(async function () { await setupBefore(this); @@ -112,7 +112,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid conti }, ]; - it("should attach pro product (arrear prorated)", async function () { + it("should attach pro product (arrear prorated)", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -132,7 +132,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid conti }, ]; - it("should create entity, then upgrade to premium product (arrear prorated)", async function () { + it("should create entity, then upgrade to premium product (arrear prorated)", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -158,7 +158,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid conti }, ]; - it("should upgrade to pro-annual product (arrear prorated)", async function () { + it("should upgrade to pro-annual product (arrear prorated)", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/attach/upgrade/upgrade5.ts b/server/tests/attach/upgrade/upgrade5.ts index b70c4bdc6..0c1d0f74c 100644 --- a/server/tests/attach/upgrade/upgrade5.ts +++ b/server/tests/attach/upgrade/upgrade5.ts @@ -1,22 +1,22 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { addWeeks } from "date-fns"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "upgrade5"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Messages, @@ -27,7 +27,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [ constructPrepaidItem({ featureId: TestFeature.Messages, @@ -39,14 +39,14 @@ export let premium = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid single use`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; let curUnix = new Date().getTime(); - let numUsers = 0; + const numUsers = 0; before(async function () { await setupBefore(this); @@ -89,7 +89,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid singl }, ]; - it("should attach pro product (prepaid single use)", async function () { + it("should attach pro product (prepaid single use)", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -109,7 +109,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrades with prepaid singl }, ]; - it("should upgrade to premium product (prepaid single use)", async function () { + it("should upgrade to premium product (prepaid single use)", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/attach/upgrade/upgrade6.ts b/server/tests/attach/upgrade/upgrade6.ts index 4df6ed4d8..53c650656 100644 --- a/server/tests/attach/upgrade/upgrade6.ts +++ b/server/tests/attach/upgrade/upgrade6.ts @@ -1,31 +1,30 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { expectSubItemsCorrect } from "tests/utils/expectUtils/expectSubUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +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 { timeout } from "@/utils/genUtils.js"; import { constructArrearItem, constructArrearProratedItem, } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; - -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; -import { attachFailedPaymentMethod } from "@/external/stripe/stripeCusUtils.js"; -import { CusService } from "@/internal/customers/CusService.js"; -import { timeout } from "@/utils/genUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expectSubItemsCorrect } from "tests/utils/expectUtils/expectSubUtils.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "upgrade6"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructArrearItem({ featureId: TestFeature.Words }), constructArrearProratedItem({ @@ -36,7 +35,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [ constructArrearItem({ featureId: TestFeature.Words }), constructArrearProratedItem({ @@ -48,8 +47,8 @@ export let premium = constructProduct({ }); describe(`${chalk.yellowBright(`${testCase}: Testing failed upgrades`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -88,7 +87,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing failed upgrades`)}`, () => testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -100,8 +99,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing failed upgrades`)}`, () => }); }); - let usage = 100012; - it("should upgrade to premium product and fail", async function () { + const usage = 100012; + it("should upgrade to premium product and fail", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Words, @@ -109,7 +108,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing failed upgrades`)}`, () => }); await timeout(4000); - let cus = await CusService.get({ + const cus = await CusService.get({ db, orgId: org.id, idOrInternalId: customerId, @@ -135,7 +134,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing failed upgrades`)}`, () => }); await timeout(4000); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, diff --git a/server/tests/attach/upgrade/upgrade7.ts b/server/tests/attach/upgrade/upgrade7.ts index 886479c6e..3ce18ed83 100644 --- a/server/tests/attach/upgrade/upgrade7.ts +++ b/server/tests/attach/upgrade/upgrade7.ts @@ -1,30 +1,30 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../utils.js"; const testCase = "upgrade7"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [], type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [], type: "premium", }); describe(`${chalk.yellowBright(`${testCase}: Testing upgrade via cancel + attach`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -63,7 +63,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrade via cancel + attach testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -75,7 +75,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing upgrade via cancel + attach }); }); - it("should cancel than attach premium product", async function () { + it("should cancel than attach premium product", async () => { await autumn.cancel({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/constants.ts b/server/tests/constants.ts index 005240c3a..ac34a8c07 100644 --- a/server/tests/constants.ts +++ b/server/tests/constants.ts @@ -1,3 +1,3 @@ -import { APIVersion } from "@autumn/shared"; +import { LegacyVersion } from "@autumn/shared"; -export const defaultApiVersion = APIVersion.v1_2; +export const defaultApiVersion = LegacyVersion.v1_2; diff --git a/server/tests/contUse/entities/entity1.ts b/server/tests/contUse/entities/entity1.ts index dfbed09a3..12ff6588a 100644 --- a/server/tests/contUse/entities/entity1.ts +++ b/server/tests/contUse/entities/entity1.ts @@ -1,29 +1,29 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../../attach/utils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { timeout } from "@/utils/genUtils.js"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../../attach/utils.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -33,7 +33,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -43,8 +43,8 @@ const testCase = "entity1"; // Pro is $20 / month, Seat is $50 / user describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create / delete entities`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -86,7 +86,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create / delete ent }); let usage = 0; - let firstEntities = [ + const firstEntities = [ { id: "1", name: "test", @@ -94,7 +94,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create / delete ent }, ]; - it("should create entity, then attach pro", async function () { + it("should create entity, then attach pro", async () => { await autumn.entities.create(customerId, firstEntities); usage += 1; @@ -128,7 +128,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create / delete ent }, ]; - it("should create 2 entities and have correct invoice", async function () { + it("should create 2 entities and have correct invoice", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -152,17 +152,17 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create / delete ent itemQuantity: usage, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices!; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices!; expect(invoices.length).to.equal(2); expect(invoices[0].total).to.equal(userItem.price! * entities.length); }); - it("should delete 1 entity and have no new invoice", async function () { + it("should delete 1 entity and have no new invoice", async () => { await autumn.entities.delete(customerId, entities[0].id); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices!; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices!; expect(invoices.length).to.equal(2); await expectSubQuantityCorrect({ @@ -191,13 +191,13 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create / delete ent }, ]; - it("should create 2 entities and have correct invoice (only pay for 1)", async function () { + it("should create 2 entities and have correct invoice (only pay for 1)", async () => { await autumn.entities.create(customerId, newEntities); await timeout(3000); usage += 1; - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices!; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices!; expect(invoices.length).to.equal(3); expect(invoices[0].total).to.equal(userItem.price!); diff --git a/server/tests/contUse/entities/entity2.ts b/server/tests/contUse/entities/entity2.ts index f7e707404..001eb441f 100644 --- a/server/tests/contUse/entities/entity2.ts +++ b/server/tests/contUse/entities/entity2.ts @@ -1,6 +1,6 @@ import { - APIVersion, type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, type Organization, @@ -44,7 +44,7 @@ const testCase = "entity2"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing entities, prorate now`)}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; diff --git a/server/tests/contUse/entities/entity3.ts b/server/tests/contUse/entities/entity3.ts index 83abcffc2..32f8fcde8 100644 --- a/server/tests/contUse/entities/entity3.ts +++ b/server/tests/contUse/entities/entity3.ts @@ -1,6 +1,6 @@ import { - APIVersion, type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, type Organization, @@ -43,7 +43,7 @@ const testCase = "entity3"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing replaceables deleted at end of cycle`)}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; diff --git a/server/tests/contUse/entities/entity4.ts b/server/tests/contUse/entities/entity4.ts index b3f9e4275..ad49d3340 100644 --- a/server/tests/contUse/entities/entity4.ts +++ b/server/tests/contUse/entities/entity4.ts @@ -1,34 +1,34 @@ // Handling per entity features! -import { TestFeature } from "tests/setup/v2Features.js"; -import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { useEntityBalanceAndExpect } from "tests/utils/expectUtils/expectContUse/expectEntityUtils.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusExpand, - LimitedItem, + LegacyVersion, + type LimitedItem, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../../attach/utils.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { useEntityBalanceAndExpect } from "tests/utils/expectUtils/expectContUse/expectEntityUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; import { constructArrearProratedItem, constructFeatureItem, } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../../attach/utils.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -38,13 +38,13 @@ let userItem = constructArrearProratedItem({ }, }); -let perEntityItem = constructFeatureItem({ +const perEntityItem = constructFeatureItem({ featureId: TestFeature.Messages, entityFeatureId: TestFeature.Users, includedUsage: 500, }) as LimitedItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem, perEntityItem], type: "pro", }); @@ -52,12 +52,12 @@ export let pro = constructProduct({ const testCase = "entity4"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -95,7 +95,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features }); let usage = 0; - let firstEntities = [ + const firstEntities = [ { id: "1", name: "test", @@ -103,7 +103,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features }, ]; - it("should create one entity, then attach pro", async function () { + it("should create one entity, then attach pro", async () => { await autumn.entities.create(customerId, firstEntities); usage += firstEntities.length; @@ -124,7 +124,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features }); }); - it("should create 3 entities and have correct message balance", async function () { + it("should create 3 entities and have correct message balance", async () => { const newEntities = [ { id: "2", @@ -141,11 +141,11 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features await autumn.entities.create(customerId, newEntities); usage += newEntities.length; - let customer = await autumn.customers.get(customerId, { + const customer = await autumn.customers.get(customerId, { expand: [CusExpand.Entities], }); - let res = await autumn.check({ + const res = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, }); @@ -154,9 +154,9 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features (perEntityItem.included_usage as number) * usage, ); - // @ts-ignore + // @ts-expect-error for (const entity of customer.entities) { - let entRes = await autumn.check({ + const entRes = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: entity.id, @@ -169,9 +169,9 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features return; // 1. Use from main balance... - it("should use from top level balance", async function () { - let deduction = 600; - let perEntityIncluded = perEntityItem.included_usage as number; + it("should use from top level balance", async () => { + const deduction = 600; + const perEntityIncluded = perEntityItem.included_usage as number; await autumn.track({ customer_id: customerId, @@ -180,7 +180,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features }); await timeout(5000); - let { balance } = await autumn.check({ + const { balance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, }); @@ -188,7 +188,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features expect(balance).to.equal(perEntityIncluded * usage - deduction); }); - it("should use from entity balance", async function () { + it("should use from entity balance", async () => { await useEntityBalanceAndExpect({ autumn, customerId, @@ -205,19 +205,19 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features }); // Delete one entity and create a new one and master balance should be same - let deletedEntityId = "2"; - let newEntity = { + const deletedEntityId = "2"; + const newEntity = { id: "4", name: "test", feature_id: TestFeature.Users, }; - it("should delete one entity and create a new one", async function () { - let { balance: masterBalanceBefore } = await autumn.check({ + it("should delete one entity and create a new one", async () => { + const { balance: masterBalanceBefore } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, }); - let { balance: entityBalanceBefore } = await autumn.check({ + const { balance: entityBalanceBefore } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: deletedEntityId, @@ -226,14 +226,14 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing per entity features await autumn.entities.delete(customerId, deletedEntityId); await autumn.entities.create(customerId, [newEntity]); - let { balance: masterBalanceAfter } = await autumn.check({ + const { balance: masterBalanceAfter } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, }); expect(masterBalanceAfter).to.equal(masterBalanceBefore); - let { balance: entityBalanceAfter } = await autumn.check({ + const { balance: entityBalanceAfter } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: newEntity.id, diff --git a/server/tests/contUse/entities/entity5.ts b/server/tests/contUse/entities/entity5.ts index f9e904d44..28f117a5b 100644 --- a/server/tests/contUse/entities/entity5.ts +++ b/server/tests/contUse/entities/entity5.ts @@ -1,31 +1,30 @@ // test payment failures -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, - ErrCode, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../../attach/utils.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { attachFailedPaymentMethod } from "@/external/stripe/stripeCusUtils.js"; -import { CusService } from "@/internal/customers/CusService.js"; import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +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 { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../../attach/utils.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -35,7 +34,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -43,12 +42,12 @@ export let pro = constructProduct({ const testCase = "entity5"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create entity payment fail`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -86,7 +85,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create entity payme }); let usage = 0; - let firstEntities = [ + const firstEntities = [ { id: "1", name: "test", @@ -94,7 +93,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create entity payme }, ]; - it("should create one entity, then attach pro", async function () { + it("should create one entity, then attach pro", async () => { await autumn.entities.create(customerId, firstEntities); usage += firstEntities.length; @@ -115,8 +114,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create entity payme }); }); - it("should attach failed payment method", async function () { - let fullCus = await CusService.getFull({ + it("should attach failed payment method", async () => { + const fullCus = await CusService.getFull({ db, idOrInternalId: customerId, orgId: org.id, @@ -129,7 +128,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create entity payme }); }); - it("should try to create entities and fail", async function () { + it("should try to create entities and fail", async () => { await expectAutumnError({ errMessage: "(Stripe Error) Your card was declined.", func: async () => { @@ -160,7 +159,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing create entity payme }); }); - it("should track usage for users and fail", async function () { + it("should track usage for users and fail", async () => { await expectAutumnError({ errMessage: "(Stripe Error) Your card was declined.", func: async () => { diff --git a/server/tests/contUse/roles/role1.ts b/server/tests/contUse/roles/role1.ts index cc3032124..d80582514 100644 --- a/server/tests/contUse/roles/role1.ts +++ b/server/tests/contUse/roles/role1.ts @@ -1,52 +1,50 @@ // Handling per entity features! import { - APIVersion, - AppEnv, - LimitedItem, - Organization, - ProductItem, + type AppEnv, + LegacyVersion, + type LimitedItem, + type Organization, + type ProductItem, } from "@autumn/shared"; - -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../../attach/utils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { Decimal } from "decimal.js"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { addPrefixToProducts } from "../../attach/utils.js"; -let user = TestFeature.Users; -let admin = TestFeature.Admin; +const user = TestFeature.Users; +const admin = TestFeature.Admin; -let userMessages = constructFeatureItem({ +const userMessages = constructFeatureItem({ featureId: TestFeature.Messages, includedUsage: 100, entityFeatureId: user, }) as LimitedItem; -let adminMessages = constructFeatureItem({ +const adminMessages = constructFeatureItem({ featureId: TestFeature.Messages, includedUsage: 500, entityFeatureId: admin, }) as LimitedItem; -let adminRights = constructFeatureItem({ +const adminRights = constructFeatureItem({ featureId: TestFeature.AdminRights, entityFeatureId: admin, isBoolean: true, }) as ProductItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userMessages, adminMessages, adminRights], type: "pro", }); @@ -54,12 +52,12 @@ export let pro = constructProduct({ const testCase = "role1"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -96,9 +94,9 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { testClockId = testClockId1!; }); - let userId = "user1"; - let adminId = "admin1"; - let firstEntities = [ + const userId = "user1"; + const adminId = "admin1"; + const firstEntities = [ { id: userId, name: "test", @@ -111,7 +109,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { }, ]; - it("should create initial entities, then attach pro", async function () { + it("should create initial entities, then attach pro", async () => { await autumn.entities.create(customerId, firstEntities); await attachAndExpectCorrect({ @@ -125,62 +123,62 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { }); }); - it("should have correct check result for admin rights", async function () { - let { allowed } = await autumn.check({ + it("should have correct check result for admin rights", async () => { + const { allowed } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.AdminRights, entity_id: adminId, }); - let entity = await autumn.entities.get(customerId, adminId); + const entity = await autumn.entities.get(customerId, adminId); expect(allowed).to.equal(true); expect(entity.features[TestFeature.AdminRights]).exist; - let { allowed: userAllowed } = await autumn.check({ + const { allowed: userAllowed } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.AdminRights, entity_id: userId, }); - let userEntity = await autumn.entities.get(customerId, userId); + const userEntity = await autumn.entities.get(customerId, userId); expect(userAllowed).to.equal(false); expect(userEntity.features[TestFeature.AdminRights]).not.exist; }); - it("should have correct total balance", async function () { - let { balance } = await autumn.check({ + it("should have correct total balance", async () => { + const { balance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, }); - let totalIncluded = + const totalIncluded = userMessages.included_usage + adminMessages.included_usage; expect(balance).to.equal(totalIncluded); }); - it("should have correct per entity balance", async function () { - let { balance: userBalance } = await autumn.check({ + it("should have correct per entity balance", async () => { + const { balance: userBalance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: userId, }); - let userEntity = await autumn.entities.get(customerId, userId); + const userEntity = await autumn.entities.get(customerId, userId); expect(userBalance).to.equal(userMessages.included_usage); expect(userEntity.features[TestFeature.Messages].included_usage).to.equal( userMessages.included_usage, ); - let { balance: adminBalance } = await autumn.check({ + const { balance: adminBalance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: adminId, }); - let adminEntity = await autumn.entities.get(customerId, adminId); + const adminEntity = await autumn.entities.get(customerId, adminId); expect(adminBalance).to.equal(adminMessages.included_usage); expect(adminEntity.features[TestFeature.Messages].included_usage).to.equal( @@ -188,11 +186,11 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { ); }); - let userUsage = Math.random() * 50; - let expectedUserBalance = new Decimal(userMessages.included_usage) + const userUsage = Math.random() * 50; + const expectedUserBalance = new Decimal(userMessages.included_usage) .minus(userUsage) .toNumber(); - it("should have correct user usage", async function () { + it("should have correct user usage", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -201,13 +199,13 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { }); await timeout(2000); - let { balance: userBalance } = await autumn.check({ + const { balance: userBalance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: userId, }); - let { balance: adminBalance } = await autumn.check({ + const { balance: adminBalance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: adminId, @@ -217,11 +215,11 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { expect(userBalance).to.equal(expectedUserBalance); }); - let adminUsage = Math.random() * 50; - let expectedAdminBalance = new Decimal(adminMessages.included_usage) + const adminUsage = Math.random() * 50; + const expectedAdminBalance = new Decimal(adminMessages.included_usage) .minus(adminUsage) .toNumber(); - it("Should have correct admin usage", async function () { + it("Should have correct admin usage", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -230,13 +228,13 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { }); await timeout(2000); - let { balance: adminBalance } = await autumn.check({ + const { balance: adminBalance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: adminId, }); - let { balance: userBalance } = await autumn.check({ + const { balance: userBalance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: userId, diff --git a/server/tests/contUse/roles/role2.ts b/server/tests/contUse/roles/role2.ts index 5cd93d1ee..ca07d4f58 100644 --- a/server/tests/contUse/roles/role2.ts +++ b/server/tests/contUse/roles/role2.ts @@ -1,42 +1,39 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - import { - APIVersion, - AppEnv, - CreateEntity, - LimitedItem, - Organization, + type AppEnv, + type CreateEntity, + LegacyVersion, + type LimitedItem, + type Organization, } from "@autumn/shared"; - -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; +import chalk from "chalk"; +import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../../attach/utils.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; -import { addHours, addMonths } from "date-fns"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { addPrefixToProducts } from "../../attach/utils.js"; -let user = TestFeature.Users; -let admin = TestFeature.Admin; +const user = TestFeature.Users; +const admin = TestFeature.Admin; -let userMessages = constructArrearItem({ +const userMessages = constructArrearItem({ featureId: TestFeature.Messages, price: 0.5, entityFeatureId: user, }) as LimitedItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userMessages], type: "pro", }); @@ -44,8 +41,8 @@ export let pro = constructProduct({ const testCase = "role2"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per entity`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; let testClockId: string; @@ -85,10 +82,10 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en testClockId = res.testClockId!; }); - let user1 = "user1"; - let user2 = "user2"; + const user1 = "user1"; + const user2 = "user2"; - let firstEntities: CreateEntity[] = [ + const firstEntities: CreateEntity[] = [ { id: user1, name: "test", @@ -101,7 +98,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en }, ]; - it("should create initial entities, then attach pro", async function () { + it("should create initial entities, then attach pro", async () => { await autumn.entities.create(customerId, firstEntities); await attachAndExpectCorrect({ @@ -115,15 +112,15 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en entities: firstEntities, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expect(customer.features[TestFeature.Messages].included_usage).to.equal( userMessages.included_usage * firstEntities.length, ); }); - let user1Usage = 125000; - let user2Usage = 150000; - it("should track correct usage for seat messages", async function () { + const user1Usage = 125000; + const user2Usage = 150000; + it("should track correct usage for seat messages", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -140,9 +137,9 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en await timeout(4000); - let includedUsage = userMessages.included_usage; + const includedUsage = userMessages.included_usage; - let { balance: userBalance } = await autumn.check({ + const { balance: userBalance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: user1, @@ -150,7 +147,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en expect(userBalance).to.equal(includedUsage - user1Usage); - let { balance: user2Balance } = await autumn.check({ + const { balance: user2Balance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: user2, @@ -159,7 +156,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en expect(user2Balance).to.equal(includedUsage - user2Usage); }); - it("should have correct invoice next cycle", async function () { + it("should have correct invoice next cycle", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -170,13 +167,13 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en waitForSeconds: 30, }); - let includedUsage = userMessages.included_usage; - let user1Overage = user1Usage - includedUsage; - let user2Overage = user2Usage - includedUsage; + const includedUsage = userMessages.included_usage; + const user1Overage = user1Usage - includedUsage; + const user2Overage = user2Usage - includedUsage; - let totalUsage = user1Overage + user2Overage + includedUsage; + const totalUsage = user1Overage + user2Overage + includedUsage; - let expectedInvoiceTotal = await getExpectedInvoiceTotal({ + const expectedInvoiceTotal = await getExpectedInvoiceTotal({ customerId, productId: pro.id, usage: [{ featureId: TestFeature.Messages, value: totalUsage }], @@ -187,7 +184,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en expectExpired: true, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expect(customer.invoices[0].total).to.equal(expectedInvoiceTotal); }); }); diff --git a/server/tests/contUse/roles/role3.ts b/server/tests/contUse/roles/role3.ts index 92302ec09..e9c5c1754 100644 --- a/server/tests/contUse/roles/role3.ts +++ b/server/tests/contUse/roles/role3.ts @@ -1,49 +1,45 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - import { - APIVersion, - AppEnv, - CreateEntity, - LimitedItem, - Organization, + type AppEnv, + type CreateEntity, + LegacyVersion, + type LimitedItem, + type Organization, } from "@autumn/shared"; - -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; +import chalk from "chalk"; +import { addMonths } from "date-fns"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "../../attach/utils.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; -import { addHours, addMonths } from "date-fns"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { addPrefixToProducts } from "../../attach/utils.js"; -let user = TestFeature.Users; -let admin = TestFeature.Admin; +const user = TestFeature.Users; +const admin = TestFeature.Admin; -let userMessages = constructArrearItem({ +const userMessages = constructArrearItem({ featureId: TestFeature.Messages, price: 0.5, entityFeatureId: user, }) as LimitedItem; -let adminMessages = constructArrearItem({ +const adminMessages = constructArrearItem({ featureId: TestFeature.Messages, includedUsage: 0, price: 0.1, entityFeatureId: admin, }) as LimitedItem; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userMessages, adminMessages], type: "pro", }); @@ -51,8 +47,8 @@ export let pro = constructProduct({ const testCase = "role3"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per entity, diff roles`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; let testClockId: string; @@ -92,11 +88,11 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en testClockId = res.testClockId!; }); - let user1 = "user1"; - let user2 = "user2"; - let admin1 = "admin1"; - let admin2 = "admin2"; - let firstEntities: CreateEntity[] = [ + const user1 = "user1"; + const user2 = "user2"; + const admin1 = "admin1"; + const admin2 = "admin2"; + const firstEntities: CreateEntity[] = [ { id: user1, name: "test", @@ -119,7 +115,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en }, ]; - it("should create initial entities, then attach pro", async function () { + it("should create initial entities, then attach pro", async () => { await autumn.entities.create(customerId, firstEntities); await attachAndExpectCorrect({ @@ -134,11 +130,11 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en }); }); - let user1Usage = 125000; - let user2Usage = 150000; + const user1Usage = 125000; + const user2Usage = 150000; // total: 275000, included: 10000, overage: 255000 - it("should track correct usage for seat messages", async function () { + it("should track correct usage for seat messages", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -155,9 +151,9 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en await timeout(4000); - let includedUsage = userMessages.included_usage; + const includedUsage = userMessages.included_usage; - let { balance: userBalance } = await autumn.check({ + const { balance: userBalance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: user1, @@ -165,7 +161,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en expect(userBalance).to.equal(includedUsage - user1Usage); - let { balance: user2Balance } = await autumn.check({ + const { balance: user2Balance } = await autumn.check({ customer_id: customerId, feature_id: TestFeature.Messages, entity_id: user2, @@ -190,10 +186,10 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en expect(admin2Balance).to.equal(adminMessages.included_usage); }); - let admin1Usage = 130000; - let admin2Usage = 140000; + const admin1Usage = 130000; + const admin2Usage = 140000; // total: 270000, included: 0, overage: 270000 - it("should track correct usage for admin messages", async function () { + it("should track correct usage for admin messages", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -211,7 +207,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en await timeout(4000); }); - it("should have correct invoice next cycle", async function () { + it("should have correct invoice next cycle", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -225,17 +221,17 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en return; - let includedUsage = userMessages.included_usage; - let user1Overage = user1Usage - includedUsage; - let user2Overage = user2Usage - includedUsage; - let totalUserUsage = user1Overage + user2Overage + includedUsage; + const includedUsage = userMessages.included_usage; + const user1Overage = user1Usage - includedUsage; + const user2Overage = user2Usage - includedUsage; + const totalUserUsage = user1Overage + user2Overage + includedUsage; - let admin1Overage = admin1Usage - adminMessages.included_usage; - let admin2Overage = admin2Usage - adminMessages.included_usage; - let totalAdminUsage = + const admin1Overage = admin1Usage - adminMessages.included_usage; + const admin2Overage = admin2Usage - adminMessages.included_usage; + const totalAdminUsage = admin1Overage + admin2Overage + adminMessages.included_usage; - let expectedInvoiceTotal = await getExpectedInvoiceTotal({ + const expectedInvoiceTotal = await getExpectedInvoiceTotal({ customerId, productId: pro.id, usage: [ @@ -257,7 +253,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en expectExpired: true, }); - let customer = await autumn.customers.get(customerId); + const customer = await autumn.customers.get(customerId); expect(customer.invoices[0].total).to.equal(expectedInvoiceTotal); }); }); diff --git a/server/tests/contUse/track/track1.ts b/server/tests/contUse/track/track1.ts index 8b7701cc5..00ae39b49 100644 --- a/server/tests/contUse/track/track1.ts +++ b/server/tests/contUse/track/track1.ts @@ -1,30 +1,29 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, - entities, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; +import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { timeout } from "@/utils/genUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type Stripe from "stripe"; import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -34,7 +33,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -42,8 +41,8 @@ export let pro = constructProduct({ const testCase = "track1"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for cont use`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -85,7 +84,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con }); let usage = 0; - it("should attach pro", async function () { + it("should attach pro", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -97,7 +96,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con }); }); - it("should create track +3 usage and have correct invoice", async function () { + it("should create track +3 usage and have correct invoice", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -125,13 +124,13 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con usage, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(2); expect(invoices[0].total).to.equal(userItem.price! * 2); }); - it("should track -3 and have no new invoice", async function () { + it("should track -3 and have no new invoice", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Users, @@ -140,8 +139,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con await timeout(5000); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(2); await expectSubQuantityCorrect({ @@ -157,7 +156,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con }); }); - it("should track +3 and have no new invoice", async function () { + it("should track +3 and have no new invoice", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Users, @@ -166,8 +165,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con await timeout(5000); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(2); await expectSubQuantityCorrect({ diff --git a/server/tests/contUse/track/track2.ts b/server/tests/contUse/track/track2.ts index ec4815c0f..ae3fb410c 100644 --- a/server/tests/contUse/track/track2.ts +++ b/server/tests/contUse/track/track2.ts @@ -1,27 +1,26 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; - +import chalk from "chalk"; +import type Stripe from "stripe"; import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -31,7 +30,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -39,12 +38,12 @@ export let pro = constructProduct({ const testCase = "track2"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for cont use (without overage)`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -82,7 +81,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con }); let usage = 0; - it("should attach pro", async function () { + it("should attach pro", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -94,7 +93,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con }); }); - it("should track +1 and have no new invoice", async function () { + it("should track +1 and have no new invoice", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Users, @@ -113,12 +112,12 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con usage, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(1); }); - it("should track -1 and have no new invoice", async function () { + it("should track -1 and have no new invoice", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Users, diff --git a/server/tests/contUse/track/track3.ts b/server/tests/contUse/track/track3.ts index 59eccc379..4f7ff6c88 100644 --- a/server/tests/contUse/track/track3.ts +++ b/server/tests/contUse/track/track3.ts @@ -1,30 +1,32 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; +import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { timeout } from "@/utils/genUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type Stripe from "stripe"; import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectUpcomingItemsCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { + expectSubQuantityCorrect, + expectUpcomingItemsCorrect, +} from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -34,7 +36,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -42,8 +44,8 @@ export let pro = constructProduct({ const testCase = "track3"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for cont use, prorate next cycle`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -85,7 +87,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con }); let usage = 0; - it("should attach pro", async function () { + it("should attach pro", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -97,7 +99,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con }); }); - it("should create track +3 usage and have correct invoice", async function () { + it("should create track +3 usage and have correct invoice", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -115,7 +117,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con usage += 3; - let { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ + const { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ stripeCli, productId: pro.id, db, @@ -135,12 +137,12 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con quantity: 2, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(1); }); - it("should track -1 and have no new invoice", async function () { + it("should track -1 and have no new invoice", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -156,7 +158,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con usage -= 1; - let { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ + const { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ stripeCli, productId: pro.id, db, @@ -176,13 +178,13 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con quantity: -1, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(1); }); - it("should track -1 and have no new invoice", async function () { - let quantity = 2; + it("should track -1 and have no new invoice", async () => { + const quantity = 2; await autumn.track({ customer_id: customerId, feature_id: TestFeature.Users, @@ -191,7 +193,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con usage += quantity; - let { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ + const { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ stripeCli, productId: pro.id, db, @@ -211,8 +213,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing track usage for con quantity, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(1); }); }); diff --git a/server/tests/contUse/track/track4.ts b/server/tests/contUse/track/track4.ts index 9dcf3e50b..939af26cb 100644 --- a/server/tests/contUse/track/track4.ts +++ b/server/tests/contUse/track/track4.ts @@ -1,32 +1,32 @@ -import chalk from "chalk"; -import Stripe from "stripe"; - -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; +import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { timeout } from "@/utils/genUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type Stripe from "stripe"; import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; -import { expectUpcomingItemsCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { + expectSubQuantityCorrect, + expectUpcomingItemsCorrect, +} from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -36,7 +36,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -44,8 +44,8 @@ export let pro = constructProduct({ const testCase = "track4"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont use, prorate next cycle`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -87,7 +87,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont }); let usage = 0; - it("should attach pro", async function () { + it("should attach pro", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -99,7 +99,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont }); }); - it("should create set usage to 3 and have correct invoice", async function () { + it("should create set usage to 3 and have correct invoice", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -117,7 +117,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont usage += 3; - let { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ + const { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ stripeCli, productId: pro.id, db, @@ -137,13 +137,13 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont quantity: 2, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(1); }); - it("should set usage to 2 and have no new invoice", async function () { - let newUsage = 2; + it("should set usage to 2 and have no new invoice", async () => { + const newUsage = 2; curUnix = await advanceTestClock({ stripeCli, @@ -158,7 +158,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont value: newUsage, }); - let { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ + const { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ stripeCli, productId: pro.id, db, @@ -178,13 +178,13 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont quantity: -1, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(1); }); - it("should set usage to 4 and have no new invoice", async function () { - let newUsage = 4; + it("should set usage to 4 and have no new invoice", async () => { + const newUsage = 4; await autumn.usage({ customer_id: customerId, feature_id: TestFeature.Users, @@ -193,7 +193,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont usage = newUsage; - let { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ + const { stripeSubs, cusProduct, fullCus } = await expectSubQuantityCorrect({ stripeCli, productId: pro.id, db, @@ -213,8 +213,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing set usage for cont quantity: 2, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(1); }); }); diff --git a/server/tests/contUse/track/track6.ts b/server/tests/contUse/track/track6.ts index 488b2c807..505c61c57 100644 --- a/server/tests/contUse/track/track6.ts +++ b/server/tests/contUse/track/track6.ts @@ -1,24 +1,29 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, LimitedItem, Organization } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "@/utils/genUtils.js"; +import { + type AppEnv, + LegacyVersion, + type LimitedItem, + type Organization, +} from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const userItem = constructFeatureItem({ featureId: TestFeature.Users, includedUsage: 5, }) as LimitedItem; -export let free = constructProduct({ +export const free = constructProduct({ items: [userItem], type: "free", isDefault: false, @@ -27,13 +32,13 @@ export let free = constructProduct({ const testCase = "track6"; describe(`${chalk.yellowBright(`${testCase}: Testing track cont use, race condition`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -70,7 +75,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing track cont use, race condit testClockId = testClockId1!; }); - it("should track 5 events in a row and have correct balance", async function () { + it("should track 5 events in a row and have correct balance", async () => { let startingBalance = userItem.included_usage; await autumn.attach({ customer_id: customerId, @@ -103,8 +108,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing track cont use, race condit await timeout(10000); - let customer = await autumn.customers.get(customerId); - let userFeature = customer.features[TestFeature.Users]; + const customer = await autumn.customers.get(customerId); + const userFeature = customer.features[TestFeature.Users]; if (userFeature.balance != startingBalance) { for (let i = 0; i < values.length; i++) { console.log(`Value: ${values[i]}, Event ID: ${results[i].id}`); diff --git a/server/tests/contUse/update/updateContUse1.ts b/server/tests/contUse/update/updateContUse1.ts index 6e3817970..92427aa36 100644 --- a/server/tests/contUse/update/updateContUse1.ts +++ b/server/tests/contUse/update/updateContUse1.ts @@ -1,28 +1,28 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; +import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type Stripe from "stripe"; import { addPrefixToProducts, replaceItems } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -32,7 +32,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -40,8 +40,8 @@ export let pro = constructProduct({ const testCase = "updateContUse1"; describe(`${chalk.yellowBright(`attach/entities/${testCase}: Testing update contUse, add included usage`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -83,7 +83,7 @@ describe(`${chalk.yellowBright(`attach/entities/${testCase}: Testing update cont }); let usage = 0; - let firstEntities = [ + const firstEntities = [ { id: "1", name: "test", @@ -101,7 +101,7 @@ describe(`${chalk.yellowBright(`attach/entities/${testCase}: Testing update cont }, ]; - it("should create entity, then attach pro", async function () { + it("should create entity, then attach pro", async () => { await autumn.entities.create(customerId, firstEntities); usage += 3; @@ -122,8 +122,8 @@ describe(`${chalk.yellowBright(`attach/entities/${testCase}: Testing update cont }); }); - let extraUsage = 2; - let newItem = constructArrearProratedItem({ + const extraUsage = 2; + const newItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: (userItem.included_usage as number) + extraUsage, @@ -135,8 +135,8 @@ describe(`${chalk.yellowBright(`attach/entities/${testCase}: Testing update cont return; - it("should update product with extra included usage", async function () { - let customItems = replaceItems({ + it("should update product with extra included usage", async () => { + const customItems = replaceItems({ featureId: TestFeature.Users, items: pro.items, newItem, @@ -178,7 +178,7 @@ describe(`${chalk.yellowBright(`attach/entities/${testCase}: Testing update cont }, ]; - it("should create 2 entities and have no invoice", async function () { + it("should create 2 entities and have no invoice", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -202,8 +202,8 @@ describe(`${chalk.yellowBright(`attach/entities/${testCase}: Testing update cont numReplaceables: 0, }); - let customer = await autumn.customers.get(customerId); - let invoices = customer.invoices; + const customer = await autumn.customers.get(customerId); + const invoices = customer.invoices; expect(invoices.length).to.equal(2); }); }); diff --git a/server/tests/contUse/update/updateContUse2.ts b/server/tests/contUse/update/updateContUse2.ts index 80ab6863a..0f29aa05f 100644 --- a/server/tests/contUse/update/updateContUse2.ts +++ b/server/tests/contUse/update/updateContUse2.ts @@ -1,28 +1,28 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; import { expect } from "chai"; +import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type Stripe from "stripe"; import { addPrefixToProducts, replaceItems } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -32,7 +32,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -40,12 +40,12 @@ export let pro = constructProduct({ const testCase = "updateContUse2"; describe(`${chalk.yellowBright(`contUse/update/${testCase}: Testing update cont use, remove included usage`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -83,7 +83,7 @@ describe(`${chalk.yellowBright(`contUse/update/${testCase}: Testing update cont }); let usage = 0; - let firstEntities = [ + const firstEntities = [ { id: "1", name: "test", @@ -101,7 +101,7 @@ describe(`${chalk.yellowBright(`contUse/update/${testCase}: Testing update cont }, ]; - it("should create entity, then attach pro", async function () { + it("should create entity, then attach pro", async () => { await autumn.entities.create(customerId, firstEntities); usage += 3; @@ -122,8 +122,8 @@ describe(`${chalk.yellowBright(`contUse/update/${testCase}: Testing update cont }); }); - let reduceUsageBy = 1; - let newItem = constructArrearProratedItem({ + const reduceUsageBy = 1; + const newItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: (userItem.included_usage as number) - reduceUsageBy, @@ -133,7 +133,7 @@ describe(`${chalk.yellowBright(`contUse/update/${testCase}: Testing update cont }, }); - it("should update product with reduced included usage", async function () { + it("should update product with reduced included usage", async () => { await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/contUse/update/updateContUse3.ts b/server/tests/contUse/update/updateContUse3.ts index c8c6bfdc0..dc2bc1318 100644 --- a/server/tests/contUse/update/updateContUse3.ts +++ b/server/tests/contUse/update/updateContUse3.ts @@ -1,26 +1,26 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; +import type Stripe from "stripe"; import { addPrefixToProducts, replaceItems } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; import { attachNewContUseAndExpectCorrect } from "tests/utils/expectUtils/expectContUse/expectUpdateContUse.js"; +import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -30,7 +30,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -38,12 +38,12 @@ export let pro = constructProduct({ const testCase = "updateContUse3"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse included usage when no entities created`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -80,7 +80,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl testClockId = testClockId1!; }); - it("should attach pro", async function () { + it("should attach pro", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -92,8 +92,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl }); }); - let extraUsage = 2; - let newItem = constructArrearProratedItem({ + const extraUsage = 2; + const newItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: (userItem.included_usage as number) + extraUsage, @@ -103,14 +103,14 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl }, }); - it("should update product with extra included usage", async function () { + it("should update product with extra included usage", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Users, value: 1, }); - let customItems = replaceItems({ + const customItems = replaceItems({ featureId: TestFeature.Users, items: pro.items, newItem, diff --git a/server/tests/contUse/update/updateContUse4.ts b/server/tests/contUse/update/updateContUse4.ts index 3483181a7..ec309ef1f 100644 --- a/server/tests/contUse/update/updateContUse4.ts +++ b/server/tests/contUse/update/updateContUse4.ts @@ -1,31 +1,31 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts, replaceItems } from "tests/attach/utils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; -import { attachNewContUseAndExpectCorrect } from "tests/utils/expectUtils/expectContUse/expectUpdateContUse.js"; import { expect } from "chai"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { calculateProrationAmount } from "@/internal/invoices/prorationUtils.js"; +import type Stripe from "stripe"; +import { addPrefixToProducts, replaceItems } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { attachNewContUseAndExpectCorrect } from "tests/utils/expectUtils/expectContUse/expectUpdateContUse.js"; +import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { subToPeriodStartEnd } from "@/external/stripe/stripeSubUtils/convertSubUtils.js"; +import { calculateProrationAmount } from "@/internal/invoices/prorationUtils.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -35,7 +35,7 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); @@ -43,8 +43,8 @@ export let pro = constructProduct({ const testCase = "updateContUse4"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse included usage, prorate now`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -99,7 +99,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl ]; let usage = 0; - it("should attach pro", async function () { + it("should attach pro", async () => { await autumn.entities.create(customerId, firstEntities); usage += firstEntities.length; @@ -120,8 +120,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl }); }); - let extraUsage = 2; - let newItem = constructArrearProratedItem({ + const extraUsage = 2; + const newItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: (userItem.included_usage as number) + extraUsage, @@ -131,7 +131,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl }, }); - it("should update product with extra included usage", async function () { + it("should update product with extra included usage", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -139,7 +139,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl waitForSeconds: 15, }); - let customItems = replaceItems({ + const customItems = replaceItems({ featureId: TestFeature.Users, items: pro.items, newItem, @@ -165,8 +165,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl }); // Do own calculation too.. - let sub = stripeSubs[0]; - let amount = -userItem.price!; + const sub = stripeSubs[0]; + const amount = -userItem.price!; const { start, end } = subToPeriodStartEnd({ sub }); let proratedAmount = calculateProrationAmount({ amount, @@ -194,7 +194,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl }, }); - it("should update product with reduced included usage", async function () { + it("should update product with reduced included usage", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, @@ -202,7 +202,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl waitForSeconds: 15, }); - let customItems = replaceItems({ + const customItems = replaceItems({ featureId: TestFeature.Users, items: pro.items, newItem: newItem2, @@ -228,8 +228,8 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl }); // Do own calculation too.. - let sub = stripeSubs[0]; - let amount = Math.min(reducedUsage, usage) * userItem.price!; + const sub = stripeSubs[0]; + const amount = Math.min(reducedUsage, usage) * userItem.price!; const { start, end } = subToPeriodStartEnd({ sub }); let proratedAmount = calculateProrationAmount({ amount, diff --git a/server/tests/contUse/update/updateContUse5.ts b/server/tests/contUse/update/updateContUse5.ts index 006f4bb31..f220b267d 100644 --- a/server/tests/contUse/update/updateContUse5.ts +++ b/server/tests/contUse/update/updateContUse5.ts @@ -1,26 +1,26 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { addWeeks } from "date-fns"; +import type Stripe from "stripe"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let userItem = constructArrearProratedItem({ +const userItem = constructArrearProratedItem({ featureId: TestFeature.Users, pricePerUnit: 50, includedUsage: 1, @@ -30,11 +30,11 @@ let userItem = constructArrearProratedItem({ }, }); -export let pro = constructProduct({ +export const pro = constructProduct({ items: [userItem], type: "pro", }); -export let proAnnual = constructProduct({ +export const proAnnual = constructProduct({ items: [ constructArrearProratedItem({ featureId: TestFeature.Users, @@ -53,8 +53,8 @@ export let proAnnual = constructProduct({ const testCase = "updateContUse5"; describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse included usage, prorate now`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; @@ -114,7 +114,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl ]; let usage = 0; - it("should attach pro", async function () { + it("should attach pro", async () => { await autumn.entities.create(customerId, firstEntities); usage += firstEntities.length; @@ -135,7 +135,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing update contUse incl }); }); - it("should upgrade to pro annual", async function () { + it("should upgrade to pro annual", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/core/cancel/cancel1.test.ts b/server/tests/core/cancel/cancel1.test.ts index 7380bc07e..cc5f8451d 100644 --- a/server/tests/core/cancel/cancel1.test.ts +++ b/server/tests/core/cancel/cancel1.test.ts @@ -7,7 +7,7 @@ // import { AutumnInt } from "@/external/autumn/autumnCli.js"; // import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // import { -// APIVersion, +// LegacyVersion, // AppEnv, // CusProductStatus, // Organization, @@ -74,7 +74,7 @@ // const testCase = "cancel1"; // describe(`${chalk.yellowBright("cancel1: Testing cancelling singular product")}`, () => { // let customerId = testCase; -// let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); +// let autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); // let stripeCli: Stripe; // let testClockId: string; @@ -184,7 +184,7 @@ // customer_id: customerId, // product_id: premium.id, // cancel_immediately: true, -// // @ts-ignore +// // @ts-expect-error // prorate: true, // }); diff --git a/server/tests/core/cancel/cancel2.test.ts b/server/tests/core/cancel/cancel2.test.ts index 7d93590aa..d184f8c78 100644 --- a/server/tests/core/cancel/cancel2.test.ts +++ b/server/tests/core/cancel/cancel2.test.ts @@ -1,37 +1,26 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, - priceToInvoiceAmount, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { - constructArrearItem, - constructArrearProratedItem, - constructPrepaidItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addWeeks } from "date-fns"; import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; - +import { createProducts } from "tests/utils/productUtils.js"; import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -47,8 +36,8 @@ const ops = [ const testCase = "cancel2"; describe(`${chalk.yellowBright("cancel2: Testing cancel at period end (with usage)")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -105,7 +94,7 @@ describe(`${chalk.yellowBright("cancel2: Testing cancel at period end (with usag }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -127,7 +116,7 @@ describe(`${chalk.yellowBright("cancel2: Testing cancel at period end (with usag } }); - it("should track usage cancel, advance test clock and have correct invoice", async function () { + it("should track usage cancel, advance test clock and have correct invoice", async () => { const cus1 = await autumn.customers.get(customerId); const prod = cus1.products.find((p) => p.id === premium.id); const proration = { diff --git a/server/tests/core/cancel/cancel3.test.ts b/server/tests/core/cancel/cancel3.test.ts index b7246f900..7972161f0 100644 --- a/server/tests/core/cancel/cancel3.test.ts +++ b/server/tests/core/cancel/cancel3.test.ts @@ -1,38 +1,32 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, - priceToInvoiceAmount, + LegacyVersion, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, - constructArrearProratedItem, constructFeatureItem, - constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let free = constructProduct({ +const free = constructProduct({ id: "free", items: [ constructFeatureItem({ @@ -53,8 +47,8 @@ const ops = [ const testCase = "cancel3"; describe(`${chalk.yellowBright("cancel3: Cancelling free product")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -111,7 +105,7 @@ describe(`${chalk.yellowBright("cancel3: Cancelling free product")}`, () => { }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -134,7 +128,7 @@ describe(`${chalk.yellowBright("cancel3: Cancelling free product")}`, () => { } }); - it("should track usage cancel, advance test clock and have correct invoice", async function () { + it("should track usage cancel, advance test clock and have correct invoice", async () => { const cus1 = await autumn.customers.get(customerId); await autumn.cancel({ diff --git a/server/tests/core/cancel/cancel4.test.ts b/server/tests/core/cancel/cancel4.test.ts index 7d3871e79..317e63814 100644 --- a/server/tests/core/cancel/cancel4.test.ts +++ b/server/tests/core/cancel/cancel4.test.ts @@ -1,7 +1,7 @@ import { - APIVersion, type AppEnv, CusProductStatus, + LegacyVersion, type Organization, } from "@autumn/shared"; import { expect } from "chai"; @@ -53,7 +53,7 @@ const ops = [ const testCase = "cancel4"; describe(`${chalk.yellowBright("cancel4: Cancelling free add on product")}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let db: DrizzleCli; diff --git a/server/tests/core/cancel/cancel5.test.ts b/server/tests/core/cancel/cancel5.test.ts index 9a292ea5e..abd1e44a9 100644 --- a/server/tests/core/cancel/cancel5.test.ts +++ b/server/tests/core/cancel/cancel5.test.ts @@ -1,34 +1,26 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addDays } from "date-fns"; -import { expectMultiAttachCorrect } from "tests/utils/expectUtils/expectMultiAttach.js"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; import { products } from "tests/global.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; import { cusProductToSub } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; import { timeout } from "@/utils/genUtils.js"; -import { expect } from "chai"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const testCase = "cancel1"; describe(`${chalk.yellowBright("cancel1: Testing cancel for trial products")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -58,7 +50,7 @@ describe(`${chalk.yellowBright("cancel1: Testing cancel for trial products")}`, testClockId = testClockId1!; }); - it("should attach pro", async function () { + it("should attach pro", async () => { await autumn.attach({ customer_id: customerId, product_id: products.pro.id, @@ -73,7 +65,7 @@ describe(`${chalk.yellowBright("cancel1: Testing cancel for trial products")}`, let sub: Stripe.Subscription | undefined; - it("should cancel pro product through stripe CLI", async function () { + it("should cancel pro product through stripe CLI", async () => { const fullCus = await CusService.getFull({ db, idOrInternalId: customerId, @@ -107,7 +99,7 @@ describe(`${chalk.yellowBright("cancel1: Testing cancel for trial products")}`, }); return; - it("should renew pro produce through stripe CLI and have it update correctly", async function () { + it("should renew pro produce through stripe CLI and have it update correctly", async () => { await stripeCli.subscriptions.update(sub!.id, { cancel_at_period_end: false, }); diff --git a/server/tests/core/cancel/mergedCancel1.test.ts b/server/tests/core/cancel/mergedCancel1.test.ts index 3da442a29..3bf9afe99 100644 --- a/server/tests/core/cancel/mergedCancel1.test.ts +++ b/server/tests/core/cancel/mergedCancel1.test.ts @@ -1,31 +1,26 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, - AttachBranch, + type AppEnv, AttachScenario, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { - constructArrearItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -71,8 +66,8 @@ const renewals = [ const testCase = "mergedCancel1"; describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -129,7 +124,7 @@ describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -153,7 +148,7 @@ describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { } }); - it("should track usage cancel, advance test clock and have correct invoice", async function () { + it("should track usage cancel, advance test clock and have correct invoice", async () => { for (const cancel of cancels) { await autumn.cancel({ customer_id: customerId, @@ -172,7 +167,7 @@ describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { } }); - it("should renew both entities", async function () { + it("should renew both entities", async () => { for (const renewal of renewals) { const checkout = await autumn.checkout({ customer_id: customerId, diff --git a/server/tests/core/cancel/mergedCancel2.test.ts b/server/tests/core/cancel/mergedCancel2.test.ts index 2508bd6e2..730c52795 100644 --- a/server/tests/core/cancel/mergedCancel2.test.ts +++ b/server/tests/core/cancel/mergedCancel2.test.ts @@ -1,30 +1,28 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // Premium, Premium // Cancel End, Cancel Immediately // Results: Canceled sub -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -58,8 +56,8 @@ const cancels = [ const testCase = "mergedCancel2"; describe(`${chalk.yellowBright("mergedCancel2: Testing cancel immediately")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -116,7 +114,7 @@ describe(`${chalk.yellowBright("mergedCancel2: Testing cancel immediately")}`, ( }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -139,7 +137,7 @@ describe(`${chalk.yellowBright("mergedCancel2: Testing cancel immediately")}`, ( } }); - it("should track usage cancel, advance test clock and have correct invoice", async function () { + it("should track usage cancel, advance test clock and have correct invoice", async () => { for (const cancel of cancels) { await autumn.cancel({ customer_id: customerId, diff --git a/server/tests/core/cancel/mergedCancel3.test.ts b/server/tests/core/cancel/mergedCancel3.test.ts index 6329b1f08..fe4383515 100644 --- a/server/tests/core/cancel/mergedCancel3.test.ts +++ b/server/tests/core/cancel/mergedCancel3.test.ts @@ -1,31 +1,28 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, - AttachScenario, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // Premium, Premium // Cancel Immediately, Cancel Immediately // Results: No sub -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -61,8 +58,8 @@ const cancels = [ const testCase = "mergedCancel3"; describe(`${chalk.yellowBright("mergedCancel3: Testing cancel immediately")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -119,7 +116,7 @@ describe(`${chalk.yellowBright("mergedCancel3: Testing cancel immediately")}`, ( }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -142,7 +139,7 @@ describe(`${chalk.yellowBright("mergedCancel3: Testing cancel immediately")}`, ( } }); - it("should track usage cancel, advance test clock and have correct invoice", async function () { + it("should track usage cancel, advance test clock and have correct invoice", async () => { for (const cancel of cancels) { await autumn.cancel({ customer_id: customerId, diff --git a/server/tests/core/multiAttach/multiAttach1.test.ts b/server/tests/core/multiAttach/multiAttach1.test.ts index 800938772..c11630711 100644 --- a/server/tests/core/multiAttach/multiAttach1.test.ts +++ b/server/tests/core/multiAttach/multiAttach1.test.ts @@ -1,25 +1,25 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import chalk from "chalk"; import { addDays } from "date-fns"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectMultiAttachCorrect } from "tests/utils/expectUtils/expectMultiAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let growth = constructProduct({ +const growth = constructProduct({ id: "growth", items: [ constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 100 }), @@ -27,7 +27,7 @@ let growth = constructProduct({ type: "growth", }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [ constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 200 }), @@ -36,7 +36,7 @@ let premium = constructProduct({ trial: true, }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [ constructFeatureItem({ @@ -63,9 +63,9 @@ const ops = [ const testCase = "multiAttach1"; describe(`${chalk.yellowBright("multiAttach1: Testing multi attach for trial products and update product quantities mid trial")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ - version: APIVersion.v1_4, + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ + version: LegacyVersion.v1_4, orgConfig: { entity_product: true }, }); @@ -111,7 +111,7 @@ describe(`${chalk.yellowBright("multiAttach1: Testing multi attach for trial pro testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -143,7 +143,7 @@ describe(`${chalk.yellowBright("multiAttach1: Testing multi attach for trial pro }); }); - it("should advance clock and update premium & growth while trialing", async function () { + it("should advance clock and update premium & growth while trialing", async () => { const newProducts = [ { product_id: premium.id, diff --git a/server/tests/core/multiAttach/multiAttach2.test.ts b/server/tests/core/multiAttach/multiAttach2.test.ts index 966e3fbcf..6091fcac7 100644 --- a/server/tests/core/multiAttach/multiAttach2.test.ts +++ b/server/tests/core/multiAttach/multiAttach2.test.ts @@ -1,7 +1,7 @@ import { - APIVersion, type AppEnv, CusProductStatus, + LegacyVersion, type Organization, } from "@autumn/shared"; import chalk from "chalk"; @@ -64,7 +64,7 @@ const ops = [ const testCase = "multiAttach2"; describe(`${chalk.yellowBright("multiAttach2: Testing multi attach for trial products and update product quantities mid trial")}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; diff --git a/server/tests/core/multiAttach/multiAttach3.test.ts b/server/tests/core/multiAttach/multiAttach3.test.ts index 319e0c458..0be6fce9c 100644 --- a/server/tests/core/multiAttach/multiAttach3.test.ts +++ b/server/tests/core/multiAttach/multiAttach3.test.ts @@ -1,7 +1,7 @@ import { - APIVersion, type AppEnv, CusProductStatus, + LegacyVersion, type Organization, } from "@autumn/shared"; import { expect } from "chai"; @@ -52,7 +52,7 @@ const testCase = "multiAttach3"; describe(`${chalk.yellowBright("multiAttach3: Testing multi attach for trial products transfer to entity, then cancel products on entities...")}`, () => { const customerId = testCase; const autumn: AutumnInt = new AutumnInt({ - version: APIVersion.v1_4, + version: LegacyVersion.v1_4, orgConfig: { entity_product: true }, }); diff --git a/server/tests/core/multiAttach/multiAttach4.test.ts b/server/tests/core/multiAttach/multiAttach4.test.ts index acdf573b6..445ded29d 100644 --- a/server/tests/core/multiAttach/multiAttach4.test.ts +++ b/server/tests/core/multiAttach/multiAttach4.test.ts @@ -1,33 +1,33 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; +import { expect } from "chai"; +import chalk from "chalk"; +import { addDays } from "date-fns"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectMultiAttachCorrect, expectResultsCorrect, } from "tests/utils/expectUtils/expectMultiAttach.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addDays } from "date-fns"; -import { expect } from "chai"; +import { + addPrefixToProducts, + getBasePrice, +} from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [ constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 200 }), @@ -35,7 +35,7 @@ let premium = constructProduct({ type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [ constructFeatureItem({ @@ -45,7 +45,7 @@ let pro = constructProduct({ ], type: "pro", }); -let proAnnual = constructProduct({ +const proAnnual = constructProduct({ id: "proAnnual", items: [ constructFeatureItem({ @@ -59,8 +59,8 @@ let proAnnual = constructProduct({ const testCase = "multiAttach4"; describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual products...")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -104,7 +104,7 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -176,7 +176,7 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr }, ]; - it("should transfer to entity and have correct sub", async function () { + it("should transfer to entity and have correct sub", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -201,7 +201,7 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr }); }); - it("should cancel one entity's sub at end of cycle and have correct schedule...", async function () { + it("should cancel one entity's sub at end of cycle and have correct schedule...", async () => { await autumn.cancel({ customer_id: customerId, product_id: pro.id, @@ -216,13 +216,13 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr }); }); - it("should cancel one entity's sub immediately", async function () { + it("should cancel one entity's sub immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: premium.id, entity_id: "1", cancel_immediately: true, - // @ts-ignore + // @ts-expect-error prorate: false, }); @@ -234,7 +234,7 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr }); }); - it("should advance test clock to end of trial and have correct sub", async function () { + it("should advance test clock to end of trial and have correct sub", async () => { await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/core/multiAttach/multiAttach5.test.ts b/server/tests/core/multiAttach/multiAttach5.test.ts index aaa9a798c..d1cba1890 100644 --- a/server/tests/core/multiAttach/multiAttach5.test.ts +++ b/server/tests/core/multiAttach/multiAttach5.test.ts @@ -1,40 +1,31 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, - organizations, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; +import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; import { expectMultiAttachCorrect, expectResultsCorrect, } from "tests/utils/expectUtils/expectMultiAttach.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addDays } from "date-fns"; -import { expect } from "chai"; -import { OrgService } from "@/internal/orgs/OrgService.js"; -import { clearOrgCache } from "@/internal/orgs/orgUtils/clearOrgCache.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; -import { eq } from "drizzle-orm"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CacheManager } from "@/external/caching/CacheManager.js"; +import { OrgService } from "@/internal/orgs/OrgService.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [ constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 200 }), @@ -42,7 +33,7 @@ let premium = constructProduct({ type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [ constructFeatureItem({ @@ -55,8 +46,8 @@ let pro = constructProduct({ const testCase = "multiAttach5"; describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get customer")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -111,7 +102,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -150,7 +141,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }, ]; - it("should transfer to entity 1 and 2", async function () { + it("should transfer to entity 1 and 2", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -216,7 +207,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }); }); - it("should try to reduce quantity of pro to less than number of entities and fail", async function () { + it("should try to reduce quantity of pro to less than number of entities and fail", async () => { await expectAutumnError({ func: async () => { await autumn.attach({ @@ -232,7 +223,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }); }); - it("should update pro product quantity and have correct amount", async function () { + it("should update pro product quantity and have correct amount", async () => { await expectMultiAttachCorrect({ customerId, products: [ @@ -266,7 +257,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }); }); - it("should decrease pro product quantity and have correct amount", async function () { + it("should decrease pro product quantity and have correct amount", async () => { await expectMultiAttachCorrect({ customerId, products: [ @@ -300,7 +291,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }); }); - after(async function () { + after(async () => { await OrgService.update({ db, orgId: org.id, diff --git a/server/tests/core/multiAttach/multiAttach6.test.ts b/server/tests/core/multiAttach/multiAttach6.test.ts index 3d4cc3621..80ec920e7 100644 --- a/server/tests/core/multiAttach/multiAttach6.test.ts +++ b/server/tests/core/multiAttach/multiAttach6.test.ts @@ -1,35 +1,33 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - FullCusProduct, + type FullCusProduct, + LegacyVersion, nullish, - Organization, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectMultiAttachCorrect, expectResultsCorrect, } from "tests/utils/expectUtils/expectMultiAttach.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; - -import { expect } from "chai"; -import { OrgService } from "@/internal/orgs/OrgService.js"; - +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CacheManager } from "@/external/caching/CacheManager.js"; import { CusService } from "@/internal/customers/CusService.js"; +import { OrgService } from "@/internal/orgs/OrgService.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [ constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 200 }), @@ -37,7 +35,7 @@ let premium = constructProduct({ type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [ constructFeatureItem({ @@ -50,8 +48,8 @@ let pro = constructProduct({ const testCase = "multiAttach6"; describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get customer")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -106,7 +104,7 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -145,7 +143,7 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo }, ]; - it("should transfer to entity 1 and 2", async function () { + it("should transfer to entity 1 and 2", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -200,7 +198,7 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo }); }); - it("should try to reduce quantity of pro to 0 and have no top level cus product...", async function () { + it("should try to reduce quantity of pro to 0 and have no top level cus product...", async () => { await autumn.attach({ customer_id: customerId, products: [ @@ -250,7 +248,7 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo expect(proProduct).to.be.undefined; }); - it("should increase pro product quantity and have correct amount", async function () { + it("should increase pro product quantity and have correct amount", async () => { await autumn.attach({ customer_id: customerId, products: [ @@ -262,7 +260,7 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo }); }); - after(async function () { + after(async () => { await OrgService.update({ db, orgId: org.id, diff --git a/server/tests/core/multiAttach/multiInvoice/multiInvoice1.test.ts b/server/tests/core/multiAttach/multiInvoice/multiInvoice1.test.ts index 1aee9cd7f..bc0eb0c6d 100644 --- a/server/tests/core/multiAttach/multiInvoice/multiInvoice1.test.ts +++ b/server/tests/core/multiAttach/multiInvoice/multiInvoice1.test.ts @@ -1,38 +1,23 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { - constructArrearItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { - advanceTestClock, - completeCheckoutForm, -} from "tests/utils/stripeUtils.js"; -import { addDays, addWeeks } from "date-fns"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectMultiAttachCorrect } from "tests/utils/expectUtils/expectMultiAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [ constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 200 }), @@ -41,7 +26,7 @@ let premium = constructProduct({ trial: true, }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [ constructFeatureItem({ @@ -68,8 +53,8 @@ const ops = [ const testCase = "multiInvoice1"; describe(`${chalk.yellowBright("multiInvoice1: Testing multi attach through invoice flow")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -113,7 +98,7 @@ describe(`${chalk.yellowBright("multiInvoice1: Testing multi attach through invo testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -143,7 +128,7 @@ describe(`${chalk.yellowBright("multiInvoice1: Testing multi attach through invo }); }); - it("should update premium & pro while trialing", async function () { + it("should update premium & pro while trialing", async () => { const newProducts = [ { product_id: premium.id, diff --git a/server/tests/core/multiAttach/multiReward/multiReward1.test.ts b/server/tests/core/multiAttach/multiReward/multiReward1.test.ts index 6136b34ed..f1a638168 100644 --- a/server/tests/core/multiAttach/multiReward/multiReward1.test.ts +++ b/server/tests/core/multiAttach/multiReward/multiReward1.test.ts @@ -1,18 +1,16 @@ +import { + type AppEnv, + CusProductStatus, + LegacyVersion, + type Organization, +} from "@autumn/shared"; import chalk from "chalk"; +import type { Stripe } from "stripe"; import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; +import { expectMultiAttachCorrect } from "tests/utils/expectUtils/expectMultiAttach.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - -import { - APIVersion, - AppEnv, - CusProductStatus, - Organization, -} from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { expectMultiAttachCorrect } from "tests/utils/expectUtils/expectMultiAttach.js"; import { multiRewardPremium, multiRewardPro, @@ -23,8 +21,8 @@ import { const testCase = "multiReward1"; describe(`${chalk.yellowBright("multiReward1: Testing multi attach with rewards")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -74,7 +72,7 @@ describe(`${chalk.yellowBright("multiReward1: Testing multi attach with rewards" testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: multiRewardPro.id, diff --git a/server/tests/core/multiAttach/multiReward/multiReward2.test.ts b/server/tests/core/multiAttach/multiReward/multiReward2.test.ts index e79f3d607..8d67e5c3b 100644 --- a/server/tests/core/multiAttach/multiReward/multiReward2.test.ts +++ b/server/tests/core/multiAttach/multiReward/multiReward2.test.ts @@ -1,18 +1,18 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; import { expectMultiAttachCorrect } from "tests/utils/expectUtils/expectMultiAttach.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { CusService } from "@/internal/customers/CusService.js"; +import { cusProductToSub } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { multiRewardPremium, multiRewardPro, @@ -20,14 +20,11 @@ import { proReward, setupMultiRewardBefore, } from "./multiRewardUtils.test.js"; -import { CusService } from "@/internal/customers/CusService.js"; -import { cusProductToSub } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; -import { createStripeCli } from "@/external/stripe/utils.js"; const testCase = "multiReward2"; describe(`${chalk.yellowBright("multiReward2: Testing multi attach with rewards -- delete reward and prorate")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -63,7 +60,7 @@ describe(`${chalk.yellowBright("multiReward2: Testing multi attach with rewards testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: multiRewardPro.id, @@ -90,7 +87,7 @@ describe(`${chalk.yellowBright("multiReward2: Testing multi attach with rewards }); }); - it("should delete discounts from subscription and prorate correctly", async function () { + it("should delete discounts from subscription and prorate correctly", async () => { const fullCus = await CusService.getFull({ db, orgId: org.id, @@ -108,7 +105,7 @@ describe(`${chalk.yellowBright("multiReward2: Testing multi attach with rewards }); }); - it("should update pro quantity and have correct checkout amount", async function () { + it("should update pro quantity and have correct checkout amount", async () => { const productsList = [ { product_id: multiRewardPro.id, diff --git a/server/tests/core/multiAttach/multiReward/multiReward3.test.ts b/server/tests/core/multiAttach/multiReward/multiReward3.test.ts index 1bbea8cfe..471249b34 100644 --- a/server/tests/core/multiAttach/multiReward/multiReward3.test.ts +++ b/server/tests/core/multiAttach/multiReward/multiReward3.test.ts @@ -1,41 +1,34 @@ +import { + type AppEnv, + CusProductStatus, + LegacyVersion, + type Organization, +} from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; +import { addDays } from "date-fns"; +import { Decimal } from "decimal.js"; +import type { Stripe } from "stripe"; import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; +import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { expectMultiAttachCorrect } from "tests/utils/expectUtils/expectMultiAttach.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, - CusProductStatus, - Organization, -} from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { expectMultiAttachCorrect } from "tests/utils/expectUtils/expectMultiAttach.js"; -import { - multiRewardPremium, - multiRewardPro, premiumReward, premiumTrial, proReward, proTrial, setupMultiRewardBefore, } from "./multiRewardUtils.test.js"; -import { CusService } from "@/internal/customers/CusService.js"; -import { cusProductToSub } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; -import { createStripeCli } from "@/external/stripe/utils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addDays } from "date-fns"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { expect } from "chai"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; -import { Decimal } from "decimal.js"; const testCase = "multiReward3"; describe(`${chalk.yellowBright("multiReward3: Testing multi attach with rewards -- advance clock and update pro quantity")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -71,7 +64,7 @@ describe(`${chalk.yellowBright("multiReward3: Testing multi attach with rewards testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: proTrial.id, @@ -100,7 +93,7 @@ describe(`${chalk.yellowBright("multiReward3: Testing multi attach with rewards let checkoutRes: any; - it("should advance clock and update pro quantity", async function () { + it("should advance clock and update pro quantity", async () => { const productsList = [ { product_id: proTrial.id, @@ -136,7 +129,7 @@ describe(`${chalk.yellowBright("multiReward3: Testing multi attach with rewards checkoutRes = res.checkoutRes; }); - it("should advance to trial end and have correct quantity", async function () { + it("should advance to trial end and have correct quantity", async () => { await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/core/multiAttach/multiReward/multiRewardUtils.test.ts b/server/tests/core/multiAttach/multiReward/multiRewardUtils.test.ts index 97ae7bc58..d6ce9ada4 100644 --- a/server/tests/core/multiAttach/multiReward/multiRewardUtils.test.ts +++ b/server/tests/core/multiAttach/multiReward/multiRewardUtils.test.ts @@ -1,20 +1,18 @@ -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { ProductService } from "@/internal/products/ProductService.js"; -import { RewardService } from "@/internal/rewards/RewardService.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { - APIVersion, - AppEnv, + type AppEnv, CouponDurationType, - CreateReward, - ProductItemInterval, + type CreateReward, + LegacyVersion, RewardType, } from "@autumn/shared"; import { TestFeature } from "tests/setup/v2Features.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { ProductService } from "@/internal/products/ProductService.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -export let premiumTrial = constructProduct({ +export const premiumTrial = constructProduct({ id: "multiReward_premiumTrial", group: "multiReward", items: [ @@ -24,7 +22,7 @@ export let premiumTrial = constructProduct({ trial: true, }); -export let proTrial = constructProduct({ +export const proTrial = constructProduct({ id: "multiReward_proTrial", group: "multiReward", items: [ @@ -33,7 +31,7 @@ export let proTrial = constructProduct({ type: "pro", trial: true, }); -export let multiRewardPremium = constructProduct({ +export const multiRewardPremium = constructProduct({ id: "multiReward_premium", group: "multiReward", items: [ @@ -42,7 +40,7 @@ export let multiRewardPremium = constructProduct({ type: "premium", }); -export let multiRewardPro = constructProduct({ +export const multiRewardPro = constructProduct({ id: "multiReward_pro", group: "multiReward", items: [ @@ -89,7 +87,7 @@ export const setupMultiRewardBefore = async ({ db: DrizzleCli; env: AppEnv; }) => { - const autumn = new AutumnInt({ version: APIVersion.v1_2 }); + const autumn = new AutumnInt({ version: LegacyVersion.v1_2 }); for (const product of [ proTrial, premiumTrial, @@ -134,7 +132,7 @@ export const setupMultiRewardBefore = async ({ ]; for (const reward of [proReward, premiumReward]) { - let rewardRes = null; + const rewardRes = null; // try { // rewardRes = await autumn.rewards.get(reward.id); // } catch (error) {} diff --git a/server/tests/core/multiAttach/multiUpgrade/multiUpgrade1.test.ts b/server/tests/core/multiAttach/multiUpgrade/multiUpgrade1.test.ts index 119017152..8e820ed24 100644 --- a/server/tests/core/multiAttach/multiUpgrade/multiUpgrade1.test.ts +++ b/server/tests/core/multiAttach/multiUpgrade/multiUpgrade1.test.ts @@ -1,35 +1,28 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectMultiAttachCorrect, expectResultsCorrect, } from "tests/utils/expectUtils/expectMultiAttach.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addDays } from "date-fns"; -import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { updateOrgConfig } from "@/internal/orgs/orgUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [ constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 200 }), @@ -37,7 +30,7 @@ let premium = constructProduct({ type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [ constructFeatureItem({ @@ -50,9 +43,9 @@ let pro = constructProduct({ const testCase = "multiUpgrade1"; describe(`${chalk.yellowBright("multiUpgrade1: Testing multi attach and upgrade")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ - version: APIVersion.v1_4, + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ + version: LegacyVersion.v1_4, orgConfig: { entity_product: true }, }); @@ -99,7 +92,7 @@ describe(`${chalk.yellowBright("multiUpgrade1: Testing multi attach and upgrade" testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -153,7 +146,7 @@ describe(`${chalk.yellowBright("multiUpgrade1: Testing multi attach and upgrade" }, ]; - it("should transfer to entity and have correct sub", async function () { + it("should transfer to entity and have correct sub", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -175,7 +168,7 @@ describe(`${chalk.yellowBright("multiUpgrade1: Testing multi attach and upgrade" }); }); - it("should upgrade entity's sub to premium", async function () { + it("should upgrade entity's sub to premium", async () => { const checkoutRes = await autumn.checkout({ customer_id: customerId, product_id: premium.id, diff --git a/server/tests/core/multiAttach/multiUpgrade/multiUpgrade2.test.ts b/server/tests/core/multiAttach/multiUpgrade/multiUpgrade2.test.ts index 630c9d052..1fb65e3c2 100644 --- a/server/tests/core/multiAttach/multiUpgrade/multiUpgrade2.test.ts +++ b/server/tests/core/multiAttach/multiUpgrade/multiUpgrade2.test.ts @@ -1,27 +1,27 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectMultiAttachCorrect, expectResultsCorrect, } from "tests/utils/expectUtils/expectMultiAttach.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [ constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 200 }), @@ -29,7 +29,7 @@ let premium = constructProduct({ type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [ constructFeatureItem({ @@ -42,9 +42,9 @@ let pro = constructProduct({ const testCase = "multiUpgrade2"; describe(`${chalk.yellowBright("multiUpgrade2: Testing multi attach and update quantities downward")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ - version: APIVersion.v1_4, + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ + version: LegacyVersion.v1_4, orgConfig: { entity_product: true }, }); @@ -90,7 +90,7 @@ describe(`${chalk.yellowBright("multiUpgrade2: Testing multi attach and update q testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async function () { + it("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -144,7 +144,7 @@ describe(`${chalk.yellowBright("multiUpgrade2: Testing multi attach and update q }, ]; - it("should transfer to entity and have correct sub", async function () { + it("should transfer to entity and have correct sub", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -166,7 +166,7 @@ describe(`${chalk.yellowBright("multiUpgrade2: Testing multi attach and update q }); }); - it("should update premium and pro quantities downward", async function () { + it("should update premium and pro quantities downward", async () => { const productsList = [ { product_id: pro.id, diff --git a/server/tests/core/reset1.ts b/server/tests/core/reset1.ts index ca0056cb7..f22aba0cb 100644 --- a/server/tests/core/reset1.ts +++ b/server/tests/core/reset1.ts @@ -1,31 +1,26 @@ -import chalk from "chalk"; -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - import { - APIVersion, - AppEnv, - Customer, - LimitedItem, - Organization, + type AppEnv, + type Customer, + LegacyVersion, + type LimitedItem, + type Organization, ProductItemInterval, - RolloverDuration, } from "@autumn/shared"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { addPrefixToProducts } from "tests/attach/utils.js"; - import { expect } from "chai"; -import { timeout } from "@/utils/genUtils.js"; -import { resetAndGetCusEnt } from "tests/advanced/rollovers/rolloverTestUtils.js"; -import { UTCDate } from "@date-fns/utc"; +import chalk from "chalk"; import { addDays, addMonths } from "date-fns"; +import type Stripe from "stripe"; +import { resetAndGetCusEnt } from "tests/advanced/rollovers/rolloverTestUtils.js"; +import { addPrefixToProducts } from "tests/attach/utils.js"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const messagesItem = constructFeatureItem({ featureId: TestFeature.Messages, @@ -41,7 +36,7 @@ const wordsItem = constructFeatureItem({ intervalCount: 4, }) as LimitedItem; -export let free = constructProduct({ +export const free = constructProduct({ items: [messagesItem, wordsItem], type: "free", isDefault: false, @@ -50,13 +45,13 @@ export let free = constructProduct({ const testCase = "reset1"; describe(`${chalk.yellowBright(`${testCase}: Testing custom reset intervals`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let customer: Customer; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -94,17 +89,17 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom reset intervals`)}`, customer = res.customer; }); - it("should attach free product", async function () { + it("should attach free product", async () => { await autumn.attach({ customer_id: customerId, product_id: free.id, }); }); - let messageUsage = 250; - let curBalance = messagesItem.included_usage; + const messageUsage = 250; + const curBalance = messagesItem.included_usage; - it("should reset messages feature and have correct next reset at", async function () { + it("should reset messages feature and have correct next reset at", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Messages, @@ -129,7 +124,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom reset intervals`)}`, ); }); - it("should reset words feature and have correct next reset at", async function () { + it("should reset words feature and have correct next reset at", async () => { await resetAndGetCusEnt({ db, customer, diff --git a/server/tests/interval/multiSub/multiSubInterval1.test.ts b/server/tests/interval/multiSub/multiSubInterval1.test.ts index ba0fc1c8a..fb30a191f 100644 --- a/server/tests/interval/multiSub/multiSubInterval1.test.ts +++ b/server/tests/interval/multiSub/multiSubInterval1.test.ts @@ -1,29 +1,29 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import { addMonths, addWeeks } from "date-fns"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addMonths, addWeeks, addYears } from "date-fns"; -import { toMilliseconds } from "@/utils/timeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { getCusSub } from "@/utils/scriptUtils/testUtils/cusTestUtils.js"; +import { toMilliseconds } from "@/utils/timeUtils.js"; -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); -let proAnnual = constructProduct({ +const proAnnual = constructProduct({ id: "proAnnual", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", @@ -32,8 +32,8 @@ let proAnnual = constructProduct({ const testCase = "multiSubInterval1"; describe(`${chalk.yellowBright("multiSubInterval1: Should attach pro and pro annual to entity mid cycle and have correct next cycle at")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -90,7 +90,7 @@ describe(`${chalk.yellowBright("multiSubInterval1: Should attach pro and pro ann }, ]; - it("should attach pro and advance test clock", async function () { + it("should attach pro and advance test clock", async () => { await autumn.entities.create(customerId, entities); await attachAndExpectCorrect({ @@ -110,7 +110,7 @@ describe(`${chalk.yellowBright("multiSubInterval1: Should attach pro and pro ann }); }); - it("should attach pro to entity 2 and have correct next cycle at", async function () { + it("should attach pro to entity 2 and have correct next cycle at", async () => { const checkoutRes = await autumn.checkout({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/interval/multiSub/multiSubInterval2.test.ts b/server/tests/interval/multiSub/multiSubInterval2.test.ts index afc2f2483..9578a7c6a 100644 --- a/server/tests/interval/multiSub/multiSubInterval2.test.ts +++ b/server/tests/interval/multiSub/multiSubInterval2.test.ts @@ -1,32 +1,29 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { - constructArrearItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; +import chalk from "chalk"; +import { addMonths, addYears, differenceInDays } from "date-fns"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addMonths, addWeeks, addYears, differenceInDays } from "date-fns"; -import { toMilliseconds } from "@/utils/timeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { getCusSub } from "@/utils/scriptUtils/testUtils/cusTestUtils.js"; +import { toMilliseconds } from "@/utils/timeUtils.js"; -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); -let proAnnual = constructProduct({ +const proAnnual = constructProduct({ id: "proAnnual", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", @@ -35,8 +32,8 @@ let proAnnual = constructProduct({ const testCase = "multiSubInterval2"; describe(`${chalk.yellowBright("multiSubInterval2: Should attach pro and pro annual to entity mid cycle and have correct next cycle at")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -93,7 +90,7 @@ describe(`${chalk.yellowBright("multiSubInterval2: Should attach pro and pro ann }, ]; - it("should attach pro and advance test clock", async function () { + it("should attach pro and advance test clock", async () => { await autumn.entities.create(customerId, entities); await attachAndExpectCorrect({ @@ -113,7 +110,7 @@ describe(`${chalk.yellowBright("multiSubInterval2: Should attach pro and pro ann }); }); - it("should attach pro annual to entity 2 and have correct next cycle at", async function () { + it("should attach pro annual to entity 2 and have correct next cycle at", async () => { const checkoutRes = await autumn.checkout({ customer_id: customerId, product_id: proAnnual.id, diff --git a/server/tests/interval/multiSub/multiSubInterval3.test.ts b/server/tests/interval/multiSub/multiSubInterval3.test.ts index e872d85b9..d51f12b73 100644 --- a/server/tests/interval/multiSub/multiSubInterval3.test.ts +++ b/server/tests/interval/multiSub/multiSubInterval3.test.ts @@ -1,32 +1,32 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; +import { addMonths, addYears, differenceInDays } from "date-fns"; +import type { Stripe } from "stripe"; import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; import { constructArrearItem, constructFeatureItem, } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addMonths, addWeeks, addYears, differenceInDays } from "date-fns"; -import { toMilliseconds } from "@/utils/timeUtils.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { getCusSub } from "@/utils/scriptUtils/testUtils/cusTestUtils.js"; +import { toMilliseconds } from "@/utils/timeUtils.js"; -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); -let proAnnual = constructProduct({ +const proAnnual = constructProduct({ id: "proAnnual", items: [ constructArrearItem({ featureId: TestFeature.Credits }), @@ -38,8 +38,8 @@ let proAnnual = constructProduct({ const testCase = "multiSubInterval3"; describe(`${chalk.yellowBright("multiSubInterval3: Should attach pro and pro annual (with monthly usage price) to entity mid cycle and have correct next cycle at")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -96,7 +96,7 @@ describe(`${chalk.yellowBright("multiSubInterval3: Should attach pro and pro ann }, ]; - it("should attach pro and advance test clock", async function () { + it("should attach pro and advance test clock", async () => { await autumn.entities.create(customerId, entities); await attachAndExpectCorrect({ @@ -116,7 +116,7 @@ describe(`${chalk.yellowBright("multiSubInterval3: Should attach pro and pro ann }); }); - it("should attach pro annual to entity 2 and have correct next cycle at", async function () { + it("should attach pro annual to entity 2 and have correct next cycle at", async () => { const checkoutRes = await autumn.checkout({ customer_id: customerId, product_id: proAnnual.id, diff --git a/server/tests/interval/upgrade/interval1.test.ts b/server/tests/interval/upgrade/interval1.test.ts index fdca5c069..23398d0cc 100644 --- a/server/tests/interval/upgrade/interval1.test.ts +++ b/server/tests/interval/upgrade/interval1.test.ts @@ -1,29 +1,29 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import chalk from "chalk"; import { addWeeks, addYears } from "date-fns"; -import { toMilliseconds } from "@/utils/timeUtils.js"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { getCusSub } from "@/utils/scriptUtils/testUtils/cusTestUtils.js"; +import { toMilliseconds } from "@/utils/timeUtils.js"; -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); -let proAnnual = constructProduct({ +const proAnnual = constructProduct({ id: "proAnnual", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", @@ -32,8 +32,8 @@ let proAnnual = constructProduct({ const testCase = "interval1"; describe(`${chalk.yellowBright("interval1: Should upgrade from pro to pro annual mid cycle and have correct next cycle at")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -77,7 +77,7 @@ describe(`${chalk.yellowBright("interval1: Should upgrade from pro to pro annual testClockId = testClockId1!; }); - it("should attach pro and advance test clock", async function () { + it("should attach pro and advance test clock", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -95,7 +95,7 @@ describe(`${chalk.yellowBright("interval1: Should upgrade from pro to pro annual }); }); - it("should upgrade to pro annual and have correct next cycle at", async function () { + it("should upgrade to pro annual and have correct next cycle at", async () => { const checkoutRes = await autumn.checkout({ customer_id: customerId, product_id: proAnnual.id, diff --git a/server/tests/interval/upgrade/interval2.test.ts b/server/tests/interval/upgrade/interval2.test.ts index b495a204d..dfa177f48 100644 --- a/server/tests/interval/upgrade/interval2.test.ts +++ b/server/tests/interval/upgrade/interval2.test.ts @@ -1,4 +1,4 @@ -import { APIVersion, type AppEnv, type Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; import chalk from "chalk"; import { addMonths, addWeeks, addYears } from "date-fns"; @@ -33,7 +33,7 @@ const proAnnual = constructProduct({ const testCase = "interval2"; describe(`${chalk.yellowBright("interval2: Should upgrade from pro to pro annual after 1.5 cycles and have correct next cycle at")}`, () => { const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; diff --git a/server/tests/interval/upgrade/interval3.test.ts b/server/tests/interval/upgrade/interval3.test.ts index 9b2917205..1aaf18989 100644 --- a/server/tests/interval/upgrade/interval3.test.ts +++ b/server/tests/interval/upgrade/interval3.test.ts @@ -1,30 +1,30 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import chalk from "chalk"; import { addDays } from "date-fns"; -import { toMilliseconds } from "@/utils/timeUtils.js"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { getCusSub } from "@/utils/scriptUtils/testUtils/cusTestUtils.js"; +import { toMilliseconds } from "@/utils/timeUtils.js"; -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", trial: true, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "premium", @@ -33,8 +33,8 @@ let premium = constructProduct({ const testCase = "interval3"; describe(`${chalk.yellowBright("interval3: Should upgrade from pro trial to premium trial and have correct next cycle at")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -78,7 +78,7 @@ describe(`${chalk.yellowBright("interval3: Should upgrade from pro trial to prem testClockId = testClockId1!; }); - it("should attach pro and advance test clock", async function () { + it("should attach pro and advance test clock", async () => { await attachAndExpectCorrect({ autumn, customerId, @@ -96,7 +96,7 @@ describe(`${chalk.yellowBright("interval3: Should upgrade from pro trial to prem }); }); - it("should upgrade to premium and have correct next cycle at", async function () { + it("should upgrade to premium and have correct next cycle at", async () => { const checkoutRes = await autumn.checkout({ customer_id: customerId, product_id: premium.id, diff --git a/server/tests/merged/add/mergedAdd1.test.ts b/server/tests/merged/add/mergedAdd1.test.ts index bae12984a..40f671267 100644 --- a/server/tests/merged/add/mergedAdd1.test.ts +++ b/server/tests/merged/add/mergedAdd1.test.ts @@ -1,36 +1,35 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; +import type { Stripe } from "stripe"; import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { getAttachPreviewTotal } from "tests/utils/testAttachUtils/getAttachPreviewTotal.js"; +import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; import { addPrefixToProducts, getBasePrice, } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils.test.js"; -import { getAttachPreviewTotal } from "tests/utils/testAttachUtils/getAttachPreviewTotal.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { timeout } from "@/utils/genUtils.js"; - // UNCOMMENT FROM HERE -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); describe(`${chalk.yellowBright("mergedAdd1: Testing merged subs, with track")}`, () => { - let customerId = "mergedAdd1"; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = "mergedAdd1"; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -87,7 +86,7 @@ describe(`${chalk.yellowBright("mergedAdd1: Testing merged subs, with track")}`, }, ]; - it("should attach pro product", async function () { + it("should attach pro product", async () => { await autumn.entities.create(customerId, entities); await autumn.attach({ @@ -121,7 +120,7 @@ describe(`${chalk.yellowBright("mergedAdd1: Testing merged subs, with track")}`, }); }); - it("should track usage and have correct invoice end of month", async function () { + it("should track usage and have correct invoice end of month", async () => { const value1 = 110000; const value2 = 310000; const values = [value1, value2]; diff --git a/server/tests/merged/add/mergedAdd2.test.ts b/server/tests/merged/add/mergedAdd2.test.ts index e2c79d5fe..1ebf254fa 100644 --- a/server/tests/merged/add/mergedAdd2.test.ts +++ b/server/tests/merged/add/mergedAdd2.test.ts @@ -1,23 +1,23 @@ +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; +import type { Stripe } from "stripe"; import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, entities, Organization } from "@autumn/shared"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // UNCOMMENT FROM HERE -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -25,8 +25,8 @@ let pro = constructProduct({ const testCase = "mergedAdd2"; describe(`${chalk.yellowBright(`${testCase}: Testing merged subs, downgrade`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -83,7 +83,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing merged subs, downgrade`)}`, }, ]; - it("should attach pro product", async function () { + it("should attach pro product", async () => { await autumn.entities.create(customerId, entities); await autumn.attach({ @@ -121,7 +121,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing merged subs, downgrade`)}`, return; - it("should track usage and have correct invoice end of month", async function () { + it("should track usage and have correct invoice end of month", async () => { const value1 = 110000; const value2 = 310000; const values = [value1, value2]; diff --git a/server/tests/merged/add/mergedAdd3.test.ts b/server/tests/merged/add/mergedAdd3.test.ts index f5e9de185..3261b4ffe 100644 --- a/server/tests/merged/add/mergedAdd3.test.ts +++ b/server/tests/merged/add/mergedAdd3.test.ts @@ -1,34 +1,30 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - entities, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { - constructArrearItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // UNCOMMENT FROM HERE -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", @@ -62,8 +58,8 @@ const ops = [ const testCase = "mergedAdd3"; describe(`${chalk.yellowBright(`${testCase}: Testing scheduled, and merged add to subscription`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -125,7 +121,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing scheduled, and merged add t }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/addOn/mergedAddOn1.test.ts b/server/tests/merged/addOn/mergedAddOn1.test.ts index 6c7e1c4de..6173b1058 100644 --- a/server/tests/merged/addOn/mergedAddOn1.test.ts +++ b/server/tests/merged/addOn/mergedAddOn1.test.ts @@ -1,36 +1,36 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; import { - constructProduct, - constructRawProduct, -} from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { expect } from "chai"; +import { + constructProduct, + constructRawProduct, +} from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; // UNCOMMENT FROM HERE -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "pro", @@ -92,8 +92,8 @@ const ops = [ const testCase = "mergedAddOn1"; describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -150,7 +150,7 @@ describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -180,7 +180,7 @@ describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { } }); - it("should cancel add on product and have correct sub items", async function () { + it("should cancel add on product and have correct sub items", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, @@ -209,7 +209,7 @@ describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { }); // return; - it("should advance to next invoice and have no add on product", async function () { + it("should advance to next invoice and have no add on product", async () => { await advanceToNextInvoice({ stripeCli, testClockId, diff --git a/server/tests/merged/addOn/mergedAddOn2.test.ts b/server/tests/merged/addOn/mergedAddOn2.test.ts index 70ca3fab5..8e3c71df0 100644 --- a/server/tests/merged/addOn/mergedAddOn2.test.ts +++ b/server/tests/merged/addOn/mergedAddOn2.test.ts @@ -1,34 +1,30 @@ +import { + type AppEnv, + CusProductStatus, + LegacyVersion, + type Organization, +} from "@autumn/shared"; import chalk from "chalk"; +import type { Stripe } from "stripe"; import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { + constructFeatureItem, + constructPrepaidItem, +} from "@/utils/scriptUtils/constructItem.js"; import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { - APIVersion, - AppEnv, - CusProductStatus, - Organization, -} from "@autumn/shared"; -import { - constructArrearItem, - constructFeatureItem, - constructPrepaidItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { expect } from "chai"; -import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "pro", @@ -108,8 +104,8 @@ const ops = [ const testCase = "mergedAddOn2"; describe(`${chalk.yellowBright("mergedAddOn2: testing add ons between multiple entities")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -166,7 +162,7 @@ describe(`${chalk.yellowBright("mergedAddOn2: testing add ons between multiple e }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/addOn/mergedAddOn3.test.ts b/server/tests/merged/addOn/mergedAddOn3.test.ts index f0cb484ed..94d1594cd 100644 --- a/server/tests/merged/addOn/mergedAddOn3.test.ts +++ b/server/tests/merged/addOn/mergedAddOn3.test.ts @@ -1,35 +1,33 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; import { - constructProduct, - constructRawProduct, -} from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - -import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expect } from "chai"; +import { + constructProduct, + constructRawProduct, +} from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "pro", @@ -94,8 +92,8 @@ const ops = [ const testCase = "mergedAddOn3"; describe(`${chalk.yellowBright("mergedAddOn3: testing add ons between multiple entities")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -152,7 +150,7 @@ describe(`${chalk.yellowBright("mergedAddOn3: testing add ons between multiple e }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -183,7 +181,7 @@ describe(`${chalk.yellowBright("mergedAddOn3: testing add ons between multiple e } }); - it("should cancel add on product immediately", async function () { + it("should cancel add on product immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, diff --git a/server/tests/merged/addOn/mergedAddOn4.test.ts b/server/tests/merged/addOn/mergedAddOn4.test.ts index 998c83754..146736fd2 100644 --- a/server/tests/merged/addOn/mergedAddOn4.test.ts +++ b/server/tests/merged/addOn/mergedAddOn4.test.ts @@ -1,41 +1,39 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; import { - constructProduct, - constructRawProduct, -} from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - -import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expect } from "chai"; +import { + constructProduct, + constructRawProduct, +} from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "pro", @@ -90,8 +88,8 @@ const ops = [ const testCase = "mergedAddOn4"; describe(`${chalk.yellowBright("mergedAddOn4: testing cancelling add on immediately while there's scheduled product")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -148,7 +146,7 @@ describe(`${chalk.yellowBright("mergedAddOn4: testing cancelling add on immediat }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -179,7 +177,7 @@ describe(`${chalk.yellowBright("mergedAddOn4: testing cancelling add on immediat } }); - it("should cancel add on product immediately", async function () { + it("should cancel add on product immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, diff --git a/server/tests/merged/addOn/mergedAddOn5.test.ts b/server/tests/merged/addOn/mergedAddOn5.test.ts index 6633347cd..4ce8374d4 100644 --- a/server/tests/merged/addOn/mergedAddOn5.test.ts +++ b/server/tests/merged/addOn/mergedAddOn5.test.ts @@ -1,42 +1,39 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; import { - constructProduct, - constructRawProduct, -} from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - -import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; - -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expect } from "chai"; +import { + constructProduct, + constructRawProduct, +} from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "pro", @@ -91,8 +88,8 @@ const ops = [ const testCase = "mergedAddOn5"; describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediately while there's scheduled product")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -149,7 +146,7 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -180,7 +177,7 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat } }); - it("should cancel add on product immediately", async function () { + it("should cancel add on product immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, @@ -214,7 +211,7 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat }); }); - it("should advance test clock and have correct products / sub", async function () { + it("should advance test clock and have correct products / sub", async () => { await advanceToNextInvoice({ stripeCli, testClockId, diff --git a/server/tests/merged/addOn/mergedAddOn6.test.ts b/server/tests/merged/addOn/mergedAddOn6.test.ts index 5a56e84d2..463829821 100644 --- a/server/tests/merged/addOn/mergedAddOn6.test.ts +++ b/server/tests/merged/addOn/mergedAddOn6.test.ts @@ -1,42 +1,36 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; import { - constructProduct, - constructRawProduct, -} from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - -import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; +import { + constructProduct, + constructRawProduct, +} from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expect } from "chai"; -import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; - -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Credits })], type: "pro", @@ -136,8 +130,8 @@ const ops = [ const testCase = "mergedAddOn6"; describe(`${chalk.yellowBright("mergedAddOn6: testing update add on quantities on many entities")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -199,7 +193,7 @@ describe(`${chalk.yellowBright("mergedAddOn6: testing update add on quantities o }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -231,7 +225,7 @@ describe(`${chalk.yellowBright("mergedAddOn6: testing update add on quantities o }); return; - it("should update prepaid quantity for entity 1 and 2", async function () { + it("should update prepaid quantity for entity 1 and 2", async () => { await attachAndExpectCorrect({ autumn, customerId, diff --git a/server/tests/merged/downgrade/mergedDowngrade1.ts b/server/tests/merged/downgrade/mergedDowngrade1.ts index aa246b8a6..66306eff2 100644 --- a/server/tests/merged/downgrade/mergedDowngrade1.ts +++ b/server/tests/merged/downgrade/mergedDowngrade1.ts @@ -1,23 +1,23 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; import { expect } from "chai"; -import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; // OPERATIONS: // Premium, Premium @@ -25,13 +25,13 @@ import { expectProductAttached } from "tests/utils/expectUtils/expectProductAtta // Premium, Premium // UNCOMMENT FROM HERE -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -76,8 +76,8 @@ const ops2 = [ ]; describe(`${chalk.yellowBright("mergedDowngrade1: Testing merged subs, downgrade 2 pros")}`, () => { - let customerId = "mergedDowngrade1"; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = "mergedDowngrade1"; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -134,7 +134,7 @@ describe(`${chalk.yellowBright("mergedDowngrade1: Testing merged subs, downgrade }, ]; - it("should attach pro product to both entities", async function () { + it("should attach pro product to both entities", async () => { await autumn.entities.create(customerId, entities); for (const op of init) { @@ -146,7 +146,7 @@ describe(`${chalk.yellowBright("mergedDowngrade1: Testing merged subs, downgrade } }); - it("should downgrade both entities to pro and have correct sub + schedule", async function () { + it("should downgrade both entities to pro and have correct sub + schedule", async () => { for (const op of ops1) { await autumn.attach({ customer_id: customerId, @@ -175,7 +175,7 @@ describe(`${chalk.yellowBright("mergedDowngrade1: Testing merged subs, downgrade } }); - it("should renew both entities and have correct sub + schedule", async function () { + it("should renew both entities and have correct sub + schedule", async () => { for (const op of ops2) { await autumn.attach({ customer_id: customerId, diff --git a/server/tests/merged/downgrade/mergedDowngrade2.ts b/server/tests/merged/downgrade/mergedDowngrade2.ts index 51705b595..32fc26dea 100644 --- a/server/tests/merged/downgrade/mergedDowngrade2.ts +++ b/server/tests/merged/downgrade/mergedDowngrade2.ts @@ -1,28 +1,28 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, constructFeatureItem, } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expect } from "chai"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; // OPERATIONS: // Premium @@ -30,20 +30,20 @@ import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js" // Free, Premium // Free, Pro -let free = constructProduct({ +const free = constructProduct({ id: "free", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "free", isDefault: false, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -81,8 +81,8 @@ const ops = [ const testCase = "mergedDowngrade2"; describe(`${chalk.yellowBright("mergedDowngrade2: Testing merged subs, downgrade free 1, add premium 2")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -139,7 +139,7 @@ describe(`${chalk.yellowBright("mergedDowngrade2: Testing merged subs, downgrade }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -180,7 +180,7 @@ describe(`${chalk.yellowBright("mergedDowngrade2: Testing merged subs, downgrade }); // return; - it("should advance test clock and have correct products for entity 1 & 2", async function () { + it("should advance test clock and have correct products for entity 1 & 2", async () => { await advanceToNextInvoice({ stripeCli, testClockId, @@ -213,7 +213,7 @@ describe(`${chalk.yellowBright("mergedDowngrade2: Testing merged subs, downgrade }); }); - it("should attach premium to entity 1 (which is free) and have correct products", async function () { + it("should attach premium to entity 1 (which is free) and have correct products", async () => { await attachAndExpectCorrect({ autumn, customerId, diff --git a/server/tests/merged/downgrade/mergedDowngrade3.ts b/server/tests/merged/downgrade/mergedDowngrade3.ts index 6f09dc040..f9ff2e621 100644 --- a/server/tests/merged/downgrade/mergedDowngrade3.ts +++ b/server/tests/merged/downgrade/mergedDowngrade3.ts @@ -1,45 +1,45 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, constructFeatureItem, } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expect } from "chai"; // OPERATIONS: // Pro, Pro // Free, Premium -let free = constructProduct({ +const free = constructProduct({ id: "free", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "free", isDefault: false, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -73,8 +73,8 @@ const ops = [ const testCase = "mergedDowngrade3"; describe(`${chalk.yellowBright("mergedDowngrade3: Testing merged subs, pro 1, pro 2, downgrade free pro 1, upgrade pro 2 ")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -131,7 +131,7 @@ describe(`${chalk.yellowBright("mergedDowngrade3: Testing merged subs, pro 1, pr }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/downgrade/mergedDowngrade4.ts b/server/tests/merged/downgrade/mergedDowngrade4.ts index 4d56be7ca..557484a01 100644 --- a/server/tests/merged/downgrade/mergedDowngrade4.ts +++ b/server/tests/merged/downgrade/mergedDowngrade4.ts @@ -1,48 +1,43 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { - constructArrearItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { expect } from "chai"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addMonths } from "date-fns"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; // OPERATIONS: // PremiumAnnual, Premium // PremiumAnnual, Pro -let premiumAnnual = constructProduct({ +const premiumAnnual = constructProduct({ id: "premiumAnnual", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", isAnnual: true, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -71,8 +66,8 @@ const ops = [ const testCase = "mergedDowngrade4"; describe(`${chalk.yellowBright("mergedDowngrade4: Testing advance clock, schedule activates")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -129,7 +124,7 @@ describe(`${chalk.yellowBright("mergedDowngrade4: Testing advance clock, schedul }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -168,7 +163,7 @@ describe(`${chalk.yellowBright("mergedDowngrade4: Testing advance clock, schedul } }); - it("should advance test clock and have correct premium downgraded for entity 2", async function () { + it("should advance test clock and have correct premium downgraded for entity 2", async () => { await advanceToNextInvoice({ stripeCli, testClockId, diff --git a/server/tests/merged/downgrade/mergedDowngrade5.test.ts b/server/tests/merged/downgrade/mergedDowngrade5.test.ts index 6ff73aea2..aff529c21 100644 --- a/server/tests/merged/downgrade/mergedDowngrade5.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade5.test.ts @@ -1,41 +1,38 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, constructFeatureItem, } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expect } from "chai"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // OPERATIONS: // Premium, Premium // Free, Free // Pro, Free -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); -let free = constructProduct({ +const free = constructProduct({ id: "free", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "free", @@ -93,8 +90,8 @@ const ops = [ const testCase = "mergedDowngrade5"; describe(`${chalk.yellowBright("mergedDowngrade5: Testing downgrade to free")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -151,7 +148,7 @@ describe(`${chalk.yellowBright("mergedDowngrade5: Testing downgrade to free")}`, }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/downgrade/mergedDowngrade6.test.ts b/server/tests/merged/downgrade/mergedDowngrade6.test.ts index 666c60fa3..0864aef21 100644 --- a/server/tests/merged/downgrade/mergedDowngrade6.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade6.test.ts @@ -1,25 +1,22 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { - constructArrearItem, - constructFeatureItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // OPERATIONS: // Growth, Growth @@ -28,13 +25,13 @@ import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js" // Premium // Free -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); -let free = constructProduct({ +const free = constructProduct({ id: "free", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "free", @@ -99,8 +96,8 @@ const ops = [ const testCase = "mergedDowngrade6"; describe(`${chalk.yellowBright("mergedDowngrade6: Testing downgrade changes")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -157,7 +154,7 @@ describe(`${chalk.yellowBright("mergedDowngrade6: Testing downgrade changes")}`, }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/downgrade/mergedDowngrade8.ts b/server/tests/merged/downgrade/mergedDowngrade8.ts index e499150e3..b9ea55b4a 100644 --- a/server/tests/merged/downgrade/mergedDowngrade8.ts +++ b/server/tests/merged/downgrade/mergedDowngrade8.ts @@ -1,39 +1,39 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; // UNCOMMENT FROM HERE -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let premiumAnnual = constructProduct({ +const premiumAnnual = constructProduct({ id: "premiumAnnual", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", isAnnual: true, }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -85,8 +85,8 @@ const ops = [ const testCase = "mergedDowngrade8"; describe(`${chalk.yellowBright("mergedDowngrade8: Testing merged subs, downgrade 2 monthly + annual")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -143,7 +143,7 @@ describe(`${chalk.yellowBright("mergedDowngrade8: Testing merged subs, downgrade }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/downgrade/mergedDowngrade9.ts b/server/tests/merged/downgrade/mergedDowngrade9.ts index 36a5c8316..e249ef7eb 100644 --- a/server/tests/merged/downgrade/mergedDowngrade9.ts +++ b/server/tests/merged/downgrade/mergedDowngrade9.ts @@ -1,41 +1,40 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; import { expect } from "chai"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // UNCOMMENT FROM HERE -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let premiumAnnual = constructProduct({ +const premiumAnnual = constructProduct({ id: "premiumAnnual", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", isAnnual: true, }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -77,8 +76,8 @@ const ops = [ const testCase = "mergedDowngrade9"; describe(`${chalk.yellowBright("mergedDowngrade9: Testing merged subs, downgrade 2 monthly + annual & advance test clock")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -135,7 +134,7 @@ describe(`${chalk.yellowBright("mergedDowngrade9: Testing merged subs, downgrade }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -182,7 +181,7 @@ describe(`${chalk.yellowBright("mergedDowngrade9: Testing merged subs, downgrade } }); - it("should advance test clock and have correct products for entity 1 & 2", async function () { + it("should advance test clock and have correct products for entity 1 & 2", async () => { const results = [ { entityId: "1", @@ -218,7 +217,7 @@ describe(`${chalk.yellowBright("mergedDowngrade9: Testing merged subs, downgrade } }); - it("should attach premium to entity 2 and have correct products", async function () { + it("should attach premium to entity 2 and have correct products", async () => { await attachAndExpectCorrect({ autumn, customerId, diff --git a/server/tests/merged/group/mergedGroup1.test.ts b/server/tests/merged/group/mergedGroup1.test.ts index 79c70961e..3eeb41135 100644 --- a/server/tests/merged/group/mergedGroup1.test.ts +++ b/server/tests/merged/group/mergedGroup1.test.ts @@ -1,56 +1,46 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; -import { expectSubToBeCorrect } from "../mergeUtils.test.js"; - -import { getAttachPreviewTotal } from "tests/utils/testAttachUtils/getAttachPreviewTotal.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { timeout } from "@/utils/genUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { expectSubToBeCorrect } from "../mergeUtils.test.js"; // UNCOMMENT FROM HERE -let g1Pro = constructProduct({ +const g1Pro = constructProduct({ id: "mergedGroups1_g1Pro", group: "mergedG1_1", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); -let g1Premium = constructProduct({ +const g1Premium = constructProduct({ id: "mergedGroups1_g1Premium", items: [constructArrearItem({ featureId: TestFeature.Words })], group: "mergedG1_1", type: "premium", }); -let g2Pro = constructProduct({ +const g2Pro = constructProduct({ id: "mergedGroups1_g2Pro", group: "mergedG1_2", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); -let g2Premium = constructProduct({ +const g2Premium = constructProduct({ id: "mergedGroups1_g2Premium", group: "mergedG1_2", items: [constructArrearItem({ featureId: TestFeature.Words })], @@ -91,8 +81,8 @@ const ops = [ ]; describe(`${chalk.yellowBright("mergedGroup1: Testing products from diff groups")}`, () => { - let customerId = "mergedGroup1"; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = "mergedGroup1"; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -131,7 +121,7 @@ describe(`${chalk.yellowBright("mergedGroup1: Testing products from diff groups" testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { for (const op of ops) { await attachAndExpectCorrect({ autumn, @@ -155,7 +145,7 @@ describe(`${chalk.yellowBright("mergedGroup1: Testing products from diff groups" } }); - it("should cancel scheduled product (g1Pro)", async function () { + it("should cancel scheduled product (g1Pro)", async () => { await autumn.cancel({ customer_id: customerId, product_id: g1Pro.id, diff --git a/server/tests/merged/group/mergedGroup2.test.ts b/server/tests/merged/group/mergedGroup2.test.ts index 55dfb132c..896a62c3a 100644 --- a/server/tests/merged/group/mergedGroup2.test.ts +++ b/server/tests/merged/group/mergedGroup2.test.ts @@ -1,56 +1,45 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; -import { expectSubToBeCorrect } from "../mergeUtils.test.js"; - -import { getAttachPreviewTotal } from "tests/utils/testAttachUtils/getAttachPreviewTotal.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { timeout } from "@/utils/genUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // UNCOMMENT FROM HERE -let g1Pro = constructProduct({ +const g1Pro = constructProduct({ id: "mergedGroups2_g1Pro", group: "mergedG2_1", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); -let g2Pro = constructProduct({ +const g2Pro = constructProduct({ id: "mergedGroups2_g2Pro", group: "mergedG2_2", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", }); -let g1Premium = constructProduct({ +const g1Premium = constructProduct({ id: "mergedGroups2_g1Premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", group: "mergedG2_1", }); -let g2Premium = constructProduct({ +const g2Premium = constructProduct({ id: "mergedGroups2_g2Premium", group: "mergedG2_2", items: [constructArrearItem({ featureId: TestFeature.Words })], @@ -83,8 +72,8 @@ const ops = [ ]; describe(`${chalk.yellowBright("mergedGroup2: Testing products from diff groups")}`, () => { - let customerId = "mergedGroup2"; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = "mergedGroup2"; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -123,7 +112,7 @@ describe(`${chalk.yellowBright("mergedGroup2: Testing products from diff groups" testClockId = testClockId1!; }); - it("should attach pro product", async function () { + it("should attach pro product", async () => { for (const op of ops) { await attachAndExpectCorrect({ autumn, @@ -148,7 +137,7 @@ describe(`${chalk.yellowBright("mergedGroup2: Testing products from diff groups" }); return; - it("should cancel scheduled product (g1Pro)", async function () { + it("should cancel scheduled product (g1Pro)", async () => { await autumn.cancel({ customer_id: customerId, product_id: g1Pro.id, diff --git a/server/tests/merged/mergeUtils.test.ts b/server/tests/merged/mergeUtils.test.ts index e20aca2a4..439e89b6b 100644 --- a/server/tests/merged/mergeUtils.test.ts +++ b/server/tests/merged/mergeUtils.test.ts @@ -1,24 +1,22 @@ -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { priceToStripeItem } from "@/external/stripe/priceToStripeItem/priceToStripeItem.js"; -import { createStripeCli } from "@/external/stripe/utils.js"; import { + type AppEnv, cusProductToEnts, cusProductToPrices, cusProductToProduct, + type FullCusProduct, + LegacyVersion, + type Organization, } from "@autumn/shared"; +import { expect } from "chai"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { priceToStripeItem } from "@/external/stripe/priceToStripeItem/priceToStripeItem.js"; +import { createStripeCli } from "@/external/stripe/utils.js"; import { CusService } from "@/internal/customers/CusService.js"; +import { isFixedPrice } from "@/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.js"; import { getPriceEntitlement, getPriceOptions, } from "@/internal/products/prices/priceUtils.js"; -import { isFixedPrice } from "@/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.js"; -import { - APIVersion, - AppEnv, - FullCusProduct, - Organization, -} from "@autumn/shared"; -import { expect } from "chai"; export const cusProductToSubIds = ({ cusProducts, @@ -83,7 +81,7 @@ export const expectSubToBeCorrect = async ({ existingUsage: 0, withEntity: true, isCheckout: false, - apiVersion: APIVersion.v1_4, + apiVersion: LegacyVersion.v1_4, }); const lineItem: any = res?.lineItem; @@ -92,7 +90,7 @@ export const expectSubToBeCorrect = async ({ (si: any) => si.price === lineItem.price, ); if (existingIndex !== -1) { - // @ts-ignore + // @ts-expect-error supposedSubItems[existingIndex].quantity += lineItem.quantity!; } else { supposedSubItems.push(res.lineItem); diff --git a/server/tests/merged/mergeUtils/expectSubCorrect.ts b/server/tests/merged/mergeUtils/expectSubCorrect.ts index 1fe1b0f64..2ede520b3 100644 --- a/server/tests/merged/mergeUtils/expectSubCorrect.ts +++ b/server/tests/merged/mergeUtils/expectSubCorrect.ts @@ -1,45 +1,39 @@ -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { createStripeCli } from "@/external/stripe/utils.js"; -import { CusService } from "@/internal/customers/CusService.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - FullCustomer, - Organization, -} from "@autumn/shared"; -import { cusProductToSubIds } from "../mergeUtils.test.js"; -import { expect } from "chai"; -import { priceToStripeItem } from "@/external/stripe/priceToStripeItem/priceToStripeItem.js"; -import { - cusProductToPrices, cusProductToEnts, + cusProductToPrices, cusProductToProduct, + type FullCustomer, + type Organization, } from "@autumn/shared"; +import { notNullish } from "@shared/utils/utils.js"; +import { expect } from "chai"; +import type Stripe from "stripe"; +import { defaultApiVersion } from "tests/constants.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { priceToStripeItem } from "@/external/stripe/priceToStripeItem/priceToStripeItem.js"; +import { subIsCanceled } from "@/external/stripe/stripeSubUtils.js"; +import { createStripeCli } from "@/external/stripe/utils.js"; +import { + cusProductInPhase, + logPhaseItems, + similarUnix, +} from "@/internal/customers/attach/mergeUtils/phaseUtils/phaseUtils.js"; +import { CusService } from "@/internal/customers/CusService.js"; +import { ACTIVE_STATUSES } from "@/internal/customers/cusProducts/CusProductService.js"; +import { getExistingUsageFromCusProducts } from "@/internal/customers/cusProducts/cusEnts/cusEntUtils.js"; +import { getExistingCusProducts } from "@/internal/customers/cusProducts/cusProductUtils/getExistingCusProducts.js"; +import { getUniqueUpcomingSchedulePairs } from "@/internal/customers/cusProducts/cusProductUtils/getUpcomingSchedules.js"; +import { PriceService } from "@/internal/products/prices/PriceService.js"; import { formatPrice, getPriceEntitlement, getPriceOptions, } from "@/internal/products/prices/priceUtils.js"; -import { logSubItems } from "@/utils/scriptUtils/logUtils/logSubItems.js"; -import { isFreeProduct, isOneOff } from "@/internal/products/productUtils.js"; -import { paramsToCurSubSchedule } from "@/internal/customers/attach/attachUtils/convertAttachParams.js"; -import { ACTIVE_STATUSES } from "@/internal/customers/cusProducts/CusProductService.js"; -import Stripe from "stripe"; -import { getUniqueUpcomingSchedulePairs } from "@/internal/customers/cusProducts/cusProductUtils/getUpcomingSchedules.js"; +import { isFreeProduct } from "@/internal/products/productUtils.js"; import { formatUnixToDateTime, nullish } from "@/utils/genUtils.js"; -import { - cusProductInPhase, - logPhaseItems, - logPhases, - similarUnix, -} from "@/internal/customers/attach/mergeUtils/phaseUtils/phaseUtils.js"; -import { PriceService } from "@/internal/products/prices/PriceService.js"; -import { getExistingUsageFromCusProducts } from "@/internal/customers/cusProducts/cusEnts/cusEntUtils.js"; -import { subIsCanceled } from "@/external/stripe/stripeSubUtils.js"; -import { defaultApiVersion } from "tests/constants.js"; -import { getExistingCusProducts } from "@/internal/customers/cusProducts/cusProductUtils/getExistingCusProducts.js"; -import { notNullish } from "@shared/utils/utils.js"; +import { cusProductToSubIds } from "../mergeUtils.test.js"; const compareActualItems = async ({ actualItems, @@ -196,7 +190,7 @@ export const expectSubToBeCorrect = async ({ }); // console.log(`\n\nChecking sub correct`); - let printCusProduct = false; + const printCusProduct = false; if (printCusProduct) { console.log(`\n\nChecking sub correct`); } @@ -286,7 +280,7 @@ export const expectSubToBeCorrect = async ({ for (const price of prices) { const relatedEnt = getPriceEntitlement(price, ents); const options = getPriceOptions(price, cusProduct.options); - let existingUsage = getExistingUsageFromCusProducts({ + const existingUsage = getExistingUsageFromCusProducts({ entitlement: relatedEnt, cusProducts, entities: fullCus.entities, @@ -330,7 +324,7 @@ export const expectSubToBeCorrect = async ({ ); if (existingIndex !== -1) { - // @ts-ignore + // @ts-expect-error supposedSubItems[existingIndex].quantity += lineItem.quantity; } else { supposedSubItems.push({ diff --git a/server/tests/merged/prepaid/mergedPrepaid1.ts b/server/tests/merged/prepaid/mergedPrepaid1.ts index 2f47404be..b0c3aa5bb 100644 --- a/server/tests/merged/prepaid/mergedPrepaid1.ts +++ b/server/tests/merged/prepaid/mergedPrepaid1.ts @@ -1,21 +1,21 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const billingUnits = 100; const creditItem = constructPrepaidItem({ @@ -25,13 +25,13 @@ const creditItem = constructPrepaidItem({ billingUnits, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [creditItem], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [creditItem], type: "pro", @@ -89,8 +89,8 @@ const ops = [ const testCase = "mergedPrepaid1"; describe(`${chalk.yellowBright("mergedPrepaid1: Testing merged subs, upgrade 1 & 2 to pro, add premium 2")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -147,7 +147,7 @@ describe(`${chalk.yellowBright("mergedPrepaid1: Testing merged subs, upgrade 1 & }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/prepaid/mergedPrepaid2.ts b/server/tests/merged/prepaid/mergedPrepaid2.ts index 113ca25d3..9c630682a 100644 --- a/server/tests/merged/prepaid/mergedPrepaid2.ts +++ b/server/tests/merged/prepaid/mergedPrepaid2.ts @@ -1,24 +1,24 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; const billingUnits = 100; const creditItem = constructPrepaidItem({ @@ -32,13 +32,13 @@ const creditItem = constructPrepaidItem({ }, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [creditItem], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [creditItem], type: "pro", @@ -107,8 +107,8 @@ const ops = [ const testCase = "mergedPrepaid2"; describe(`${chalk.yellowBright("mergedPrepaid2: Testing merged subs, upgrade 1 & 2 to pro, add premium 2")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -165,7 +165,7 @@ describe(`${chalk.yellowBright("mergedPrepaid2: Testing merged subs, upgrade 1 & }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -191,7 +191,7 @@ describe(`${chalk.yellowBright("mergedPrepaid2: Testing merged subs, upgrade 1 & } }); - it("should have correct balances after update", async function () { + it("should have correct balances after update", async () => { await advanceToNextInvoice({ stripeCli, testClockId, diff --git a/server/tests/merged/prepaid/mergedPrepaid3.ts b/server/tests/merged/prepaid/mergedPrepaid3.ts index 5bedfb78f..f7cb0221c 100644 --- a/server/tests/merged/prepaid/mergedPrepaid3.ts +++ b/server/tests/merged/prepaid/mergedPrepaid3.ts @@ -1,26 +1,27 @@ // PREPAID WITH DOWNGRADE (SCHEDULED...) -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; + import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, + LegacyVersion, OnDecrease, OnIncrease, - Organization, + type Organization, } from "@autumn/shared"; -import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; const billingUnits = 100; @@ -35,13 +36,13 @@ const creditItem = constructPrepaidItem({ }, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [creditItem], type: "premium", }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [creditItem], type: "pro", @@ -87,8 +88,8 @@ const ops = [ const testCase = "mergedPrepaid3"; describe(`${chalk.yellowBright("mergedPrepaid3: Testing merged subs, upgrade 1 & 2 to premium, downgrade 1 to pro")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -145,7 +146,7 @@ describe(`${chalk.yellowBright("mergedPrepaid3: Testing merged subs, upgrade 1 & }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -171,7 +172,7 @@ describe(`${chalk.yellowBright("mergedPrepaid3: Testing merged subs, upgrade 1 & } }); - it("should have correct products after update", async function () { + it("should have correct products after update", async () => { await advanceToNextInvoice({ stripeCli, testClockId, diff --git a/server/tests/merged/separate/separate1.test.ts b/server/tests/merged/separate/separate1.test.ts index 3f15a213c..d6915f126 100644 --- a/server/tests/merged/separate/separate1.test.ts +++ b/server/tests/merged/separate/separate1.test.ts @@ -1,21 +1,21 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; -import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { setupBefore } from "tests/before.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { expect } from "chai"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import type Stripe from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -25,7 +25,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -61,12 +61,12 @@ const ops = [ const testCase = "separate1"; describe(`${chalk.yellowBright(`${testCase}: Testing separate subscriptions because of invoice checkout`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -103,8 +103,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing separate subscriptions beca testClockId = testClockId1!; }); - let subIds: string[] = []; - it("should attach pro product", async function () { + const subIds: string[] = []; + it("should attach pro product", async () => { await autumn.entities.create(customerId, entities); for (const op of ops) { const res = await autumn.attach({ @@ -146,7 +146,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing separate subscriptions beca }); }); - it("should upgrade both entities to premium", async function () { + it("should upgrade both entities to premium", async () => { await autumn.attach({ customer_id: customerId, product_id: premium.id, diff --git a/server/tests/merged/separate/separate2.test.ts b/server/tests/merged/separate/separate2.test.ts index df3ce5951..bb07c2473 100644 --- a/server/tests/merged/separate/separate2.test.ts +++ b/server/tests/merged/separate/separate2.test.ts @@ -1,33 +1,27 @@ -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import { expect } from "chai"; import chalk from "chalk"; -import Stripe from "stripe"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import type Stripe from "stripe"; import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { createProducts } from "tests/utils/productUtils.js"; -import { - constructProduct, - constructRawProduct, -} from "@/utils/scriptUtils/createTestProducts.js"; +import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { CusService } from "@/internal/customers/CusService.js"; import { constructFeatureItem, constructPrepaidItem, } from "@/utils/scriptUtils/constructItem.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expect } from "chai"; import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; -import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { CusService } from "@/internal/customers/CusService.js"; + constructProduct, + constructRawProduct, +} from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -export let pro = constructProduct({ +export const pro = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -37,7 +31,7 @@ export let pro = constructProduct({ type: "pro", }); -export let premium = constructProduct({ +export const premium = constructProduct({ items: [ constructFeatureItem({ featureId: TestFeature.Messages, @@ -87,12 +81,12 @@ const ops = [ const testCase = "separate2"; describe(`${chalk.yellowBright(`${testCase}: Testing separate subscriptions because of force checkout`)}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_2 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_2 }); let testClockId: string; let db: DrizzleCli, org: Organization, env: AppEnv; let stripeCli: Stripe; - let curUnix = new Date().getTime(); + const curUnix = new Date().getTime(); before(async function () { await setupBefore(this); @@ -129,8 +123,8 @@ describe(`${chalk.yellowBright(`${testCase}: Testing separate subscriptions beca testClockId = testClockId1!; }); - let subIds: string[] = []; - it("should attach pro product", async function () { + const subIds: string[] = []; + it("should attach pro product", async () => { await autumn.entities.create(customerId, entities); for (const op of ops) { const res = await autumn.attach({ @@ -172,7 +166,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing separate subscriptions beca }); }); - it("should upgrade both entities to premium", async function () { + it("should upgrade both entities to premium", async () => { for (const id of ["1", "2"]) { await autumn.attach({ customer_id: customerId, @@ -197,7 +191,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing separate subscriptions beca } }); - it("should attach add on to entity 2 and correct sub", async function () { + it("should attach add on to entity 2 and correct sub", async () => { await autumn.attach({ customer_id: customerId, product_id: addOn.id, diff --git a/server/tests/merged/trial/mergedTrial1.test.ts b/server/tests/merged/trial/mergedTrial1.test.ts index a37c8f814..a7203b22a 100644 --- a/server/tests/merged/trial/mergedTrial1.test.ts +++ b/server/tests/merged/trial/mergedTrial1.test.ts @@ -1,32 +1,29 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import chalk from "chalk"; import { addDays } from "date-fns"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // Premium, Premium // Cancel End, Cancel Immediately // Results: Canceled sub -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -35,8 +32,8 @@ let premium = constructProduct({ const testCase = "mergedTrial1"; describe(`${chalk.yellowBright("mergedTrial1: Testing trial")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -93,7 +90,7 @@ describe(`${chalk.yellowBright("mergedTrial1: Testing trial")}`, () => { }, ]; - it("should attach first trial, and advance clock past trial", async function () { + it("should attach first trial, and advance clock past trial", async () => { await autumn.entities.create(customerId, entities); await autumn.attach({ diff --git a/server/tests/merged/trial/mergedTrial2.test.ts b/server/tests/merged/trial/mergedTrial2.test.ts index 16fe3a195..7658c8712 100644 --- a/server/tests/merged/trial/mergedTrial2.test.ts +++ b/server/tests/merged/trial/mergedTrial2.test.ts @@ -1,26 +1,25 @@ +import { + type AppEnv, + CusProductStatus, + LegacyVersion, + type Organization, +} from "@autumn/shared"; import chalk from "chalk"; import { addDays } from "date-fns"; +import type { Stripe } from "stripe"; import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { - APIVersion, - AppEnv, - CusProductStatus, - Organization, -} from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -42,8 +41,8 @@ const ops = [ const testCase = "mergedTrial2"; describe(`${chalk.yellowBright("mergedTrial2: Testing add second trial product after first trial ends")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -100,7 +99,7 @@ describe(`${chalk.yellowBright("mergedTrial2: Testing add second trial product a }, ]; - it("should attach first trial, and advance clock past trial", async function () { + it("should attach first trial, and advance clock past trial", async () => { await autumn.entities.create(customerId, entities); await autumn.attach({ diff --git a/server/tests/merged/trial/mergedTrial3.test.ts b/server/tests/merged/trial/mergedTrial3.test.ts index efd89f68f..27a61b2d9 100644 --- a/server/tests/merged/trial/mergedTrial3.test.ts +++ b/server/tests/merged/trial/mergedTrial3.test.ts @@ -1,33 +1,32 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import chalk from "chalk"; import { addDays } from "date-fns"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", trial: true, }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -49,8 +48,8 @@ const ops = [ const testCase = "mergedTrial3"; describe(`${chalk.yellowBright("mergedTrial3: Testing upgrade to product with trial in merged state")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -107,7 +106,7 @@ describe(`${chalk.yellowBright("mergedTrial3: Testing upgrade to product with tr }, ]; - it("should attach first trial, and advance clock past trial", async function () { + it("should attach first trial, and advance clock past trial", async () => { await autumn.entities.create(customerId, entities); await autumn.attach({ diff --git a/server/tests/merged/trial/mergedTrial4.test.ts b/server/tests/merged/trial/mergedTrial4.test.ts index 527400b25..346b1d042 100644 --- a/server/tests/merged/trial/mergedTrial4.test.ts +++ b/server/tests/merged/trial/mergedTrial4.test.ts @@ -1,34 +1,31 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addDays } from "date-fns"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", trial: true, }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -50,8 +47,8 @@ const ops = [ const testCase = "mergedTrial4"; describe(`${chalk.yellowBright("mergedTrial4: Testing cancel immediately on merged sub trial")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -108,7 +105,7 @@ describe(`${chalk.yellowBright("mergedTrial4: Testing cancel immediately on merg }, ]; - it("should attach pro trial for entity 1 and entity 2", async function () { + it("should attach pro trial for entity 1 and entity 2", async () => { await autumn.entities.create(customerId, entities); for (const op of ops) { @@ -125,7 +122,7 @@ describe(`${chalk.yellowBright("mergedTrial4: Testing cancel immediately on merg } }); - it("should cancel one of subs immediately and have sub still trialing", async function () { + it("should cancel one of subs immediately and have sub still trialing", async () => { await autumn.cancel({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/merged/trial/mergedTrial5.test.ts b/server/tests/merged/trial/mergedTrial5.test.ts index 17591a6db..3bbaf031a 100644 --- a/server/tests/merged/trial/mergedTrial5.test.ts +++ b/server/tests/merged/trial/mergedTrial5.test.ts @@ -1,34 +1,31 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addDays } from "date-fns"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", trial: true, }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -55,8 +52,8 @@ const ops = [ const testCase = "mergedTrial5"; describe(`${chalk.yellowBright("mergedTrial5: Testing cancel at end of cycle and cancel immediately on merged sub trial")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -118,7 +115,7 @@ describe(`${chalk.yellowBright("mergedTrial5: Testing cancel at end of cycle and }, ]; - it("should attach pro trial for entity 1 and entity 2", async function () { + it("should attach pro trial for entity 1 and entity 2", async () => { await autumn.entities.create(customerId, entities); for (const op of ops) { @@ -135,7 +132,7 @@ describe(`${chalk.yellowBright("mergedTrial5: Testing cancel at end of cycle and } }); - it("should cancel one sub end of cycle", async function () { + it("should cancel one sub end of cycle", async () => { await autumn.cancel({ customer_id: customerId, product_id: pro.id, @@ -151,7 +148,7 @@ describe(`${chalk.yellowBright("mergedTrial5: Testing cancel at end of cycle and }); }); - it("should cancel one sub immediately", async function () { + it("should cancel one sub immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: pro.id, @@ -168,7 +165,7 @@ describe(`${chalk.yellowBright("mergedTrial5: Testing cancel at end of cycle and }); }); - it("should cancel last sub at end of cycle", async function () { + it("should cancel last sub at end of cycle", async () => { await autumn.cancel({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/merged/trial/trial1.test.ts b/server/tests/merged/trial/trial1.test.ts index 41bdd607c..93c0c0dab 100644 --- a/server/tests/merged/trial/trial1.test.ts +++ b/server/tests/merged/trial/trial1.test.ts @@ -1,41 +1,40 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, AttachBranch, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import chalk from "chalk"; import { addDays } from "date-fns"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // Premium, Premium // Cancel End, Cancel Immediately // Results: Canceled sub -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", trial: true, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -56,8 +55,8 @@ const ops = [ const testCase = "trial1"; describe(`${chalk.yellowBright("trial1: Testing main trial branch, upgrade from pro trial -> premium trial")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -101,7 +100,7 @@ describe(`${chalk.yellowBright("trial1: Testing main trial branch, upgrade from testClockId = testClockId1!; }); - it("should attach first trial, and advance clock past trial", async function () { + it("should attach first trial, and advance clock past trial", async () => { for (const op of ops) { await attachAndExpectCorrect({ autumn, @@ -122,7 +121,7 @@ describe(`${chalk.yellowBright("trial1: Testing main trial branch, upgrade from }); }); - it("should advance test clock to before trial ends and attach premium", async function () { + it("should advance test clock to before trial ends and attach premium", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/merged/trial/trial2.test.ts b/server/tests/merged/trial/trial2.test.ts index 748fd66fc..2207a216b 100644 --- a/server/tests/merged/trial/trial2.test.ts +++ b/server/tests/merged/trial/trial2.test.ts @@ -1,43 +1,42 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, AttachBranch, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; import { expect } from "chai"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import chalk from "chalk"; import { addDays } from "date-fns"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { timeout } from "@/utils/genUtils.js"; import { Decimal } from "decimal.js"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // Pro Trial // Trial Finishes // Premium Trial -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", trial: true, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -58,8 +57,8 @@ const ops = [ const testCase = "trial2"; describe(`${chalk.yellowBright("trial2: Testing main trial branch, upgrade from pro trial -> trial finished -> premium trial")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -103,7 +102,7 @@ describe(`${chalk.yellowBright("trial2: Testing main trial branch, upgrade from testClockId = testClockId1!; }); - it("should attach first trial", async function () { + it("should attach first trial", async () => { for (const op of ops) { await attachAndExpectCorrect({ autumn, @@ -124,7 +123,7 @@ describe(`${chalk.yellowBright("trial2: Testing main trial branch, upgrade from }); }); - it("should advance test clock to past trial ends and attach premium", async function () { + it("should advance test clock to past trial ends and attach premium", async () => { curUnix = await advanceTestClock({ stripeCli, testClockId, diff --git a/server/tests/merged/trial/trial3.test.ts b/server/tests/merged/trial/trial3.test.ts index 8af537ff9..ac95d4155 100644 --- a/server/tests/merged/trial/trial3.test.ts +++ b/server/tests/merged/trial/trial3.test.ts @@ -1,41 +1,39 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - FullCusProduct, - Organization, + type FullCusProduct, + LegacyVersion, + type Organization, } from "@autumn/shared"; - -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; import { expect } from "chai"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; - import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; import { cusProductToSub } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // Pro Trial // Trial Finishes // Premium Trial -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", trial: true, }); -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", @@ -56,8 +54,8 @@ const ops = [ const testCase = "trial3"; describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -101,7 +99,7 @@ describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => testClockId = testClockId1!; }); - it("should attach first trial, and advance clock past trial", async function () { + it("should attach first trial, and advance clock past trial", async () => { for (const op of ops) { await attachAndExpectCorrect({ autumn, @@ -124,7 +122,7 @@ describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => let cusProduct: FullCusProduct; - it("should have canceled trial product at the end of cycle", async function () { + it("should have canceled trial product at the end of cycle", async () => { await autumn.cancel({ customer_id: customerId, product_id: pro.id, @@ -151,7 +149,7 @@ describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => expect(canceled).to.exist; }); - it("should have sub not canceled if renew product", async function () { + it("should have sub not canceled if renew product", async () => { await autumn.attach({ customer_id: customerId, product_id: pro.id, @@ -163,7 +161,7 @@ describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => }); expect(sub?.cancel_at_period_end).to.equal(false); }); - it("should be canceled completely", async function () { + it("should be canceled completely", async () => { await autumn.cancel({ customer_id: customerId, product_id: pro.id, diff --git a/server/tests/merged/upgrade/mergedUpgrade1.test.ts b/server/tests/merged/upgrade/mergedUpgrade1.test.ts index 17e574fc8..f649a46f9 100644 --- a/server/tests/merged/upgrade/mergedUpgrade1.test.ts +++ b/server/tests/merged/upgrade/mergedUpgrade1.test.ts @@ -1,43 +1,43 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; +import { expect } from "chai"; +import chalk from "chalk"; +import { addWeeks } from "date-fns"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; import { addPrefixToProducts, getBasePrice, } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expect } from "chai"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { addWeeks } from "date-fns"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -let premium = constructProduct({ +const premium = constructProduct({ id: "premium", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", }); -let premiumAnnual = constructProduct({ +const premiumAnnual = constructProduct({ id: "premiumAnnual", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "premium", isAnnual: true, }); -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructArrearItem({ featureId: TestFeature.Words })], type: "pro", @@ -58,8 +58,8 @@ const ops = [ const testCase = "mergedUpgrade1"; describe(`${chalk.yellowBright("mergedUpgrade1: Testing merged subs, upgrade 1 & 2 to pro, add premium 2")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -116,7 +116,7 @@ describe(`${chalk.yellowBright("mergedUpgrade1: Testing merged subs, upgrade 1 & }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -144,7 +144,7 @@ describe(`${chalk.yellowBright("mergedUpgrade1: Testing merged subs, upgrade 1 & const entity1Val = 100000; const entity2Val = 300000; - it("should advance test clock and upgrade entity 1 to premium, and have correct invoice", async function () { + it("should advance test clock and upgrade entity 1 to premium, and have correct invoice", async () => { await autumn.track({ customer_id: customerId, feature_id: TestFeature.Words, @@ -178,7 +178,7 @@ describe(`${chalk.yellowBright("mergedUpgrade1: Testing merged subs, upgrade 1 & }); }); - it("should advance to next invoice and have correct invoice", async function () { + it("should advance to next invoice and have correct invoice", async () => { await advanceToNextInvoice({ stripeCli, testClockId, diff --git a/server/tests/merged/upgrade/mergedUpgrade2.test.ts b/server/tests/merged/upgrade/mergedUpgrade2.test.ts index 9fd56a92f..b178b1e86 100644 --- a/server/tests/merged/upgrade/mergedUpgrade2.test.ts +++ b/server/tests/merged/upgrade/mergedUpgrade2.test.ts @@ -1,32 +1,32 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // UNCOMMENT FROM HERE -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); -let free = constructProduct({ +const free = constructProduct({ id: "free", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "free", @@ -72,8 +72,8 @@ const ops = [ const testCase = "mergedUpgrade2"; describe(`${chalk.yellowBright("mergedUpgrade2: Upgrading when there's a scheduled downgrade")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -130,7 +130,7 @@ describe(`${chalk.yellowBright("mergedUpgrade2: Upgrading when there's a schedul }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/upgrade/mergedUpgrade3.test.ts b/server/tests/merged/upgrade/mergedUpgrade3.test.ts index a858a8ae8..07e4ef0ec 100644 --- a/server/tests/merged/upgrade/mergedUpgrade3.test.ts +++ b/server/tests/merged/upgrade/mergedUpgrade3.test.ts @@ -1,32 +1,32 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // UNCOMMENT FROM HERE -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); -let free = constructProduct({ +const free = constructProduct({ id: "free", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "free", @@ -81,8 +81,8 @@ const ops = [ const testCase = "mergedUpgrade3"; describe(`${chalk.yellowBright("mergedUpgrade3: Upgrading when there's a scheduled downgrade")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -139,7 +139,7 @@ describe(`${chalk.yellowBright("mergedUpgrade3: Upgrading when there's a schedul }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/merged/upgrade/mergedUpgrade4.test.ts b/server/tests/merged/upgrade/mergedUpgrade4.test.ts index cfde4874a..32a49aa77 100644 --- a/server/tests/merged/upgrade/mergedUpgrade4.test.ts +++ b/server/tests/merged/upgrade/mergedUpgrade4.test.ts @@ -1,35 +1,35 @@ -import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { Stripe } from "stripe"; -import { createProducts } from "tests/utils/productUtils.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; import { - APIVersion, - AppEnv, + type AppEnv, CusProductStatus, - Organization, + LegacyVersion, + type Organization, } from "@autumn/shared"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import { setupBefore } from "tests/before.js"; +import { TestFeature } from "tests/setup/v2Features.js"; import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; // OPERATIONS: // Pro, Pro // Free // Premium -let pro = constructProduct({ +const pro = constructProduct({ id: "pro", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "pro", }); -let free = constructProduct({ +const free = constructProduct({ id: "free", items: [constructFeatureItem({ featureId: TestFeature.Words })], type: "free", @@ -75,8 +75,8 @@ const ops = [ const testCase = "mergedUpgrade4"; describe(`${chalk.yellowBright("mergedUpgrade4: Upgrading when there's a cancel")}`, () => { - let customerId = testCase; - let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); + const customerId = testCase; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; let testClockId: string; @@ -133,7 +133,7 @@ describe(`${chalk.yellowBright("mergedUpgrade4: Upgrading when there's a cancel" }, ]; - it("should run operations", async function () { + it("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { diff --git a/server/tests/template.ts b/server/tests/template.ts index bc93655eb..032393b40 100644 --- a/server/tests/template.ts +++ b/server/tests/template.ts @@ -1,6 +1,6 @@ // import { AutumnInt } from "@/external/autumn/autumnCli.js"; // import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -// import { APIVersion, AppEnv, Organization } from "@autumn/shared"; +// import { LegacyVersion, AppEnv, Organization } from "@autumn/shared"; // import chalk from "chalk"; // import Stripe from "stripe"; // import { DrizzleCli } from "@/db/initDrizzle.js"; @@ -33,7 +33,7 @@ // describe(`${chalk.yellowBright(`${testCase}: Testing entities`)}`, () => { // let customerId = testCase; -// let autumn: AutumnInt = new AutumnInt({ version: APIVersion.v1_4 }); +// let autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); // let testClockId: string; // let db: DrizzleCli, org: Organization, env: AppEnv; // let stripeCli: Stripe; diff --git a/server/tests/utils/expectUtils/expectMultiAttach.ts b/server/tests/utils/expectUtils/expectMultiAttach.ts index efa92e0e7..855e85c4e 100644 --- a/server/tests/utils/expectUtils/expectMultiAttach.ts +++ b/server/tests/utils/expectUtils/expectMultiAttach.ts @@ -1,36 +1,19 @@ -import Stripe from "stripe"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { - APIVersion, - AppEnv, - AttachBranch, - CreateEntity, - CreateReward, - CusProductStatus, - FeatureOptions, - Organization, - ProductOptions, - ProductV2, + type AppEnv, + type CusProductStatus, + LegacyVersion, + type Organization, + type ProductOptions, + type ProductV2, } from "@autumn/shared"; - -import { - getAttachTotal, - getCurrentOptions, -} from "tests/utils/testAttachUtils/testAttachUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expectInvoicesCorrect } from "tests/utils/expectUtils/expectProductAttached.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { notNullish, timeout, toSnakeCase } from "@/utils/genUtils.js"; -import { expectSubItemsCorrect } from "tests/utils/expectUtils/expectSubUtils.js"; -import { DrizzleCli } from "@/db/initDrizzle.js"; - import { expect } from "chai"; -import { completeCheckoutForm } from "../stripeUtils.js"; -import { AttachParams, Customer } from "autumn-js"; -import { isFreeProductV2 } from "@/internal/products/productUtils/classifyProduct.js"; import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { Decimal } from "decimal.js"; +import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { timeout } from "@/utils/genUtils.js"; import { completeInvoiceCheckout } from "../stripeUtils/completeInvoiceCheckout.js"; +import { completeCheckoutForm } from "../stripeUtils.js"; export const expectMultiAttachCorrect = async ({ autumn, @@ -62,12 +45,12 @@ export const expectMultiAttachCorrect = async ({ org: Organization; env: AppEnv; }) => { - autumn = autumn || new AutumnInt({ version: APIVersion.v1_2 }); + autumn = autumn || new AutumnInt({ version: LegacyVersion.v1_2 }); const checkoutRes = await autumn.checkout({ customer_id: customerId, products: products, entity_id: entityId, - // @ts-ignore + // @ts-expect-error reward: rewards, ...attachParams, }); @@ -76,7 +59,7 @@ export const expectMultiAttachCorrect = async ({ customer_id: customerId, products: products, entity_id: entityId, - // @ts-ignore + // @ts-expect-error reward: rewards, ...attachParams, }); @@ -139,7 +122,7 @@ export const expectResultsCorrect = async ({ entityId?: string; }[]; }) => { - autumn = autumn || new AutumnInt({ version: APIVersion.v1_2 }); + autumn = autumn || new AutumnInt({ version: LegacyVersion.v1_2 }); for (const result of results) { let customer; if (result.entityId) { diff --git a/server/tests/utils/testAttachUtils/getAttachPreviewTotal.ts b/server/tests/utils/testAttachUtils/getAttachPreviewTotal.ts index 5e0c255e5..92a8be1fa 100644 --- a/server/tests/utils/testAttachUtils/getAttachPreviewTotal.ts +++ b/server/tests/utils/testAttachUtils/getAttachPreviewTotal.ts @@ -1,6 +1,6 @@ +import { type FeatureOptions, LegacyVersion } from "@autumn/shared"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { getAttachTotal } from "./testAttachUtils.js"; -import { APIVersion, FeatureOptions } from "@autumn/shared"; export const getAttachPreviewTotal = async ({ customerId, @@ -13,7 +13,7 @@ export const getAttachPreviewTotal = async ({ entityId: string; options?: FeatureOptions[]; }) => { - const autumn = new AutumnInt({ version: APIVersion.v1_2 }); + const autumn = new AutumnInt({ version: LegacyVersion.v1_2 }); const preview = await autumn.attachPreview({ customer_id: customerId, product_id: productId, diff --git a/shared/db/auth-schema.ts b/shared/db/auth-schema.ts index 591462d63..f66a1846d 100644 --- a/shared/db/auth-schema.ts +++ b/shared/db/auth-schema.ts @@ -1,14 +1,14 @@ import { + boolean, + foreignKey, pgTable, text, timestamp, - boolean, - integer, - foreignKey, } from "drizzle-orm/pg-core"; -import { organizations } from "./schema.js"; -import { relations } from "drizzle-orm"; -import { Organization } from "../models/orgModels/orgTable.js"; +import { + type Organization, + organizations, +} from "../models/orgModels/orgTable.js"; export const user = pgTable( "user", @@ -87,15 +87,6 @@ export const verification = pgTable("verification", { ), }).enableRLS(); -// export const organization = pgTable("organization", { -// id: text("id").primaryKey(), -// name: text("name").notNull(), -// slug: text("slug").unique(), -// logo: text("logo"), -// createdAt: timestamp("created_at").notNull(), -// metadata: text("metadata"), -// }); - export const member = pgTable("member", { id: text("id").primaryKey(), organizationId: text("organization_id") diff --git a/shared/enums/APIVersion.ts b/shared/enums/APIVersion.ts index a69ce9df9..4a267f10d 100644 --- a/shared/enums/APIVersion.ts +++ b/shared/enums/APIVersion.ts @@ -1,4 +1,13 @@ -export enum APIVersion { +export const Version = { + 1: 1, + 11: 1.1, + 12: 1.2, + 14: 1.4, +} as const; + +// export type ApiVersion = (typeof V)[keyof typeof V]; + +export enum LegacyVersion { v1 = 1, v1_1 = 1.1, v1_2 = 1.2, diff --git a/shared/models/orgModels/orgTable.ts b/shared/models/orgModels/orgTable.ts index ff94da07d..a4246fb1d 100644 --- a/shared/models/orgModels/orgTable.ts +++ b/shared/models/orgModels/orgTable.ts @@ -1,15 +1,14 @@ +import { sql } from "drizzle-orm"; import { + boolean, + jsonb, + numeric, pgTable, text, - numeric, - jsonb, - boolean, - unique, timestamp, + unique, } from "drizzle-orm/pg-core"; - -import { OrgConfig } from "./orgConfig.js"; -import { sql } from "drizzle-orm"; +import type { OrgConfig } from "./orgConfig.js"; export type SvixConfig = { sandbox_app_id: string; @@ -21,7 +20,6 @@ export type StripeConfig = { live_api_key?: string; test_webhook_secret?: string; live_webhook_secret?: string; - sandbox_success_url?: string; success_url?: string; }; @@ -34,6 +32,13 @@ export type OrgProcessorConfig = { // createdAt: timestamp("created_at").notNull(), // metadata: text("metadata"), +export interface VersionConfig { + sandbox?: string; + live?: string; + // sandbox_webhooks: string; + // live_webhooks: string; +} + export const organizations = pgTable( "organizations", { @@ -59,6 +64,7 @@ export const organizations = pgTable( created_at: numeric({ mode: "number" }), config: jsonb().default({}).notNull().$type(), created_by: text("created_by"), + version: jsonb("version").$type().default(sql`'{}'::jsonb`), }, (table) => [ unique("organizations_test_pkey_key").on(table.test_pkey), diff --git a/shared/utils/productUtils/priceUtils.ts b/shared/utils/productUtils/priceUtils.ts index 949bce0a8..c0a07b800 100644 --- a/shared/utils/productUtils/priceUtils.ts +++ b/shared/utils/productUtils/priceUtils.ts @@ -1,6 +1,6 @@ import { Decimal } from "decimal.js"; import type Stripe from "stripe"; -import { APIVersion } from "../../enums/APIVersion.js"; +import { LegacyVersion } from "../../enums/APIVersion.js"; import type { FullCusProduct } from "../../models/cusProductModels/cusProductModels.js"; import type { FixedPriceConfig } from "../../models/productModels/priceModels/priceConfig/fixedPriceConfig.js"; import { @@ -119,7 +119,7 @@ export const isV4Usage = ({ return ( billingType === BillingType.UsageInArrear && - (cusProduct.api_version === APIVersion.v1_4 || + (cusProduct.api_version === LegacyVersion.v1_4 || notNullish(cusProduct.internal_entity_id)) ); };