diff --git a/.bun-version b/.bun-version index f37ae4a16..d5e98f723 100644 --- a/.bun-version +++ b/.bun-version @@ -1 +1 @@ -1.2.19 \ No newline at end of file +1.3.2 \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md index 305350836..f8f78d0be 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,6 +5,7 @@ - JS Doc comments should be SHORT and SWEET. Don't need examples unless ABSOLUTELY necessary - When writing DB queries, for the `customers`, `products` and `features` tables (and others possibly not mentioned here), the primary key when updating is `internal_id`, not `id` - When using db schemas in Drizzle, import them from '@autumn/shared', and don't do schemas. +- Do NOT use "any" type. # Testing - When writing tests, ALWAYS read: diff --git a/bun.lock b/bun.lock index 6d323be55..38823d947 100644 --- a/bun.lock +++ b/bun.lock @@ -120,7 +120,7 @@ "recaseai": "^0.0.37", "resend": "^4.1.1", "semver": "^7.7.2", - "stripe": "18.4.0-beta.2", + "stripe": "catalog:", "svix": "^1.45.1", "tsc-alias": "^1.8.16", "ws": "^8.18.0", @@ -159,13 +159,13 @@ "dotenv": "^16.5.0", "drizzle-kit": "catalog:", "drizzle-orm": "catalog:", + "stripe": "catalog:", "yaml": "^2.8.1", "zod-openapi": "^5.4.1", }, "devDependencies": { "@types/bun": "latest", "@types/node": "^24.0.3", - "@typescript/native-preview": "^7.0.0-dev.20250731.1", "cross-env": "^7.0.3", "nodemon": "^3.1.7", "tsx": "^4.19.4", @@ -262,6 +262,7 @@ "@types/react": "^18.3.18", "@types/react-dom": "^18.3.5", "@types/react-router-dom": "^5.3.3", + "@typescript/native-preview": "^7.0.0-dev.20251111.1", "@vitejs/plugin-react": "^4.3.4", "eslint": "^9.21.0", "eslint-plugin-react-hooks": "^5.1.0", @@ -270,12 +271,14 @@ "typescript": "~5.7.2", "typescript-eslint": "^8.24.1", "vite": "^6.2.0", + "vite-tsconfig-paths": "^5.1.4", }, }, }, "catalog": { "drizzle-kit": "^0.31.1", "drizzle-orm": "0.43.1", + "stripe": "18.4.0-beta.2", }, "packages": { "@ai-sdk/anthropic": ["@ai-sdk/anthropic@1.2.12", "", { "dependencies": { "@ai-sdk/provider": "1.1.3", "@ai-sdk/provider-utils": "2.2.8" }, "peerDependencies": { "zod": "^3.0.0" } }, "sha512-YSzjlko7JvuiyQFmI9RN1tNZdEiZxc+6xld/0tq/VkJaHpEzGAb1yiNxxvmYVcjvfu/PcvCxAAYXmTYQQ63IHQ=="], @@ -486,23 +489,23 @@ "@better-fetch/fetch": ["@better-fetch/fetch@1.1.18", "", {}, "sha512-rEFOE1MYIsBmoMJtQbl32PGHHXuG2hDxvEd7rUHE0vCBoFQVSDqaVs9hkZEtHCxRoY+CljXKFCOuJ8uxqw1LcA=="], - "@biomejs/biome": ["@biomejs/biome@2.3.4", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.3.4", "@biomejs/cli-darwin-x64": "2.3.4", "@biomejs/cli-linux-arm64": "2.3.4", "@biomejs/cli-linux-arm64-musl": "2.3.4", "@biomejs/cli-linux-x64": "2.3.4", "@biomejs/cli-linux-x64-musl": "2.3.4", "@biomejs/cli-win32-arm64": "2.3.4", "@biomejs/cli-win32-x64": "2.3.4" }, "bin": { "biome": "bin/biome" } }, "sha512-TU08LXjBHdy0mEY9APtEtZdNQQijXUDSXR7IK1i45wgoPD5R0muK7s61QcFir6FpOj/RP1+YkPx5QJlycXUU3w=="], + "@biomejs/biome": ["@biomejs/biome@2.3.5", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.3.5", "@biomejs/cli-darwin-x64": "2.3.5", "@biomejs/cli-linux-arm64": "2.3.5", "@biomejs/cli-linux-arm64-musl": "2.3.5", "@biomejs/cli-linux-x64": "2.3.5", "@biomejs/cli-linux-x64-musl": "2.3.5", "@biomejs/cli-win32-arm64": "2.3.5", "@biomejs/cli-win32-x64": "2.3.5" }, "bin": { "biome": "bin/biome" } }, "sha512-HvLhNlIlBIbAV77VysRIBEwp55oM/QAjQEin74QQX9Xb259/XP/D5AGGnZMOyF1el4zcvlNYYR3AyTMUV3ILhg=="], - "@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.3.4", "", { "os": "darwin", "cpu": "arm64" }, "sha512-w40GvlNzLaqmuWYiDU6Ys9FNhJiclngKqcGld3iJIiy2bpJ0Q+8n3haiaC81uTPY/NA0d8Q/I3Z9+ajc14102Q=="], + "@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.3.5", "", { "os": "darwin", "cpu": "arm64" }, "sha512-fLdTur8cJU33HxHUUsii3GLx/TR0BsfQx8FkeqIiW33cGMtUD56fAtrh+2Fx1uhiCsVZlFh6iLKUU3pniZREQw=="], - "@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.3.4", "", { "os": "darwin", "cpu": "x64" }, "sha512-3s7TLVtjJ7ni1xADXsS7x7GMUrLBZXg8SemXc3T0XLslzvqKj/dq1xGeBQ+pOWQzng9MaozfacIHdK2UlJ3jGA=="], + "@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.3.5", "", { "os": "darwin", "cpu": "x64" }, "sha512-qpT8XDqeUlzrOW8zb4k3tjhT7rmvVRumhi2657I2aGcY4B+Ft5fNwDdZGACzn8zj7/K1fdWjgwYE3i2mSZ+vOA=="], - "@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.3.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-y7efHyyM2gYmHy/AdWEip+VgTMe9973aP7XYKPzu/j8JxnPHuSUXftzmPhkVw0lfm4ECGbdBdGD6+rLmTgNZaA=="], + "@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.3.5", "", { "os": "linux", "cpu": "arm64" }, "sha512-u/pybjTBPGBHB66ku4pK1gj+Dxgx7/+Z0jAriZISPX1ocTO8aHh8x8e7Kb1rB4Ms0nA/SzjtNOVJ4exVavQBCw=="], - "@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.3.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-IruVGQRwMURivWazchiq7gKAqZSFs5so6gi0hJyxk7x6HR+iwZbO2IxNOqyLURBvL06qkIHs7Wffl6Bw30vCbQ=="], + "@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.3.5", "", { "os": "linux", "cpu": "arm64" }, "sha512-eGUG7+hcLgGnMNl1KHVZUYxahYAhC462jF/wQolqu4qso2MSk32Q+QrpN7eN4jAHAg7FUMIo897muIhK4hXhqg=="], - "@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.3.4", "", { "os": "linux", "cpu": "x64" }, "sha512-gKfjWR/6/dfIxPJCw8REdEowiXCkIpl9jycpNVHux8aX2yhWPLjydOshkDL6Y/82PcQJHn95VCj7J+BRcE5o1Q=="], + "@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.3.5", "", { "os": "linux", "cpu": "x64" }, "sha512-XrIVi9YAW6ye0CGQ+yax0gLfx+BFOtKaNX74n+xHWla6Cl6huUmcKNO7HPx7BiKnJUzrxXY1qYlm7xMvi08X4g=="], - "@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.3.4", "", { "os": "linux", "cpu": "x64" }, "sha512-mzKFFv/w66e4/jCobFmD3kymCqG+FuWE7sVa4Yjqd9v7qt2UhXo67MSZKY9Ih18V2IwPzRKQPCw6KwdZs6AXSA=="], + "@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.3.5", "", { "os": "linux", "cpu": "x64" }, "sha512-awVuycTPpVTH/+WDVnEEYSf6nbCBHf/4wB3lquwT7puhNg8R4XvonWNZzUsfHZrCkjkLhFH/vCZK5jHatD9FEg=="], - "@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.3.4", "", { "os": "win32", "cpu": "arm64" }, "sha512-5TJ6JfVez+yyupJ/iGUici2wzKf0RrSAxJhghQXtAEsc67OIpdwSKAQboemILrwKfHDi5s6mu7mX+VTCTUydkw=="], + "@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.3.5", "", { "os": "win32", "cpu": "arm64" }, "sha512-DlBiMlBZZ9eIq4H7RimDSGsYcOtfOIfZOaI5CqsWiSlbTfqbPVfWtCf92wNzx8GNMbu1s7/g3ZZESr6+GwM/SA=="], - "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.3.4", "", { "os": "win32", "cpu": "x64" }, "sha512-FGCijXecmC4IedQ0esdYNlMpx0Jxgf4zceCaMu6fkjWyjgn50ZQtMiqZZQ0Q/77yqPxvtkgZAvt5uGw0gAAjig=="], + "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.3.5", "", { "os": "win32", "cpu": "x64" }, "sha512-nUmR8gb6yvrKhtRgzwo/gDimPwnO5a4sCydf8ZS2kHIJhEmSmk+STsusr1LHTuM//wXppBawvSQi2xFXJCdgKQ=="], "@browserbasehq/sdk": ["@browserbasehq/sdk@2.6.0", "", { "dependencies": { "@types/node": "^18.11.18", "@types/node-fetch": "^2.6.4", "abort-controller": "^3.0.0", "agentkeepalive": "^4.2.1", "form-data-encoder": "1.7.2", "formdata-node": "^4.3.2", "node-fetch": "^2.6.7" } }, "sha512-83iXP5D7xMm8Wyn66TUaUrgoByCmAJuoMoZQI3sGg3JAiMlTfnCIMqyVBoNSaItaPIkaCnrsj6LiusmXV2X9YA=="], @@ -1684,7 +1687,7 @@ "base64id": ["base64id@2.0.0", "", {}, "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog=="], - "baseline-browser-mapping": ["baseline-browser-mapping@2.8.25", "", { "bin": { "baseline-browser-mapping": "dist/cli.js" } }, "sha512-2NovHVesVF5TXefsGX1yzx1xgr7+m9JQenvz6FQY3qd+YXkKkYiv+vTCc7OriP9mcDZpTC5mAOYN4ocd29+erA=="], + "baseline-browser-mapping": ["baseline-browser-mapping@2.8.26", "", { "bin": { "baseline-browser-mapping": "dist/cli.js" } }, "sha512-73lC1ugzwoaWCLJ1LvOgrR5xsMLTqSKIEoMHVtL9E/HNk0PXtTM76ZIm84856/SF7Nv8mPZxKoBsgpm0tR1u1Q=="], "basic-ftp": ["basic-ftp@5.0.5", "", {}, "sha512-4Bcg1P8xhUuqcii/S0Z9wiHIrQVPMermM1any+MX5GeGD7faD3/msQUDGLol9wOcz4/jbg/WJnGqoJF6LiBdtg=="], @@ -2154,6 +2157,8 @@ "globby": ["globby@11.1.0", "", { "dependencies": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", "fast-glob": "^3.2.9", "ignore": "^5.2.0", "merge2": "^1.4.1", "slash": "^3.0.0" } }, "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g=="], + "globrex": ["globrex@0.1.2", "", {}, "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg=="], + "goober": ["goober@2.1.18", "", { "peerDependencies": { "csstype": "^3.0.10" } }, "sha512-2vFqsaDVIT9Gz7N6kAL++pLpp41l3PfDuusHcjnGLfR6+huZkl6ziX+zgVC3ZxpqWhzH6pyDdGrCeDhMIvwaxw=="], "google-logging-utils": ["google-logging-utils@0.0.2", "", {}, "sha512-NEgUnEcBiP5HrPzufUkBzJOD/Sxsco3rLNo1F1TNf7ieU8ryUzBhqba8r756CjLX7rn3fHl6iLEwPYuqpoKgQQ=="], @@ -2182,7 +2187,7 @@ "hoist-non-react-statics": ["hoist-non-react-statics@3.3.2", "", { "dependencies": { "react-is": "^16.7.0" } }, "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw=="], - "hono": ["hono@4.10.4", "", {}, "sha512-YG/fo7zlU3KwrBL5vDpWKisLYiM+nVstBQqfr7gCPbSYURnNEP9BDxEMz8KfsDR9JX0lJWDRNc6nXX31v7ZEyg=="], + "hono": ["hono@4.10.5", "", {}, "sha512-h/MXuTkoAK8NG1EfDp0jI1YLf6yGdDnfkebRO2pwEh5+hE3RAJFXkCsnD0vamSiARK4ZrB6MY+o3E/hCnOyHrQ=="], "hono-rate-limiter": ["hono-rate-limiter@0.4.2", "", { "peerDependencies": { "hono": "^4.1.1" } }, "sha512-AAtFqgADyrmbDijcRTT/HJfwqfvhalya2Zo+MgfdrMPas3zSMD8SU03cv+ZsYwRU1swv7zgVt0shwN059yzhjw=="], @@ -2976,6 +2981,8 @@ "tsc-alias": ["tsc-alias@1.8.16", "", { "dependencies": { "chokidar": "^3.5.3", "commander": "^9.0.0", "get-tsconfig": "^4.10.0", "globby": "^11.0.4", "mylas": "^2.1.9", "normalize-path": "^3.0.0", "plimit-lit": "^1.2.6" }, "bin": { "tsc-alias": "dist/bin/index.js" } }, "sha512-QjCyu55NFyRSBAl6+MTFwplpFcnm2Pq01rR/uxfqJoLMm6X3O14KEGtaSDZpJYaE1bJBGDjD0eSuiIWPe2T58g=="], + "tsconfck": ["tsconfck@3.1.6", "", { "peerDependencies": { "typescript": "^5.0.0" }, "optionalPeers": ["typescript"], "bin": { "tsconfck": "bin/tsconfck.js" } }, "sha512-ks6Vjr/jEw0P1gmOVwutM3B7fWxoWBL2KRDb1JfqGVawBmO5UsvmWOQFGHBPl5yxYz4eERr19E6L7NMv+Fej4w=="], + "tsconfig-paths": ["tsconfig-paths@4.2.0", "", { "dependencies": { "json5": "^2.2.2", "minimist": "^1.2.6", "strip-bom": "^3.0.0" } }, "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg=="], "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], @@ -3048,6 +3055,8 @@ "vite": ["vite@6.4.1", "", { "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.4.4", "picomatch": "^4.0.2", "postcss": "^8.5.3", "rollup": "^4.34.9", "tinyglobby": "^0.2.13" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", "jiti": ">=1.21.0", "less": "*", "lightningcss": "^1.21.0", "sass": "*", "sass-embedded": "*", "stylus": "*", "sugarss": "*", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g=="], + "vite-tsconfig-paths": ["vite-tsconfig-paths@5.1.4", "", { "dependencies": { "debug": "^4.1.1", "globrex": "^0.1.2", "tsconfck": "^3.0.3" }, "peerDependencies": { "vite": "*" }, "optionalPeers": ["vite"] }, "sha512-cYj0LRuLV2c2sMqhqhGpaO3LretdtMn/BVX4cPLanIZuwwrkVl+lK84E/miEXkCHWXuq65rhNN4rXsBcOB3S4w=="], + "vscode-oniguruma": ["vscode-oniguruma@2.0.1", "", {}, "sha512-poJU8iHIWnC3vgphJnrLZyI3YdqRlR27xzqDmpPXYzA93R4Gk8z7T6oqDzDoHjoikA2aS82crdXFkjELCdJsjQ=="], "vscode-textmate": ["vscode-textmate@9.2.1", "", {}, "sha512-eXiUi2yYFv9bdvgrYtJynA7UemCEkpVNE50S9iBBA08LYG5t9+/TB+8IRS/YoYOubCez2OkSyZ1Q12eQMwzbrw=="], @@ -3938,8 +3947,6 @@ "cloudflare/@types/node": ["@types/node@18.19.130", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg=="], - "cmdk/@radix-ui/react-primitive": ["@radix-ui/react-primitive@2.1.4", "", { "dependencies": { "@radix-ui/react-slot": "1.2.4" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-9hQc4+GNVtJAIEPEqlYqW5RiYdrr8ea5XQ0ZOnD6fgru+83kqT15mq2OCcbe8KnjRZl5vF3ks69AKz3kh1jrhg=="], - "concurrently/chalk": ["chalk@4.1.2", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="], "convex/esbuild": ["esbuild@0.25.4", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.25.4", "@esbuild/android-arm": "0.25.4", "@esbuild/android-arm64": "0.25.4", "@esbuild/android-x64": "0.25.4", "@esbuild/darwin-arm64": "0.25.4", "@esbuild/darwin-x64": "0.25.4", "@esbuild/freebsd-arm64": "0.25.4", "@esbuild/freebsd-x64": "0.25.4", "@esbuild/linux-arm": "0.25.4", "@esbuild/linux-arm64": "0.25.4", "@esbuild/linux-ia32": "0.25.4", "@esbuild/linux-loong64": "0.25.4", "@esbuild/linux-mips64el": "0.25.4", "@esbuild/linux-ppc64": "0.25.4", "@esbuild/linux-riscv64": "0.25.4", "@esbuild/linux-s390x": "0.25.4", "@esbuild/linux-x64": "0.25.4", "@esbuild/netbsd-arm64": "0.25.4", "@esbuild/netbsd-x64": "0.25.4", "@esbuild/openbsd-arm64": "0.25.4", "@esbuild/openbsd-x64": "0.25.4", "@esbuild/sunos-x64": "0.25.4", "@esbuild/win32-arm64": "0.25.4", "@esbuild/win32-ia32": "0.25.4", "@esbuild/win32-x64": "0.25.4" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-8pgjLUcUjcgDg+2Q4NYXnPbo/vncAY4UmyaCm0jZevERqCHZIaWwdJHkf8XQtu4AxSKCdvrUbT0XUr1IdZzI8Q=="], diff --git a/conductor-setup.sh b/conductor-setup.sh index aec9635a9..3e452507e 100644 --- a/conductor-setup.sh +++ b/conductor-setup.sh @@ -126,9 +126,7 @@ fi # echo "āœ… Copied migration files" # fi -# Build shared workspace (required for other workspaces) -echo "šŸ”Ø Building shared workspace..." -bun -F @autumn/shared build +# Shared workspace is now used directly from source (no build needed) # # Run database migrations if DATABASE_URL exists # if grep -q "DATABASE_URL=" server/.env 2>/dev/null; then diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml deleted file mode 100644 index 6be24242e..000000000 --- a/docker-compose.prod.yml +++ /dev/null @@ -1,64 +0,0 @@ - -services: - valkey: - image: docker.io/valkey/valkey:8.0 - environment: - - ALLOW_EMPTY_PASSWORD=yes - - VALKEY_DISABLE_COMMANDS=FLUSHDB,FLUSHALL - volumes: - - valkey-data:/bitnami/valkey/data - healthcheck: - test: ['CMD', 'redis-cli', '-h', 'localhost', '-p', '6379', 'ping'] - interval: 10s - timeout: 5s - retries: 5 - ports: - - "6379:6379" - restart: unless-stopped - - vite: - build: - context: . - dockerfile: docker/prod.dockerfile - target: vite-prod - ports: - - "3000:3000" - restart: always - - server: - environment: - - REDIS_URL=redis://valkey:6379 - build: - context: . - dockerfile: docker/prod.dockerfile - target: server-prod - ports: - - "8080:8080" - restart: always - - localtunnel: - image: oven/bun:latest - build: - dockerfile: docker/prod.dockerfile - context: . - target: localtunnel - volumes: - - ./server:/app/server - depends_on: - - server - restart: unless-stopped - - workers: - environment: - - REDIS_URL=redis://valkey:6379 - build: - context: . - dockerfile: docker/prod.dockerfile - target: workers-prod - restart: always - -volumes: - valkey-data: - shared-dist: - shared-node-modules: - root-node-modules: \ No newline at end of file diff --git a/docker/dev.dockerfile b/docker/dev.dockerfile index e40e25501..4fec00979 100644 --- a/docker/dev.dockerfile +++ b/docker/dev.dockerfile @@ -21,32 +21,25 @@ WORKDIR /app COPY localtunnel-start.sh ./ CMD ["sh", "localtunnel-start.sh"] -# Stage 2: /shared -FROM base AS shared -COPY shared/ ./shared/ -WORKDIR /app/shared -RUN bun run build -CMD ["bun", "dev"] - -# Stage 3: /vite +# Stage 2: /vite FROM base AS vite -COPY --from=shared /app/shared/dist ./shared/dist +COPY shared/ ./shared/ WORKDIR /app/vite COPY vite/ ./ EXPOSE 3000 CMD ["bun", "dev"] -# Stage 4: /server +# Stage 3: /server FROM base AS server -COPY --from=shared /app/shared/dist ./shared/dist +COPY shared/ ./shared/ COPY server/ ./server/ WORKDIR /app/server EXPOSE 8080 CMD ["bun", "dev"] -# Stage 5: Workers +# Stage 4: Workers FROM base AS workers -COPY --from=shared /app/shared/dist ./shared/dist +COPY shared/ ./shared/ COPY server/ ./server/ WORKDIR /app/server CMD ["bun", "workers:dev"] \ No newline at end of file diff --git a/docker/prod.dockerfile b/docker/prod.dockerfile deleted file mode 100644 index 213cdbb92..000000000 --- a/docker/prod.dockerfile +++ /dev/null @@ -1,52 +0,0 @@ -# ---- Base dependencies ---- -FROM oven/bun:latest AS base -WORKDIR /app -RUN bun install -g serve typescript tsc tsc-alias tsx - -COPY package.json bun.lock ./ -COPY shared/package*.json ./shared/ -COPY server/package*.json ./server/ -COPY vite/package*.json ./vite/ - -RUN bun install - -FROM base AS localtunnel -WORKDIR /app -COPY localtunnel-start.sh ./ -CMD ["sh", "localtunnel-start.sh"] - -# ---- Build shared package ---- -FROM base AS shared-build -COPY shared/ ./shared/ -WORKDIR /app/shared -RUN bun run build - -# ---- Build frontend (vite) ---- -FROM base AS vite-build -COPY --from=shared-build /app/shared/dist ./shared/dist -COPY . . -WORKDIR /app -RUN bun run build - -# ---- Build backend (server) ---- -FROM base AS server-build -COPY --from=shared-build /app/shared/dist ./shared/dist -COPY . . -WORKDIR /app -# RUN bun run server:build:bun - -# ---- Production frontend image ---- -FROM vite-build AS vite-prod -EXPOSE 3000 -WORKDIR /app -CMD ["bun", "start"] - -FROM server-build AS server-prod -EXPOSE 8080 -WORKDIR /app/server -CMD ["bun", "start"] - -FROM server-build AS workers-prod -EXPOSE 8080 -WORKDIR /app/server -CMD ["bun", "workers"] diff --git a/package.json b/package.json index cef911677..48ffcd851 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "scripts" ], "catalog": { + "stripe": "18.4.0-beta.2", "drizzle-orm": "0.43.1", "drizzle-kit": "^0.31.1" } @@ -16,32 +17,18 @@ "type": "module", "scripts": { "dev": "bun scripts/start-dev.js", - "d": "ENV_FILE=.env infisical run --env=dev -- bun scripts/start-dev.js", "p": "ENV_FILE=.env.prod infisical run --env=prod -- bun scripts/start-dev.js", - "vite:build": "bun -F @autumn/shared build && bun -F @autumn/vite build:bun", - "vite:start": "bun -F @autumn/vite start:bun", - "shared": "bun -F @autumn/shared build", - "server": "cd server && bun start", - "workers": "bun -F @autumn/shared build && bun -F @autumn/server workers", - "cron": "bun -F @autumn/shared build && bun -F @autumn/server cron", - "check": "bun -F @autumn/shared build && bun -F @autumn/server check", - "server:cron": "pnpm -F server cron:start", - "server:check": "NODE_ENV=production pnpm -F server check", "setup": "node scripts/setup.js", "setup:test": "bun scripts/setup-test.ts", "tests": "bun scripts/test.ts", + "setupci": "node scripts/setupci.js", "replicate": "bun scripts/replicate.ts", "db:push": " bun -F @autumn/shared db:push", "db:generate": "bun -F @autumn/shared db:generate", - "db:migrate": " bun -F @autumn/shared db:migrate", - "docker:up": "docker compose -f docker-compose.dev.yml up --build", - "docker:up:unix": "docker compose -f docker-compose.unix.yml up --build", - "docker:up:ci": "docker compose -f docker-compose.ci.yml up --build", - "vite:build:bun": "bun -F @autumn/shared build && bun -F @autumn/vite build:bun", - "vite:start:bun": "bun -F @autumn/shared build && bun -F @autumn/vite start:bun" + "db:migrate": " bun -F @autumn/shared db:migrate" }, "dependencies": { "@wooorm/starry-night": "^3.8.0", diff --git a/scripts/start-dev.js b/scripts/start-dev.js index f6d740a21..97fcefa2a 100644 --- a/scripts/start-dev.js +++ b/scripts/start-dev.js @@ -145,27 +145,6 @@ async function startDev() { // await handlePorts(); } - // Step 1: Build shared package first (initial build) - console.log("\nšŸ“¦ Building shared package...\n"); - const buildShared = spawn("bun", ["run", "build"], { - cwd: "shared", - stdio: "inherit", - shell: true, - }); - - await new Promise((resolve, reject) => { - buildShared.on("close", (code) => { - if (code !== 0) { - reject(new Error(`Shared package build failed with code ${code}`)); - } else { - resolve(); - } - }); - buildShared.on("error", reject); - }); - - console.log("\nāœ… Shared package built successfully!\n"); - // Clear Vite cache to prevent dep optimization issues const viteCachePath = path.join( projectRoot, @@ -180,19 +159,18 @@ async function startDev() { console.log("šŸš€ Starting development servers in watch mode...\n"); - // Step 2: Start server, workers, and vite first (they'll use the built shared package) + // Start server, workers, and vite (they'll use the shared package source files directly) const concurrentlyCmd = spawn( "bunx", [ "concurrently", "-n", - "server,workers,vite,shared", + "server,workers,vite", "-c", - "green,yellow,blue,cyan", + "green,yellow,blue", `"cd server && SERVER_PORT=${SERVER_PORT} bun dev"`, `"cd server && bun workers:dev"`, `"cd vite && VITE_PORT=${VITE_PORT} bun dev"`, - `"cd shared && bun run dev:watch"`, ], { stdio: "inherit", diff --git a/server/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc b/server/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc new file mode 120000 index 000000000..6100270f8 --- /dev/null +++ b/server/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc @@ -0,0 +1 @@ +../../CLAUDE.md \ No newline at end of file diff --git a/server/CLAUDE.md b/server/CLAUDE.md new file mode 100644 index 000000000..b8100b77e --- /dev/null +++ b/server/CLAUDE.md @@ -0,0 +1,111 @@ +--- +description: Use Bun instead of Node.js, npm, pnpm, or vite. +globs: "*.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json" +alwaysApply: false +--- + +Default to using Bun instead of Node.js. + +- Use `bun ` instead of `node ` or `ts-node ` +- Use `bun test` instead of `jest` or `vitest` +- Use `bun build ` instead of `webpack` or `esbuild` +- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install` +- Use `bun run + + +``` + +With the following `frontend.tsx`: + +```tsx#frontend.tsx +import React from "react"; + +// import .css files directly and it works +import './index.css'; + +import { createRoot } from "react-dom/client"; + +const root = createRoot(document.body); + +export default function Frontend() { + return

Hello, world!

; +} + +root.render(); +``` + +Then, run index.ts + +```sh +bun --hot ./index.ts +``` + +For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`. diff --git a/server/README.md b/server/README.md new file mode 100644 index 000000000..5069040e7 --- /dev/null +++ b/server/README.md @@ -0,0 +1,15 @@ +# @autumn/server + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.js +``` + +This project was created using `bun init` in bun v1.3.2. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. diff --git a/server/experiments/redis.ts b/server/experiments/redis.ts deleted file mode 100644 index 862514e86..000000000 --- a/server/experiments/redis.ts +++ /dev/null @@ -1,173 +0,0 @@ -import { Redis } from "ioredis"; -import { AutumnInt } from "../src/external/autumn/autumnCli.js"; -import { readFileSync } from "node:fs"; -import { join } from "node:path"; -import crypto from "node:crypto"; - -const client = new Redis("redis://localhost:6379"); - -// Load Lua scripts -const setCustomerScript = readFileSync( - join(import.meta.dir, "setCustomer.lua"), - "utf-8", -); -const getCustomerScript = readFileSync( - join(import.meta.dir, "getCustomer.lua"), - "utf-8", -); - -// Calculate SHA1 hashes for script caching -const setCustomerSha = crypto - .createHash("sha1") - .update(setCustomerScript) - .digest("hex"); -const getCustomerSha = crypto - .createHash("sha1") - .update(getCustomerScript) - .digest("hex"); - -// Load scripts into Redis -await client.script("LOAD", setCustomerScript); -await client.script("LOAD", getCustomerScript); - -/** - * Atomically stores a customer object in Redis with features as HSETs - */ -async function setCustomer({ customerData }: { customerData: any }) { - const customerId = customerData.id; - try { - const result = await client.evalsha( - setCustomerSha, - 1, - customerId, - JSON.stringify(customerData), - ); - return result; - } catch (error: any) { - // If script not found, reload and retry - if (error.message.includes("NOSCRIPT")) { - await client.script("LOAD", setCustomerScript); - return await client.evalsha( - setCustomerSha, - 1, - customerId, - JSON.stringify(customerData), - ); - } - throw error; - } -} - -/** - * Atomically retrieves a customer object from Redis, reconstructing from HSETs - */ -async function getCustomer({ customerId }: { customerId: string }) { - try { - const result = await client.evalsha(getCustomerSha, 1, customerId); - if (!result) { - return null; - } - return JSON.parse(result as string); - } catch (error: any) { - // If script not found, reload and retry - if (error.message.includes("NOSCRIPT")) { - await client.script("LOAD", getCustomerScript); - const retryResult = await client.evalsha(getCustomerSha, 1, customerId); - if (!retryResult) { - return null; - } - return JSON.parse(retryResult as string); - } - throw error; - } -} - -/** - * Atomically updates a feature balance using HINCRBYFLOAT - */ -async function updateFeatureBalance({ - customerId, - featureId, - amount, - breakdownIndex, -}: { - customerId: string; - featureId: string; - amount: number; - breakdownIndex?: number; -}) { - // Update breakdown-specific balance if index provided - if (breakdownIndex !== undefined) { - const breakdownKey = `customer:${customerId}:features:${featureId}:breakdown:${breakdownIndex}`; - await client.hincrbyfloat(breakdownKey, "balance", amount); - } - - // Always update aggregate feature balance - const featureKey = `customer:${customerId}:features:${featureId}`; - await client.hincrbyfloat(featureKey, "balance", amount); -} - -/** - * Atomically updates a feature usage using HINCRBYFLOAT - */ -async function updateFeatureUsage({ - customerId, - featureId, - amount, - breakdownIndex, -}: { - customerId: string; - featureId: string; - amount: number; - breakdownIndex?: number; -}) { - // Update breakdown-specific usage if index provided - if (breakdownIndex !== undefined) { - const breakdownKey = `customer:${customerId}:features:${featureId}:breakdown:${breakdownIndex}`; - await client.hincrbyfloat(breakdownKey, "usage", amount); - } - - // Always update aggregate feature usage - const featureKey = `customer:${customerId}:features:${featureId}`; - await client.hincrbyfloat(featureKey, "usage", amount); -} - -const main = async () => { - const autumn = new AutumnInt({ secretKey: process.env.JDEV! }); - - const customer = await autumn.customers.get("john"); - - // 1. Set customer - const setStart = performance.now(); - await setCustomer({ - customerData: customer, - }); - const setEnd = performance.now(); - console.log(`āœ“ Stored customer in Redis (${(setEnd - setStart).toFixed(2)}ms)`); - - // 2. Get customer - console.time("Get cached customer"); - const cachedCustomer = await getCustomer({ customerId: "john" }); - console.timeEnd("Get cached customer"); - - // Compare features - console.log("\n=== Comparison ==="); - console.log(`Original credits feature balance: `, cachedCustomer?.features?.credits?.balance); - - // Time the decrement of lifetime balance using HDECRBYFLOAT - console.time("Decrement lifetime balance"); - await client.hincrbyfloat("customer:john:features:credits", "balance", -1.42513); - console.timeEnd("Decrement lifetime balance"); - - // Get updated customer - const updatedCustomer = await getCustomer({ customerId: "john" }); - console.log('Updated credits feature balance:', updatedCustomer?.features?.credits?.balance); - - // Time getting the customer object - console.time("Get base customer"); - await client.get("customer:john"); - console.timeEnd("Get base customer"); -}; - -await main(); -process.exit(0); \ No newline at end of file diff --git a/server/experiments/redis2.ts b/server/experiments/redis2.ts deleted file mode 100644 index 3251cac14..000000000 --- a/server/experiments/redis2.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { AppEnv } from "@autumn/shared"; -import { - buildCachedApiCustomerKey, - getCachedApiCustomer, -} from "../src/internal/customers/cusUtils/apiCusCacheUtils/getCachedApiCustomer.js"; -import { initDrizzle } from "../src/db/initDrizzle.js"; -import { initScript } from "../src/utils/scriptUtils/scriptUtils.js"; -import { redis } from "../src/external/redis/initRedis.js"; -import { AutumnInt } from "../src/external/autumn/autumnCli.js"; - -const DEDUCTION_COUNT = 15_000; -const DEDUCTION_AMOUNT = 1; - -const logCredits = (label: string, customer: Awaited>) => { - const credits = customer?.features?.credits; - console.log(`\n${label}`); - console.log(` Total Balance: ${credits?.balance ?? "N/A"}`); - console.log(` Monthly Credits: ${credits?.breakdown?.[0]?.balance ?? "N/A"}`); - console.log(` Lifetime Credits: ${credits?.breakdown?.[1]?.balance ?? "N/A"}`); -}; - -const main = async () => { - const orgId = "org_2s4vfEyYVgFZDlOwcMHjsHR0eef"; - const env = AppEnv.Sandbox; - const customerId = "john"; - - - const { db } = initDrizzle(); - const { req } = await initScript({ orgId, env }); - const autumn = new AutumnInt({ - secretKey: process.env.JDEV!, - }); - - await redis.del(buildCachedApiCustomerKey({ customerId, orgId, env })); - - const customerBefore = await getCachedApiCustomer({ - ctx: req as any, - customerId, - }); - logCredits("šŸ“Š Credits Before:", customerBefore); - - console.log(`\nā³ Processing ${DEDUCTION_COUNT.toLocaleString()} deductions...`); - const start = Date.now(); - - - const promises = Array.from({ length: DEDUCTION_COUNT }, () => - autumn.track({ - customer_id: customerId, - feature_id: "credits", - value: DEDUCTION_AMOUNT, - }), - ); - - await Promise.all(promises); - const elapsed = Date.now() - start; - - const customerAfter = await getCachedApiCustomer({ - ctx: req as any, - customerId, - }); - logCredits("šŸ“Š Credits After:", customerAfter); - - const deductionDiff = (customerBefore?.features?.credits?.balance ?? 0) - (customerAfter?.features?.credits?.balance ?? 0); - - console.log("\nāœ… Test Complete!"); - console.log(` Time Elapsed: ${elapsed.toLocaleString()}ms`); - console.log(` Total Deducted: ${deductionDiff}`); - console.log(` Avg per Deduction: ${(elapsed / DEDUCTION_COUNT).toFixed(3)}ms\n`); -}; - -await main(); -process.exit(0); \ No newline at end of file diff --git a/server/experiments/test-lua-debug.ts b/server/experiments/test-lua-debug.ts deleted file mode 100644 index 4990229ec..000000000 --- a/server/experiments/test-lua-debug.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { globalBatchingManager } from "../src/internal/balances/track/redisTrackUtils/BatchingManager.js"; - -/** - * Test script to debug the simplified batchDeduction.lua - * This will show you what the Lua script can retrieve about a feature - */ -async function testLuaDebug() { - // Replace these with real values from your test data - const customerId = "your-customer-id"; - const orgId = "your-org-id"; - const env = "development"; - - console.log("Testing Lua script with:"); - console.log("- Customer ID:", customerId); - console.log("- Org ID:", orgId); - console.log("- Environment:", env); - console.log(""); - - try { - const result = await globalBatchingManager.deduct({ - customerId, - featureDeductions: [ - { featureId: "credits", amount: 10 }, - { featureId: "api_calls", amount: 5 }, - ], - orgId, - env, - overageBehavior: "cap", - }); - - console.log("šŸ“¦ Batching manager result:"); - console.log(JSON.stringify(result, null, 2)); - } catch (error) { - console.error("āŒ Error:", error); - } - - process.exit(0); -} - -testLuaDebug(); - diff --git a/server/index.js b/server/index.js new file mode 100644 index 000000000..f67b2c645 --- /dev/null +++ b/server/index.js @@ -0,0 +1 @@ +console.log("Hello via Bun!"); \ No newline at end of file diff --git a/server/package.json b/server/package.json index b04b2ef61..98ab2342a 100644 --- a/server/package.json +++ b/server/package.json @@ -23,7 +23,9 @@ "parallel-tests:v1": "ENV_FILE=.env infisical run --env=dev -- bun tests/testRunner/runParallelGroups.ts", "parallel-tests:verbose": "ENV_FILE=.env infisical run --env=dev -- bun tests/testRunner/runParallelGroups.ts --verbose", "parallel-tests:debug": "ENV_FILE=.env infisical run --env=dev -- bun tests/testRunner/runParallelGroups.ts --debug", - "clear-master": "ENV_FILE=.env infisical run --env=dev -- bun tests/clearMasterOrg.ts" + "clear-master": "ENV_FILE=.env infisical run --env=dev -- bun tests/clearMasterOrg.ts", + + "ts": "bunx tsgo --build --noEmit" }, "mocha": { "node-option": [ @@ -113,7 +115,7 @@ "recaseai": "^0.0.37", "resend": "^4.1.1", "semver": "^7.7.2", - "stripe": "18.4.0-beta.2", + "stripe": "catalog:", "svix": "^1.45.1", "tsc-alias": "^1.8.16", "ws": "^8.18.0", diff --git a/server/src/check.ts b/server/src/check.ts index c68a5605a..577955911 100644 --- a/server/src/check.ts +++ b/server/src/check.ts @@ -36,16 +36,16 @@ import { checkCusSubCorrect } from "./utils/checkUtils/checkCustomerCorrect.js"; const { db } = initDrizzle({ maxConnections: 5 }); -let orgSlugs = process.env.ORG_SLUGS!.split(","); +const orgSlugs = process.env.ORG_SLUGS!.split(","); const skipEmails = process.env.SKIP_EMAILS!.split(","); const skipIds = [ "cus_2tXCCwC6iyiftgA6ndSo1Ubb2dx", "DxG668K7uDd0Vahk54YWjvCGVgf2", ]; -orgSlugs = ["welcome-back-1747670264"]; -let customerId = null; -customerId = "56"; +// orgSlugs = ["welcome-back-1747670264"]; +// let customerId = null; +const customerId = null; const getSingleCustomer = async ({ stripeCli, diff --git a/server/src/external/autumn/autumnCli.ts b/server/src/external/autumn/autumnCli.ts index 99f0d6be1..c3ea0e807 100644 --- a/server/src/external/autumn/autumnCli.ts +++ b/server/src/external/autumn/autumnCli.ts @@ -18,6 +18,7 @@ import { type RewardRedemption, type TrackParams, } from "@autumn/shared"; +import { defaultApiVersion } from "@tests/constants.js"; import type { CancelParams, CheckoutParams, @@ -27,7 +28,6 @@ import type { Customer, UsageParams, } from "autumn-js"; -import { defaultApiVersion } from "tests/constants.js"; export default class AutumnError extends Error { message: string; diff --git a/server/src/external/autumn/autumnCliV2.ts b/server/src/external/autumn/autumnCliV2.ts index 12ef4a2a1..96b8ea7b6 100644 --- a/server/src/external/autumn/autumnCliV2.ts +++ b/server/src/external/autumn/autumnCliV2.ts @@ -5,7 +5,7 @@ dotenv.config(); import { type AttachBody, - type CreateEntity, + type CreateEntityParams, type CreateRewardProgram, CusExpand, EntityExpand, @@ -321,7 +321,7 @@ export class AutumnCliV2 { create: async ( customerId: string, - entity: CreateEntity | CreateEntity[], + entity: CreateEntityParams | CreateEntityParams[], ) => { return await this.post( `/customers/${customerId}/entities?with_autumn_id=true`, diff --git a/server/src/external/llm/llmUtils.ts b/server/src/external/llm/llmUtils.ts index 450a51ec3..e10ec98f7 100644 --- a/server/src/external/llm/llmUtils.ts +++ b/server/src/external/llm/llmUtils.ts @@ -1,5 +1,5 @@ import { createAnthropic } from "@ai-sdk/anthropic"; -import { Feature } from "@autumn/shared"; +import type { Feature } from "@autumn/shared"; import { generateObject } from "ai"; import { z } from "zod"; @@ -20,8 +20,8 @@ export const generateFeatureDisplay = async (feature: Feature) => { `; - let { object } = await generateObject({ - model: anthropic("claude-3-5-sonnet-latest"), + const { object } = await generateObject({ + model: anthropic("claude-haiku-4-5"), schema: z.object({ singular: z.string(), plural: z.string(), diff --git a/server/src/external/stripe/handleStripeWebhookEvent.ts b/server/src/external/stripe/handleStripeWebhookEvent.ts index 2b4b6821c..b5d918420 100644 --- a/server/src/external/stripe/handleStripeWebhookEvent.ts +++ b/server/src/external/stripe/handleStripeWebhookEvent.ts @@ -155,7 +155,7 @@ export const handleStripeWebhookEvent = async ({ case "customer.subscription.updated": { const subscription = event.data.object; await handleSubscriptionUpdated({ - req: ctx as ExtendedRequest, + req: ctx as unknown as ExtendedRequest, db, org, subscription, @@ -168,7 +168,7 @@ export const handleStripeWebhookEvent = async ({ case "customer.subscription.deleted": await handleSubDeleted({ - req: ctx as ExtendedRequest, + req: ctx as unknown as ExtendedRequest, stripeCli, data: event.data.object, logger, @@ -178,7 +178,7 @@ export const handleStripeWebhookEvent = async ({ case "checkout.session.completed": { const checkoutSession = event.data.object; await handleCheckoutSessionCompleted({ - req: ctx as ExtendedRequest, + req: ctx as unknown as ExtendedRequest, db, data: checkoutSession, org, @@ -196,7 +196,7 @@ export const handleStripeWebhookEvent = async ({ invoiceData: invoice, env, event, - req: ctx as ExtendedRequest, + req: ctx as unknown as ExtendedRequest, }); break; } @@ -206,7 +206,7 @@ export const handleStripeWebhookEvent = async ({ stripeCli, env, event, - req: ctx as ExtendedRequest, + req: ctx as unknown as ExtendedRequest, }); break; diff --git a/server/src/external/stripe/stripeSubUtils.ts b/server/src/external/stripe/stripeSubUtils.ts index 2fdba7ae0..5d0cbafff 100644 --- a/server/src/external/stripe/stripeSubUtils.ts +++ b/server/src/external/stripe/stripeSubUtils.ts @@ -141,7 +141,7 @@ export const getUsageBasedSub = async ({ let usageFeatures: string[] | null = null; // 1. Check if there's autumn sub - const autumnSub = autumnSubs?.find((sub) => sub.stripe_id == stripeSub.id); + const autumnSub = autumnSubs?.find((sub) => sub.stripe_id === stripeSub.id); if (autumnSub) { const containsFeature = autumnSub.usage_features.includes( feature.internal_id!, @@ -153,14 +153,14 @@ export const getUsageBasedSub = async ({ try { usageFeatures = JSON.parse(stripeSub.metadata.usage_features); - } catch (error) { + } catch { continue; } if ( !usageFeatures || usageFeatures.find( - (feat: any) => feat.internal_id == feature.internal_id, + (feat: any) => feat.internal_id === feature.internal_id, ) === undefined ) { continue; diff --git a/server/src/external/stripe/webhookHandlers/handleInvoiceCreated/handleInvoiceCreated.ts b/server/src/external/stripe/webhookHandlers/handleInvoiceCreated/handleInvoiceCreated.ts index f7c686f85..79cdebed5 100644 --- a/server/src/external/stripe/webhookHandlers/handleInvoiceCreated/handleInvoiceCreated.ts +++ b/server/src/external/stripe/webhookHandlers/handleInvoiceCreated/handleInvoiceCreated.ts @@ -301,8 +301,6 @@ export const handleInvoiceCreated = async ({ const subId = invoiceToSubId({ invoice }); - console.log("HANDLING INVOICE CREATED", invoice.id); - if (subId) { const activeProducts = await CusProductService.getByStripeSubId({ db, diff --git a/server/src/honoMiddlewares/expandMiddleware.ts b/server/src/honoMiddlewares/expandMiddleware.ts index d771f8d5e..040e1e223 100644 --- a/server/src/honoMiddlewares/expandMiddleware.ts +++ b/server/src/honoMiddlewares/expandMiddleware.ts @@ -4,16 +4,33 @@ import type { HonoEnv } from "@/honoUtils/HonoEnv.js"; /** * Extracts expand from validated query and sets it in context. * Must run AFTER versionedValidator so expand has been transformed. + * Uses c.req.query("expand") to access the parsed expand field. */ export const expandMiddleware = (): MiddlewareHandler => { return async (c, next) => { - const validatedQuery = c.req.valid("query"); - const expand = validatedQuery?.expand || []; + // Query is parsed by queryMiddleware and validated by versionedValidator/validator + // queryStringArray normalizes expand to an array during validation, but we access + // the parsed query which may still be a string for single values + const expandValue = c.req.query("expand"); + // queryMiddleware converts "true"/"false" strings to boolean values + // Handle both boolean (from queryMiddleware) and string (fallback) cases + const skipCacheQuery = c.req.query("skip_cache"); + const skipCacheValue = + (typeof skipCacheQuery === "boolean" && skipCacheQuery === true) || + (typeof skipCacheQuery === "string" && skipCacheQuery === "true"); + + // Normalize to array: undefined -> [], string -> [string], array -> array + const expand: string[] = !expandValue + ? [] + : Array.isArray(expandValue) + ? expandValue + : [expandValue]; const ctx = c.get("ctx"); c.set("ctx", { ...ctx, - expand: Array.isArray(expand) ? expand : [expand], + expand, + skipCache: skipCacheValue, }); await next(); diff --git a/server/src/honoMiddlewares/versionedValidator.ts b/server/src/honoMiddlewares/versionedValidator.ts index 88f32a411..79225bd37 100644 --- a/server/src/honoMiddlewares/versionedValidator.ts +++ b/server/src/honoMiddlewares/versionedValidator.ts @@ -65,7 +65,7 @@ export const versionedValidator = ({ throw result.error; } validatedData = result.data as Record; - c.req.addValidatedData(target, result.data); + c.req.addValidatedData(target, validatedData); } else { // For other targets, use zValidator const validatorMiddleware = zValidator(target, schema, (result, _c) => { diff --git a/server/src/honoUtils/HonoEnv.ts b/server/src/honoUtils/HonoEnv.ts index 79193d472..60c8ecbe7 100644 --- a/server/src/honoUtils/HonoEnv.ts +++ b/server/src/honoUtils/HonoEnv.ts @@ -30,6 +30,7 @@ export type RequestContext = { // Query params expand: string[]; + skipCache: boolean; }; export type AutumnContext = RequestContext; diff --git a/server/src/internal/analytics/analyticsRouter.ts b/server/src/internal/analytics/analyticsRouter.ts index 581053cef..b80f4a6fe 100644 --- a/server/src/internal/analytics/analyticsRouter.ts +++ b/server/src/internal/analytics/analyticsRouter.ts @@ -80,7 +80,7 @@ analyticsRouter.post("", (req, res) => } events.data.forEach((event: any) => { - event["period"] = parseInt(format(new Date(event["period"]), "T")); + event.period = parseInt(format(new Date(event.period), "T")); }); const usageList = events.data.filter( diff --git a/server/src/internal/customers/add-product/createFullCusProduct.ts b/server/src/internal/customers/add-product/createFullCusProduct.ts index ccfe4da75..ad8dca691 100644 --- a/server/src/internal/customers/add-product/createFullCusProduct.ts +++ b/server/src/internal/customers/add-product/createFullCusProduct.ts @@ -404,6 +404,7 @@ export const createFullCusProduct = async ({ isDowngrade, entities: attachParams.entities, features: attachParams.features, + prices, }); // 4. Get new rollovers diff --git a/server/src/internal/customers/attach/attachFunctions/scheduleFlow/handleScheduleFlow2.ts b/server/src/internal/customers/attach/attachFunctions/scheduleFlow/handleScheduleFlow2.ts index 538e25dce..fadd84903 100644 --- a/server/src/internal/customers/attach/attachFunctions/scheduleFlow/handleScheduleFlow2.ts +++ b/server/src/internal/customers/attach/attachFunctions/scheduleFlow/handleScheduleFlow2.ts @@ -102,7 +102,6 @@ export const handleScheduleFunction2 = async ({ }); const currentPhaseIndex = getCurrentPhaseIndex({ - // biome-ignore lint/suspicious/noExplicitAny: ok schedule: { phases: newItems.phases } as any, now: attachParams.now, }); diff --git a/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getPricesAndEnts.ts b/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getPricesAndEnts.ts index 221277a15..6bf5933f2 100644 --- a/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getPricesAndEnts.ts +++ b/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getPricesAndEnts.ts @@ -122,7 +122,7 @@ export const getPricesAndEnts = async ({ optionsInput: optionsInput || [], features, prices, - curCusProduct: curMainProduct, + curCusProduct, }), prices, entitlements: getEntsWithFeature({ diff --git a/server/src/internal/customers/attach/attachUtils/getAttachConfig.ts b/server/src/internal/customers/attach/attachUtils/getAttachConfig.ts index fff77c459..140bd96cd 100644 --- a/server/src/internal/customers/attach/attachUtils/getAttachConfig.ts +++ b/server/src/internal/customers/attach/attachUtils/getAttachConfig.ts @@ -7,6 +7,7 @@ import { intervalToValue, ProrationBehavior, } from "@autumn/shared"; +import { isDefaultTrialFullProduct } from "@/internal/products/productUtils/classifyProduct.js"; import { isFreeProduct } from "@/internal/products/productUtils.js"; import { notNullish, nullish } from "@/utils/genUtils.js"; import type { AttachParams } from "../../cusProducts/AttachParams.js"; @@ -16,7 +17,6 @@ import { attachParamsToProduct, attachParamToCusProducts, } from "./convertAttachParams.js"; -import { isDefaultTrialFullProduct } from "@/internal/products/productUtils/classifyProduct.js"; export const intervalsAreSame = ({ attachParams, @@ -118,10 +118,11 @@ export const getAttachConfig = async ({ let isUpgradingFromDefaultTrial = false; if (curMainProduct && branch === AttachBranch.Upgrade) { const product = cusProductToProduct({ cusProduct: curMainProduct }); - isUpgradingFromDefaultTrial = isDefaultTrialFullProduct({ - product, - skipDefault: true, - }) || false; + isUpgradingFromDefaultTrial = + isDefaultTrialFullProduct({ + product, + skipDefault: true, + }) || false; } const checkoutFlow = @@ -172,7 +173,6 @@ export const getAttachConfig = async ({ ? attachBody.finalize_invoice! : true, requirePaymentMethod: paymentMethodRequired, - }; return { flags, config }; diff --git a/server/src/internal/customers/attach/handleAttachPreview/getNewProductPreview.ts b/server/src/internal/customers/attach/handleAttachPreview/getNewProductPreview.ts index a5dd1f4bc..070ee4ab3 100644 --- a/server/src/internal/customers/attach/handleAttachPreview/getNewProductPreview.ts +++ b/server/src/internal/customers/attach/handleAttachPreview/getNewProductPreview.ts @@ -99,6 +99,10 @@ export const getNewProductPreview = async ({ let trialEnds: number | undefined; + if (config.disableTrial) { + attachParams.freeTrial = null; + } + // Scenario where we update a current sub with new product (so no create sub) let anchor: number | undefined; if (mergeSub && !config.disableMerge) { diff --git a/server/src/internal/customers/attach/mergeUtils/paramsToSubItems.ts b/server/src/internal/customers/attach/mergeUtils/paramsToSubItems.ts index 411bc7f7c..5965f1d38 100644 --- a/server/src/internal/customers/attach/mergeUtils/paramsToSubItems.ts +++ b/server/src/internal/customers/attach/mergeUtils/paramsToSubItems.ts @@ -1,20 +1,25 @@ -import Stripe from "stripe"; -import { AttachParams } from "../../cusProducts/AttachParams.js"; +import { + type AttachConfig, + CusProductStatus, + cusProductToPrices, + cusProductToProduct, + type FullCusProduct, +} from "@autumn/shared"; +import type Stripe from "stripe"; import { getStripeSubItems2 } from "@/external/stripe/stripeSubUtils/getStripeSubItems.js"; -import { AttachConfig, CusProductStatus, FullCusProduct } from "@autumn/shared"; -import { getExistingCusProducts } from "../../cusProducts/cusProductUtils/getExistingCusProducts.js"; -import { ExtendedRequest } from "@/utils/models/Request.js"; -import { cusProductToPrices, cusProductToProduct } from "@autumn/shared"; -import { isArrearPrice } from "@/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.js"; import { findStripeItemForPrice, subItemInCusProduct, } from "@/external/stripe/stripeSubUtils/stripeSubItemUtils.js"; -import { mergeNewSubItems } from "./mergeNewSubItems.js"; +import { isArrearPrice } from "@/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.js"; import { formatPrice } from "@/internal/products/prices/priceUtils.js"; -import { getQuantityToRemove } from "./mergeUtils.js"; import { notNullish } from "@/utils/genUtils.js"; -import { ItemSet } from "@/utils/models/ItemSet.js"; +import type { ItemSet } from "@/utils/models/ItemSet.js"; +import type { ExtendedRequest } from "@/utils/models/Request.js"; +import type { AttachParams } from "../../cusProducts/AttachParams.js"; +import { getExistingCusProducts } from "../../cusProducts/cusProductUtils/getExistingCusProducts.js"; +import { mergeNewSubItems } from "./mergeNewSubItems.js"; +import { getQuantityToRemove } from "./mergeUtils.js"; export const getCusProductsToRemove = ({ attachParams, @@ -53,12 +58,12 @@ export const getCusProductsToRemove = ({ cusProductsToRemove.push(curScheduledProduct); } - // 1. If product is an add on, and there's current same, add it - else if (curSameProduct) { + // 2. If cancelling, and same product exists (add on / main), add it. + else if (curSameProduct && attachParams.fromCancel) { cusProductsToRemove.push(curSameProduct); } - // 2. If product is a main product, add curMain + // 3. If product is a main product, add curMain else if (!product.is_add_on && curMainProduct) { cusProductsToRemove.push(curMainProduct); } @@ -100,8 +105,7 @@ export const paramsToSubItems = async ({ removeCusProducts?: FullCusProduct[]; addItemSet?: ItemSet; }) => { - const { logger } = req; - let curSubItems = sub?.items.data || []; + const curSubItems = sub?.items.data || []; const itemSet = notNullish(addItemSet) ? addItemSet! @@ -120,7 +124,7 @@ export const paramsToSubItems = async ({ cusProductsToRemove.map((cp) => cp.product.name), ); - let newSubItems = mergeNewSubItems({ + const newSubItems = mergeNewSubItems({ itemSet, curSubItems, }); @@ -165,7 +169,7 @@ export const paramsToSubItems = async ({ allCusProducts.some((cp) => { if (cp.id === cusProduct.id) return false; - if (cp.status == CusProductStatus.Scheduled) return false; + if (cp.status === CusProductStatus.Scheduled) return false; return subItemInCusProduct({ cusProduct: cp, @@ -177,7 +181,7 @@ export const paramsToSubItems = async ({ } if ( - itemSet.subItems.some((si) => si.price == existingSubItem.price?.id) + itemSet.subItems.some((si) => si.price === existingSubItem.price?.id) ) { continue; } diff --git a/server/src/internal/customers/attach/mergeUtils/subToNewSchedule.ts b/server/src/internal/customers/attach/mergeUtils/subToNewSchedule.ts index f896e6414..7731e7c2d 100644 --- a/server/src/internal/customers/attach/mergeUtils/subToNewSchedule.ts +++ b/server/src/internal/customers/attach/mergeUtils/subToNewSchedule.ts @@ -33,9 +33,10 @@ export const subToNewSchedule = async ({ attachParams, includeCanceled: true, }); + console.log( `REMOVING CUS PRODUCTS: ${cusProductsToRemove.map((cp) => `${cp.product.id} (E: ${cp.entity_id})`).join(", ")}`, - ); // See mergedDowngrade5.test.ts -- if there's no schedule and creating one, might need to include canceled cus products + ); const res = await paramsToScheduleItems({ req, diff --git a/server/src/internal/customers/cancel/handleCancelProduct.ts b/server/src/internal/customers/cancel/handleCancelProduct.ts index 0fde911b6..25af3344e 100644 --- a/server/src/internal/customers/cancel/handleCancelProduct.ts +++ b/server/src/internal/customers/cancel/handleCancelProduct.ts @@ -158,6 +158,7 @@ export const handleCancelProduct = async ({ replaceables: [], entities: fullCus.entities, features: req.features, + fromCancel: true, }, config: getDefaultAttachConfig(), skipInsertCusProduct, diff --git a/server/src/internal/customers/cusProducts/cusEnts/cusEntUtils/getExistingUsage.ts b/server/src/internal/customers/cusProducts/cusEnts/cusEntUtils/getExistingUsage.ts index 947054e03..7b9792db7 100644 --- a/server/src/internal/customers/cusProducts/cusEnts/cusEntUtils/getExistingUsage.ts +++ b/server/src/internal/customers/cusProducts/cusEnts/cusEntUtils/getExistingUsage.ts @@ -15,6 +15,7 @@ import { import { getEntOptions } from "@/internal/products/prices/priceUtils.js"; import { performDeductionOnCusEnt } from "@/trigger/updateBalanceTask.js"; import { notNullish, nullish } from "@/utils/genUtils.js"; +import { isOneOff } from "../../../../products/productUtils.js"; import { getRelatedCusPrice, getUnlimitedAndUsageAllowed, @@ -161,6 +162,7 @@ export const getExistingUsages = ({ export const addExistingUsagesToCusEnts = ({ cusEnts, entitlements, + prices, curCusProduct, carryExistingUsages = false, printLogs = false, @@ -170,6 +172,7 @@ export const addExistingUsagesToCusEnts = ({ }: { cusEnts: CustomerEntitlement[]; entitlements: EntitlementWithFeature[]; + prices: Price[]; curCusProduct: FullCusProduct; carryExistingUsages?: boolean; printLogs?: boolean; @@ -177,9 +180,7 @@ export const addExistingUsagesToCusEnts = ({ entities: Entity[]; features: Feature[]; }) => { - if (isDowngrade) { - return cusEnts; - } + if (isDowngrade || isOneOff(prices)) return cusEnts; const existingUsages = getExistingUsages({ curCusProduct, diff --git a/server/src/internal/customers/cusProducts/insertCusProduct/initCusEnt/initNextResetAt.ts b/server/src/internal/customers/cusProducts/insertCusProduct/initCusEnt/initNextResetAt.ts index 231553887..4388f87a9 100644 --- a/server/src/internal/customers/cusProducts/insertCusProduct/initCusEnt/initNextResetAt.ts +++ b/server/src/internal/customers/cusProducts/insertCusProduct/initCusEnt/initNextResetAt.ts @@ -63,13 +63,6 @@ export const initNextResetAt = ({ entitlement.interval_count || 1, ).getTime(); - // console.log(`--------------------------------`); - // console.log(`Interval: `, entitlement.interval); - // console.log(`Interval count: `, entitlement.interval_count); - // console.log(`Now: `, formatUnixToDateTime(now)); - // console.log(`Next reset at: `, formatUnixToDateTime(nextResetAtCalculated)); - // console.log(`Anchor to unix: `, formatUnixToDateTime(anchorToUnix)); - // If anchorToUnix, align next reset at to anchorToUnix... if ( anchorToUnix && diff --git a/server/src/internal/customers/cusUtils/apiCusCacheUtils/getCachedApiCustomer.ts b/server/src/internal/customers/cusUtils/apiCusCacheUtils/getCachedApiCustomer.ts index e62b7372d..35cab4c31 100644 --- a/server/src/internal/customers/cusUtils/apiCusCacheUtils/getCachedApiCustomer.ts +++ b/server/src/internal/customers/cusUtils/apiCusCacheUtils/getCachedApiCustomer.ts @@ -38,17 +38,15 @@ export const buildCachedApiCustomerKey = ({ export const getCachedApiCustomer = async ({ ctx, customerId, - skipCache = false, skipEntityMerge = false, source, }: { ctx: AutumnContext; customerId: string; - skipCache?: boolean; skipEntityMerge?: boolean; // If true, returns only customer's own features (no entity merging) source?: string; }): Promise<{ apiCustomer: ApiCustomer; legacyData: CustomerLegacyData }> => { - const { org, env, db } = ctx; + const { org, env, db, skipCache } = ctx; const getExpandedApiCustomer = async () => { // await redis.del( diff --git a/server/src/internal/customers/cusUtils/apiCusUtils/getApiBalance/getApiBalance.ts b/server/src/internal/customers/cusUtils/apiCusUtils/getApiBalance/getApiBalance.ts index 4adc792f2..9feca6894 100644 --- a/server/src/internal/customers/cusUtils/apiCusUtils/getApiBalance/getApiBalance.ts +++ b/server/src/internal/customers/cusUtils/apiCusUtils/getApiBalance/getApiBalance.ts @@ -166,12 +166,12 @@ export const getApiBalance = ({ }), ); - const totalUnused = sumValues( - cusEnts.map((cusEnt) => { - const { unused } = getCusEntBalance({ cusEnt, entityId }); - return unused; - }), - ); + // const totalUnused = sumValues( + // cusEnts.map((cusEnt) => { + // const { unused } = getCusEntBalance({ cusEnt, entityId }); + // return unused; + // }), + // ); const totalAdditionalBalance = sumValues( cusEnts.map((cusEnt) => { @@ -183,25 +183,6 @@ export const getApiBalance = ({ const totalMaxPurchase = sumValues( cusEnts.map((cusEnt) => cusEntToMaxPurchase({ cusEnt })), ); - // const totalUsageLimit = sumValues( - // cusEnts.map((cusEnt) => cusEntToUsageLimit({ cusEnt, entityId })), - // ); - - // const totalIncludedUsage = sumValues( - // cusEnts.map((cusEnt) => cusEntToIncludedUsage({ cusEnt, entityId })), - // ); - - // const totalIncludedUsageWithRollovers = sumValues( - // cusEnts.map((cusEnt) => - // cusEntToIncludedUsage({ cusEnt, entityId, withRollovers: true }), - // ), - // ); - - // const totalUsage = new Decimal(totalIncludedUsageWithRollovers) - // .add(totalAdjustment) - // .sub(totalBalanceWithRollovers) - // .sub(totalUnused) - // .toNumber(); // 1. Granted balance const totalGrantedBalanceWithRollovers = sumValues( @@ -257,10 +238,6 @@ export const getApiBalance = ({ const reset = cusEntsToReset({ cusEnts, feature }); const rollovers = cusEntsToRollovers({ cusEnts, entityId }); - // console.log( - // `Feature: ${feature.id}, Total Max Purchase: ${totalMaxPurchase}, Usage Allowed: ${usageAllowed}`, - // ); - const { data: apiBalance, error } = ApiBalanceSchema.safeParse({ feature: ctx.expand.includes(CusExpand.BalanceFeature) ? apiFeature diff --git a/server/src/internal/customers/handlers/handleUpdateEntitlement.ts b/server/src/internal/customers/handlers/handleUpdateEntitlement.ts index c6d1277e2..077fce9d6 100644 --- a/server/src/internal/customers/handlers/handleUpdateEntitlement.ts +++ b/server/src/internal/customers/handlers/handleUpdateEntitlement.ts @@ -82,13 +82,13 @@ export const handleUpdateEntitlement = async (req: any, res: any) => { env: req.env, }); - if (balance < 0 && !cusEnt.usage_allowed) { - throw new RecaseError({ - message: "Entitlement does not allow usage", - code: ErrCode.InvalidRequest, - statusCode: StatusCodes.BAD_REQUEST, - }); - } + // if (balance < 0 && !cusEnt.usage_allowed) { + // throw new RecaseError({ + // message: "Entitlement does not allow usage", + // code: ErrCode.InvalidRequest, + // statusCode: StatusCodes.BAD_REQUEST, + // }); + // } if (cusEnt.unlimited) { throw new RecaseError({ @@ -115,7 +115,7 @@ export const handleUpdateEntitlement = async (req: any, res: any) => { }, toDeduct: deducted, addAdjustment: true, - allowNegativeBalance: cusEnt.usage_allowed || false, + allowNegativeBalance: true, entityId: entity_id, }, ); diff --git a/server/src/internal/features/handlers/handleUpdateFeature/handleFeatureTypeChanged.ts b/server/src/internal/features/handlers/handleUpdateFeature/handleFeatureTypeChanged.ts index 98c53c381..3dc9595d6 100644 --- a/server/src/internal/features/handlers/handleUpdateFeature/handleFeatureTypeChanged.ts +++ b/server/src/internal/features/handlers/handleUpdateFeature/handleFeatureTypeChanged.ts @@ -24,6 +24,18 @@ export const handleFeatureTypeChanged = async ({ const { linkedEntitlements, entitlements, prices, creditSystems, cusEnts } = objectsUsingFeature; + // Cannot switch between credit system <-> metered / boolean + if ( + (feature.type === FeatureType.CreditSystem && + newType !== FeatureType.CreditSystem) || + (feature.type !== FeatureType.CreditSystem && + newType === FeatureType.CreditSystem) + ) { + throw new RecaseError({ + message: `Cannot change type of feature ${feature.id} from ${feature.type} to ${newType}`, + }); + } + if (cusEnts.length > 0) { throw new RecaseError({ message: `Cannot change type of feature ${feature.id} because it has been attached to a customer before`, diff --git a/server/src/internal/invoices/InvoiceService.ts b/server/src/internal/invoices/InvoiceService.ts index 9a71bb609..bbb1b0d46 100644 --- a/server/src/internal/invoices/InvoiceService.ts +++ b/server/src/internal/invoices/InvoiceService.ts @@ -60,11 +60,17 @@ export class InvoiceService { with: { customer: { with: { - org: true, + org: { + with: { + master: true, + }, + }, }, }, }, - })) as Invoice & { customer: Customer & { org: Organization } }; + })) as Invoice & { + customer: Customer & { org: Organization & { master: Organization } }; + }; } static async list({ diff --git a/server/src/internal/invoices/invoiceMemoUtils.ts b/server/src/internal/invoices/invoiceMemoUtils.ts index ce92eb449..952615d9a 100644 --- a/server/src/internal/invoices/invoiceMemoUtils.ts +++ b/server/src/internal/invoices/invoiceMemoUtils.ts @@ -2,12 +2,13 @@ import { type EntitlementWithFeature, type Feature, type FullProduct, + getProductItemDisplay, type Organization, type Price, } from "@autumn/shared"; import { mapToProductItems } from "@/internal/products/productV2Utils.js"; import { isFeatureItem } from "../products/product-items/productItemUtils/getItemType.js"; -import { getProductItemDisplay } from "../products/productUtils/productResponseUtils/getProductItemDisplay.js"; +// import { getProductItemDisplay } from "../products/productUtils/productResponseUtils/getProductItemDisplay.js"; export const buildInvoiceMemo = async ({ org, diff --git a/server/src/internal/mainRouter.ts b/server/src/internal/mainRouter.ts index a702901c0..426a68793 100644 --- a/server/src/internal/mainRouter.ts +++ b/server/src/internal/mainRouter.ts @@ -63,10 +63,12 @@ mainRouter.use( try { const org = invoice.customer.org; const env = invoice.customer.env; + const stripeCli = createStripeCli({ org, env, }); + const stripeInvoice = await stripeCli.invoices.retrieve( invoice.stripe_id, ); diff --git a/server/src/internal/products/prices/priceUtils/arrearProratedUtils/getContUsageDowngradeItem.ts b/server/src/internal/products/prices/priceUtils/arrearProratedUtils/getContUsageDowngradeItem.ts index 97b6cbd6a..defb0d727 100644 --- a/server/src/internal/products/prices/priceUtils/arrearProratedUtils/getContUsageDowngradeItem.ts +++ b/server/src/internal/products/prices/priceUtils/arrearProratedUtils/getContUsageDowngradeItem.ts @@ -22,16 +22,12 @@ export const getReplaceables = ({ } const numReplaceables = prevOverage - newOverage; - const newReplaceables = Array.from( - { length: numReplaceables }, - (_, i) => - ({ - id: generateId("rep"), - cus_ent_id: cusEnt.id, - created_at: Date.now(), - delete_next_cycle: deleteNextCycle, - }) satisfies InsertReplaceable, - ); + const newReplaceables = Array.from({ length: numReplaceables }, (_, i) => ({ + id: generateId("rep"), + cus_ent_id: cusEnt.id, + created_at: Date.now(), + delete_next_cycle: deleteNextCycle, + })); return newReplaceables; }; diff --git a/server/src/internal/products/prices/priceUtils/prorationConfigUtils.ts b/server/src/internal/products/prices/priceUtils/prorationConfigUtils.ts index 872e32590..7b458f31b 100644 --- a/server/src/internal/products/prices/priceUtils/prorationConfigUtils.ts +++ b/server/src/internal/products/prices/priceUtils/prorationConfigUtils.ts @@ -16,6 +16,26 @@ export const shouldBillNow = (onIncrease: OnIncrease | OnDecrease) => { ); }; +export const shouldProrateDowngradeNow = ({ + onIncrease, + onDecrease, +}: { + onIncrease: OnIncrease; + onDecrease: OnDecrease; +}) => { + if ( + onDecrease === OnDecrease.NoProrations || + onDecrease === OnDecrease.None + ) { + return false; + } + + return ( + onIncrease === OnIncrease.ProrateImmediately || + onIncrease === OnIncrease.BillImmediately + ); +}; + export const shouldProrate = (onIncrease?: OnIncrease | OnDecrease) => { if (!onIncrease) { return true; diff --git a/server/src/internal/products/product-items/productItemUtils/itemToPriceAndEnt.ts b/server/src/internal/products/product-items/productItemUtils/itemToPriceAndEnt.ts index def09f496..9759ae126 100644 --- a/server/src/internal/products/product-items/productItemUtils/itemToPriceAndEnt.ts +++ b/server/src/internal/products/product-items/productItemUtils/itemToPriceAndEnt.ts @@ -256,7 +256,8 @@ export const toFeatureAndPrice = ({ if (shouldProrate(onDecrease) || onDecrease === OnDecrease.Prorate) { onDecrease = - onIncrease === OnIncrease.ProrateImmediately + onIncrease === OnIncrease.ProrateImmediately || + onIncrease === OnIncrease.BillImmediately ? OnDecrease.ProrateImmediately : OnDecrease.ProrateNextCycle; } diff --git a/server/src/internal/saved-views/ViewsService.ts b/server/src/internal/saved-views/ViewsService.ts index c0158eec4..dbf1d20dd 100644 --- a/server/src/internal/saved-views/ViewsService.ts +++ b/server/src/internal/saved-views/ViewsService.ts @@ -1,5 +1,5 @@ import { ErrCode } from "@autumn/shared"; -import { type Response } from "express"; +import type { Response } from "express"; import { nanoid } from "nanoid"; import { CacheManager } from "@/utils/cacheUtils/CacheManager.js"; import RecaseError from "@/utils/errorUtils.js"; diff --git a/server/src/queue/bullmq/initBullMqWorkers.ts b/server/src/queue/bullmq/initBullMqWorkers.ts index bae9a97f7..59fa91262 100644 --- a/server/src/queue/bullmq/initBullMqWorkers.ts +++ b/server/src/queue/bullmq/initBullMqWorkers.ts @@ -74,10 +74,9 @@ const initWorker = ({ id, db }: { id: number; db: DrizzleCli }) => { if (actionHandlers.includes(job.name as JobName)) { await runActionHandlerTask({ - queue: queue, - job, - logger: workerLogger, - db, + jobName: job.name as JobName, + payload: job.data, + ctx, }); return; } diff --git a/server/src/trigger/adjustAllowance.ts b/server/src/trigger/adjustAllowance.ts index 7b67974df..aabaaed54 100644 --- a/server/src/trigger/adjustAllowance.ts +++ b/server/src/trigger/adjustAllowance.ts @@ -17,10 +17,10 @@ import type Stripe from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { createStripeCli } from "@/external/connect/createStripeCli.js"; import { findStripeItemForPrice } from "@/external/stripe/stripeSubUtils/stripeSubItemUtils.js"; -import { getUsageBasedSub } from "@/external/stripe/stripeSubUtils.js"; import { getRelatedCusPrice } from "@/internal/customers/cusProducts/cusEnts/cusEntUtils.js"; import { getBillingType } from "@/internal/products/prices/priceUtils.js"; import RecaseError from "@/utils/errorUtils.js"; +import { cusProductToSub } from "../internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; import { handleProratedDowngrade } from "./arrearProratedUsage/handleProratedDowngrade.js"; import { handleProratedUpgrade } from "./arrearProratedUsage/handleProratedUpgrade.js"; @@ -115,13 +115,18 @@ export const adjustAllowance = async ({ logger.info(`Customer: ${customer.name}, Org: ${org.slug}`); const stripeCli = createStripeCli({ org, env }); - const sub = await getUsageBasedSub({ - db, + const sub = await cusProductToSub({ + cusProduct, stripeCli, - subIds: cusProduct.subscription_ids!, - feature: affectedFeature, }); + // const sub = await getUsageBasedSub({ + // db, + // stripeCli, + // subIds: cusProduct.subscription_ids!, + // feature: affectedFeature, + // }); + if (!sub) { logger.error("adjustAllowance: no usage-based sub found"); return { newReplaceables: null, invoice: null, deletedReplaceables: null }; diff --git a/server/src/trigger/arrearProratedUsage/handleProratedDowngrade.ts b/server/src/trigger/arrearProratedUsage/handleProratedDowngrade.ts index dbe8b3236..05253cfe1 100644 --- a/server/src/trigger/arrearProratedUsage/handleProratedDowngrade.ts +++ b/server/src/trigger/arrearProratedUsage/handleProratedDowngrade.ts @@ -5,6 +5,7 @@ import { getFeatureInvoiceDescription, type InsertReplaceable, OnDecrease, + OnIncrease, type Organization, type Product, type UsagePriceConfig, @@ -21,12 +22,12 @@ import { priceToInvoiceAmount } from "@/internal/products/prices/priceUtils/pric import { shouldBillNow, shouldProrate, + shouldProrateDowngradeNow, } from "@/internal/products/prices/priceUtils/prorationConfigUtils.js"; import { roundUsage } from "@/internal/products/prices/priceUtils/usagePriceUtils/classifyUsagePrice.js"; import { formatUnixToDate } from "@/utils/genUtils.js"; import { getStripeNow } from "@/utils/scriptUtils/testClockUtils.js"; import { getUsageFromBalance } from "../adjustAllowance.js"; - export const createDowngradeProrationInvoice = async ({ org, cusPrice, @@ -38,6 +39,7 @@ export const createDowngradeProrationInvoice = async ({ newRoundedUsage, feature, product, + onIncrease, onDecrease, logger, }: { @@ -51,6 +53,7 @@ export const createDowngradeProrationInvoice = async ({ newRoundedUsage: number; feature: Feature; product: Product; + onIncrease: OnIncrease; onDecrease: OnDecrease; logger: any; }) => { @@ -102,7 +105,12 @@ export const createDowngradeProrationInvoice = async ({ await stripeCli.invoiceItems.create(invoiceItem); let invoice = null; - if (shouldBillNow(onDecrease)) { + if ( + shouldProrateDowngradeNow({ + onIncrease, + onDecrease, + }) + ) { const { invoice: finalInvoice } = await createAndFinalizeInvoice({ stripeCli, paymentMethod: null, @@ -196,6 +204,9 @@ export const handleProratedDowngrade = async ({ }), feature, product, + onIncrease: + cusPrice.price.proration_config?.on_increase || + OnIncrease.ProrateImmediately, onDecrease, logger, }); diff --git a/server/src/utils/auth.ts b/server/src/utils/auth.ts index f4dd8ee1f..dd54b0f3d 100644 --- a/server/src/utils/auth.ts +++ b/server/src/utils/auth.ts @@ -1,9 +1,14 @@ import "dotenv/config"; import { invitation } from "@autumn/shared"; -import { betterAuth } from "better-auth"; +import { betterAuth, type User } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; -import { admin, emailOTP, organization } from "better-auth/plugins"; +import { + admin, + emailOTP, + type Organization, + organization, +} from "better-auth/plugins"; import { eq } from "drizzle-orm"; import { db } from "@/db/initDrizzle.js"; import { logger } from "@/external/logtail/logtailUtils.js"; @@ -104,7 +109,11 @@ export const auth = betterAuth({ }), organization({ - async sendInvitationEmail(data) { + async sendInvitationEmail(data: { + id: string; + email: string; + organization: Organization; + }) { const inviteLink = `${process.env.CLIENT_URL}/accept?id=${data.id}`; await sendInvitationEmail({ email: data.email, @@ -135,7 +144,13 @@ export const auth = betterAuth({ organizationCreation: { disabled: false, - afterCreate: async ({ organization, user }) => { + afterCreate: async ({ + organization, + user, + }: { + organization: Organization; + user: User; + }) => { await afterOrgCreated({ org: organization, user }); }, }, diff --git a/server/src/utils/scriptUtils/testUtils/initProductsV0.ts b/server/src/utils/scriptUtils/testUtils/initProductsV0.ts index 14c37f54f..2d07507f9 100644 --- a/server/src/utils/scriptUtils/testUtils/initProductsV0.ts +++ b/server/src/utils/scriptUtils/testUtils/initProductsV0.ts @@ -1,7 +1,7 @@ import { ApiVersion, type ProductV2 } from "@autumn/shared"; -import { addPrefixToProducts } from "tests/attach/utils.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import type { TestContext } from "tests/utils/testInitUtils/createTestContext.js"; +import { createProducts } from "@tests/utils/productUtils.js"; +import type { TestContext } from "@tests/utils/testInitUtils/createTestContext.js"; +import { addPrefixToProducts } from "@tests/utils/testProductUtils/testProductUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; export const initProductsV0 = async ({ diff --git a/server/tests/00_setup.ts b/server/tests/00_setup.ts index 1f703781f..7d30961e5 100644 --- a/server/tests/00_setup.ts +++ b/server/tests/00_setup.ts @@ -3,7 +3,7 @@ import dotenv from "dotenv"; dotenv.config(); import { AppEnv } from "@autumn/shared"; -import { clearOrg, setupOrg } from "tests/utils/setup.js"; +import { clearOrg, setupOrg } from "@tests/utils/setup.js"; import { initDrizzle } from "@/db/initDrizzle.js"; import { advanceProducts, @@ -33,16 +33,6 @@ describe("Initialize org for tests", () => { await setupOrg({ orgId: this.org.id, env: DEFAULT_ENV, - features: { ...features, ...creditSystems } as any, - products: { - ...products, - ...advanceProducts, - ...attachProducts, - ...oneTimeProducts, - ...entityProducts, - } as any, - rewards: { ...rewards } as any, - rewardTriggers: { ...referralPrograms } as any, }); console.log("--------------------------------"); diff --git a/server/tests/_temp/temp.test.ts b/server/tests/_temp/temp.test.ts index 9306afbb7..d22958334 100644 --- a/server/tests/_temp/temp.test.ts +++ b/server/tests/_temp/temp.test.ts @@ -1,13 +1,13 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, - type CheckResponse, type CheckResponseV0, + type CheckResponseV1, SuccessCode, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; @@ -44,7 +44,7 @@ describe(`${chalk.yellowBright("temp: temporary script for testing")}`, () => { const res = (await autumnV1.check({ customer_id: customerId, feature_id: TestFeature.Messages, - })) as unknown as CheckResponse; + })) as unknown as CheckResponseV1; expect(res).toStrictEqual({ allowed: false, diff --git a/server/tests/_temp/temp1.test.ts b/server/tests/_temp/temp1.test.ts new file mode 100644 index 000000000..1d608e350 --- /dev/null +++ b/server/tests/_temp/temp1.test.ts @@ -0,0 +1,118 @@ +import { beforeAll, describe, test } from "bun:test"; +import { + type AppEnv, + LegacyVersion, + OnDecrease, + OnIncrease, + type Organization, +} from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import { AutumnInt } from "@/external/autumn/autumnCli.js"; +import { + constructArrearProratedItem, + constructFeatureItem, +} from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; + +// UNCOMMENT FROM HERE +const addOn = constructProduct({ + type: "pro", + isAddOn: true, + items: [ + // constructFeatureItem({ featureId: TestFeature.Words, includedUsage: 100 }), + constructArrearProratedItem({ + featureId: TestFeature.Users, + includedUsage: 1, + pricePerUnit: 10, + config: { + on_increase: OnIncrease.BillImmediately, + on_decrease: OnDecrease.Prorate, + }, + }), + ], +}); + +describe(`${chalk.yellowBright("temp1: Testing add ons")}`, () => { + const customerId = "temp1"; + const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); + + let stripeCli: Stripe; + let testClockId: string; + let curUnix: number; + let db: DrizzleCli; + let org: Organization; + let env: AppEnv; + + beforeAll(async () => { + db = ctx.db; + org = ctx.org; + env = ctx.env; + stripeCli = ctx.stripeCli; + + const { testClockId: testClockId1 } = await initCustomerV3({ + ctx, + customerId, + customerData: {}, + attachPm: "success", + withTestClock: true, + }); + + await initProductsV0({ + ctx, + products: [addOn], + prefix: customerId, + }); + + testClockId = testClockId1!; + }); + + test("should attach pro product", async () => { + await autumn.attach({ + customer_id: customerId, + product_id: addOn.id, + }); + + await autumn.entities.create(customerId, [ + { + id: "1", + name: "Entity 1", + feature_id: TestFeature.Users, + }, + { + id: "2", + name: "Entity 2", + feature_id: TestFeature.Users, + }, + ]); + + await autumn.entities.delete(customerId, "1"); + // await autumn.attach({ + // customer_id: customerId, + // product_id: addOn.id, + // }); + // await autumn.attach({ + // customer_id: customerId, + // product_id: addOn.id, + // }); + }); + + // test("should cancel one add on", async () => { + // await autumn.cancel({ + // customer_id: customerId, + // product_id: addOn.id, + // }); + + // await expectSubToBeCorrect({ + // customerId, + // db, + // org, + // env, + // }); + // }); +}); diff --git a/server/tests/advanced/coupons/coupon1.backup.ts b/server/tests/advanced/coupons/coupon1.backup.ts deleted file mode 100644 index 2e97e1924..000000000 --- a/server/tests/advanced/coupons/coupon1.backup.ts +++ /dev/null @@ -1,234 +0,0 @@ -import { - type AppEnv, - type Customer, - 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 { rewards } from "tests/global.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { - advanceTestClock, - completeCheckoutForm, - getDiscount, -} from "tests/utils/stripeUtils.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; -import type { DrizzleCli } from "@/db/initDrizzle.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { getOriginalCouponId } from "@/internal/rewards/rewardUtils.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; - -const testCase = "coupon1"; - -const pro = constructProduct({ - type: "pro", - items: [constructArrearItem({ featureId: TestFeature.Words })], -}); - -const simulateOneCycle = async ({ - customerId, - db, - org, - env, - stripeCli, - autumn, - testClockId, - couponAmount, - curUnix, -}: { - customerId: string; - db: DrizzleCli; - org: Organization; - env: AppEnv; - stripeCli: Stripe; - autumn: AutumnInt; - testClockId: string; - couponAmount: number; - curUnix: number; -}) => { - const usage = Math.random() * 100000 + 10000; - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Words, - value: usage, - }); - - // Expected invoice total - const expectedTotal = await getExpectedInvoiceTotal({ - usage: [{ featureId: TestFeature.Words, value: usage }], - customerId, - productId: pro.id, - db, - org, - env, - stripeCli, - }); - - couponAmount -= expectedTotal; - - curUnix = await advanceTestClock({ - stripeCli, - testClockId, - advanceTo: addHours( - addMonths(curUnix, 1), - hoursToFinalizeInvoice, - ).getTime(), - waitForSeconds: 30, - }); - - const customer = await autumn.customers.get(customerId); - expect(customer.invoices![0].total).to.equal(0); - - const cusDiscount = await getDiscount({ - stripeCli: stripeCli, - stripeId: customer.stripe_id!, - }); - - expect(cusDiscount).to.exist; - - expect(getOriginalCouponId(cusDiscount.coupon?.id)).to.equal( - rewards.rolloverAll.id, - ); - - expect(cusDiscount.coupon?.amount_off).to.equal( - Math.round(couponAmount * 100), - `Expected stripe cus to have coupon amount ${couponAmount * 100}`, - ); - - return { - couponAmount, - curUnix, - }; -}; - -describe( - chalk.yellow( - `${testCase} - Testing invoice credits reward, apply to all product`, - ), - () => { - const customerId = "coupon1"; - let stripeCli: Stripe; - let customer: Customer; - let testClockId: string; - let db: DrizzleCli; - let org: Organization; - let env: AppEnv; - - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - - let couponAmount = rewards.rolloverAll.discount_config.discount_value; - let curUnix = new Date().getTime(); - - before(async function () { - await setupBefore(this); - db = this.db; - org = this.org; - env = this.env; - stripeCli = this.stripeCli; - - const res = await initCustomer({ - customerId, - org, - env, - db, - autumn: this.autumnJs, - }); - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - products: [pro], - orgId: org.id, - env, - db, - autumn, - }); - - testClockId = res.testClockId; - customer = res.customer; - }); - - // CYCLE 0 - it("should attach pro", async () => { - const res = await autumn.attach({ - customer_id: customerId, - product_id: pro.id, - }); - - await completeCheckoutForm( - res.checkout_url, - undefined, - rewards.rolloverAll.id, - ); - - await timeout(10000); - - couponAmount -= getBasePrice({ product: pro }); - - const customer = await autumn.customers.get(customerId); - expectProductAttached({ customer, product: pro }); - - expect(customer.invoices![0].total).to.equal(0); - - const cusDiscount = await getDiscount({ - stripeCli, - stripeId: customer.stripe_id!, - }); - - expect(cusDiscount).to.exist; - expect(getOriginalCouponId(cusDiscount.coupon?.id)).to.equal( - rewards.rolloverAll.id, - ); - expect(cusDiscount.coupon?.amount_off).to.equal(couponAmount * 100); - }); - - it("should run one cycle and have correct invoice + coupon amount", async () => { - const res = await simulateOneCycle({ - customerId, - db, - org, - env, - stripeCli, - autumn, - testClockId, - couponAmount, - curUnix: new Date().getTime(), - }); - - couponAmount = res.couponAmount; - curUnix = res.curUnix; - }); - - // CYCLE 1 - it("should run another cycle and have correct invoice + coupon amount", async () => { - const res = await simulateOneCycle({ - customerId, - db, - org, - env, - stripeCli, - autumn, - testClockId, - couponAmount, - curUnix, - }); - }); - }, -); diff --git a/server/tests/advanced/coupons/coupon1.test.ts b/server/tests/advanced/coupons/coupon1.test.ts index 0d3e760c7..23a293bb0 100644 --- a/server/tests/advanced/coupons/coupon1.test.ts +++ b/server/tests/advanced/coupons/coupon1.test.ts @@ -7,22 +7,22 @@ import { type Organization, RewardType, } from "@autumn/shared"; -import chalk from "chalk"; -import { addHours, addMonths } from "date-fns"; -import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { createReward } from "tests/utils/productUtils.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { createReward } from "@tests/utils/productUtils.js"; import { advanceTestClock, completeCheckoutForm, getDiscount, -} from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import { addHours, addMonths } from "date-fns"; +import type Stripe from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { getOriginalCouponId } from "@/internal/rewards/rewardUtils.js"; diff --git a/server/tests/advanced/coupons/coupon2.backup.ts b/server/tests/advanced/coupons/coupon2.backup.ts deleted file mode 100644 index cadd28dd8..000000000 --- a/server/tests/advanced/coupons/coupon2.backup.ts +++ /dev/null @@ -1,197 +0,0 @@ -import { - type AppEnv, - CouponDurationType, - type CreateReward, - LegacyVersion, - type Organization, - RewardType, -} from "@autumn/shared"; -import { expect } from "chai"; -import chalk from "chalk"; -import { addHours, addMonths } from "date-fns"; -import { Decimal } from "decimal.js"; -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 { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { createProducts, createReward } from "tests/utils/productUtils.js"; -import { completeCheckoutForm, getDiscount } from "tests/utils/stripeUtils.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; -import type { DrizzleCli } from "@/db/initDrizzle.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { getOriginalCouponId } from "@/internal/rewards/rewardUtils.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"; - -const pro = constructProduct({ - type: "pro", - items: [constructArrearItem({ featureId: TestFeature.Words })], -}); - -const testCase = "coupon2"; - -// Create reward input -const reward: CreateReward = { - id: "usage", - name: "usage", - promo_codes: [{ code: "usage" }], - type: RewardType.InvoiceCredits, - discount_config: { - discount_value: 10000, - duration_type: CouponDurationType.Forever, - duration_value: 1, - should_rollover: true, - apply_to_all: false, - price_ids: [], - }, -}; - -describe( - chalk.yellow(`${testCase} - Testing one-off rollover, apply to usage only`), - () => { - const customerId = testCase; - let stripeCli: Stripe; - let testClockId: string; - - 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 ?? 0; - - before(async function () { - await setupBefore(this); - - org = this.org; - env = this.env; - db = this.db; - stripeCli = this.stripeCli; - - const { testClockId: testClockId1 } = await initCustomer({ - customerId, - org: this.org, - env: this.env, - db: this.db, - autumn: this.autumnJs, - }); - - testClockId = testClockId1; - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - orgId: this.org.id, - env: this.env, - db: this.db, - autumn, - products: [pro], - }); - - await createReward({ - orgId: org.id, - env, - db, - autumn, - reward, - productId: pro.id, - onlyUsage: true, - }); - }); - - // CYCLE 0 - it("should attach pro with promo code", async () => { - const res = await autumn.attach({ - customer_id: customerId, - product_id: pro.id, - }); - - await completeCheckoutForm(res.checkout_url, undefined, reward.id); - - await timeout(10000); - - const customer = await autumn.customers.get(customerId); - expectProductAttached({ - customer, - product: pro, - }); - }); - - it("should have fixed price invoice and correct remaining coupon amount", async () => { - const customer = await autumn.customers.get(customerId); - const fixedPrice = getBasePrice({ product: pro }); - expect(customer.invoices![0].total).to.equal(fixedPrice); - - const cusDiscount = await getDiscount({ - stripeCli, - stripeId: customer.stripe_id!, - }); - - expect(getOriginalCouponId(cusDiscount.coupon?.id)).to.equal(reward.id); - expect(cusDiscount.coupon?.amount_off).to.equal(couponAmount * 100); - }); - - // CYCLE 1 - it("should track usage and have correct invoice amount", async () => { - const usage = new Decimal(Math.random() * 1250120 + 10000) - .toDecimalPlaces(2) - .toNumber(); - - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Words, - value: usage, - }); - - const usageTotal = await getExpectedInvoiceTotal({ - org, - env, - db, - customerId, - productId: pro.id, - usage: [{ featureId: TestFeature.Words, value: usage }], - stripeCli, - onlyIncludeUsage: true, - }); - - const basePrice = getBasePrice({ product: pro }); - - couponAmount = couponAmount - usageTotal; - - await advanceTestClock({ - stripeCli, - testClockId, - advanceTo: addHours( - addMonths(new Date(), 1), - hoursToFinalizeInvoice, - ).getTime(), - waitForSeconds: 20, - }); - - const customer = await autumn.customers.get(customerId); - expect(customer.invoices![0].total).to.equal(basePrice); - - const cusDiscount = await getDiscount({ - stripeCli, - stripeId: customer.stripe_id!, - }); - - expect(getOriginalCouponId(cusDiscount.coupon?.id)).to.equal(reward.id); - - expect(cusDiscount.coupon?.amount_off).to.equal( - Math.round(couponAmount * 100), - ); - }); - }, -); diff --git a/server/tests/advanced/coupons/coupon2.test.ts b/server/tests/advanced/coupons/coupon2.test.ts index 14b0678db..3fd238800 100644 --- a/server/tests/advanced/coupons/coupon2.test.ts +++ b/server/tests/advanced/coupons/coupon2.test.ts @@ -11,18 +11,18 @@ import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import { Decimal } from "decimal.js"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { createProducts, createReward } from "tests/utils/productUtils.js"; -import { completeCheckoutForm, getDiscount } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { createProducts, createReward } from "@tests/utils/productUtils.js"; +import { completeCheckoutForm, getDiscount } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { addPrefixToProducts, getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/testProductUtils/testProductUtils.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { getOriginalCouponId } from "@/internal/rewards/rewardUtils.js"; diff --git a/server/tests/advanced/coupons/coupon3.backup.ts b/server/tests/advanced/coupons/coupon3.backup.ts deleted file mode 100644 index ce9c002c5..000000000 --- a/server/tests/advanced/coupons/coupon3.backup.ts +++ /dev/null @@ -1,176 +0,0 @@ -import { - type AppEnv, - CouponDurationType, - type CreateReward, - LegacyVersion, - type Organization, - RewardType, -} 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 { 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 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", - items: [constructArrearItem({ featureId: TestFeature.Words })], -}); - -const oneOff = constructProduct({ - type: "one_off", - items: [ - constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 500, - }), - ], -}); - -// Create reward input -const rewardId = "attach_coupon"; -const promoCode = "attach_coupon_code"; -const reward: CreateReward = { - id: rewardId, - name: "attach_coupon", - promo_codes: [{ code: promoCode }], - type: RewardType.FixedDiscount, - discount_config: { - discount_value: 5, - duration_type: CouponDurationType.OneOff, - duration_value: 1, - should_rollover: true, - apply_to_all: true, - price_ids: [], - }, -}; - -const testCase = "coupon3"; -describe(chalk.yellow(`${testCase} - Testing attach coupon`), () => { - const customerId = testCase; - let stripeCli: Stripe; - let testClockId: string; - - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - let org: Organization; - let env: AppEnv; - let db: DrizzleCli; - - const couponAmount = reward.discount_config!.discount_value; - - before(async function () { - await setupBefore(this); - - org = this.org; - env = this.env; - db = this.db; - stripeCli = this.stripeCli; - - const { testClockId: testClockId1 } = await initCustomer({ - customerId, - org: this.org, - env: this.env, - db: this.db, - autumn: this.autumnJs, - attachPm: "success", - }); - - testClockId = testClockId1; - - addPrefixToProducts({ - products: [pro, oneOff], - prefix: testCase, - }); - - await createProducts({ - orgId: this.org.id, - env: this.env, - db: this.db, - autumn, - products: [pro, oneOff], - }); - - await createReward({ - orgId: org.id, - env, - db, - autumn, - reward, - productId: pro.id, - }); - }); - - // CYCLE 0 - it("should attach pro with reward ID", async () => { - const res = await autumn.attach({ - customer_id: customerId, - product_id: pro.id, - reward: rewardId, - }); - - const customer = await autumn.customers.get(customerId); - expectAttachCorrect({ - customer, - product: pro, - }); - - const invoice = customer.invoices![0]; - const basePrice = getBasePrice({ product: pro }); - expect(invoice.total).to.equal(basePrice - couponAmount); - }); - - it("should attach one off with reward ID", async () => { - await autumn.attach({ - customer_id: customerId, - product_id: oneOff.id, - reward: rewardId, - }); - - const customer = await autumn.customers.get(customerId); - expectAttachCorrect({ - customer, - product: oneOff, - }); - - const invoice = customer.invoices![0]; - const basePrice = getBasePrice({ product: oneOff }); - expect(invoice.total).to.equal(basePrice - couponAmount); - expect(invoice.product_ids).to.include(oneOff.id); - }); - - it("should attach one off with promo code", async () => { - await autumn.attach({ - customer_id: customerId, - product_id: oneOff.id, - reward: promoCode, - }); - - const customer = await autumn.customers.get(customerId); - expectAttachCorrect({ - customer, - product: oneOff, - }); - - expect(customer.invoices!.length).to.equal(3); - const basePrice = getBasePrice({ product: oneOff }); - for (let i = 0; i < 2; 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/coupons/coupon3.test.ts b/server/tests/advanced/coupons/coupon3.test.ts index 99711b138..be2b09478 100644 --- a/server/tests/advanced/coupons/coupon3.test.ts +++ b/server/tests/advanced/coupons/coupon3.test.ts @@ -9,14 +9,14 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { createProducts, createReward } from "tests/utils/productUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectAttachCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { createProducts, createReward } from "@tests/utils/productUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { addPrefixToProducts, getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/testProductUtils/testProductUtils.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { diff --git a/server/tests/advanced/customInterval/customInterval1.backup.ts b/server/tests/advanced/customInterval/customInterval1.backup.ts index c864b9417..a053aae4e 100644 --- a/server/tests/advanced/customInterval/customInterval1.backup.ts +++ b/server/tests/advanced/customInterval/customInterval1.backup.ts @@ -3,14 +3,14 @@ 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 { 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 { 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 { 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"; diff --git a/server/tests/advanced/customInterval/customInterval1.test.ts b/server/tests/advanced/customInterval/customInterval1.test.ts index 552c53a5a..1305acc80 100644 --- a/server/tests/advanced/customInterval/customInterval1.test.ts +++ b/server/tests/advanced/customInterval/customInterval1.test.ts @@ -3,11 +3,11 @@ import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } 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"; diff --git a/server/tests/advanced/customInterval/customInterval1.ts b/server/tests/advanced/customInterval/customInterval1.ts index c864b9417..a053aae4e 100644 --- a/server/tests/advanced/customInterval/customInterval1.ts +++ b/server/tests/advanced/customInterval/customInterval1.ts @@ -3,14 +3,14 @@ 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 { 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 { 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 { 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"; diff --git a/server/tests/advanced/customInterval/customInterval2.backup.ts b/server/tests/advanced/customInterval/customInterval2.backup.ts index 9cf54f547..256e0e0d9 100644 --- a/server/tests/advanced/customInterval/customInterval2.backup.ts +++ b/server/tests/advanced/customInterval/customInterval2.backup.ts @@ -3,14 +3,14 @@ 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 { 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 { 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 { 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"; diff --git a/server/tests/advanced/customInterval/customInterval2.test.ts b/server/tests/advanced/customInterval/customInterval2.test.ts index 083102f2b..d4b8c729d 100644 --- a/server/tests/advanced/customInterval/customInterval2.test.ts +++ b/server/tests/advanced/customInterval/customInterval2.test.ts @@ -3,11 +3,11 @@ import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructRawProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/customInterval/customInterval2.ts b/server/tests/advanced/customInterval/customInterval2.ts index 9cf54f547..256e0e0d9 100644 --- a/server/tests/advanced/customInterval/customInterval2.ts +++ b/server/tests/advanced/customInterval/customInterval2.ts @@ -3,14 +3,14 @@ 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 { 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 { 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 { 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"; diff --git a/server/tests/advanced/customInterval/customInterval3.backup.ts b/server/tests/advanced/customInterval/customInterval3.backup.ts index 424ab4ead..bdb9ad2b4 100644 --- a/server/tests/advanced/customInterval/customInterval3.backup.ts +++ b/server/tests/advanced/customInterval/customInterval3.backup.ts @@ -3,13 +3,13 @@ import { expect } from "chai"; import chalk from "chalk"; 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 { 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"; diff --git a/server/tests/advanced/customInterval/customInterval3.test.ts b/server/tests/advanced/customInterval/customInterval3.test.ts index 5a99870f7..a4d7012fb 100644 --- a/server/tests/advanced/customInterval/customInterval3.test.ts +++ b/server/tests/advanced/customInterval/customInterval3.test.ts @@ -3,10 +3,10 @@ import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addDays, addMonths } from "date-fns"; import type 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 ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { calculateProrationAmount } from "@/internal/invoices/prorationUtils.js"; import { diff --git a/server/tests/advanced/customInterval/customInterval3.ts b/server/tests/advanced/customInterval/customInterval3.ts index 424ab4ead..bdb9ad2b4 100644 --- a/server/tests/advanced/customInterval/customInterval3.ts +++ b/server/tests/advanced/customInterval/customInterval3.ts @@ -3,13 +3,13 @@ import { expect } from "chai"; import chalk from "chalk"; 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 { 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"; diff --git a/server/tests/advanced/customInterval/customInterval4.backup.ts b/server/tests/advanced/customInterval/customInterval4.backup.ts index b68f29764..4eb464492 100644 --- a/server/tests/advanced/customInterval/customInterval4.backup.ts +++ b/server/tests/advanced/customInterval/customInterval4.backup.ts @@ -3,16 +3,16 @@ 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 { 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"; +} from "@tests/utils/expectUtils/expectScheduleUtils.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 { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/advanced/customInterval/customInterval4.test.ts b/server/tests/advanced/customInterval/customInterval4.test.ts index 97a1a2dab..a4de915eb 100644 --- a/server/tests/advanced/customInterval/customInterval4.test.ts +++ b/server/tests/advanced/customInterval/customInterval4.test.ts @@ -3,14 +3,14 @@ import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addMonths } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.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 ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/expectUtils/expectScheduleUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } 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"; diff --git a/server/tests/advanced/customInterval/customInterval4.ts b/server/tests/advanced/customInterval/customInterval4.ts index b68f29764..4eb464492 100644 --- a/server/tests/advanced/customInterval/customInterval4.ts +++ b/server/tests/advanced/customInterval/customInterval4.ts @@ -3,16 +3,16 @@ 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 { 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"; +} from "@tests/utils/expectUtils/expectScheduleUtils.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 { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/advanced/customInterval/customInterval5.backup.ts b/server/tests/advanced/customInterval/customInterval5.backup.ts index cca80a257..fdee88bf5 100644 --- a/server/tests/advanced/customInterval/customInterval5.backup.ts +++ b/server/tests/advanced/customInterval/customInterval5.backup.ts @@ -3,11 +3,11 @@ import type { Customer } from "autumn-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 { createProducts } from "tests/utils/productUtils.js"; +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"; diff --git a/server/tests/advanced/customInterval/customInterval5.test.ts b/server/tests/advanced/customInterval/customInterval5.test.ts index 53311f48a..e7d8978ef 100644 --- a/server/tests/advanced/customInterval/customInterval5.test.ts +++ b/server/tests/advanced/customInterval/customInterval5.test.ts @@ -3,9 +3,9 @@ import { LegacyVersion } from "@autumn/shared"; import type { Customer } from "autumn-js"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/advanced/customInterval/customInterval5.ts b/server/tests/advanced/customInterval/customInterval5.ts index cca80a257..fdee88bf5 100644 --- a/server/tests/advanced/customInterval/customInterval5.ts +++ b/server/tests/advanced/customInterval/customInterval5.ts @@ -3,11 +3,11 @@ import type { Customer } from "autumn-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 { createProducts } from "tests/utils/productUtils.js"; +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"; diff --git a/server/tests/advanced/defaultTrial/defaultTrial1.test.ts b/server/tests/advanced/defaultTrial/defaultTrial1.test.ts index 095488ad9..cfbb35fa6 100644 --- a/server/tests/advanced/defaultTrial/defaultTrial1.test.ts +++ b/server/tests/advanced/defaultTrial/defaultTrial1.test.ts @@ -1,23 +1,22 @@ // Manual customer creation - not using initCustomer to control test clock properly +import { beforeAll, describe, it } from "bun:test"; import { - type AppEnv, CusProductStatus, + FreeTrialDuration, LegacyVersion, - type Organization, + ProductItemInterval, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; 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 { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; // Case 1: āœ… // Pro product with default trial exists alongside a free default product @@ -28,35 +27,66 @@ import { // Pro product with default trial exists alone // -> Creating a new customer should attach the pro product with default trial +const defaultTrialPro = constructProduct({ + items: [ + constructFeatureItem({ + featureId: TestFeature.Words, + includedUsage: 1500, + interval: ProductItemInterval.Month, + }), + ], + isDefault: true, + forcePaidDefault: true, + id: "defaultTrial_pro", + group: "defaultTrial", + type: "pro", + freeTrial: { + length: 7, + duration: FreeTrialDuration.Day, + unique_fingerprint: false, + card_required: false, + }, +}); + +const defaultTrialFree = constructProduct({ + items: [ + constructFeatureItem({ + featureId: TestFeature.Words, + includedUsage: 500, + interval: ProductItemInterval.Month, + }), + ], + id: "defaultTrial_free", + group: "defaultTrial", + type: "free", + isDefault: true, +}); + const testCase = "defaultTrial1"; describe(`${chalk.yellowBright(`advanced/${testCase}: ensure default trials are attached when creating a customer`)}`, () => { 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; - const curUnix = Math.floor(new Date().getTime() / 1000); + beforeAll(async () => { + // Products must be initialized BEFORE customer creation for default products + await initProductsV0({ + ctx, + products: [defaultTrialPro, defaultTrialFree], + prefix: testCase, + customerId, + }); - beforeAll(async function () { - await setupBefore(this); - await setupDefaultTrialBefore({}); - const { autumnJs } = this; - stripeCli = this.stripeCli; - db = this.db; - org = this.org; - env = this.env; - - const res = await initCustomerV2({ - autumn: autumnJs, - customerId: testCase, - db, - org, - env, + const res = await initCustomerV3({ + ctx, + customerId, + withTestClock: true, }); testClockID = res.testClockId; + stripeCli = ctx.stripeCli; }); it("should create a customer with the paid default trial", async () => { diff --git a/server/tests/advanced/defaultTrial/defaultTrial2.test.ts b/server/tests/advanced/defaultTrial/defaultTrial2.test.ts index 1ae38d4ef..d3e2968c7 100644 --- a/server/tests/advanced/defaultTrial/defaultTrial2.test.ts +++ b/server/tests/advanced/defaultTrial/defaultTrial2.test.ts @@ -1,59 +1,76 @@ // Manual customer creation - not using initCustomer to control test clock properly +import { beforeAll, describe, it } from "bun:test"; import { - type AppEnv, CusProductStatus, + FreeTrialDuration, LegacyVersion, - type Organization, + ProductItemInterval, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; 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 { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; // 2.2: // -> Creating a new customer with a payment method should attach the pro product with default trial // --> Advancing the test clock should cancel the trial and attach the pro product +const defaultTrialPro = constructProduct({ + items: [ + constructFeatureItem({ + featureId: TestFeature.Words, + includedUsage: 1500, + interval: ProductItemInterval.Month, + }), + ], + isDefault: true, + forcePaidDefault: true, + id: "defaultTrial_pro", + group: "defaultTrial", + type: "pro", + freeTrial: { + length: 7, + duration: FreeTrialDuration.Day, + unique_fingerprint: false, + card_required: false, + }, +}); + const testCase = "defaultTrial2"; describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trial transitions into full product if payment method is valid`)}`, () => { 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; - const curUnix = Math.floor(new Date().getTime() / 1000); + beforeAll(async () => { + // Products must be initialized BEFORE customer creation for default products + await initProductsV0({ + ctx, + products: [defaultTrialPro], + prefix: testCase, + customerId, + }); - beforeAll(async function () { - await setupBefore(this); - await setupDefaultTrialBefore({}); - const { autumnJs } = this; - stripeCli = this.stripeCli; - db = this.db; - org = this.org; - env = this.env; - - const res = await initCustomerV2({ - autumn: autumnJs, - customerId: testCase, - db, - org, - env, + const res = await initCustomerV3({ + ctx, + customerId, attachPm: "success", + withTestClock: true, }); testClockID = res.testClockId; + stripeCli = ctx.stripeCli; }); it("should create a customer with the paid default trial", async () => { diff --git a/server/tests/advanced/defaultTrial/defaultTrial3.test.ts b/server/tests/advanced/defaultTrial/defaultTrial3.test.ts index 2d81de4b1..44c18af2b 100644 --- a/server/tests/advanced/defaultTrial/defaultTrial3.test.ts +++ b/server/tests/advanced/defaultTrial/defaultTrial3.test.ts @@ -1,59 +1,76 @@ // Manual customer creation - not using initCustomer to control test clock properly +import { beforeAll, describe, it } from "bun:test"; import { - type AppEnv, CusProductStatus, + FreeTrialDuration, LegacyVersion, - type Organization, + ProductItemInterval, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; 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 { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; // 2.3: // -> Creating a new customer with a fake payment method should attach the pro product with default trial // --> Advancing the test clock should cancel the trial and attach the free product +const defaultTrialPro = constructProduct({ + items: [ + constructFeatureItem({ + featureId: TestFeature.Words, + includedUsage: 1500, + interval: ProductItemInterval.Month, + }), + ], + isDefault: true, + forcePaidDefault: true, + id: "defaultTrial_pro", + group: "defaultTrial", + type: "pro", + freeTrial: { + length: 7, + duration: FreeTrialDuration.Day, + unique_fingerprint: false, + card_required: false, + }, +}); + const testCase = "defaultTrial3"; describe(`${chalk.yellowBright(`advanced/${testCase}: ensure trials cancel with bad payment method`)}`, () => { 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; - const curUnix = Math.floor(new Date().getTime() / 1000); + beforeAll(async () => { + // Products must be initialized BEFORE customer creation for default products + await initProductsV0({ + ctx, + products: [defaultTrialPro], + prefix: testCase, + customerId, + }); - beforeAll(async function () { - await setupBefore(this); - await setupDefaultTrialBefore({}); - const { autumnJs } = this; - stripeCli = this.stripeCli; - db = this.db; - org = this.org; - env = this.env; - - const res = await initCustomerV2({ - autumn: autumnJs, - customerId: testCase, - db, - org, - env, + const res = await initCustomerV3({ + ctx, + customerId, attachPm: "fail", + withTestClock: true, }); testClockID = res.testClockId; + stripeCli = ctx.stripeCli; }); it("should create a customer with the paid default trial", async () => { diff --git a/server/tests/advanced/defaultTrial/defaultTrialBefore.test.ts b/server/tests/advanced/defaultTrial/defaultTrialBefore.test.ts deleted file mode 100644 index 3ef5195a6..000000000 --- a/server/tests/advanced/defaultTrial/defaultTrialBefore.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { - 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 const defaultTrialPro = constructProduct({ - items: [ - constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 1500, - interval: ProductItemInterval.Month, - }), - ], - isDefault: true, - forcePaidDefault: true, - id: "defaultTrial_pro", - group: "defaultTrial", - type: "pro", - freeTrial: { - length: 7, - duration: FreeTrialDuration.Day, - unique_fingerprint: false, - card_required: false, - }, -}); - -export const defaultTrialFree = constructProduct({ - items: [ - constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 500, - interval: ProductItemInterval.Month, - }), - ], - id: "defaultTrial_free", - group: "defaultTrial", - type: "free", - isDefault: true, -}); - -export const setupDefaultTrialBefore = async ({}: {}) => { - const autumn = new AutumnInt({ version: LegacyVersion.v1_2 }); - for (const product of [defaultTrialPro, defaultTrialFree]) { - const res = await autumn.products.get(product.id); - - if (res.code === "product_not_found") { - try { - await autumn.products.create(product); - } catch (error) {} - } - } -}; diff --git a/server/tests/advanced/misc/advanced-misc1.test.ts b/server/tests/advanced/misc/advanced-misc1.test.ts index e28d49990..f6a1c05cd 100644 --- a/server/tests/advanced/misc/advanced-misc1.test.ts +++ b/server/tests/advanced/misc/advanced-misc1.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { getMainCusProduct } from "tests/utils/cusProductUtils/cusProductUtils.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { cusProductToSub } from "@/internal/customers/cusProducts/cusProductUtils/convertCusProduct.js"; diff --git a/server/tests/advanced/multiFeature/multiFeature1.test.ts b/server/tests/advanced/multiFeature/multiFeature1.test.ts index 5cafc417b..44a12ca8e 100644 --- a/server/tests/advanced/multiFeature/multiFeature1.test.ts +++ b/server/tests/advanced/multiFeature/multiFeature1.test.ts @@ -1,13 +1,13 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type AppEnv, LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import { getPrepaidCusEnt, getUsageCusEnt, -} from "tests/utils/cusProductUtils/cusEntSearchUtils.js"; -import { getMainCusProduct } from "tests/utils/cusProductUtils/cusProductUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/cusProductUtils/cusEntSearchUtils.js"; +import { getMainCusProduct } from "@tests/utils/cusProductUtils/cusProductUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/advanced/multiFeature/multiFeature1.ts b/server/tests/advanced/multiFeature/multiFeature1.ts index 489667e57..5602fbecc 100644 --- a/server/tests/advanced/multiFeature/multiFeature1.ts +++ b/server/tests/advanced/multiFeature/multiFeature1.ts @@ -7,14 +7,14 @@ import { } from "@autumn/shared"; import { expect } from "chai"; import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { features } from "tests/global.js"; +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 { createProducts } from "tests/utils/productUtils.js"; +} from "@tests/utils/cusProductUtils/cusEntSearchUtils.js"; +import { getMainCusProduct } from "@tests/utils/cusProductUtils/cusProductUtils.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"; diff --git a/server/tests/advanced/multiFeature/multiFeature2.test.ts b/server/tests/advanced/multiFeature/multiFeature2.test.ts index 74678e191..0a243dcbd 100644 --- a/server/tests/advanced/multiFeature/multiFeature2.test.ts +++ b/server/tests/advanced/multiFeature/multiFeature2.test.ts @@ -1,13 +1,13 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type AppEnv, LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import { getLifetimeFreeCusEnt, getUsageCusEnt, -} from "tests/utils/cusProductUtils/cusEntSearchUtils.js"; -import { getMainCusProduct } from "tests/utils/cusProductUtils/cusProductUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/cusProductUtils/cusEntSearchUtils.js"; +import { getMainCusProduct } from "@tests/utils/cusProductUtils/cusProductUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/advanced/multiFeature/multiFeature2.ts b/server/tests/advanced/multiFeature/multiFeature2.ts index 2cb146ae1..3b160391e 100644 --- a/server/tests/advanced/multiFeature/multiFeature2.ts +++ b/server/tests/advanced/multiFeature/multiFeature2.ts @@ -8,14 +8,14 @@ import { } from "@autumn/shared"; import { expect } from "chai"; import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { features } from "tests/global.js"; +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"; +} 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 { diff --git a/server/tests/advanced/multiFeature/multiFeature3.test.ts b/server/tests/advanced/multiFeature/multiFeature3.test.ts index cc10ce442..fefd01f37 100644 --- a/server/tests/advanced/multiFeature/multiFeature3.test.ts +++ b/server/tests/advanced/multiFeature/multiFeature3.test.ts @@ -4,13 +4,13 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type AppEnv } from "@autumn/shared"; import chalk from "chalk"; import { addMonths } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import { getLifetimeFreeCusEnt, getUsageCusEnt, -} from "tests/utils/cusProductUtils/cusEntSearchUtils.js"; -import { getMainCusProduct } from "tests/utils/cusProductUtils/cusProductUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/cusProductUtils/cusEntSearchUtils.js"; +import { getMainCusProduct } from "@tests/utils/cusProductUtils/cusProductUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/advanced/multiFeature/multiFeature3.ts b/server/tests/advanced/multiFeature/multiFeature3.ts index 49f0a5e01..228007203 100644 --- a/server/tests/advanced/multiFeature/multiFeature3.ts +++ b/server/tests/advanced/multiFeature/multiFeature3.ts @@ -9,15 +9,15 @@ import { import { expect } from "chai"; import chalk from "chalk"; import { addMonths } from "date-fns"; -import { setupBefore } from "tests/before.js"; -import { features } from "tests/global.js"; +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 { createProducts } from "tests/utils/productUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +} from "@tests/utils/cusProductUtils/cusEntSearchUtils.js"; +import { getMainCusProduct } from "@tests/utils/cusProductUtils/cusProductUtils.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 { diff --git a/server/tests/advanced/referrals/paid/referrals13.backup.ts b/server/tests/advanced/referrals/paid/referrals13.backup.ts index 14dcc6704..5f1aefaaf 100644 --- a/server/tests/advanced/referrals/paid/referrals13.backup.ts +++ b/server/tests/advanced/referrals/paid/referrals13.backup.ts @@ -10,9 +10,9 @@ import { import { assert } from "chai"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { setupBefore } from "tests/before.js"; -import { expectProductV1Attached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { setupBefore } from "@tests/before.js"; +import { expectProductV1Attached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; diff --git a/server/tests/advanced/referrals/paid/referrals13.test.ts b/server/tests/advanced/referrals/paid/referrals13.test.ts index ee79f0c01..5b8354de2 100644 --- a/server/tests/advanced/referrals/paid/referrals13.test.ts +++ b/server/tests/advanced/referrals/paid/referrals13.test.ts @@ -10,9 +10,9 @@ import { import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { expectProductV1Attached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { expectProductV1Attached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/advanced/referrals/paid/referrals14.backup.ts b/server/tests/advanced/referrals/paid/referrals14.backup.ts index 6b12ddf22..123f098bf 100644 --- a/server/tests/advanced/referrals/paid/referrals14.backup.ts +++ b/server/tests/advanced/referrals/paid/referrals14.backup.ts @@ -10,9 +10,9 @@ import { import { assert } from "chai"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { setupBefore } from "tests/before.js"; -import { expectProductV1Attached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { setupBefore } from "@tests/before.js"; +import { expectProductV1Attached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/advanced/referrals/paid/referrals14.test.ts b/server/tests/advanced/referrals/paid/referrals14.test.ts index a03ff9327..5861e8fe1 100644 --- a/server/tests/advanced/referrals/paid/referrals14.test.ts +++ b/server/tests/advanced/referrals/paid/referrals14.test.ts @@ -10,9 +10,9 @@ import { import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { expectProductV1Attached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { expectProductV1Attached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/advanced/referrals/paid/referrals15.backup.ts b/server/tests/advanced/referrals/paid/referrals15.backup.ts index 1f8c15c82..2213852a3 100644 --- a/server/tests/advanced/referrals/paid/referrals15.backup.ts +++ b/server/tests/advanced/referrals/paid/referrals15.backup.ts @@ -10,9 +10,9 @@ import { import { assert } from "chai"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { setupBefore } from "tests/before.js"; -import { expectProductV1Attached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { setupBefore } from "@tests/before.js"; +import { expectProductV1Attached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/advanced/referrals/paid/referrals15.test.ts b/server/tests/advanced/referrals/paid/referrals15.test.ts index 71ba24132..34deaa7d8 100644 --- a/server/tests/advanced/referrals/paid/referrals15.test.ts +++ b/server/tests/advanced/referrals/paid/referrals15.test.ts @@ -10,9 +10,9 @@ import { import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { expectProductV1Attached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { expectProductV1Attached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/advanced/referrals/paid/referrals16.backup.ts b/server/tests/advanced/referrals/paid/referrals16.backup.ts index 0b56bcab2..2b47ff965 100644 --- a/server/tests/advanced/referrals/paid/referrals16.backup.ts +++ b/server/tests/advanced/referrals/paid/referrals16.backup.ts @@ -10,12 +10,12 @@ // import { assert } from "chai"; // import chalk from "chalk"; // import type { Stripe } from "stripe"; -// import { setupBefore } from "tests/before.js"; -// import { expectProductV1Attached } from "tests/utils/expectUtils/expectProductAttached.js"; +// import { setupBefore } from "@tests/before.js"; +// import { expectProductV1Attached } from "@tests/utils/expectUtils/expectProductAttached.js"; // import { // advanceTestClock, // completeCheckoutForm, -// } from "tests/utils/stripeUtils.js"; +// } from "@tests/utils/stripeUtils.js"; // import type { DrizzleCli } from "@/db/initDrizzle.js"; // import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; // import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/advanced/referrals/paid/referrals16.test.ts b/server/tests/advanced/referrals/paid/referrals16.test.ts index f9e739cb5..66a9d48cc 100644 --- a/server/tests/advanced/referrals/paid/referrals16.test.ts +++ b/server/tests/advanced/referrals/paid/referrals16.test.ts @@ -13,12 +13,12 @@ // import { beforeAll, describe, expect, test } from "bun:test"; // import chalk from "chalk"; // import type { Stripe } from "stripe"; -// import { expectProductV1Attached } from "tests/utils/expectUtils/expectProductAttached.js"; +// import { expectProductV1Attached } from "@tests/utils/expectUtils/expectProductAttached.js"; // import { // advanceTestClock, // completeCheckoutForm, -// } from "tests/utils/stripeUtils.js"; -// import ctx from "tests/utils/testInitUtils/createTestContext.js"; +// } from "@tests/utils/stripeUtils.js"; +// import ctx from "@tests/utils/testInitUtils/createTestContext.js"; // import type { DrizzleCli } from "@/db/initDrizzle.js"; // import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; // import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/advanced/referrals/referrals1.test.ts b/server/tests/advanced/referrals/referrals1.test.ts index 6a2442adb..bae341373 100644 --- a/server/tests/advanced/referrals/referrals1.test.ts +++ b/server/tests/advanced/referrals/referrals1.test.ts @@ -15,11 +15,11 @@ import { import chalk from "chalk"; import { addDays } from "date-fns"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { createReferralProgram } from "tests/utils/productUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { createReferralProgram } from "@tests/utils/productUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/advanced/referrals/referrals2.test.ts b/server/tests/advanced/referrals/referrals2.test.ts index 33071a2ce..308b95867 100644 --- a/server/tests/advanced/referrals/referrals2.test.ts +++ b/server/tests/advanced/referrals/referrals2.test.ts @@ -16,11 +16,11 @@ import { import chalk from "chalk"; import { addDays } from "date-fns"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { createReferralProgram } from "tests/utils/productUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { createReferralProgram } from "@tests/utils/productUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; import { createStripeCli } from "@/external/connect/createStripeCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/advanced/referrals/referrals3.test.ts b/server/tests/advanced/referrals/referrals3.test.ts index bded0cde7..dff57591b 100644 --- a/server/tests/advanced/referrals/referrals3.test.ts +++ b/server/tests/advanced/referrals/referrals3.test.ts @@ -11,10 +11,10 @@ import { RewardType, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { createReferralProgram } from "tests/utils/productUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { createReferralProgram } from "@tests/utils/productUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import AutumnError, { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/referrals/referrals4.test.ts b/server/tests/advanced/referrals/referrals4.test.ts index ad0d01f88..0a50956ee 100644 --- a/server/tests/advanced/referrals/referrals4.test.ts +++ b/server/tests/advanced/referrals/referrals4.test.ts @@ -12,12 +12,12 @@ import { import chalk from "chalk"; import { addDays, addHours } from "date-fns"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { createReferralProgram } from "tests/utils/productUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { createReferralProgram } from "@tests/utils/productUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/rollovers/rollover1.test.ts b/server/tests/advanced/rollovers/rollover1.test.ts index 2d9aecf5b..cfa76de7e 100644 --- a/server/tests/advanced/rollovers/rollover1.test.ts +++ b/server/tests/advanced/rollovers/rollover1.test.ts @@ -8,8 +8,8 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/advanced/rollovers/rollover2.test.ts b/server/tests/advanced/rollovers/rollover2.test.ts index 95f0de580..6c7086a7a 100644 --- a/server/tests/advanced/rollovers/rollover2.test.ts +++ b/server/tests/advanced/rollovers/rollover2.test.ts @@ -8,8 +8,8 @@ import { import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/advanced/rollovers/rollover3.test.ts b/server/tests/advanced/rollovers/rollover3.test.ts index 768491861..01404022d 100644 --- a/server/tests/advanced/rollovers/rollover3.test.ts +++ b/server/tests/advanced/rollovers/rollover3.test.ts @@ -8,8 +8,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addMonths } from "date-fns"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/advanced/rollovers/rollover4.test.ts b/server/tests/advanced/rollovers/rollover4.test.ts index 8c9084441..06d945145 100644 --- a/server/tests/advanced/rollovers/rollover4.test.ts +++ b/server/tests/advanced/rollovers/rollover4.test.ts @@ -1,22 +1,23 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { + type ApiCusFeatureV3, type Customer, LegacyVersion, type LimitedItem, RolloverDuration, } from "@autumn/shared"; -import { beforeAll, describe, expect, test } from "bun:test"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addMonths } from "date-fns"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.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 { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; -import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; const rolloverConfig = { max: 400, @@ -105,25 +106,24 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f }); const cus = await autumn.customers.get(customerId); - const msgesFeature = cus.features[TestFeature.Messages]; + const msgesFeature = cus.features[TestFeature.Messages] as ApiCusFeatureV3; - // @ts-expect-error const rollovers = msgesFeature?.rollovers; - expect(msgesFeature).toBeDefined(); expect(msgesFeature?.balance).toBe(balance + rollover); - expect(rollovers[0].balance).toBe(rollover); + expect(rollovers?.[0].balance).toBe(rollover); // Verify non-cached customer balance await timeout(2000); const nonCachedCustomer = await autumn.customers.get(customerId, { skip_cache: "true", }); - const nonCachedMsgesFeature = nonCachedCustomer.features[TestFeature.Messages]; - // @ts-expect-error + const nonCachedMsgesFeature = nonCachedCustomer.features[ + TestFeature.Messages + ] as ApiCusFeatureV3; const nonCachedRollovers = nonCachedMsgesFeature?.rollovers; expect(nonCachedMsgesFeature?.balance).toBe(balance + rollover); - expect(nonCachedRollovers[0].balance).toBe(rollover); + expect(nonCachedRollovers?.[0].balance).toBe(rollover); }); // let usage2 = 50; @@ -137,25 +137,27 @@ describe(`${chalk.yellowBright(`${testCase}: Testing rollovers for usage price f 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 msgesFeature = cus.features[TestFeature.Messages] as ApiCusFeatureV3; + const rollovers = msgesFeature?.rollovers; expect(msgesFeature).toBeDefined(); expect(msgesFeature?.balance).toBe(balance + newRollover); - expect(rollovers[0].balance).toBe(0); - expect(rollovers[1].balance).toBe(400); + expect(rollovers?.[0].balance).toBe(0); + expect(rollovers?.[1].balance).toBe(400); // Verify non-cached customer balance await timeout(2000); const nonCachedCustomer = await autumn.customers.get(customerId, { skip_cache: "true", }); - const nonCachedMsgesFeature = nonCachedCustomer.features[TestFeature.Messages]; - // @ts-expect-error - const nonCachedRollovers = nonCachedMsgesFeature?.rollovers; + const nonCachedMsgesFeature = + nonCachedCustomer.features[TestFeature.Messages]; + + const nonCachedRollovers = + nonCachedMsgesFeature?.rollovers as ApiCusFeatureV3["rollovers"]; expect(nonCachedMsgesFeature?.balance).toBe(balance + newRollover); - expect(nonCachedRollovers[0].balance).toBe(0); - expect(nonCachedRollovers[1].balance).toBe(400); + expect(nonCachedRollovers?.[0].balance).toBe(0); + expect(nonCachedRollovers?.[1].balance).toBe(400); }); }); diff --git a/server/tests/advanced/rollovers/rollover5.test.ts b/server/tests/advanced/rollovers/rollover5.test.ts index 9e86fc6df..0fbc9af24 100644 --- a/server/tests/advanced/rollovers/rollover5.test.ts +++ b/server/tests/advanced/rollovers/rollover5.test.ts @@ -7,8 +7,8 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/rollovers/rollover6.test.ts b/server/tests/advanced/rollovers/rollover6.test.ts index 89e370c7f..6640c572c 100644 --- a/server/tests/advanced/rollovers/rollover6.test.ts +++ b/server/tests/advanced/rollovers/rollover6.test.ts @@ -8,9 +8,9 @@ import { import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/usage/sharedProducts.ts b/server/tests/advanced/usage/sharedProducts.ts index 7d25fbf8a..f15ec74fb 100644 --- a/server/tests/advanced/usage/sharedProducts.ts +++ b/server/tests/advanced/usage/sharedProducts.ts @@ -1,6 +1,6 @@ import { BillingInterval, ProductItemInterval } from "@autumn/shared"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructFeatureItem, diff --git a/server/tests/advanced/usage/usage1.test.ts b/server/tests/advanced/usage/usage1.test.ts index 05f01c67f..861301f00 100644 --- a/server/tests/advanced/usage/usage1.test.ts +++ b/server/tests/advanced/usage/usage1.test.ts @@ -7,10 +7,10 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { convertProductV2ToV1 } from "@/internal/products/productUtils/productV2Utils/convertProductV2ToV1.js"; import { constructRawProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/usage/usage2.test.ts b/server/tests/advanced/usage/usage2.test.ts index fa43cf39a..20ccd2998 100644 --- a/server/tests/advanced/usage/usage2.test.ts +++ b/server/tests/advanced/usage/usage2.test.ts @@ -7,11 +7,11 @@ import { import chalk from "chalk"; import { Decimal } from "decimal.js"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { advanceClockForInvoice } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { advanceClockForInvoice } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { convertProductV2ToV1 } from "@/internal/products/productUtils/productV2Utils/convertProductV2ToV1.js"; import { constructRawProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/usage/usage3.test.ts b/server/tests/advanced/usage/usage3.test.ts index aa1c89bb4..5696c3afa 100644 --- a/server/tests/advanced/usage/usage3.test.ts +++ b/server/tests/advanced/usage/usage3.test.ts @@ -7,12 +7,12 @@ import { import chalk from "chalk"; import { Decimal } from "decimal.js"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { getSubsFromCusId } from "tests/utils/expectUtils/expectSubUtils.js"; -import { checkSubscriptionContainsProducts } from "tests/utils/scheduleCheckUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { v1ProductToBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { getSubsFromCusId } from "@tests/utils/expectUtils/expectSubUtils.js"; +import { checkSubscriptionContainsProducts } from "@tests/utils/scheduleCheckUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { v1ProductToBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; import { subToPeriodStartEnd } from "@/external/stripe/stripeSubUtils/convertSubUtils.js"; import { getCreditCost } from "@/internal/features/creditSystemUtils.js"; import { calculateProrationAmount } from "@/internal/invoices/prorationUtils.js"; diff --git a/server/tests/advanced/usage/usage4.test.ts b/server/tests/advanced/usage/usage4.test.ts index 0945d3cdb..04dd7f31f 100644 --- a/server/tests/advanced/usage/usage4.test.ts +++ b/server/tests/advanced/usage/usage4.test.ts @@ -7,9 +7,9 @@ import { import chalk from "chalk"; import { Decimal } from "decimal.js"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { convertProductV2ToV1 } from "@/internal/products/productUtils/productV2Utils/convertProductV2ToV1.js"; import { constructRawProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/usageLimit/usageLimit1.test.ts b/server/tests/advanced/usageLimit/usageLimit1.test.ts index 5be589ad3..ae4291292 100644 --- a/server/tests/advanced/usageLimit/usageLimit1.test.ts +++ b/server/tests/advanced/usageLimit/usageLimit1.test.ts @@ -1,10 +1,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ErrCode, LegacyVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/usageLimit/usageLimit2.test.ts b/server/tests/advanced/usageLimit/usageLimit2.test.ts index 4a3b91d7c..be1c3f5e9 100644 --- a/server/tests/advanced/usageLimit/usageLimit2.test.ts +++ b/server/tests/advanced/usageLimit/usageLimit2.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { diff --git a/server/tests/advanced/usageLimit/usageLimit3.test.ts b/server/tests/advanced/usageLimit/usageLimit3.test.ts index 66858627c..1b9309634 100644 --- a/server/tests/advanced/usageLimit/usageLimit3.test.ts +++ b/server/tests/advanced/usageLimit/usageLimit3.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, test } from "bun:test"; import { ErrCode, LegacyVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/advanced/usageLimit/usageLimit4.test.ts b/server/tests/advanced/usageLimit/usageLimit4.test.ts index ffffed6f6..7748aa387 100644 --- a/server/tests/advanced/usageLimit/usageLimit4.test.ts +++ b/server/tests/advanced/usageLimit/usageLimit4.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/alex/00_setup.ts b/server/tests/alex/00_setup.ts index 53b3f0e62..e66240486 100644 --- a/server/tests/alex/00_setup.ts +++ b/server/tests/alex/00_setup.ts @@ -1,21 +1,16 @@ import { AppEnv } from "@autumn/shared"; -import { clearOrg, setupOrg } from "tests/utils/setup.js"; -import { alexFeatures, alexProducts } from "./init.js"; +import { clearOrg, setupOrg } from "@tests/utils/setup.js"; const ORG_SLUG = process.env.TESTS_ORG!; const DEFAULT_ENV = AppEnv.Sandbox; -describe("Initialize org for tests", () => { +describe("Initialize alex org for tests", () => { it("should initialize org", async function () { this.org = await clearOrg({ orgSlug: ORG_SLUG, env: DEFAULT_ENV }); this.env = DEFAULT_ENV; await setupOrg({ orgId: this.org.id, env: DEFAULT_ENV, - features: { ...alexFeatures } as any, - products: { ...alexProducts }, - rewards: {}, - rewardTriggers: {}, }); console.log("--------------------------------"); diff --git a/server/tests/alex/01_free.ts b/server/tests/alex/01_free.ts index d5a656f4e..2a62b526e 100644 --- a/server/tests/alex/01_free.ts +++ b/server/tests/alex/01_free.ts @@ -1,7 +1,7 @@ import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { compareMainProduct } from "tests/utils/compare.js"; -import { initCustomer } from "tests/utils/init.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { compareMainProduct } from "@tests/utils/compare.js"; +import { initCustomer } from "@tests/utils/init.js"; import { alexProducts } from "./init.js"; import { runEventsAndCheckBalances } from "./utils.js"; diff --git a/server/tests/alex/02_pro.ts b/server/tests/alex/02_pro.ts index 10d388ce6..7b03f047d 100644 --- a/server/tests/alex/02_pro.ts +++ b/server/tests/alex/02_pro.ts @@ -1,10 +1,10 @@ import { CusProductStatus, InvoiceStatus } from "@autumn/shared"; import { expect } from "chai"; -import { timeout } from "tests/utils/genUtils.js"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { compareMainProduct } from "tests/utils/compare.js"; -import { initCustomer } from "tests/utils/init.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { compareMainProduct } from "@tests/utils/compare.js"; +import { initCustomer } from "@tests/utils/init.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; import { alexProducts } from "./init.js"; import { runEventsAndCheckBalances } from "./utils.js"; import chalk from "chalk"; diff --git a/server/tests/alex/03_premium.ts b/server/tests/alex/03_premium.ts index 29aae7f54..ac86d87f0 100644 --- a/server/tests/alex/03_premium.ts +++ b/server/tests/alex/03_premium.ts @@ -1,10 +1,10 @@ -import { compareMainProduct } from "tests/utils/compare.js"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { initCustomer } from "tests/utils/init.js"; +import { compareMainProduct } from "@tests/utils/compare.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { initCustomer } from "@tests/utils/init.js"; import { alexProducts } from "./init.js"; import { CusProductStatus } from "@autumn/shared"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import { timeout } from "tests/utils/genUtils.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; +import { timeout } from "@tests/utils/genUtils.js"; import { runEventsAndCheckBalances } from "./utils.js"; import chalk from "chalk"; diff --git a/server/tests/alex/04_topups.ts b/server/tests/alex/04_topups.ts index 7edcfad79..4f79e4568 100644 --- a/server/tests/alex/04_topups.ts +++ b/server/tests/alex/04_topups.ts @@ -7,10 +7,10 @@ import { } from "@autumn/shared"; import { expect } from "chai"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { compareMainProduct } from "tests/utils/compare.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { compareMainProduct } from "@tests/utils/compare.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; import { alexFeatures, alexProducts } from "./init.js"; diff --git a/server/tests/alex/05_cancel.ts b/server/tests/alex/05_cancel.ts index 06a510349..547b7cbbe 100644 --- a/server/tests/alex/05_cancel.ts +++ b/server/tests/alex/05_cancel.ts @@ -3,11 +3,11 @@ import { expect } from "chai"; import chalk from "chalk"; import { addDays, addHours } from "date-fns"; import type Stripe from "stripe"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { compareMainProduct } from "tests/utils/compare.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { compareMainProduct } from "@tests/utils/compare.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { createStripeCli } from "@/external/connect/createStripeCli.js"; import { attachFailedPaymentMethod } from "@/external/stripe/stripeCusUtils.js"; diff --git a/server/tests/alex/06_switch.ts b/server/tests/alex/06_switch.ts index 2341361bc..a88cfea40 100644 --- a/server/tests/alex/06_switch.ts +++ b/server/tests/alex/06_switch.ts @@ -3,10 +3,10 @@ import { expect } from "chai"; import chalk from "chalk"; import { addDays, addHours } from "date-fns"; import type Stripe from "stripe"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { compareMainProduct } from "tests/utils/compare.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { compareMainProduct } from "@tests/utils/compare.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { createStripeCli } from "@/external/connect/createStripeCli.js"; import { initCustomerV2 } from "@/utils/scriptUtils/initCustomer.js"; diff --git a/server/tests/alex/utils.ts b/server/tests/alex/utils.ts index 9d942d12a..663ed2a95 100644 --- a/server/tests/alex/utils.ts +++ b/server/tests/alex/utils.ts @@ -5,8 +5,8 @@ import { Feature, } from "@autumn/shared"; import { expect } from "chai"; -import { timeout } from "tests/utils/genUtils.js"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; import { alexFeatures } from "./init.js"; const checkEntitledOnFeatures = async (customerId: string, product: any) => { diff --git a/server/tests/archives/arrear_prorated/arrear_prorated2.ts b/server/tests/archives/arrear_prorated/arrear_prorated2.ts index 8ee7f684d..fb2b035b5 100644 --- a/server/tests/archives/arrear_prorated/arrear_prorated2.ts +++ b/server/tests/archives/arrear_prorated/arrear_prorated2.ts @@ -2,16 +2,16 @@ // import Stripe from "stripe"; // import { expect } from "chai"; -// import { AutumnCli } from "tests/cli/AutumnCli.js"; -// import { advanceProducts, features } from "tests/global.js"; -// import { compareMainProduct } from "tests/utils/compare.js"; -// import { advanceTestClock } from "tests/utils/stripeUtils.js"; -// import { timeout } from "tests/utils/genUtils.js"; +// import { AutumnCli } from "@tests/cli/AutumnCli.js"; +// import { advanceProducts, features } from "@tests/global.js"; +// import { compareMainProduct } from "@tests/utils/compare.js"; +// import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +// import { timeout } from "@tests/utils/genUtils.js"; // import { addDays, addMonths, format } from "date-fns"; -// import { initCustomerWithTestClock } from "tests/utils/testInitUtils.js"; -// import { checkSubscriptionContainsProducts } from "tests/utils/scheduleCheckUtils.js"; +// import { initCustomerWithTestClock } from "@tests/utils/testInitUtils.js"; +// import { checkSubscriptionContainsProducts } from "@tests/utils/scheduleCheckUtils.js"; // import { CacheManager } from "@/external/caching/CacheManager.js"; // import { CacheType } from "@/external/caching/cacheActions.js"; // import { hashApiKey } from "@/internal/dev/api-keys/apiKeyUtils.js"; diff --git a/server/tests/archives/arrear_prorated/arrear_prorated3.ts b/server/tests/archives/arrear_prorated/arrear_prorated3.ts index 80161e59b..1711ffe1d 100644 --- a/server/tests/archives/arrear_prorated/arrear_prorated3.ts +++ b/server/tests/archives/arrear_prorated/arrear_prorated3.ts @@ -3,13 +3,13 @@ import chalk from "chalk"; import { addDays, addMonths, format } from "date-fns"; import { Decimal } from "decimal.js"; import type Stripe from "stripe"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { advanceProducts, features } from "tests/global.js"; -import { compareMainProduct } from "tests/utils/compare.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { checkSubscriptionContainsProducts } from "tests/utils/scheduleCheckUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { initCustomerWithTestClock } from "tests/utils/testInitUtils.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { advanceProducts, features } from "@tests/global.js"; +import { compareMainProduct } from "@tests/utils/compare.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { checkSubscriptionContainsProducts } from "@tests/utils/scheduleCheckUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import { initCustomerWithTestClock } from "@tests/utils/testInitUtils.js"; import { createStripeCli } from "@/external/connect/createStripeCli.js"; const advanceAPThroughBalances = async ({ diff --git a/server/tests/archives/basic10.backup.ts b/server/tests/archives/basic10.backup.ts index 2cc23e44b..7e48e8314 100644 --- a/server/tests/archives/basic10.backup.ts +++ b/server/tests/archives/basic10.backup.ts @@ -1,16 +1,16 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { features, oneTimeProducts } from "tests/global.js"; -import { compareMainProduct } from "tests/utils/compare.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { features, oneTimeProducts } from "@tests/global.js"; +import { compareMainProduct } from "@tests/utils/compare.js"; import { getFixedPriceAmount, getUsagePriceTiers, timeout, -} from "tests/utils/genUtils.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/genUtils.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; const testCase = "basic10"; diff --git a/server/tests/archives/coupon1 copy.ts b/server/tests/archives/coupon1 copy.ts index bc5792712..6d373d6ec 100644 --- a/server/tests/archives/coupon1 copy.ts +++ b/server/tests/archives/coupon1 copy.ts @@ -3,17 +3,17 @@ 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 { 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 { 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"; +} from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { getPriceForOverage } from "@/internal/products/prices/priceUtils.js"; import { getOriginalCouponId } from "@/internal/rewards/rewardUtils.js"; diff --git a/server/tests/archives/entities1.ts b/server/tests/archives/entities1.ts index 1ca584d09..f7f50d0ac 100644 --- a/server/tests/archives/entities1.ts +++ b/server/tests/archives/entities1.ts @@ -1,12 +1,12 @@ // import { Autumn } from "@/external/autumn/autumnCli.js"; -// import { setupBefore } from "tests/before.js"; +// import { setupBefore } from "@tests/before.js"; // import { CusProductStatus, organizations } from "@autumn/shared"; -// import { getFeaturePrice, getUsagePriceTiers } from "tests/utils/genUtils.js"; +// import { getFeaturePrice, getUsagePriceTiers } from "@tests/utils/genUtils.js"; // import { entityProducts, features } from "../global.js"; // import { Stripe } from "stripe"; -// import { checkBalance } from "tests/utils/autumnUtils.js"; -// import { initCustomerWithTestClock } from "tests/utils/testInitUtils.js"; -// import { advanceTestClock } from "tests/utils/stripeUtils.js"; +// import { checkBalance } from "@tests/utils/autumnUtils.js"; +// import { initCustomerWithTestClock } from "@tests/utils/testInitUtils.js"; +// import { advanceTestClock } from "@tests/utils/stripeUtils.js"; // import { addDays, addHours, addMonths } from "date-fns"; // import { CacheManager } from "@/external/caching/CacheManager.js"; // import { CacheType } from "@/external/caching/cacheActions.js"; diff --git a/server/tests/archives/mergedAdd2.test.ts b/server/tests/archives/mergedAdd2.test.ts index 3c48276d8..fb68589a3 100644 --- a/server/tests/archives/mergedAdd2.test.ts +++ b/server/tests/archives/mergedAdd2.test.ts @@ -2,8 +2,8 @@ // import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; // import chalk from "chalk"; // import type { Stripe } from "stripe"; -// import { TestFeature } from "tests/setup/v2Features.js"; -// import ctx from "tests/utils/testInitUtils/createTestContext.js"; +// import { TestFeature } from "@tests/setup/v2Features.js"; +// import ctx from "@tests/utils/testInitUtils/createTestContext.js"; // import type { DrizzleCli } from "@/db/initDrizzle.js"; // import { AutumnInt } from "@/external/autumn/autumnCli.js"; // import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/addOn/addOn1.test.ts b/server/tests/attach/addOn/addOn1.test.ts index 01172972e..4563c8df7 100644 --- a/server/tests/attach/addOn/addOn1.test.ts +++ b/server/tests/attach/addOn/addOn1.test.ts @@ -1,10 +1,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { diff --git a/server/tests/attach/addOn/addOn2.test.ts b/server/tests/attach/addOn/addOn2.test.ts index 8dfdd33b3..6b4276851 100644 --- a/server/tests/attach/addOn/addOn2.test.ts +++ b/server/tests/attach/addOn/addOn2.test.ts @@ -2,11 +2,11 @@ import { beforeAll, describe, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -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 ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/basic/basic1.test.ts b/server/tests/attach/basic/basic1.test.ts index 91f905381..8661515d1 100644 --- a/server/tests/attach/basic/basic1.test.ts +++ b/server/tests/attach/basic/basic1.test.ts @@ -1,12 +1,12 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { expectFeaturesCorrect } from "@tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/basic/basic2.test.ts b/server/tests/attach/basic/basic2.test.ts index b7fa2f82f..508a27a25 100644 --- a/server/tests/attach/basic/basic2.test.ts +++ b/server/tests/attach/basic/basic2.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ProductItemInterval } from "@autumn/shared"; import type { ApiCustomerV1 } from "@shared/api/customers/previousVersions/apiCustomerV1.js"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, diff --git a/server/tests/attach/basic/basic3.test.ts b/server/tests/attach/basic/basic3.test.ts index 504ab03b1..3b593dd10 100644 --- a/server/tests/attach/basic/basic3.test.ts +++ b/server/tests/attach/basic/basic3.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, CusProductStatus } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { createStripeCli } from "@/external/connect/createStripeCli.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/attach/basic/basic6.test.ts b/server/tests/attach/basic/basic6.test.ts index 6ff12985e..a786e750e 100644 --- a/server/tests/attach/basic/basic6.test.ts +++ b/server/tests/attach/basic/basic6.test.ts @@ -8,11 +8,11 @@ import { import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { attachFailedPaymentMethod } from "@/external/stripe/stripeCusUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/basic/basic7.test.ts b/server/tests/attach/basic/basic7.test.ts index a9dda0168..cba077c89 100644 --- a/server/tests/attach/basic/basic7.test.ts +++ b/server/tests/attach/basic/basic7.test.ts @@ -7,11 +7,11 @@ import { ProductItemInterval, } from "@autumn/shared"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { convertProductV2ToV1 } from "@/internal/products/productUtils/productV2Utils/convertProductV2ToV1.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/basic/basic8.test.ts b/server/tests/attach/basic/basic8.test.ts index 3cab882be..55a7b09db 100644 --- a/server/tests/attach/basic/basic8.test.ts +++ b/server/tests/attach/basic/basic8.test.ts @@ -6,10 +6,10 @@ import { ProductItemInterval, } from "@autumn/shared"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/basic/sharedProducts.ts b/server/tests/attach/basic/sharedProducts.ts index 2ad42211f..ad21ce708 100644 --- a/server/tests/attach/basic/sharedProducts.ts +++ b/server/tests/attach/basic/sharedProducts.ts @@ -1,6 +1,6 @@ import { ProductItemInterval } from "@autumn/shared"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { createSharedProducts } from "@/utils/scriptUtils/testUtils/createSharedProduct.js"; diff --git a/server/tests/attach/checkout/checkout1.test.ts b/server/tests/attach/checkout/checkout1.test.ts index 1a4363d29..c11bec24d 100644 --- a/server/tests/attach/checkout/checkout1.test.ts +++ b/server/tests/attach/checkout/checkout1.test.ts @@ -6,12 +6,12 @@ import { ProductItemInterval, } from "@autumn/shared"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { convertProductV2ToV1 } from "@/internal/products/productUtils/productV2Utils/convertProductV2ToV1.js"; diff --git a/server/tests/attach/checkout/checkout2.test.ts b/server/tests/attach/checkout/checkout2.test.ts index acec84b78..dfda1e789 100644 --- a/server/tests/attach/checkout/checkout2.test.ts +++ b/server/tests/attach/checkout/checkout2.test.ts @@ -7,12 +7,12 @@ import { } from "@autumn/shared"; import type { ApiCustomerV1 } from "@shared/api/customers/previousVersions/apiCustomerV1.js"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, diff --git a/server/tests/attach/checkout/checkout3.test.ts b/server/tests/attach/checkout/checkout3.test.ts index 2c5efbe18..4e598237c 100644 --- a/server/tests/attach/checkout/checkout3.test.ts +++ b/server/tests/attach/checkout/checkout3.test.ts @@ -1,11 +1,11 @@ import { beforeAll, describe, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/checkout/checkout4.test.ts b/server/tests/attach/checkout/checkout4.test.ts index 28da3ebf6..14bd20e43 100644 --- a/server/tests/attach/checkout/checkout4.test.ts +++ b/server/tests/attach/checkout/checkout4.test.ts @@ -1,12 +1,12 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { RewardType } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { createReward } from "tests/utils/productUtils.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { createReward } from "@tests/utils/productUtils.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } 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"; diff --git a/server/tests/attach/checkout/checkout5.test.ts b/server/tests/attach/checkout/checkout5.test.ts index d59c77fb1..205a7d1d4 100644 --- a/server/tests/attach/checkout/checkout5.test.ts +++ b/server/tests/attach/checkout/checkout5.test.ts @@ -1,12 +1,12 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.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 { completeInvoiceCheckout } from "@tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } 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"; diff --git a/server/tests/attach/checkout/checkout6.test.ts b/server/tests/attach/checkout/checkout6.test.ts index 70a643916..a9db26784 100644 --- a/server/tests/attach/checkout/checkout6.test.ts +++ b/server/tests/attach/checkout/checkout6.test.ts @@ -1,13 +1,13 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -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 { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.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 { completeInvoiceCheckout } from "@tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } 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"; diff --git a/server/tests/attach/checkout/checkout7.test.ts b/server/tests/attach/checkout/checkout7.test.ts index 441166a7e..cc69290cf 100644 --- a/server/tests/attach/checkout/checkout7.test.ts +++ b/server/tests/attach/checkout/checkout7.test.ts @@ -1,11 +1,11 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { completeInvoiceCheckout } from "@tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, diff --git a/server/tests/attach/checkout/checkout8.test.ts b/server/tests/attach/checkout/checkout8.test.ts index aec3d0c41..b9fb3c961 100644 --- a/server/tests/attach/checkout/checkout8.test.ts +++ b/server/tests/attach/checkout/checkout8.test.ts @@ -1,12 +1,12 @@ import { beforeAll, describe, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { timeout } from "tests/utils/genUtils.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/downgrade/downgrade1.test.ts b/server/tests/attach/downgrade/downgrade1.test.ts index 6019edca8..8701912af 100644 --- a/server/tests/attach/downgrade/downgrade1.test.ts +++ b/server/tests/attach/downgrade/downgrade1.test.ts @@ -2,13 +2,13 @@ import { beforeAll, describe, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.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 ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/expectUtils/expectScheduleUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/downgrade/downgrade2.test.ts b/server/tests/attach/downgrade/downgrade2.test.ts index f66293c13..efd6e8d91 100644 --- a/server/tests/attach/downgrade/downgrade2.test.ts +++ b/server/tests/attach/downgrade/downgrade2.test.ts @@ -2,13 +2,13 @@ import { beforeAll, describe, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.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 ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/expectUtils/expectScheduleUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; diff --git a/server/tests/attach/downgrade/downgrade3.test.ts b/server/tests/attach/downgrade/downgrade3.test.ts index 4276b1dc2..933dd9c9b 100644 --- a/server/tests/attach/downgrade/downgrade3.test.ts +++ b/server/tests/attach/downgrade/downgrade3.test.ts @@ -7,11 +7,11 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type 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 { expectDowngradeCorrect } from "tests/utils/expectUtils/expectScheduleUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { expectDowngradeCorrect } from "@tests/utils/expectUtils/expectScheduleUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; diff --git a/server/tests/attach/downgrade/downgrade4.test.ts b/server/tests/attach/downgrade/downgrade4.test.ts index 3b71a8ff1..617d577c7 100644 --- a/server/tests/attach/downgrade/downgrade4.test.ts +++ b/server/tests/attach/downgrade/downgrade4.test.ts @@ -8,14 +8,14 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.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 { advanceMonths } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/expectUtils/expectScheduleUtils.js"; +import { advanceMonths } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/attach/downgrade/downgrade5.test.ts b/server/tests/attach/downgrade/downgrade5.test.ts index 905c345f7..94951c0f7 100644 --- a/server/tests/attach/downgrade/downgrade5.test.ts +++ b/server/tests/attach/downgrade/downgrade5.test.ts @@ -1,19 +1,19 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { CusProductStatus } from "@autumn/shared"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { advanceTestClock } from "@/utils/scriptUtils/testClockUtils.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import { - sharedProProduct, - sharedPremiumProduct, initDowngradeSharedProducts, + sharedPremiumProduct, + sharedProProduct, } from "./sharedProducts.js"; const testCase = "downgrade5"; @@ -60,7 +60,6 @@ describe(`${chalk.yellowBright(`${testCase}: testing basic downgrade (paid to pa expectCustomerV0Correct({ sent: sharedPremiumProduct, cusRes: res, - ctx, }); const { products: resProducts } = res; @@ -90,7 +89,6 @@ describe(`${chalk.yellowBright(`${testCase}: testing basic downgrade (paid to pa expectCustomerV0Correct({ sent: sharedPremiumProduct, cusRes: res, - ctx, }); }); diff --git a/server/tests/attach/downgrade/downgrade6.test.ts b/server/tests/attach/downgrade/downgrade6.test.ts index 06e8ec128..0d9c1bb0d 100644 --- a/server/tests/attach/downgrade/downgrade6.test.ts +++ b/server/tests/attach/downgrade/downgrade6.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, test } from "bun:test"; import type { Customer } from "@autumn/shared"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import { diff --git a/server/tests/attach/downgrade/downgrade7.test.ts b/server/tests/attach/downgrade/downgrade7.test.ts index 3640e511d..4e294176d 100644 --- a/server/tests/attach/downgrade/downgrade7.test.ts +++ b/server/tests/attach/downgrade/downgrade7.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import type { Customer } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { getSubsFromCusId } from "tests/utils/expectUtils/expectSubUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { getSubsFromCusId } from "@tests/utils/expectUtils/expectSubUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import { diff --git a/server/tests/attach/downgrade/sharedProducts.ts b/server/tests/attach/downgrade/sharedProducts.ts index b6bc7fba7..979f49c65 100644 --- a/server/tests/attach/downgrade/sharedProducts.ts +++ b/server/tests/attach/downgrade/sharedProducts.ts @@ -1,6 +1,6 @@ import { BillingInterval, ProductItemInterval } from "@autumn/shared"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/entities/entity1.test.ts b/server/tests/attach/entities/entity1.test.ts index 190cf9c9c..feba0ad7b 100644 --- a/server/tests/attach/entities/entity1.test.ts +++ b/server/tests/attach/entities/entity1.test.ts @@ -1,10 +1,10 @@ import { beforeAll, describe, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/entities/entity2.test.ts b/server/tests/attach/entities/entity2.test.ts index 1d7117448..1d9aee1fa 100644 --- a/server/tests/attach/entities/entity2.test.ts +++ b/server/tests/attach/entities/entity2.test.ts @@ -1,14 +1,14 @@ import { beforeAll, describe, test } from "bun:test"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; -import { defaultApiVersion } from "tests/constants.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { expectInvoiceAfterUsage } from "tests/utils/expectUtils/expectSingleUse/expectUsageInvoice.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { defaultApiVersion } from "@tests/constants.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectFeaturesCorrect } from "@tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectInvoiceAfterUsage } from "@tests/utils/expectUtils/expectSingleUse/expectUsageInvoice.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/entities/entity3.test.ts b/server/tests/attach/entities/entity3.test.ts index 7dd97d0a8..e87f1a911 100644 --- a/server/tests/attach/entities/entity3.test.ts +++ b/server/tests/attach/entities/entity3.test.ts @@ -1,13 +1,13 @@ import { beforeAll, describe, test } from "bun:test"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; -import { defaultApiVersion } from "tests/constants.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectInvoiceAfterUsage } from "tests/utils/expectUtils/expectSingleUse/expectUsageInvoice.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { defaultApiVersion } from "@tests/constants.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectInvoiceAfterUsage } from "@tests/utils/expectUtils/expectSingleUse/expectUsageInvoice.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/entities/entity4.test.ts b/server/tests/attach/entities/entity4.test.ts index 8eaab1e91..db30fecfa 100644 --- a/server/tests/attach/entities/entity4.test.ts +++ b/server/tests/attach/entities/entity4.test.ts @@ -1,10 +1,10 @@ import { beforeAll, describe, test } from "bun:test"; import chalk from "chalk"; -import { defaultApiVersion } from "tests/constants.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 ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { defaultApiVersion } from "@tests/constants.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/entities/entity5.test.ts b/server/tests/attach/entities/entity5.test.ts index 1b0781513..60685972a 100644 --- a/server/tests/attach/entities/entity5.test.ts +++ b/server/tests/attach/entities/entity5.test.ts @@ -2,12 +2,12 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { CusProductStatus } from "@autumn/shared"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; -import { defaultApiVersion } from "tests/constants.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { defaultApiVersion } from "@tests/constants.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/free/free1.test.ts b/server/tests/attach/free/free1.test.ts index 19c9814d3..d2d5c3f5d 100644 --- a/server/tests/attach/free/free1.test.ts +++ b/server/tests/attach/free/free1.test.ts @@ -1,14 +1,16 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { + type ApiCusProductV3, + type ApiCustomerV3, CreateFreeTrialSchema, CusProductStatus, FreeTrialDuration, LegacyVersion, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addDays } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; @@ -85,7 +87,9 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and }); const customer = await autumn.customers.get(customerId); - const freeProduct = customer.products.find((p) => p.id === free.id); + const freeProduct = customer.products.find( + (p) => p.id === free.id, + ) as ApiCusProductV3; expect(freeProduct).toBeDefined(); expect(freeProduct?.status).toBe(CusProductStatus.Trialing); @@ -118,7 +122,9 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and }); const customer = await autumn.customers.get(customerId); - const freeProduct = customer.products.find((p) => p.id === free.id); + const freeProduct = customer.products.find( + (p) => p.id === free.id, + ) as ApiCusProductV3; expect(freeProduct?.status).toBe(CusProductStatus.Trialing); expect(freeProduct?.current_period_end).toBeGreaterThanOrEqual( @@ -140,7 +146,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing free product with trial and product_id: addOn.id, }); - const customer = await autumn.customers.get(customerId); + const customer = (await autumn.customers.get(customerId)) as ApiCustomerV3; const addOnProduct = customer.products.find((p) => p.id === addOn.id); const freeProduct = customer.products.find((p) => p.id === free.id); diff --git a/server/tests/attach/free/free2.test.ts b/server/tests/attach/free/free2.test.ts index 10b3a354f..76f490bd7 100644 --- a/server/tests/attach/free/free2.test.ts +++ b/server/tests/attach/free/free2.test.ts @@ -1,10 +1,10 @@ import { beforeAll, describe, test } from "bun:test"; import { BillingInterval, LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/migrations/migration1.test.ts b/server/tests/attach/migrations/migration1.test.ts index a9c5213b0..fd80dd269 100644 --- a/server/tests/attach/migrations/migration1.test.ts +++ b/server/tests/attach/migrations/migration1.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, test } from "bun:test"; import type { LimitedItem, ProductV2 } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { defaultApiVersion } from "tests/constants.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { defaultApiVersion } from "@tests/constants.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/migrations/migration1.ts b/server/tests/attach/migrations/migration1.ts index 2a5ebf738..aa9358da1 100644 --- a/server/tests/attach/migrations/migration1.ts +++ b/server/tests/attach/migrations/migration1.ts @@ -6,11 +6,11 @@ import type { } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { setupBefore } from "tests/before.js"; -import { defaultApiVersion } from "tests/constants.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { createProducts } from "tests/utils/productUtils.js"; +import { setupBefore } from "@tests/before.js"; +import { defaultApiVersion } from "@tests/constants.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"; diff --git a/server/tests/attach/migrations/migration2.test.ts b/server/tests/attach/migrations/migration2.test.ts index d3b08d81c..080c4f324 100644 --- a/server/tests/attach/migrations/migration2.test.ts +++ b/server/tests/attach/migrations/migration2.test.ts @@ -6,11 +6,11 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { defaultApiVersion } from "tests/constants.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { defaultApiVersion } from "@tests/constants.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/migrations/migration3.test.ts b/server/tests/attach/migrations/migration3.test.ts index 53deb2b1f..6e5c05761 100644 --- a/server/tests/attach/migrations/migration3.test.ts +++ b/server/tests/attach/migrations/migration3.test.ts @@ -3,11 +3,11 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addDays } from "date-fns"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { defaultApiVersion } from "tests/constants.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { defaultApiVersion } from "@tests/constants.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/migrations/migration4.test.ts b/server/tests/attach/migrations/migration4.test.ts index 9232ae5a8..05ce2a571 100644 --- a/server/tests/attach/migrations/migration4.test.ts +++ b/server/tests/attach/migrations/migration4.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; -import { defaultApiVersion } from "tests/constants.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { defaultApiVersion } from "@tests/constants.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/migrations/runMigrationTest.ts b/server/tests/attach/migrations/runMigrationTest.ts index 61967a786..1358e85a6 100644 --- a/server/tests/attach/migrations/runMigrationTest.ts +++ b/server/tests/attach/migrations/runMigrationTest.ts @@ -5,16 +5,16 @@ import { AppEnv } from "autumn-js"; import { expectSubItemsCorrect, getSubsFromCusId, -} from "tests/utils/expectUtils/expectSubUtils.js"; +} from "@tests/utils/expectUtils/expectSubUtils.js"; import Stripe from "stripe"; import { expect } from "bun:test"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; -import { expectResetAtCorrect } from "tests/utils/expectUtils/expectAttach/expectResetAtCorrect.js"; +import { expectFeaturesCorrect } from "@tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectResetAtCorrect } from "@tests/utils/expectUtils/expectAttach/expectResetAtCorrect.js"; import { isFreeProductV2 } from "@/internal/products/productUtils/classifyProduct.js"; -import { expectTrialEndsAtCorrect } from "tests/utils/expectUtils/expectAttach/expectTrialEndsAt.js"; +import { expectTrialEndsAtCorrect } from "@tests/utils/expectUtils/expectAttach/expectTrialEndsAt.js"; import { timeout } from "@/utils/genUtils.js"; import { subToPeriodStartEnd } from "@/external/stripe/stripeSubUtils/convertSubUtils.js"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; export const expectSubsSame = ({ subsBefore, diff --git a/server/tests/attach/misc/attach-misc1.test.ts b/server/tests/attach/misc/attach-misc1.test.ts index 1e8831541..7cc85dd6c 100644 --- a/server/tests/attach/misc/attach-misc1.test.ts +++ b/server/tests/attach/misc/attach-misc1.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/multiProduct/multiProduct1.test.ts b/server/tests/attach/multiProduct/multiProduct1.test.ts index 865e27c06..7a02f45b4 100644 --- a/server/tests/attach/multiProduct/multiProduct1.test.ts +++ b/server/tests/attach/multiProduct/multiProduct1.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, test } from "bun:test"; import chalk from "chalk"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; diff --git a/server/tests/attach/multiProduct/sharedProducts.ts b/server/tests/attach/multiProduct/sharedProducts.ts deleted file mode 100644 index b4deee1bc..000000000 --- a/server/tests/attach/multiProduct/sharedProducts.ts +++ /dev/null @@ -1,173 +0,0 @@ -import { BillingInterval, ProductItemInterval } from "@autumn/shared"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; -import { - constructFeatureItem, - constructArrearItem, -} from "@/utils/scriptUtils/constructItem.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { createSharedProducts } from "@/utils/scriptUtils/testUtils/createSharedProduct.js"; - -/** - * Shared products for multiProduct test group - * Matches global attachProducts.{proGroup1, premiumGroup1, proGroup2, premiumGroup2, etc.} - */ - -// Group 1 products (use Messages feature) -export const sharedProGroup1 = constructProduct({ - id: "proGroup1", - group: "g1", - type: "pro", - items: [ - constructFeatureItem({ - featureId: TestFeature.Messages, - includedUsage: 10, - interval: ProductItemInterval.Month, - }), - constructPriceItem({ - price: 3000, // $30 - interval: BillingInterval.Month, - }), - constructArrearItem({ - featureId: TestFeature.Messages, - pricePerUnit: 100, // $1.00 per unit - }), - ], -}); - -export const sharedPremiumGroup1 = constructProduct({ - id: "premiumGroup1", - group: "g1", - type: "premium", - items: [ - constructFeatureItem({ - featureId: TestFeature.Messages, - includedUsage: 100, - interval: ProductItemInterval.Month, - }), - constructPriceItem({ - price: 5000, // $50 - interval: BillingInterval.Month, - }), - constructArrearItem({ - featureId: TestFeature.Messages, - pricePerUnit: 200, // $2.00 per unit - }), - ], -}); - -export const sharedStarterGroup1 = constructProduct({ - id: "starterGroup1", - group: "g1", - type: "starter", - items: [ - constructFeatureItem({ - featureId: TestFeature.Messages, - includedUsage: 10, - interval: ProductItemInterval.Month, - }), - constructPriceItem({ - price: 1000, // $10 - interval: BillingInterval.Month, - }), - constructArrearItem({ - featureId: TestFeature.Messages, - pricePerUnit: 50, // $0.50 per unit - }), - ], -}); - -// Group 2 products (use Words feature) -export const sharedProGroup2 = constructProduct({ - id: "proGroup2", - group: "g2", - type: "pro", - items: [ - constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 10, - interval: ProductItemInterval.Month, - }), - constructPriceItem({ - price: 4000, // $40 - interval: BillingInterval.Month, - }), - constructArrearItem({ - featureId: TestFeature.Words, - pricePerUnit: 60, // $0.60 per unit - }), - ], -}); - -export const sharedPremiumGroup2 = constructProduct({ - id: "premiumGroup2", - group: "g2", - type: "premium", - items: [ - constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 10, - interval: ProductItemInterval.Month, - }), - constructPriceItem({ - price: 6000, // $60 - interval: BillingInterval.Month, - }), - constructArrearItem({ - featureId: TestFeature.Words, - pricePerUnit: 90, // $0.90 per unit - }), - ], -}); - -export const sharedStarterGroup2 = constructProduct({ - id: "starterGroup2", - group: "g2", - type: "starter", - items: [ - constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 10, - interval: ProductItemInterval.Month, - }), - constructPriceItem({ - price: 2000, // $20 - interval: BillingInterval.Month, - }), - constructArrearItem({ - featureId: TestFeature.Words, - pricePerUnit: 30, // $0.30 per unit - }), - ], -}); - -export const sharedFreeGroup2 = constructProduct({ - id: "freeGroup2", - group: "g2", - type: "free", - items: [ - constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 10, - }), - ], -}); - -export const initMultiProductSharedProducts = async () => { - await createSharedProducts({ - ctx, - products: [ - sharedProGroup1, - sharedPremiumGroup1, - sharedStarterGroup1, - sharedProGroup2, - sharedPremiumGroup2, - sharedStarterGroup2, - sharedFreeGroup2, - ], - }); -}; - -// Auto-init on import (backwards compat) -await initMultiProductSharedProducts(); diff --git a/server/tests/attach/newVersion/newVersion1.test.ts b/server/tests/attach/newVersion/newVersion1.test.ts index 9298dd902..117222bd5 100644 --- a/server/tests/attach/newVersion/newVersion1.test.ts +++ b/server/tests/attach/newVersion/newVersion1.test.ts @@ -1,17 +1,13 @@ -import { - BillingInterval, - LegacyVersion, - type ProductV2, -} from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; +import { BillingInterval, LegacyVersion, type ProductV2 } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addHours, addMonths, addWeeks } from "date-fns"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/attach/newVersion/newVersion2.test.ts b/server/tests/attach/newVersion/newVersion2.test.ts index aa3f59c2f..19d37b6e0 100644 --- a/server/tests/attach/newVersion/newVersion2.test.ts +++ b/server/tests/attach/newVersion/newVersion2.test.ts @@ -5,9 +5,9 @@ import { } from "@autumn/shared"; import { beforeAll, describe, test } from "bun:test"; import chalk from "chalk"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/newVersion/newVersion3.test.ts b/server/tests/attach/newVersion/newVersion3.test.ts index cc002d76a..9a57379f1 100644 --- a/server/tests/attach/newVersion/newVersion3.test.ts +++ b/server/tests/attach/newVersion/newVersion3.test.ts @@ -5,16 +5,16 @@ // 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 { setupBefore } from "@tests/before.js"; +// import { createProducts } from "@tests/utils/productUtils.js"; // import { addPrefixToProducts } from "../utils.js"; // import { constructRawProduct } from "@/utils/scriptUtils/createTestProducts.js"; // import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; -// import { TestFeature } from "tests/setup/v2Features.js"; +// import { TestFeature } from "@tests/setup/v2Features.js"; // import { replaceItems } from "../utils.js"; -// import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -// import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -// import { defaultApiVersion } from "tests/constants.js"; +// import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +// import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +// import { defaultApiVersion } from "@tests/constants.js"; // export let pro = constructRawProduct({ // id: "pro", diff --git a/server/tests/attach/others/others1.backup.ts b/server/tests/attach/others/others1.backup.ts deleted file mode 100644 index 059295f26..000000000 --- a/server/tests/attach/others/others1.backup.ts +++ /dev/null @@ -1,128 +0,0 @@ -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 { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { - expectDowngradeCorrect, - expectNextCycleCorrect, -} 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 { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { addPrefixToProducts } from "../utils.js"; - -const testCase = "others1"; - -export const free = constructProduct({ - items: [], - type: "free", - isDefault: false, -}); - -export const pro = constructProduct({ - items: [], - type: "pro", - trial: true, -}); - -export const premium = constructProduct({ - items: [], - type: "premium", - trial: true, -}); - -describe(`${chalk.yellowBright(`${testCase}: Testing trials: pro with trial -> premium with trial -> free`)}`, () => { - 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; - - const curUnix = new Date().getTime(); - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [free, pro, premium], - prefix: testCase, - }); - - await createProducts({ - autumn, - products: [free, pro, premium], - db, - orgId: org.id, - env, - customerId, - }); - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = testClockId1!; - }); - - it("should attach pro product (with trial)", async () => { - await attachAndExpectCorrect({ - autumn, - stripeCli, - customerId, - product: pro, - db, - org, - env, - }); - }); - - it("should attach premium product (with trial)", async () => { - await attachAndExpectCorrect({ - autumn, - stripeCli, - customerId, - product: premium, - db, - org, - env, - }); - }); - - it("should attach free product at the end of the trial", async () => { - const { preview } = await expectDowngradeCorrect({ - autumn, - stripeCli, - customerId, - curProduct: premium, - newProduct: free, - db, - org, - env, - }); - expectNextCycleCorrect({ - autumn, - preview, - stripeCli, - customerId, - testClockId, - product: free, - db, - org, - env, - }); - }); -}); diff --git a/server/tests/attach/others/others1.test.ts b/server/tests/attach/others/others1.test.ts index 568eea815..57b4af188 100644 --- a/server/tests/attach/others/others1.test.ts +++ b/server/tests/attach/others/others1.test.ts @@ -2,12 +2,12 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; import { expectDowngradeCorrect, expectNextCycleCorrect, -} from "tests/utils/expectUtils/expectScheduleUtils.js"; +} from "@tests/utils/expectUtils/expectScheduleUtils.js"; import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; diff --git a/server/tests/attach/others/others2.backup.ts b/server/tests/attach/others/others2.backup.ts deleted file mode 100644 index 16f2aa0df..000000000 --- a/server/tests/attach/others/others2.backup.ts +++ /dev/null @@ -1,144 +0,0 @@ -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 { 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 const oneOff = constructProduct({ - type: "one_off", - items: [ - constructPrepaidItem({ - isOneOff: true, - featureId: TestFeature.Messages, - price: 8, - billingUnits: 250, - }), - ], -}); - -describe(`${chalk.yellowBright(`${testCase}: Testing one-off`)}`, () => { - 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; - - const curUnix = new Date().getTime(); - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [oneOff], - prefix: testCase, - }); - - await createProducts({ - autumn, - products: [oneOff], - db, - orgId: org.id, - env, - customerId, - }); - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = testClockId1!; - }); - - const options = [ - { - feature_id: TestFeature.Messages, - quantity: 500, - }, - ]; - - it("should attach one-off product", async () => { - await attachAndExpectCorrect({ - autumn, - stripeCli, - customerId, - product: oneOff, - db, - org, - env, - options, - }); - }); - - const options2 = [ - { - feature_id: TestFeature.Messages, - quantity: 750, - }, - ]; - it("should be able to attach again", async () => { - await attachAndExpectCorrect({ - autumn, - stripeCli, - customerId, - product: oneOff, - db, - org, - env, - options: options2, - skipFeatureCheck: true, - }); - - const totalBalance = options[0].quantity + options2[0].quantity; - const customer = await autumn.customers.get(customerId); - - const balance = customer.features[TestFeature.Messages].balance; - expect(balance).to.equal(totalBalance, "balance should be correct"); - }); - - // Payment failure - it("should handle payment failure", async () => { - const customer = await CusService.get({ - db, - idOrInternalId: customerId, - orgId: org.id, - env, - }); - - await attachFailedPaymentMethod({ - stripeCli, - customer: customer!, - }); - - const res = await autumn.attach({ - customer_id: customerId, - product_id: oneOff.id, - options, - }); - - expect(res.checkout_url).to.exist; - }); -}); diff --git a/server/tests/attach/others/others2.test.ts b/server/tests/attach/others/others2.test.ts index 54e5fb8c7..c58da7844 100644 --- a/server/tests/attach/others/others2.test.ts +++ b/server/tests/attach/others/others2.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { attachFailedPaymentMethod } from "@/external/stripe/stripeCusUtils.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/attach/others/others3.backup.ts b/server/tests/attach/others/others3.backup.ts deleted file mode 100644 index 257f0322d..000000000 --- a/server/tests/attach/others/others3.backup.ts +++ /dev/null @@ -1,88 +0,0 @@ -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 { 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 { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -import { addPrefixToProducts } from "../utils.js"; - -const testCase = "others3"; - -export const pro = constructProduct({ - type: "pro", - items: [], -}); - -describe(`${chalk.yellowBright(`${testCase}: Testing attach payment failure`)}`, () => { - const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - let testClockId: string; - let db: DrizzleCli, org: Organization, env: AppEnv; - let stripeCli: Stripe; - - const curUnix = new Date().getTime(); - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - autumn, - products: [pro], - db, - orgId: org.id, - env, - customerId, - }); - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = testClockId1!; - }); - - // Payment failure - it("should handle payment failure", async () => { - const customer = await CusService.get({ - db, - idOrInternalId: customerId, - orgId: org.id, - env, - }); - - await attachFailedPaymentMethod({ - stripeCli, - customer: customer!, - }); - - const res = await autumn.attach({ - customer_id: customerId, - product_id: pro.id, - }); - - // console.log(res); - - expect(res.checkout_url).to.exist; - }); -}); diff --git a/server/tests/attach/others/others3.test.ts b/server/tests/attach/others/others3.test.ts index ddc246121..e6329133d 100644 --- a/server/tests/attach/others/others3.test.ts +++ b/server/tests/attach/others/others3.test.ts @@ -2,7 +2,7 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; diff --git a/server/tests/attach/others/others4.backup.ts b/server/tests/attach/others/others4.backup.ts deleted file mode 100644 index 29a18002a..000000000 --- a/server/tests/attach/others/others4.backup.ts +++ /dev/null @@ -1,161 +0,0 @@ -// import { assert } from "chai"; -// import { features, products } from "tests/global.js"; -// import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; -// import { getPublicAxiosInstance } from "tests/utils/setup.js"; -// import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -// import { timeout } from "tests/utils/genUtils.js"; -// import { ErrCode } from "@autumn/shared"; -// import { compareMainProduct } from "tests/utils/compare.js"; -// import { AutumnCli } from "tests/cli/AutumnCli.js"; -// import chalk from "chalk"; -// import { setupBefore } from "tests/before.js"; - -// const testCase = "others4"; -// describe(`${chalk.yellowBright("others4: Testing publishable key")}`, () => { -// // 1. Initialize customer with card -// let customerId = testCase; -// const bearerPublicAxios = getPublicAxiosInstance({ -// withBearer: true, -// }); - -// before(async function () { -// await setupBefore(this); -// await initCustomer({ -// customerId, -// db: this.db, -// org: this.org, -// env: this.env, -// autumn: this.autumnJs, -// }); -// }); - -// it("should return a 401 if the pkey is invalid", async function () { -// this.timeout(30000); -// const axiosInstance = getPublicAxiosInstance({ -// withBearer: true, -// pkey: "am_pk_test_invalid", -// }); - -// try { -// const { data } = await axiosInstance.post("/v1/attach", { -// customer_id: customerId, -// product_id: products.pro.id, -// }); - -// throw new Error("Should not be able to attach"); -// } catch (error: any) { -// assert.equal(error.response.status, 401); -// } -// }); - -// it("should return checkout URL for both bearer key", async function () { -// this.timeout(30000); -// const axiosInstanceBearer = getPublicAxiosInstance({ -// withBearer: true, -// }); - -// // 1. Should be able to upgrade to pro -// const { data } = await axiosInstanceBearer.post("/v1/attach", { -// customer_id: customerId, -// product_id: products.pro.id, -// }); - -// assert.exists(data.checkout_url); - -// await completeCheckoutForm(data.checkout_url); - -// await timeout(5000); -// }); - -// it("should have customer with product", async function () { -// this.timeout(30000); -// const res = await AutumnCli.getCustomer(customerId); -// compareMainProduct({ -// sent: products.pro, -// cusRes: res, -// }); -// }); - -// it("should return error if try to upgrade or downgrade without pkey", async function () { -// this.timeout(30000); -// const axiosInstance = getPublicAxiosInstance({ -// withBearer: true, -// }); - -// try { -// await axiosInstance.post("/v1/attach", { -// customer_id: customerId, -// product_id: products.premium.id, -// }); - -// throw new Error("Should not be able to attach"); -// } catch (error: any) { -// assert.equal(error.response.status, 400); -// assert.equal(error.response.data.code, ErrCode.InvalidRequest); -// } -// }); - -// it("should return error if try to downgrade to free", async function () { -// try { -// await bearerPublicAxios.post("/v1/attach", { -// customer_id: customerId, -// product_id: products.free.id, -// }); - -// throw new Error("Should not be able to attach"); -// } catch (error: any) { -// assert.equal(error.response.status, 400); -// assert.equal(error.response.data.code, ErrCode.InvalidRequest); -// } -// }); - -// // Next, check entitled for pro -// it("should return correct metered1 amount for pro", async function () { -// const { data } = await bearerPublicAxios.post("/v1/entitled", { -// customer_id: customerId, -// feature_id: features.metered1.id, -// }); - -// assert.equal(data.allowed, true); -// const metered1Balance = data.balances.find( -// (b: any) => b.feature_id === features.metered1.id, -// ); -// assert.equal( -// metered1Balance.balance, -// products.pro.entitlements.metered1.allowance, -// ); -// }); - -// it("should return same balance for entitled with bearer and x-publishable-key", async function () { -// const { data } = await bearerPublicAxios.post("/v1/entitled", { -// customer_id: customerId, -// feature_id: features.metered1.id, -// }); - -// assert.equal(data.allowed, true); -// const metered1Balance = data.balances.find( -// (b: any) => b.feature_id === features.metered1.id, -// ); -// assert.equal( -// metered1Balance.balance, -// products.pro.entitlements.metered1.allowance, -// ); -// }); - -// it("should return error when try to send event", async function () { -// try { -// await bearerPublicAxios.post("/v1/events", { -// customer_id: customerId, -// event_name: features.metered1.id, -// properties: { -// value: 10, -// }, -// }); - -// throw new Error("Should not be able to send event"); -// } catch (error: any) { -// assert.equal(error.response.status, 401); -// assert.equal(error.response.data.code, ErrCode.EndpointNotPublic); -// } -// }); -// }); diff --git a/server/tests/attach/others/others6.backup.ts b/server/tests/attach/others/others6.backup.ts deleted file mode 100644 index 86fc70d14..000000000 --- a/server/tests/attach/others/others6.backup.ts +++ /dev/null @@ -1,134 +0,0 @@ -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 { 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 const pro = constructProduct({ - items: [constructArrearItem({ featureId: TestFeature.Words })], - type: "pro", -}); - -const testCase = "others6"; - -describe(`${chalk.yellowBright(`${testCase}: Testing attach with customer ID and entity ID null`)}`, () => { - 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; - - const email = `${customerId}@test.com`; - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - const customer = await CusService.getByEmail({ - db, - orgId: org.id, - env, - email, - }); - - if (customer.length > 0) { - await autumn.customers.delete(customer[0].internal_id); - } - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - db, - orgId: org.id, - env, - autumn, - products: [pro], - }); - }); - - let internalCustomerId = ""; - let internalEntityId = ""; - 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, - }); - - expect(customer.autumn_id, "Customer ID should exist").to.exist; - - internalCustomerId = customer.autumn_id; - - const data = await autumn.entities.create(internalCustomerId, { - // @ts-expect-error - id: null, - feature_id: TestFeature.Users, - }); - - internalEntityId = data.autumn_id; - - expect(internalEntityId, "Entity ID should exist").to.exist; - }); - - it("should be able to attach pro product, invoice only", async () => { - await autumn.attach({ - customer_id: internalCustomerId, - entity_id: internalEntityId, - product_id: pro.id, - invoice: true, - enable_product_immediately: true, - }); - - const customer = await autumn.customers.get(internalCustomerId); - - expectAttachCorrect({ - customer, - product: pro, - }); - - expect(customer.invoices.length).to.equal(1); - expect(customer.invoices[0].status).to.equal("draft"); - }); - - 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); - - const entity = await autumn.entities.create(customer.autumn_id, { - id: entityId, - feature_id: TestFeature.Users, - }); - - internalEntityId = entity.autumn_id; - - const customer2 = await autumn.customers.get(customerId); - - expectAttachCorrect({ - customer: customer2, - product: pro, - entityId, - }); - }); -}); diff --git a/server/tests/attach/others/others6.test.ts b/server/tests/attach/others/others6.test.ts index da1cc3313..58dc7d79b 100644 --- a/server/tests/attach/others/others6.test.ts +++ b/server/tests/attach/others/others6.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectAttachCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; @@ -47,7 +47,6 @@ describe(`${chalk.yellowBright(`${testCase}: Testing attach with customer ID and const entityId = "1"; test("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, diff --git a/server/tests/attach/others/others7.backup.ts b/server/tests/attach/others/others7.backup.ts deleted file mode 100644 index 881110ac7..000000000 --- a/server/tests/attach/others/others7.backup.ts +++ /dev/null @@ -1,80 +0,0 @@ -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 { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.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 const pro = constructProduct({ - items: [constructArrearItem({ featureId: TestFeature.Words })], - type: "pro", - trial: true, -}); - -const testCase = "others7"; - -describe(`${chalk.yellowBright(`${testCase}: Testing attach with free_trial=False`)}`, () => { - const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - let db: DrizzleCli, org: Organization, env: AppEnv; - let stripeCli: Stripe; - - before(async function () { - await setupBefore(this); - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - await initCustomer({ - db, - org, - env, - autumn: this.autumnJs, - customerId, - fingerprint: "test", - attachPm: "success", - }); - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - db, - orgId: org.id, - env, - autumn, - products: [pro], - }); - }); - - it("should attach pro product with free_trial=False", async () => { - await autumn.attach({ - customer_id: customerId, - product_id: pro.id, - free_trial: false, - }); - - const customer = await autumn.customers.get(customerId); - - expectAttachCorrect({ - customer, - product: pro, - }); - - expect(customer.invoices.length).to.equal(1); - expect(customer.invoices[0].total).to.equal(getBasePrice({ product: pro })); - }); -}); diff --git a/server/tests/attach/others/others7.test.ts b/server/tests/attach/others/others7.test.ts index 3fdcce2fc..b1b9f42e3 100644 --- a/server/tests/attach/others/others7.test.ts +++ b/server/tests/attach/others/others7.test.ts @@ -2,12 +2,12 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectAttachCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectAttachCorrect } from "@tests/utils/expectUtils/expectAttach.js"; import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.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"; diff --git a/server/tests/attach/others/others8.backup.ts b/server/tests/attach/others/others8.backup.ts deleted file mode 100644 index f33d9b75a..000000000 --- a/server/tests/attach/others/others8.backup.ts +++ /dev/null @@ -1,105 +0,0 @@ -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 { 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 { - constructFeatureItem, - 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"; - -export const pro = constructProduct({ - items: [ - constructFeatureItem({ - featureId: TestFeature.Words, - }), - constructPrepaidItem({ - isOneOff: true, - featureId: TestFeature.Users, - billingUnits: 1, - price: 100, - }), - ], - isAnnual: true, - type: "pro", -}); - -const testCase = "others8"; - -describe(`${chalk.yellowBright(`${testCase}: Testing annual pro with one off prepaid`)}`, () => { - const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - let db: DrizzleCli, org: Organization, env: AppEnv; - let stripeCli: Stripe; - - before(async function () { - await setupBefore(this); - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - await initCustomer({ - db, - org, - env, - autumn: this.autumnJs, - customerId, - fingerprint: "test", - attachPm: "success", - }); - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - db, - orgId: org.id, - env, - autumn, - products: [pro], - }); - }); - - it("should attach annual pro product with one off prepaid", async () => { - const options = [ - { - feature_id: TestFeature.Users, - quantity: 1, - }, - ]; - - const preview = await autumn.attachPreview({ - customer_id: customerId, - product_id: pro.id, - options, - }); - - await autumn.attach({ - customer_id: customerId, - product_id: pro.id, - options, - }); - - console.log(preview); - - const customer = await autumn.customers.get(customerId); - - const invoice = customer.invoices[0]; - // expect(preview.total).to.equal(invoice.total); - expect(invoice.total).to.equal( - getBasePrice({ product: pro }) + options[0].quantity * 100, - ); - }); -}); diff --git a/server/tests/attach/others/others8.test.ts b/server/tests/attach/others/others8.test.ts index 86f4127ed..bea79292a 100644 --- a/server/tests/attach/others/others8.test.ts +++ b/server/tests/attach/others/others8.test.ts @@ -2,11 +2,11 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import { getBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { diff --git a/server/tests/attach/others/others9.backup.ts b/server/tests/attach/others/others9.backup.ts deleted file mode 100644 index 14edf188c..000000000 --- a/server/tests/attach/others/others9.backup.ts +++ /dev/null @@ -1,92 +0,0 @@ -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 { 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 { 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: [ - constructFeatureItem({ - featureId: TestFeature.Words, - }), - ], - isAnnual: false, - type: "free", - isDefault: false, -}); - -// Pro trial - -// Pro - -const testCase = "others9"; - -describe(`${chalk.yellowBright(`${testCase}: Testing attach free product again`)}`, () => { - const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - let db: DrizzleCli, org: Organization, env: AppEnv; - let stripeCli: Stripe; - - before(async function () { - await setupBefore(this); - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - await initCustomer({ - db, - org, - env, - autumn: this.autumnJs, - customerId, - fingerprint: "test", - attachPm: "success", - }); - - addPrefixToProducts({ - products: [free], - prefix: testCase, - }); - - await createProducts({ - db, - orgId: org.id, - env, - autumn, - products: [free], - }); - }); - - it("should attach free product, then try again and hit error", async () => { - await attachAndExpectCorrect({ - autumn, - customerId, - product: free, - stripeCli, - db, - org, - env, - skipSubCheck: true, - }); - - await expectAutumnError({ - func: async () => { - await autumn.attach({ - customer_id: customerId, - product_id: free.id, - }); - }, - }); - }); -}); diff --git a/server/tests/attach/others/others9.test.ts b/server/tests/attach/others/others9.test.ts index 2cd76137f..fe191e873 100644 --- a/server/tests/attach/others/others9.test.ts +++ b/server/tests/attach/others/others9.test.ts @@ -2,10 +2,10 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.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 { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; diff --git a/server/tests/attach/prepaid/prepaid1.backup.ts b/server/tests/attach/prepaid/prepaid1.backup.ts index ceb714e29..cddf0c365 100644 --- a/server/tests/attach/prepaid/prepaid1.backup.ts +++ b/server/tests/attach/prepaid/prepaid1.backup.ts @@ -10,12 +10,12 @@ 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 { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { createProducts } from "tests/utils/productUtils.js"; +import { setupBefore } from "@tests/before.js"; +import { TestFeature } from "@tests/setup/v2Features.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 { getMainCusProduct } from "@/internal/customers/cusProducts/cusProductUtils.js"; diff --git a/server/tests/attach/prepaid/prepaid1.test.ts b/server/tests/attach/prepaid/prepaid1.test.ts index be7c7aba0..19823e8e3 100644 --- a/server/tests/attach/prepaid/prepaid1.test.ts +++ b/server/tests/attach/prepaid/prepaid1.test.ts @@ -3,11 +3,11 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.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 { AutumnInt } from "@/external/autumn/autumnCli.js"; import { getMainCusProduct } from "@/internal/customers/cusProducts/cusProductUtils.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/prepaid/prepaid2.backup.ts b/server/tests/attach/prepaid/prepaid2.backup.ts index 6f1d241a6..aeca85de3 100644 --- a/server/tests/attach/prepaid/prepaid2.backup.ts +++ b/server/tests/attach/prepaid/prepaid2.backup.ts @@ -8,11 +8,11 @@ import { 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 { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { createProducts } from "tests/utils/productUtils.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 type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/prepaid/prepaid2.test.ts b/server/tests/attach/prepaid/prepaid2.test.ts index af81f156d..27f4cb5b9 100644 --- a/server/tests/attach/prepaid/prepaid2.test.ts +++ b/server/tests/attach/prepaid/prepaid2.test.ts @@ -3,10 +3,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.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 { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/prepaid/prepaid3.backup.ts b/server/tests/attach/prepaid/prepaid3.backup.ts index d14b645de..b98aee0b2 100644 --- a/server/tests/attach/prepaid/prepaid3.backup.ts +++ b/server/tests/attach/prepaid/prepaid3.backup.ts @@ -9,12 +9,12 @@ 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 { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { createProducts } from "tests/utils/productUtils.js"; +import { setupBefore } from "@tests/before.js"; +import { TestFeature } from "@tests/setup/v2Features.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"; diff --git a/server/tests/attach/prepaid/prepaid3.test.ts b/server/tests/attach/prepaid/prepaid3.test.ts index 5233d1404..3c89f6976 100644 --- a/server/tests/attach/prepaid/prepaid3.test.ts +++ b/server/tests/attach/prepaid/prepaid3.test.ts @@ -3,11 +3,11 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.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 { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/prepaid/prepaid4.backup.ts b/server/tests/attach/prepaid/prepaid4.backup.ts index 9a3ad00c6..6c58b4a32 100644 --- a/server/tests/attach/prepaid/prepaid4.backup.ts +++ b/server/tests/attach/prepaid/prepaid4.backup.ts @@ -9,12 +9,12 @@ 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 { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { createProducts } from "tests/utils/productUtils.js"; +import { setupBefore } from "@tests/before.js"; +import { TestFeature } from "@tests/setup/v2Features.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 { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/attach/prepaid/prepaid4.test.ts b/server/tests/attach/prepaid/prepaid4.test.ts index 12e685703..ac36c2ad7 100644 --- a/server/tests/attach/prepaid/prepaid4.test.ts +++ b/server/tests/attach/prepaid/prepaid4.test.ts @@ -3,11 +3,11 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.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 { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/prepaid/prepaid5.backup.ts b/server/tests/attach/prepaid/prepaid5.backup.ts index 4c73347e5..2be01fdaf 100644 --- a/server/tests/attach/prepaid/prepaid5.backup.ts +++ b/server/tests/attach/prepaid/prepaid5.backup.ts @@ -9,10 +9,10 @@ import { 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 { 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 { diff --git a/server/tests/attach/prepaid/prepaid5.test.ts b/server/tests/attach/prepaid/prepaid5.test.ts index 999aafb82..f12fa1c0b 100644 --- a/server/tests/attach/prepaid/prepaid5.test.ts +++ b/server/tests/attach/prepaid/prepaid5.test.ts @@ -2,9 +2,9 @@ import { type Customer, LegacyVersion, OnDecrease, OnIncrease } from "@autumn/sh import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem, diff --git a/server/tests/attach/prepaid/prepaid6.backup.ts b/server/tests/attach/prepaid/prepaid6.backup.ts index cf50e6202..3e5e89be3 100644 --- a/server/tests/attach/prepaid/prepaid6.backup.ts +++ b/server/tests/attach/prepaid/prepaid6.backup.ts @@ -10,12 +10,12 @@ 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 { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { createProducts } from "tests/utils/productUtils.js"; +import { setupBefore } from "@tests/before.js"; +import { TestFeature } from "@tests/setup/v2Features.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 { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/attach/prepaid/prepaid6.test.ts b/server/tests/attach/prepaid/prepaid6.test.ts index 0b13600d4..1fc43da68 100644 --- a/server/tests/attach/prepaid/prepaid6.test.ts +++ b/server/tests/attach/prepaid/prepaid6.test.ts @@ -3,11 +3,11 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; import type Stripe from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.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 { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/prepaid/prepaid7.backup.ts b/server/tests/attach/prepaid/prepaid7.backup.ts index 651bedf84..1cd1874b9 100644 --- a/server/tests/attach/prepaid/prepaid7.backup.ts +++ b/server/tests/attach/prepaid/prepaid7.backup.ts @@ -11,16 +11,16 @@ // 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 { setupBefore } from "@tests/before.js"; +// import { createProducts } from "@tests/utils/productUtils.js"; // import { addPrefixToProducts } from "../utils.js"; // import { // constructFeatureItem, // constructPrepaidItem, // } from "@/utils/scriptUtils/constructItem.js"; -// import { TestFeature } from "tests/setup/v2Features.js"; +// import { TestFeature } from "@tests/setup/v2Features.js"; // import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -// import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +// import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; // import { expect } from "chai"; // const testCase = "prepaid6"; diff --git a/server/tests/attach/prepaid/prepaid7.ts b/server/tests/attach/prepaid/prepaid7.ts index 651bedf84..1cd1874b9 100644 --- a/server/tests/attach/prepaid/prepaid7.ts +++ b/server/tests/attach/prepaid/prepaid7.ts @@ -11,16 +11,16 @@ // 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 { setupBefore } from "@tests/before.js"; +// import { createProducts } from "@tests/utils/productUtils.js"; // import { addPrefixToProducts } from "../utils.js"; // import { // constructFeatureItem, // constructPrepaidItem, // } from "@/utils/scriptUtils/constructItem.js"; -// import { TestFeature } from "tests/setup/v2Features.js"; +// import { TestFeature } from "@tests/setup/v2Features.js"; // import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -// import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +// import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; // import { expect } from "chai"; // const testCase = "prepaid6"; diff --git a/server/tests/attach/renew/renew1.ts b/server/tests/attach/renew/renew1.ts index d29b9fc89..3a4a38c7a 100644 --- a/server/tests/attach/renew/renew1.ts +++ b/server/tests/attach/renew/renew1.ts @@ -7,11 +7,11 @@ import { 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 { 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"; diff --git a/server/tests/attach/updateEnts/expectUpdateEnts.ts b/server/tests/attach/updateEnts/expectUpdateEnts.ts new file mode 100644 index 000000000..f337eac6f --- /dev/null +++ b/server/tests/attach/updateEnts/expectUpdateEnts.ts @@ -0,0 +1,130 @@ +import { expect } from "bun:test"; +import { + type AppEnv, + AttachBranch, + type Organization, + type ProductItem, + type ProductV2, +} from "@autumn/shared"; +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 Stripe from "stripe"; +import type { DrizzleCli } from "@/db/initDrizzle.js"; +import type { AutumnInt } from "@/external/autumn/autumnCli.js"; + +const runUpdateEntsTest = async ({ + autumn, + stripeCli, + customerId, + customProduct, + newVersion, + db, + org, + env, + customItems, + usage, +}: { + autumn: AutumnInt; + stripeCli: Stripe; + customerId: string; + customProduct: ProductV2; + newVersion?: number; + db: DrizzleCli; + org: Organization; + env: AppEnv; + customItems?: ProductItem[]; + usage?: { + featureId: string; + value: number; + }[]; +}) => { + // 1. Get subs before + + const { subs: subsBefore } = await getSubsFromCusId({ + stripeCli, + customerId, + productId: customProduct.id, + db, + org, + env, + }); + + const preview = await autumn.attachPreview({ + customer_id: customerId, + product_id: customProduct.id, + version: newVersion, + is_custom: customItems ? true : undefined, + items: customItems, + }); + + if (newVersion) { + expect(preview.branch).toBe(AttachBranch.NewVersion); + } else { + expect(preview.branch).toBe(AttachBranch.SameCustomEnts); + expect(preview.due_today).toBeUndefined(); + } + + await autumn.attach({ + customer_id: customerId, + product_id: customProduct.id, + version: newVersion, + is_custom: customItems ? true : undefined, + items: customItems, + }); + + // 1. Ensure no new invoices created + const { subs: subsAfter, cusProduct } = await getSubsFromCusId({ + stripeCli, + customerId, + productId: customProduct.id, + db, + org, + env, + }); + + 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); + + expect(invoicesAfter).toStrictEqual(invoicesBefore); + expect(subIdsAfter).toStrictEqual(subIdsBefore); + // expect(periodEndsAfter).toStrictEqual(periodEndsBefore); + + if (customItems) { + expect(cusProduct.is_custom).toBe(true); + } + + const customer = await autumn.customers.get(customerId); + expectFeaturesCorrect({ + customer, + product: customProduct, + usage, + }); + + // 2. Expect product attached + await expectSubItemsCorrect({ + stripeCli, + customerId, + product: customProduct, + db, + org, + env, + }); + + await expectSubToBeCorrect({ + customerId, + db, + org, + env, + }); +}; + +export default runUpdateEntsTest; diff --git a/server/tests/attach/updateEnts/updateEnts1.test.ts b/server/tests/attach/updateEnts/updateEnts1.test.ts index 6e9630abb..a2805156f 100644 --- a/server/tests/attach/updateEnts/updateEnts1.test.ts +++ b/server/tests/attach/updateEnts/updateEnts1.test.ts @@ -2,12 +2,12 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/updateEnts/updateEnts2.test.ts b/server/tests/attach/updateEnts/updateEnts2.test.ts index b16b12604..40087551f 100644 --- a/server/tests/attach/updateEnts/updateEnts2.test.ts +++ b/server/tests/attach/updateEnts/updateEnts2.test.ts @@ -2,12 +2,12 @@ import { LegacyVersion } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addHours, addMonths, addWeeks } from "date-fns"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/updateEnts/updateEnts3.test.ts b/server/tests/attach/updateEnts/updateEnts3.test.ts index ccc4f981d..52bfd7da3 100644 --- a/server/tests/attach/updateEnts/updateEnts3.test.ts +++ b/server/tests/attach/updateEnts/updateEnts3.test.ts @@ -1,11 +1,11 @@ -import { LegacyVersion } from "@autumn/shared"; import { beforeAll, describe, test } from "bun:test"; +import { LegacyVersion } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; @@ -158,7 +158,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing update ents (changing featu test("should attach custom pro product with removed feature item", async () => { const customItems2 = customItems.filter( - (item) => item.feature_id != TestFeature.Messages, + (item) => item.feature_id !== TestFeature.Messages, ); const customProduct = { diff --git a/server/tests/attach/updateEnts/updateEnts4.test.ts b/server/tests/attach/updateEnts/updateEnts4.test.ts index d5160ce99..66a1864b5 100644 --- a/server/tests/attach/updateEnts/updateEnts4.test.ts +++ b/server/tests/attach/updateEnts/updateEnts4.test.ts @@ -5,9 +5,9 @@ import { } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { nullish } from "@/utils/genUtils.js"; diff --git a/server/tests/attach/updateQuantity/updateQuantity1.test.ts b/server/tests/attach/updateQuantity/updateQuantity1.test.ts index 776166a49..4ed6c56b7 100644 --- a/server/tests/attach/updateQuantity/updateQuantity1.test.ts +++ b/server/tests/attach/updateQuantity/updateQuantity1.test.ts @@ -8,13 +8,13 @@ import { import chalk from "chalk"; import { addWeeks } from "date-fns"; import type Stripe from "stripe"; -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 ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.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 ctx from "@tests/utils/testInitUtils/createTestContext.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"; diff --git a/server/tests/attach/upgrade/upgrade1.test.ts b/server/tests/attach/upgrade/upgrade1.test.ts index af24ae359..47a286b26 100644 --- a/server/tests/attach/upgrade/upgrade1.test.ts +++ b/server/tests/attach/upgrade/upgrade1.test.ts @@ -1,12 +1,12 @@ import { beforeAll, describe, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/upgrade/upgrade2.test.ts b/server/tests/attach/upgrade/upgrade2.test.ts index 89b92e8e7..42133c73b 100644 --- a/server/tests/attach/upgrade/upgrade2.test.ts +++ b/server/tests/attach/upgrade/upgrade2.test.ts @@ -3,10 +3,10 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/upgrade/upgrade3.test.ts b/server/tests/attach/upgrade/upgrade3.test.ts index 6bfdf3523..01cc1f113 100644 --- a/server/tests/attach/upgrade/upgrade3.test.ts +++ b/server/tests/attach/upgrade/upgrade3.test.ts @@ -3,10 +3,10 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/attach/upgrade/upgrade4.test.ts b/server/tests/attach/upgrade/upgrade4.test.ts index 5d5fbf52d..080bfbac3 100644 --- a/server/tests/attach/upgrade/upgrade4.test.ts +++ b/server/tests/attach/upgrade/upgrade4.test.ts @@ -3,10 +3,10 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/upgrade/upgrade5.test.ts b/server/tests/attach/upgrade/upgrade5.test.ts index 1db7f5e3b..060452727 100644 --- a/server/tests/attach/upgrade/upgrade5.test.ts +++ b/server/tests/attach/upgrade/upgrade5.test.ts @@ -3,10 +3,10 @@ import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/upgrade/upgrade6.test.ts b/server/tests/attach/upgrade/upgrade6.test.ts index a11e36415..e72cfc381 100644 --- a/server/tests/attach/upgrade/upgrade6.test.ts +++ b/server/tests/attach/upgrade/upgrade6.test.ts @@ -2,13 +2,13 @@ import { beforeAll, describe, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -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 ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { attachFailedPaymentMethod } from "@/external/stripe/stripeCusUtils.js"; diff --git a/server/tests/attach/upgrade/upgrade7.test.ts b/server/tests/attach/upgrade/upgrade7.test.ts index 019c6c3d5..4e5943ad8 100644 --- a/server/tests/attach/upgrade/upgrade7.test.ts +++ b/server/tests/attach/upgrade/upgrade7.test.ts @@ -2,8 +2,8 @@ import { beforeAll, describe, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/upgradeOld/sharedProducts.ts b/server/tests/attach/upgradeOld/sharedProducts.ts index 502d1225c..cfd150a60 100644 --- a/server/tests/attach/upgradeOld/sharedProducts.ts +++ b/server/tests/attach/upgradeOld/sharedProducts.ts @@ -3,8 +3,8 @@ import { FreeTrialDuration, ProductItemInterval, } from "@autumn/shared"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/attach/upgradeOld/upgradeOld1.test.ts b/server/tests/attach/upgradeOld/upgradeOld1.test.ts index 09bb612ce..fcce2390b 100644 --- a/server/tests/attach/upgradeOld/upgradeOld1.test.ts +++ b/server/tests/attach/upgradeOld/upgradeOld1.test.ts @@ -7,9 +7,9 @@ import { import chalk from "chalk"; import { addDays } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/upgradeOld/upgradeOld2.test.ts b/server/tests/attach/upgradeOld/upgradeOld2.test.ts index 6b12da151..c978bddaf 100644 --- a/server/tests/attach/upgradeOld/upgradeOld2.test.ts +++ b/server/tests/attach/upgradeOld/upgradeOld2.test.ts @@ -5,8 +5,8 @@ import { ProductItemInterval, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/upgradeOld/upgradeOld3.test.ts b/server/tests/attach/upgradeOld/upgradeOld3.test.ts index e56b5507b..5abba4318 100644 --- a/server/tests/attach/upgradeOld/upgradeOld3.test.ts +++ b/server/tests/attach/upgradeOld/upgradeOld3.test.ts @@ -8,9 +8,9 @@ import { import chalk from "chalk"; import { addDays } from "date-fns"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPriceItem } from "@/internal/products/product-items/productItemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/attach/upgradeOld/upgradeOld4.test.ts b/server/tests/attach/upgradeOld/upgradeOld4.test.ts index 680b8d802..4d9178d29 100644 --- a/server/tests/attach/upgradeOld/upgradeOld4.test.ts +++ b/server/tests/attach/upgradeOld/upgradeOld4.test.ts @@ -8,11 +8,11 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectCustomerV0Correct } from "tests/utils/expectUtils/expectCustomerV0Correct.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectCustomerV0Correct } from "@tests/utils/expectUtils/expectCustomerV0Correct.js"; +import { expectAutumnError } from "@tests/utils/expectUtils/expectErrUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { attachFailedPaymentMethod, diff --git a/server/tests/balances/check/basic/check1.test.ts b/server/tests/balances/check/basic/check1.test.ts index 94691e4df..0c0252875 100644 --- a/server/tests/balances/check/basic/check1.test.ts +++ b/server/tests/balances/check/basic/check1.test.ts @@ -7,8 +7,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/check/basic/check2.test.ts b/server/tests/balances/check/basic/check2.test.ts index 2f4a53f22..a629ebf5b 100644 --- a/server/tests/balances/check/basic/check2.test.ts +++ b/server/tests/balances/check/basic/check2.test.ts @@ -7,8 +7,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/check/basic/check3.test.ts b/server/tests/balances/check/basic/check3.test.ts index de2a551f6..376f317f9 100644 --- a/server/tests/balances/check/basic/check3.test.ts +++ b/server/tests/balances/check/basic/check3.test.ts @@ -9,8 +9,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/check/basic/check4.test.ts b/server/tests/balances/check/basic/check4.test.ts index 94874561c..67c4589e1 100644 --- a/server/tests/balances/check/basic/check4.test.ts +++ b/server/tests/balances/check/basic/check4.test.ts @@ -7,8 +7,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/check/basic/check5.test.ts b/server/tests/balances/check/basic/check5.test.ts index 38dcb934f..f9642085c 100644 --- a/server/tests/balances/check/basic/check5.test.ts +++ b/server/tests/balances/check/basic/check5.test.ts @@ -9,8 +9,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/check/basic/check6.test.ts b/server/tests/balances/check/basic/check6.test.ts index 9d613c383..d87ac6754 100644 --- a/server/tests/balances/check/basic/check6.test.ts +++ b/server/tests/balances/check/basic/check6.test.ts @@ -10,8 +10,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, diff --git a/server/tests/balances/check/basic/check7.test.ts b/server/tests/balances/check/basic/check7.test.ts index 0c47325c8..49168c100 100644 --- a/server/tests/balances/check/basic/check7.test.ts +++ b/server/tests/balances/check/basic/check7.test.ts @@ -8,8 +8,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/check/basic/check8.test.ts b/server/tests/balances/check/basic/check8.test.ts index 1977be0ac..2d8b113f6 100644 --- a/server/tests/balances/check/basic/check8.test.ts +++ b/server/tests/balances/check/basic/check8.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type CheckResponseV1, SuccessCode } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/balances/check/credit-systems/credit-systems1.test.ts b/server/tests/balances/check/credit-systems/credit-systems1.test.ts index 139b684b2..995df7db4 100644 --- a/server/tests/balances/check/credit-systems/credit-systems1.test.ts +++ b/server/tests/balances/check/credit-systems/credit-systems1.test.ts @@ -8,8 +8,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { featureToCreditSystem, diff --git a/server/tests/balances/check/credit-systems/credit-systems2.test.ts b/server/tests/balances/check/credit-systems/credit-systems2.test.ts index c55658b48..ee189f8a0 100644 --- a/server/tests/balances/check/credit-systems/credit-systems2.test.ts +++ b/server/tests/balances/check/credit-systems/credit-systems2.test.ts @@ -7,8 +7,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/check/credit-systems/credit-systems3.test.ts b/server/tests/balances/check/credit-systems/credit-systems3.test.ts index 969165a5a..1656a39ee 100644 --- a/server/tests/balances/check/credit-systems/credit-systems3.test.ts +++ b/server/tests/balances/check/credit-systems/credit-systems3.test.ts @@ -6,8 +6,8 @@ import { SuccessCode, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { featureToCreditSystem } from "@/internal/features/creditSystemUtils.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/balances/check/credit-systems/credit-systems4.test.ts b/server/tests/balances/check/credit-systems/credit-systems4.test.ts index efebc6994..9fee702ab 100644 --- a/server/tests/balances/check/credit-systems/credit-systems4.test.ts +++ b/server/tests/balances/check/credit-systems/credit-systems4.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type CheckResponseV1, SuccessCode } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { featureToCreditSystem } from "@/internal/features/creditSystemUtils.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/balances/check/misc/check-misc1.test.ts b/server/tests/balances/check/misc/check-misc1.test.ts index c2b180743..5b6c3f219 100644 --- a/server/tests/balances/check/misc/check-misc1.test.ts +++ b/server/tests/balances/check/misc/check-misc1.test.ts @@ -2,8 +2,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/balances/check/misc/check-misc2.test.ts b/server/tests/balances/check/misc/check-misc2.test.ts index bd7f1b6a4..b59d4f693 100644 --- a/server/tests/balances/check/misc/check-misc2.test.ts +++ b/server/tests/balances/check/misc/check-misc2.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, CusExpand } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/check/prepaid/check-prepaid1.test.ts b/server/tests/balances/check/prepaid/check-prepaid1.test.ts index fb12b7a1f..1d02b4d36 100644 --- a/server/tests/balances/check/prepaid/check-prepaid1.test.ts +++ b/server/tests/balances/check/prepaid/check-prepaid1.test.ts @@ -4,10 +4,11 @@ import { type CheckResponseV0, type CheckResponseV1, type CheckResponseV2, + type LimitedItem, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; @@ -27,10 +28,10 @@ const freeProd = constructProduct({ items: [prepaidMessagesFeature], }); -const testCase = "check1"; +const testCase = "check-prepaid1"; describe(`${chalk.yellowBright("check-prepaid1: test /check when prepaid feature attached")}`, () => { - const customerId = "check1"; + const customerId = testCase; const autumnV0: AutumnInt = new AutumnInt({ version: ApiVersion.V0_2 }); const autumnV1: AutumnInt = new AutumnInt({ version: ApiVersion.V1_2 }); const autumnV2: AutumnInt = new AutumnInt({ version: ApiVersion.V2_0 }); diff --git a/server/tests/balances/track/allocated/track-allocated1.test.ts b/server/tests/balances/track/allocated/track-allocated1.test.ts index 3e01f7dd3..2323189ce 100644 --- a/server/tests/balances/track/allocated/track-allocated1.test.ts +++ b/server/tests/balances/track/allocated/track-allocated1.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ProductItemFeatureType } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/allocated/track-allocated2.test.ts b/server/tests/balances/track/allocated/track-allocated2.test.ts index 5297bd3cb..ff6fab77b 100644 --- a/server/tests/balances/track/allocated/track-allocated2.test.ts +++ b/server/tests/balances/track/allocated/track-allocated2.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ProductItemFeatureType } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/allocated/track-allocated3.test.ts b/server/tests/balances/track/allocated/track-allocated3.test.ts index aac4811cb..c548aff7c 100644 --- a/server/tests/balances/track/allocated/track-allocated3.test.ts +++ b/server/tests/balances/track/allocated/track-allocated3.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ProductItemFeatureType } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/allocated/track-allocated4.test.ts b/server/tests/balances/track/allocated/track-allocated4.test.ts index 238e41092..27227699d 100644 --- a/server/tests/balances/track/allocated/track-allocated4.test.ts +++ b/server/tests/balances/track/allocated/track-allocated4.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ProductItemFeatureType } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/allocated/track-allocated5.test.ts b/server/tests/balances/track/allocated/track-allocated5.test.ts index 9d911bbfc..2271e976f 100644 --- a/server/tests/balances/track/allocated/track-allocated5.test.ts +++ b/server/tests/balances/track/allocated/track-allocated5.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic1.test.ts b/server/tests/balances/track/basic/track-basic1.test.ts index e022cb39b..a3b30157a 100644 --- a/server/tests/balances/track/basic/track-basic1.test.ts +++ b/server/tests/balances/track/basic/track-basic1.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type TrackResponseV2 } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic10.test.ts b/server/tests/balances/track/basic/track-basic10.test.ts index 49e85358e..a50e04a59 100644 --- a/server/tests/balances/track/basic/track-basic10.test.ts +++ b/server/tests/balances/track/basic/track-basic10.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, diff --git a/server/tests/balances/track/basic/track-basic11.test.ts b/server/tests/balances/track/basic/track-basic11.test.ts index 7da32ac88..599616aa8 100644 --- a/server/tests/balances/track/basic/track-basic11.test.ts +++ b/server/tests/balances/track/basic/track-basic11.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic2.test.ts b/server/tests/balances/track/basic/track-basic2.test.ts index 915b237b7..33bc8b287 100644 --- a/server/tests/balances/track/basic/track-basic2.test.ts +++ b/server/tests/balances/track/basic/track-basic2.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type TrackResponseV2 } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic3.test.ts b/server/tests/balances/track/basic/track-basic3.test.ts index e288e5885..76dcfcb4e 100644 --- a/server/tests/balances/track/basic/track-basic3.test.ts +++ b/server/tests/balances/track/basic/track-basic3.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type TrackResponseV2 } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic4.test.ts b/server/tests/balances/track/basic/track-basic4.test.ts index 5c9ade78b..768a40f74 100644 --- a/server/tests/balances/track/basic/track-basic4.test.ts +++ b/server/tests/balances/track/basic/track-basic4.test.ts @@ -6,9 +6,9 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic5.test.ts b/server/tests/balances/track/basic/track-basic5.test.ts index dfd444ffa..d088b645a 100644 --- a/server/tests/balances/track/basic/track-basic5.test.ts +++ b/server/tests/balances/track/basic/track-basic5.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic6.test.ts b/server/tests/balances/track/basic/track-basic6.test.ts index 528e40348..233a7f33b 100644 --- a/server/tests/balances/track/basic/track-basic6.test.ts +++ b/server/tests/balances/track/basic/track-basic6.test.ts @@ -2,8 +2,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic7.test.ts b/server/tests/balances/track/basic/track-basic7.test.ts index d72657738..20a1b0c8b 100644 --- a/server/tests/balances/track/basic/track-basic7.test.ts +++ b/server/tests/balances/track/basic/track-basic7.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type TrackResponseV2 } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic8.test.ts b/server/tests/balances/track/basic/track-basic8.test.ts index ce4aea940..153c9164f 100644 --- a/server/tests/balances/track/basic/track-basic8.test.ts +++ b/server/tests/balances/track/basic/track-basic8.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ErrCode, type TrackResponseV2 } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/basic/track-basic9.test.ts b/server/tests/balances/track/basic/track-basic9.test.ts index a8799b833..a6f99c1ca 100644 --- a/server/tests/balances/track/basic/track-basic9.test.ts +++ b/server/tests/balances/track/basic/track-basic9.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/concurrency/concurrent-track1.test.ts b/server/tests/balances/track/concurrency/concurrent-track1.test.ts index 58ed24585..8589ef30e 100644 --- a/server/tests/balances/track/concurrency/concurrent-track1.test.ts +++ b/server/tests/balances/track/concurrency/concurrent-track1.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/concurrency/concurrent-track2.test.ts b/server/tests/balances/track/concurrency/concurrent-track2.test.ts index 688afcfdf..0bedaaf5d 100644 --- a/server/tests/balances/track/concurrency/concurrent-track2.test.ts +++ b/server/tests/balances/track/concurrency/concurrent-track2.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ProductItemFeatureType } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/concurrency/concurrent-track3.test.ts b/server/tests/balances/track/concurrency/concurrent-track3.test.ts index 50a623559..8d44fea73 100644 --- a/server/tests/balances/track/concurrency/concurrent-track3.test.ts +++ b/server/tests/balances/track/concurrency/concurrent-track3.test.ts @@ -1,8 +1,8 @@ // import { beforeAll, describe, expect, test } from "bun:test"; // import { ApiVersion, ProductItemFeatureType } from "@autumn/shared"; // import chalk from "chalk"; -// import { TestFeature } from "tests/setup/v2Features.js"; -// import ctx from "tests/utils/testInitUtils/createTestContext.js"; +// import { TestFeature } from "@tests/setup/v2Features.js"; +// import ctx from "@tests/utils/testInitUtils/createTestContext.js"; // import { AutumnInt } from "@/external/autumn/autumnCli.js"; // import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; // import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/concurrency/concurrent-track4.test.ts b/server/tests/balances/track/concurrency/concurrent-track4.test.ts index 2807b5638..1ad99ee32 100644 --- a/server/tests/balances/track/concurrency/concurrent-track4.test.ts +++ b/server/tests/balances/track/concurrency/concurrent-track4.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/concurrency/concurrent-track5.test.ts b/server/tests/balances/track/concurrency/concurrent-track5.test.ts index 6c532b4a1..3579e8ea0 100644 --- a/server/tests/balances/track/concurrency/concurrent-track5.test.ts +++ b/server/tests/balances/track/concurrency/concurrent-track5.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ProductItemFeatureType } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, diff --git a/server/tests/balances/track/concurrency/concurrent-track6.test.ts b/server/tests/balances/track/concurrency/concurrent-track6.test.ts index 35dfa2749..d54e01514 100644 --- a/server/tests/balances/track/concurrency/concurrent-track6.test.ts +++ b/server/tests/balances/track/concurrency/concurrent-track6.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/credit-systems/track-credit-system1.test.ts b/server/tests/balances/track/credit-systems/track-credit-system1.test.ts index 3c0b9bdcc..a41472bdf 100644 --- a/server/tests/balances/track/credit-systems/track-credit-system1.test.ts +++ b/server/tests/balances/track/credit-systems/track-credit-system1.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/credit-systems/track-credit-system2.test.ts b/server/tests/balances/track/credit-systems/track-credit-system2.test.ts index 77040d0f1..235786026 100644 --- a/server/tests/balances/track/credit-systems/track-credit-system2.test.ts +++ b/server/tests/balances/track/credit-systems/track-credit-system2.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { getCreditCost } from "@/internal/features/creditSystemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/balances/track/credit-systems/track-credit-system3.test.ts b/server/tests/balances/track/credit-systems/track-credit-system3.test.ts index 0e6e683a5..196090b78 100644 --- a/server/tests/balances/track/credit-systems/track-credit-system3.test.ts +++ b/server/tests/balances/track/credit-systems/track-credit-system3.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { getCreditCost } from "@/internal/features/creditSystemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/balances/track/credit-systems/track-credit-system4.test.ts b/server/tests/balances/track/credit-systems/track-credit-system4.test.ts index 00d1d1a54..d71a6fcc3 100644 --- a/server/tests/balances/track/credit-systems/track-credit-system4.test.ts +++ b/server/tests/balances/track/credit-systems/track-credit-system4.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { getCreditCost } from "@/internal/features/creditSystemUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/balances/track/entity-balances/track-entity-balances1.test.ts b/server/tests/balances/track/entity-balances/track-entity-balances1.test.ts index 61aa11d40..f9a540125 100644 --- a/server/tests/balances/track/entity-balances/track-entity-balances1.test.ts +++ b/server/tests/balances/track/entity-balances/track-entity-balances1.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/entity-balances/track-entity-balances2.test.ts b/server/tests/balances/track/entity-balances/track-entity-balances2.test.ts index d77500497..947ed1abc 100644 --- a/server/tests/balances/track/entity-balances/track-entity-balances2.test.ts +++ b/server/tests/balances/track/entity-balances/track-entity-balances2.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/entity-balances/track-entity-balances3.test.ts b/server/tests/balances/track/entity-balances/track-entity-balances3.test.ts index 798c086bf..b7069255a 100644 --- a/server/tests/balances/track/entity-balances/track-entity-balances3.test.ts +++ b/server/tests/balances/track/entity-balances/track-entity-balances3.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/entity-balances/track-entity-balances4.test.ts b/server/tests/balances/track/entity-balances/track-entity-balances4.test.ts index 44cf2bdd7..91e903fe5 100644 --- a/server/tests/balances/track/entity-balances/track-entity-balances4.test.ts +++ b/server/tests/balances/track/entity-balances/track-entity-balances4.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/entity-balances/track-entity-balances5.test.ts b/server/tests/balances/track/entity-balances/track-entity-balances5.test.ts index d2e9f94fe..b1419b04a 100644 --- a/server/tests/balances/track/entity-balances/track-entity-balances5.test.ts +++ b/server/tests/balances/track/entity-balances/track-entity-balances5.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { timeout } from "tests/utils/genUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { timeout } from "@tests/utils/genUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/entity-products/track-entity-products1.test.ts b/server/tests/balances/track/entity-products/track-entity-products1.test.ts index 9ab63ec43..7258435d0 100644 --- a/server/tests/balances/track/entity-products/track-entity-products1.test.ts +++ b/server/tests/balances/track/entity-products/track-entity-products1.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/entity-products/track-entity-products2.test.ts b/server/tests/balances/track/entity-products/track-entity-products2.test.ts index 138d957b4..ec78185bb 100644 --- a/server/tests/balances/track/entity-products/track-entity-products2.test.ts +++ b/server/tests/balances/track/entity-products/track-entity-products2.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/entity-products/track-entity-products3.test.ts b/server/tests/balances/track/entity-products/track-entity-products3.test.ts index 8f4f99f2f..39d9b15c8 100644 --- a/server/tests/balances/track/entity-products/track-entity-products3.test.ts +++ b/server/tests/balances/track/entity-products/track-entity-products3.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, ProductItemFeatureType } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/legacy/track-legacy1.test.ts b/server/tests/balances/track/legacy/track-legacy1.test.ts index 1b007e4b6..280b247f6 100644 --- a/server/tests/balances/track/legacy/track-legacy1.test.ts +++ b/server/tests/balances/track/legacy/track-legacy1.test.ts @@ -2,8 +2,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/legacy/track-legacy2.test.ts b/server/tests/balances/track/legacy/track-legacy2.test.ts index 992b662c7..0b1269219 100644 --- a/server/tests/balances/track/legacy/track-legacy2.test.ts +++ b/server/tests/balances/track/legacy/track-legacy2.test.ts @@ -1,7 +1,7 @@ import { beforeAll, describe, expect, test } from "bun:test"; import type { LimitedItem } from "@autumn/shared"; import chalk from "chalk"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructArrearItem } from "../../../../src/utils/scriptUtils/constructItem.js"; import { constructProduct } from "../../../../src/utils/scriptUtils/createTestProducts.js"; import { initCustomerV3 } from "../../../../src/utils/scriptUtils/testUtils/initCustomerV3.js"; diff --git a/server/tests/balances/track/legacy/track-legacy3.test.ts b/server/tests/balances/track/legacy/track-legacy3.test.ts index 1d6e0aa95..70402768b 100644 --- a/server/tests/balances/track/legacy/track-legacy3.test.ts +++ b/server/tests/balances/track/legacy/track-legacy3.test.ts @@ -1,7 +1,7 @@ import { beforeAll, describe, test } from "bun:test"; import { ProductItemInterval } from "@autumn/shared"; import chalk from "chalk"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { constructFeatureItem, constructPrepaidItem, diff --git a/server/tests/balances/track/misc/track-misc1.test.ts b/server/tests/balances/track/misc/track-misc1.test.ts index 7cdd037d1..949b930b3 100644 --- a/server/tests/balances/track/misc/track-misc1.test.ts +++ b/server/tests/balances/track/misc/track-misc1.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, CusExpand } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/track/misc/track-misc2.test.ts b/server/tests/balances/track/misc/track-misc2.test.ts index e0a34f003..415fcb3a2 100644 --- a/server/tests/balances/track/misc/track-misc2.test.ts +++ b/server/tests/balances/track/misc/track-misc2.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { EventService } from "../../../../src/internal/api/events/EventService.js"; import { timeout } from "../../../utils/genUtils.js"; diff --git a/server/tests/balances/track/misc/track-misc3.test.ts b/server/tests/balances/track/misc/track-misc3.test.ts index a2662a887..ba69fc8fe 100644 --- a/server/tests/balances/track/misc/track-misc3.test.ts +++ b/server/tests/balances/track/misc/track-misc3.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { EventService } from "../../../../src/internal/api/events/EventService.js"; import { initCustomerV3 } from "../../../../src/utils/scriptUtils/testUtils/initCustomerV3.js"; diff --git a/server/tests/balances/track/trackTestUtils.ts b/server/tests/balances/track/trackTestUtils.ts index f3f7d521d..0755e0d53 100644 --- a/server/tests/balances/track/trackTestUtils.ts +++ b/server/tests/balances/track/trackTestUtils.ts @@ -1,5 +1,5 @@ -import { SuccessCode, type TrackResponse } from "@autumn/shared"; +import { SuccessCode, type TrackResponseV1 } from "@autumn/shared"; -export const trackWasSuccessful = ({ res }: { res: TrackResponse }) => { +export const trackWasSuccessful = ({ res }: { res: TrackResponseV1 }) => { return res.code === SuccessCode.EventReceived; }; diff --git a/server/tests/balances/update/balances-update1.test.ts b/server/tests/balances/update/balances-update1.test.ts index 0b86dee14..0fee32f9a 100644 --- a/server/tests/balances/update/balances-update1.test.ts +++ b/server/tests/balances/update/balances-update1.test.ts @@ -1,14 +1,13 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { - type ApiCusFeature, type ApiCusFeatureV3, ApiVersion, type LimitedItem, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; @@ -65,9 +64,7 @@ describe(`${chalk.yellowBright("balances-update1: testing update balance after t await timeout(2000); const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; + const feature = customer.features[TestFeature.Messages] as any; const currentBalance = new Decimal(messagesFeature.included_usage) .minus(usage) diff --git a/server/tests/balances/update/balances-update2.test.ts b/server/tests/balances/update/balances-update2.test.ts index f5f3deeb1..f2690a675 100644 --- a/server/tests/balances/update/balances-update2.test.ts +++ b/server/tests/balances/update/balances-update2.test.ts @@ -6,8 +6,8 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/balances/update/balances-update3.test.ts b/server/tests/balances/update/balances-update3.test.ts index 6b96a42c3..40537a6c8 100644 --- a/server/tests/balances/update/balances-update3.test.ts +++ b/server/tests/balances/update/balances-update3.test.ts @@ -1,8 +1,8 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { type ApiCustomer, ApiVersion, type LimitedItem } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/clearMasterOrg.ts b/server/tests/clearMasterOrg.ts index b12598840..00f56ccbe 100644 --- a/server/tests/clearMasterOrg.ts +++ b/server/tests/clearMasterOrg.ts @@ -20,19 +20,12 @@ async function main() { console.log(chalk.green("\nāœ… Master org cleared successfully!\n")); - // Ask if user wants to set up features - const shouldSetup = confirm( - "Do you want to set up v2 features for the master org?", - ); - - if (shouldSetup) { - console.log(chalk.blue("\nšŸ—ļø Setting up master org...\n")); - await setupOrg({ - orgId: org.id, - env: AppEnv.Sandbox, - }); - console.log(chalk.green("\nāœ… Master org setup complete!\n")); - } + console.log(chalk.blue("\nšŸ—ļø Setting up master org...\n")); + await setupOrg({ + orgId: org.id, + env: AppEnv.Sandbox, + }); + console.log(chalk.green("\nāœ… Master org setup complete!\n")); } catch (error) { console.error(chalk.red("\nāŒ Error:"), error); process.exit(1); diff --git a/server/tests/contUse/entities/entity1.test.ts b/server/tests/contUse/entities/entity1.test.ts index 8cd1d7eec..e4ced6b5b 100644 --- a/server/tests/contUse/entities/entity1.test.ts +++ b/server/tests/contUse/entities/entity1.test.ts @@ -1,10 +1,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/contUse/entities/entity2.test.ts b/server/tests/contUse/entities/entity2.test.ts index e7b0744ff..ac0cef128 100644 --- a/server/tests/contUse/entities/entity2.test.ts +++ b/server/tests/contUse/entities/entity2.test.ts @@ -2,14 +2,14 @@ import { beforeAll, describe, test } from "bun:test"; import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; import { calcProrationAndExpectInvoice, expectSubQuantityCorrect, -} from "tests/utils/expectUtils/expectContUseUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/expectUtils/expectContUseUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/contUse/entities/entity3.test.ts b/server/tests/contUse/entities/entity3.test.ts index aaf5bfb0c..e7e494e26 100644 --- a/server/tests/contUse/entities/entity3.test.ts +++ b/server/tests/contUse/entities/entity3.test.ts @@ -2,13 +2,13 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import chalk from "chalk"; import { addHours, addMonths, addWeeks } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectSubQuantityCorrect } from "@tests/utils/expectUtils/expectContUseUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/contUse/entities/entity4.test.ts b/server/tests/contUse/entities/entity4.test.ts index 6ac017a7d..193f93149 100644 --- a/server/tests/contUse/entities/entity4.test.ts +++ b/server/tests/contUse/entities/entity4.test.ts @@ -9,10 +9,10 @@ import { OnIncrease, } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { useEntityBalanceAndExpect } from "tests/utils/expectUtils/expectContUse/expectEntityUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { useEntityBalanceAndExpect } from "@tests/utils/expectUtils/expectContUse/expectEntityUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { diff --git a/server/tests/contUse/entities/entity5.test.ts b/server/tests/contUse/entities/entity5.test.ts index f9648e5e4..6285fc46a 100644 --- a/server/tests/contUse/entities/entity5.test.ts +++ b/server/tests/contUse/entities/entity5.test.ts @@ -3,11 +3,11 @@ import { beforeAll, describe, test } from "bun:test"; import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; -import { expectAutumnError } from "tests/utils/expectUtils/expectErrUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { expectAutumnError } from "@tests/utils/expectUtils/expectErrUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { attachFailedPaymentMethod } from "@/external/stripe/stripeCusUtils.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/contUse/roles/role1.backup.ts b/server/tests/contUse/roles/role1.backup.ts deleted file mode 100644 index d80582514..000000000 --- a/server/tests/contUse/roles/role1.backup.ts +++ /dev/null @@ -1,246 +0,0 @@ -// Handling per entity features! - -import { - type AppEnv, - LegacyVersion, - type LimitedItem, - type Organization, - type ProductItem, -} from "@autumn/shared"; -import { expect } from "chai"; -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 { 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"; - -const user = TestFeature.Users; -const admin = TestFeature.Admin; - -const userMessages = constructFeatureItem({ - featureId: TestFeature.Messages, - includedUsage: 100, - entityFeatureId: user, -}) as LimitedItem; - -const adminMessages = constructFeatureItem({ - featureId: TestFeature.Messages, - includedUsage: 500, - entityFeatureId: admin, -}) as LimitedItem; - -const adminRights = constructFeatureItem({ - featureId: TestFeature.AdminRights, - entityFeatureId: admin, - isBoolean: true, -}) as ProductItem; - -export const pro = constructProduct({ - items: [userMessages, adminMessages, adminRights], - type: "pro", -}); - -const testCase = "role1"; - -describe(`${chalk.yellowBright(`contUse/${testCase}: Testing roles`)}`, () => { - 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; - const curUnix = new Date().getTime(); - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - autumn, - products: [pro], - customerId, - db, - orgId: org.id, - env, - }); - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = testClockId1!; - }); - - const userId = "user1"; - const adminId = "admin1"; - const firstEntities = [ - { - id: userId, - name: "test", - feature_id: user, - }, - { - id: adminId, - name: "test", - feature_id: admin, - }, - ]; - - it("should create initial entities, then attach pro", async () => { - await autumn.entities.create(customerId, firstEntities); - - await attachAndExpectCorrect({ - autumn, - customerId, - product: pro, - stripeCli, - db, - org, - env, - }); - }); - - 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, - }); - - const entity = await autumn.entities.get(customerId, adminId); - - expect(allowed).to.equal(true); - expect(entity.features[TestFeature.AdminRights]).exist; - - const { allowed: userAllowed } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.AdminRights, - entity_id: 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 () => { - const { balance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - }); - - const totalIncluded = - userMessages.included_usage + adminMessages.included_usage; - - expect(balance).to.equal(totalIncluded); - }); - - it("should have correct per entity balance", async () => { - const { balance: userBalance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: 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, - ); - - const { balance: adminBalance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: 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( - adminMessages.included_usage, - ); - }); - - const userUsage = Math.random() * 50; - const expectedUserBalance = new Decimal(userMessages.included_usage) - .minus(userUsage) - .toNumber(); - it("should have correct user usage", async () => { - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: userUsage, - entity_id: userId, - }); - await timeout(2000); - - const { balance: userBalance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: userId, - }); - - const { balance: adminBalance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: adminId, - }); - - expect(adminBalance).to.equal(adminMessages.included_usage); - expect(userBalance).to.equal(expectedUserBalance); - }); - - const adminUsage = Math.random() * 50; - const expectedAdminBalance = new Decimal(adminMessages.included_usage) - .minus(adminUsage) - .toNumber(); - it("Should have correct admin usage", async () => { - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: adminUsage, - entity_id: adminId, - }); - await timeout(2000); - - const { balance: adminBalance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: adminId, - }); - - const { balance: userBalance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: userId, - }); - - expect(adminBalance).to.equal(expectedAdminBalance); - expect(userBalance).to.equal(expectedUserBalance); - }); -}); diff --git a/server/tests/contUse/roles/role1.test.ts b/server/tests/contUse/roles/role1.test.ts index f9dc2dcc4..5226110ac 100644 --- a/server/tests/contUse/roles/role1.test.ts +++ b/server/tests/contUse/roles/role1.test.ts @@ -8,9 +8,9 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/contUse/roles/role2.backup.ts b/server/tests/contUse/roles/role2.backup.ts deleted file mode 100644 index ca07d4f58..000000000 --- a/server/tests/contUse/roles/role2.backup.ts +++ /dev/null @@ -1,190 +0,0 @@ -import { - type AppEnv, - type CreateEntity, - LegacyVersion, - type LimitedItem, - 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 { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.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 { addPrefixToProducts } from "../../attach/utils.js"; - -const user = TestFeature.Users; -const admin = TestFeature.Admin; - -const userMessages = constructArrearItem({ - featureId: TestFeature.Messages, - price: 0.5, - entityFeatureId: user, -}) as LimitedItem; - -export const pro = constructProduct({ - items: [userMessages], - type: "pro", -}); - -const testCase = "role2"; - -describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per entity`)}`, () => { - 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; - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - autumn, - products: [pro], - customerId, - db, - orgId: org.id, - env, - }); - - const res = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = res.testClockId!; - }); - - const user1 = "user1"; - const user2 = "user2"; - - const firstEntities: CreateEntity[] = [ - { - id: user1, - name: "test", - feature_id: user, - }, - { - id: user2, - name: "test", - feature_id: user, - }, - ]; - - it("should create initial entities, then attach pro", async () => { - await autumn.entities.create(customerId, firstEntities); - - await attachAndExpectCorrect({ - autumn, - customerId, - product: pro, - stripeCli, - db, - org, - env, - entities: firstEntities, - }); - - const customer = await autumn.customers.get(customerId); - expect(customer.features[TestFeature.Messages].included_usage).to.equal( - userMessages.included_usage * firstEntities.length, - ); - }); - - 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, - value: user1Usage, - entity_id: user1, - }); - - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: user2Usage, - entity_id: user2, - }); - - await timeout(4000); - - const includedUsage = userMessages.included_usage; - - const { balance: userBalance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: user1, - }); - - expect(userBalance).to.equal(includedUsage - user1Usage); - - const { balance: user2Balance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: user2, - }); - - expect(user2Balance).to.equal(includedUsage - user2Usage); - }); - - it("should have correct invoice next cycle", async () => { - await advanceTestClock({ - stripeCli, - testClockId, - advanceTo: addHours( - addMonths(new Date(), 1), - hoursToFinalizeInvoice, - ).getTime(), - waitForSeconds: 30, - }); - - const includedUsage = userMessages.included_usage; - const user1Overage = user1Usage - includedUsage; - const user2Overage = user2Usage - includedUsage; - - const totalUsage = user1Overage + user2Overage + includedUsage; - - const expectedInvoiceTotal = await getExpectedInvoiceTotal({ - customerId, - productId: pro.id, - usage: [{ featureId: TestFeature.Messages, value: totalUsage }], - stripeCli, - db, - org, - env, - expectExpired: true, - }); - - const customer = await autumn.customers.get(customerId); - expect(customer.invoices[0].total).to.equal(expectedInvoiceTotal); - }); -}); diff --git a/server/tests/contUse/roles/role2.test.ts b/server/tests/contUse/roles/role2.test.ts index cc0bd2cbd..7719ffaa9 100644 --- a/server/tests/contUse/roles/role2.test.ts +++ b/server/tests/contUse/roles/role2.test.ts @@ -1,16 +1,16 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { - type CreateEntity, + type CreateEntityParams, LegacyVersion, type LimitedItem, } from "@autumn/shared"; -import { beforeAll, describe, expect, test } from "bun:test"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addHours, addMonths } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; @@ -62,7 +62,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en const user1 = "user1"; const user2 = "user2"; - const firstEntities: CreateEntity[] = [ + const firstEntities: CreateEntityParams[] = [ { id: user1, name: "test", diff --git a/server/tests/contUse/roles/role3.backup.ts b/server/tests/contUse/roles/role3.backup.ts deleted file mode 100644 index e9c5c1754..000000000 --- a/server/tests/contUse/roles/role3.backup.ts +++ /dev/null @@ -1,259 +0,0 @@ -import { - type AppEnv, - type CreateEntity, - LegacyVersion, - type LimitedItem, - type Organization, -} from "@autumn/shared"; -import { expect } from "chai"; -import chalk from "chalk"; -import { addMonths } 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 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 { addPrefixToProducts } from "../../attach/utils.js"; - -const user = TestFeature.Users; -const admin = TestFeature.Admin; - -const userMessages = constructArrearItem({ - featureId: TestFeature.Messages, - price: 0.5, - entityFeatureId: user, -}) as LimitedItem; - -const adminMessages = constructArrearItem({ - featureId: TestFeature.Messages, - includedUsage: 0, - price: 0.1, - entityFeatureId: admin, -}) as LimitedItem; - -export const pro = constructProduct({ - items: [userMessages, adminMessages], - type: "pro", -}); - -const testCase = "role3"; - -describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per entity, diff roles`)}`, () => { - 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; - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [pro], - prefix: testCase, - }); - - await createProducts({ - autumn, - products: [pro], - customerId, - db, - orgId: org.id, - env, - }); - - const res = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = res.testClockId!; - }); - - const user1 = "user1"; - const user2 = "user2"; - const admin1 = "admin1"; - const admin2 = "admin2"; - const firstEntities: CreateEntity[] = [ - { - id: user1, - name: "test", - feature_id: user, - }, - { - id: user2, - name: "test", - feature_id: user, - }, - { - id: admin1, - name: "test", - feature_id: admin, - }, - { - id: admin2, - name: "test", - feature_id: admin, - }, - ]; - - it("should create initial entities, then attach pro", async () => { - await autumn.entities.create(customerId, firstEntities); - - await attachAndExpectCorrect({ - autumn, - customerId, - product: pro, - stripeCli, - db, - org, - env, - entities: firstEntities, - }); - }); - - const user1Usage = 125000; - const user2Usage = 150000; - - // total: 275000, included: 10000, overage: 255000 - it("should track correct usage for seat messages", async () => { - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: user1Usage, - entity_id: user1, - }); - - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: user2Usage, - entity_id: user2, - }); - - await timeout(4000); - - const includedUsage = userMessages.included_usage; - - const { balance: userBalance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: user1, - }); - - expect(userBalance).to.equal(includedUsage - user1Usage); - - const { balance: user2Balance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: user2, - }); - - expect(user2Balance).to.equal(includedUsage - user2Usage); - - const { balance: admin1Balance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: admin1, - }); - - expect(admin1Balance).to.equal(adminMessages.included_usage); - - const { balance: admin2Balance } = await autumn.check({ - customer_id: customerId, - feature_id: TestFeature.Messages, - entity_id: admin2, - }); - - expect(admin2Balance).to.equal(adminMessages.included_usage); - }); - - const admin1Usage = 130000; - const admin2Usage = 140000; - // total: 270000, included: 0, overage: 270000 - it("should track correct usage for admin messages", async () => { - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: admin1Usage, - entity_id: admin1, - }); - - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: admin2Usage, - entity_id: admin2, - }); - - await timeout(4000); - }); - - it("should have correct invoice next cycle", async () => { - await advanceTestClock({ - stripeCli, - testClockId, - advanceTo: addMonths(new Date(), 1).getTime(), - // addHours( - // addMonths(new Date(), 1), - // hoursToFinalizeInvoice - // ).getTime(), - waitForSeconds: 30, - }); - - return; - - const includedUsage = userMessages.included_usage; - const user1Overage = user1Usage - includedUsage; - const user2Overage = user2Usage - includedUsage; - const totalUserUsage = user1Overage + user2Overage + includedUsage; - - const admin1Overage = admin1Usage - adminMessages.included_usage; - const admin2Overage = admin2Usage - adminMessages.included_usage; - const totalAdminUsage = - admin1Overage + admin2Overage + adminMessages.included_usage; - - const expectedInvoiceTotal = await getExpectedInvoiceTotal({ - customerId, - productId: pro.id, - usage: [ - { - featureId: TestFeature.Messages, - entityFeatureId: user, - value: totalUserUsage, - }, - { - featureId: TestFeature.Messages, - entityFeatureId: admin, - value: totalAdminUsage, - }, - ], - stripeCli, - db, - org, - env, - expectExpired: true, - }); - - const customer = await autumn.customers.get(customerId); - expect(customer.invoices[0].total).to.equal(expectedInvoiceTotal); - }); -}); diff --git a/server/tests/contUse/roles/role3.test.ts b/server/tests/contUse/roles/role3.test.ts index 5682a818c..13ffaa960 100644 --- a/server/tests/contUse/roles/role3.test.ts +++ b/server/tests/contUse/roles/role3.test.ts @@ -1,15 +1,15 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { - type CreateEntity, + type CreateEntityParams, LegacyVersion, type LimitedItem, } from "@autumn/shared"; -import { beforeAll, describe, expect, test } from "bun:test"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addMonths } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; @@ -69,7 +69,7 @@ describe(`${chalk.yellowBright(`contUse/${testCase}: Testing overages for per en const user2 = "user2"; const admin1 = "admin1"; const admin2 = "admin2"; - const firstEntities: CreateEntity[] = [ + const firstEntities: CreateEntityParams[] = [ { id: user1, name: "test", diff --git a/server/tests/contUse/track/track1.test.ts b/server/tests/contUse/track/track1.test.ts index 3f293096b..1f84899ee 100644 --- a/server/tests/contUse/track/track1.test.ts +++ b/server/tests/contUse/track/track1.test.ts @@ -2,11 +2,11 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/contUse/track/track2.test.ts b/server/tests/contUse/track/track2.test.ts index 735073786..4998ed128 100644 --- a/server/tests/contUse/track/track2.test.ts +++ b/server/tests/contUse/track/track2.test.ts @@ -5,10 +5,10 @@ import { } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { expectSubQuantityCorrect } from "tests/utils/expectUtils/expectContUseUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/contUse/track/track3.test.ts b/server/tests/contUse/track/track3.test.ts index 0d682a772..b351e23b0 100644 --- a/server/tests/contUse/track/track3.test.ts +++ b/server/tests/contUse/track/track3.test.ts @@ -2,14 +2,14 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; import { expectSubQuantityCorrect, expectUpcomingItemsCorrect, -} from "tests/utils/expectUtils/expectContUseUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/expectUtils/expectContUseUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/contUse/track/track4.test.ts b/server/tests/contUse/track/track4.test.ts index aa0ff7654..7d3b8c60a 100644 --- a/server/tests/contUse/track/track4.test.ts +++ b/server/tests/contUse/track/track4.test.ts @@ -2,14 +2,14 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; import { expectSubQuantityCorrect, expectUpcomingItemsCorrect, -} from "tests/utils/expectUtils/expectContUseUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +} from "@tests/utils/expectUtils/expectContUseUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/contUse/track/track5.test.ts b/server/tests/contUse/track/track5.test.ts index 66b7e0d66..ba5c70b5c 100644 --- a/server/tests/contUse/track/track5.test.ts +++ b/server/tests/contUse/track/track5.test.ts @@ -4,14 +4,14 @@ import chalk from "chalk"; import { addDays, addHours } from "date-fns"; import { Decimal } from "decimal.js"; import type Stripe from "stripe"; -import { defaultApiVersion } from "tests/constants.js"; -import { features } from "tests/global.js"; -import { hoursToFinalizeInvoice } from "tests/utils/constants.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { getSubsFromCusId } from "tests/utils/expectUtils/expectSubUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import { defaultApiVersion } from "@tests/constants.js"; +import { features } from "@tests/global.js"; +import { hoursToFinalizeInvoice } from "@tests/utils/constants.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getSubsFromCusId } from "@tests/utils/expectUtils/expectSubUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { subToPeriodStartEnd } from "@/external/stripe/stripeSubUtils/convertSubUtils.js"; import { calculateProrationAmount } from "@/internal/invoices/prorationUtils.js"; diff --git a/server/tests/contUse/update/updateContUse1.backup.ts b/server/tests/contUse/update/updateContUse1.backup.ts index 92427aa36..71114599e 100644 --- a/server/tests/contUse/update/updateContUse1.backup.ts +++ b/server/tests/contUse/update/updateContUse1.backup.ts @@ -9,13 +9,13 @@ import { expect } from "chai"; import chalk from "chalk"; import { addWeeks } from "date-fns"; 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 { 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"; diff --git a/server/tests/contUse/update/updateContUse1.test.ts b/server/tests/contUse/update/updateContUse1.test.ts index f77318f58..8e9c04cfe 100644 --- a/server/tests/contUse/update/updateContUse1.test.ts +++ b/server/tests/contUse/update/updateContUse1.test.ts @@ -3,12 +3,12 @@ import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type Stripe from "stripe"; -import { replaceItems } from "tests/attach/utils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { replaceItems } from "@tests/attach/utils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { advanceTestClock } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/contUse/update/updateContUse2.backup.ts b/server/tests/contUse/update/updateContUse2.backup.ts index 0f29aa05f..67674e133 100644 --- a/server/tests/contUse/update/updateContUse2.backup.ts +++ b/server/tests/contUse/update/updateContUse2.backup.ts @@ -9,13 +9,13 @@ import { expect } from "chai"; import chalk from "chalk"; import { addWeeks } from "date-fns"; 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 { 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"; diff --git a/server/tests/contUse/update/updateContUse2.test.ts b/server/tests/contUse/update/updateContUse2.test.ts index 7502ad2b1..972444231 100644 --- a/server/tests/contUse/update/updateContUse2.test.ts +++ b/server/tests/contUse/update/updateContUse2.test.ts @@ -2,12 +2,12 @@ import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { replaceItems } from "tests/attach/utils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { replaceItems } from "@tests/attach/utils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { advanceTestClock } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/contUse/update/updateContUse3.backup.ts b/server/tests/contUse/update/updateContUse3.backup.ts index dc2bc1318..a0f057c2d 100644 --- a/server/tests/contUse/update/updateContUse3.backup.ts +++ b/server/tests/contUse/update/updateContUse3.backup.ts @@ -7,13 +7,13 @@ import { } from "@autumn/shared"; import chalk from "chalk"; 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 { 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 type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/contUse/update/updateContUse3.test.ts b/server/tests/contUse/update/updateContUse3.test.ts index d702ee327..765de4eea 100644 --- a/server/tests/contUse/update/updateContUse3.test.ts +++ b/server/tests/contUse/update/updateContUse3.test.ts @@ -1,12 +1,12 @@ import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import { beforeAll, describe, test } from "bun:test"; import chalk from "chalk"; -import { replaceItems } from "tests/attach/utils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { replaceItems } from "@tests/attach/utils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/contUse/update/updateContUse4.backup.ts b/server/tests/contUse/update/updateContUse4.backup.ts index ec309ef1f..244c7311e 100644 --- a/server/tests/contUse/update/updateContUse4.backup.ts +++ b/server/tests/contUse/update/updateContUse4.backup.ts @@ -9,14 +9,14 @@ import { expect } from "chai"; import chalk from "chalk"; import { addWeeks } from "date-fns"; 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 { 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"; diff --git a/server/tests/contUse/update/updateContUse4.test.ts b/server/tests/contUse/update/updateContUse4.test.ts index 34a9fbbc2..c74dbae5f 100644 --- a/server/tests/contUse/update/updateContUse4.test.ts +++ b/server/tests/contUse/update/updateContUse4.test.ts @@ -2,13 +2,13 @@ import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import { beforeAll, describe, expect, test } from "bun:test"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import { replaceItems } from "tests/attach/utils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { advanceTestClock } from "tests/utils/stripeUtils.js"; +import { replaceItems } from "@tests/attach/utils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { advanceTestClock } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { subToPeriodStartEnd } from "@/external/stripe/stripeSubUtils/convertSubUtils.js"; import { calculateProrationAmount } from "@/internal/invoices/prorationUtils.js"; diff --git a/server/tests/contUse/update/updateContUse5.backup.ts b/server/tests/contUse/update/updateContUse5.backup.ts index f220b267d..e2f00710e 100644 --- a/server/tests/contUse/update/updateContUse5.backup.ts +++ b/server/tests/contUse/update/updateContUse5.backup.ts @@ -8,12 +8,12 @@ import { import chalk from "chalk"; 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 { 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"; diff --git a/server/tests/contUse/update/updateContUse5.test.ts b/server/tests/contUse/update/updateContUse5.test.ts index 27078b81e..2950cea54 100644 --- a/server/tests/contUse/update/updateContUse5.test.ts +++ b/server/tests/contUse/update/updateContUse5.test.ts @@ -2,10 +2,10 @@ import { LegacyVersion, OnDecrease, OnIncrease } from "@autumn/shared"; import { beforeAll, describe, test } from "bun:test"; import chalk from "chalk"; import { addWeeks } from "date-fns"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearProratedItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/contUse/update/updateContUse6.ts b/server/tests/contUse/update/updateContUse6.ts index dfdf32687..d85f3a69e 100644 --- a/server/tests/contUse/update/updateContUse6.ts +++ b/server/tests/contUse/update/updateContUse6.ts @@ -8,10 +8,10 @@ import { import { expect } from "chai"; import chalk from "chalk"; 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 { createProducts } from "tests/utils/productUtils.js"; +import { addPrefixToProducts, replaceItems } 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 { diff --git a/server/tests/core/cancel/cancel2.test.ts b/server/tests/core/cancel/cancel2.test.ts index 4d4f882b1..de158098e 100644 --- a/server/tests/core/cancel/cancel2.test.ts +++ b/server/tests/core/cancel/cancel2.test.ts @@ -1,24 +1,23 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { 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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -46,39 +45,26 @@ describe(`${chalk.yellowBright("cancel2: Testing cancel at period end (with usag let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -94,7 +80,7 @@ describe(`${chalk.yellowBright("cancel2: Testing cancel at period end (with usag }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -116,12 +102,12 @@ describe(`${chalk.yellowBright("cancel2: Testing cancel at period end (with usag } }); - it("should track usage cancel, advance test clock and have correct invoice", async () => { + test("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 = { - start: prod?.current_period_start!, - end: prod?.current_period_end!, + start: prod?.current_period_start || Date.now(), + end: prod?.current_period_end || Date.now(), }; await autumn.track({ @@ -159,10 +145,10 @@ describe(`${chalk.yellowBright("cancel2: Testing cancel at period end (with usag }); const cus = await autumn.customers.get(customerId); - const prods = cus.products.filter((p) => p.group == premium.group); - expect(prods.length).to.equal(0); + const prods = cus.products.filter((p) => p.group === premium.group); + expect(prods.length).toBe(0); - expect(cus.invoices.length).to.equal(2); - expect(cus.invoices[0].total).to.equal(wordsAmount); + expect(cus.invoices.length).toBe(2); + expect(cus.invoices[0].total).toBe(wordsAmount); }); }); diff --git a/server/tests/core/cancel/cancel3.test.ts b/server/tests/core/cancel/cancel3.test.ts index c3d9f06c1..83d6fbe82 100644 --- a/server/tests/core/cancel/cancel3.test.ts +++ b/server/tests/core/cancel/cancel3.test.ts @@ -1,17 +1,15 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { @@ -19,7 +17,8 @@ import { constructFeatureItem, } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -57,39 +56,26 @@ describe(`${chalk.yellowBright("cancel3: Cancelling free product")}`, () => { let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [free], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [free], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -105,7 +91,7 @@ describe(`${chalk.yellowBright("cancel3: Cancelling free product")}`, () => { }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -128,7 +114,7 @@ describe(`${chalk.yellowBright("cancel3: Cancelling free product")}`, () => { } }); - it("should track usage cancel, advance test clock and have correct invoice", async () => { + test("should track usage cancel, advance test clock and have correct invoice", async () => { const cus1 = await autumn.customers.get(customerId); await autumn.cancel({ @@ -138,7 +124,7 @@ describe(`${chalk.yellowBright("cancel3: Cancelling free product")}`, () => { }); const cus = await autumn.customers.get(customerId); - const prods = cus.products.filter((p) => p.group == free.group); - expect(prods.length).to.equal(0); + const prods = cus.products.filter((p) => p.group === free.group); + expect(prods.length).toBe(0); }); }); diff --git a/server/tests/core/cancel/cancel4.test.ts b/server/tests/core/cancel/cancel4.test.ts index d25ab36b6..a6b0c55c2 100644 --- a/server/tests/core/cancel/cancel4.test.ts +++ b/server/tests/core/cancel/cancel4.test.ts @@ -1,18 +1,16 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { @@ -20,7 +18,8 @@ import { constructFeatureItem, } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -60,37 +59,25 @@ describe(`${chalk.yellowBright("cancel4: Cancelling free add on product")}`, () let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [premium, addOn], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [premium, addOn], - db, - orgId: org.id, - env, customerId, }); - await initCustomer({ - autumn: autumnJs, + await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: false, }); + + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; }); const entities = [ @@ -106,7 +93,7 @@ describe(`${chalk.yellowBright("cancel4: Cancelling free add on product")}`, () }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -129,7 +116,7 @@ describe(`${chalk.yellowBright("cancel4: Cancelling free add on product")}`, () } }); - it("should track usage cancel, advance test clock and have correct invoice", async () => { + test("should track usage cancel, advance test clock and have correct invoice", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, @@ -143,6 +130,6 @@ describe(`${chalk.yellowBright("cancel4: Cancelling free add on product")}`, () }); const products = cus.products.filter((p) => p.group === addOn.group); - expect(products.length).to.equal(1); + expect(products.length).toBe(1); }); }); diff --git a/server/tests/core/cancel/cancel5.test.ts b/server/tests/core/cancel/cancel5.test.ts index 071dbb664..4bf981ee5 100644 --- a/server/tests/core/cancel/cancel5.test.ts +++ b/server/tests/core/cancel/cancel5.test.ts @@ -1,65 +1,90 @@ +import { beforeAll, describe, expect, it } from "bun:test"; import { - type AppEnv, CusProductStatus, LegacyVersion, - type Organization, + ProductItemInterval, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; 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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; +import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; -const testCase = "cancel1"; -describe(`${chalk.yellowBright("cancel1: Testing cancel for trial products")}`, () => { +const freeProd = constructProduct({ + type: "free", + isDefault: true, + items: [ + constructFeatureItem({ + featureId: TestFeature.Messages, + includedUsage: 5, + interval: ProductItemInterval.Month, + }), + ], +}); + +const proProd = constructProduct({ + type: "pro", + items: [ + constructFeatureItem({ + featureId: TestFeature.Dashboard, + isBoolean: true, + }), + constructFeatureItem({ + featureId: TestFeature.Messages, + includedUsage: 10, + interval: ProductItemInterval.Month, + }), + constructFeatureItem({ + featureId: TestFeature.Admin, + unlimited: true, + }), + ], +}); + +const testCase = "cancel5"; +describe(`${chalk.yellowBright("cancel5: Testing cancel for trial products")}`, () => { const customerId = testCase; const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; - let testClockId: string; - let curUnix: number; - let db: DrizzleCli; - let org: Organization; - let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + beforeAll(async () => { + await initProductsV0({ + ctx, + products: [freeProd, proProd], + prefix: testCase, customerId, - db, - org, - env, - attachPm: "success", }); - testClockId = testClockId1!; + await initCustomerV3({ + ctx, + customerId, + attachPm: "success", + withTestClock: true, + withDefault: true, + }); + + stripeCli = ctx.stripeCli; }); it("should attach pro", async () => { await autumn.attach({ customer_id: customerId, - product_id: products.pro.id, + product_id: proProd.id, }); const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, - productId: products.pro.id, + product: proProd, }); }); @@ -67,10 +92,10 @@ describe(`${chalk.yellowBright("cancel1: Testing cancel for trial products")}`, it("should cancel pro product through stripe CLI", async () => { const fullCus = await CusService.getFull({ - db, + db: ctx.db, idOrInternalId: customerId, - orgId: org.id, - env, + orgId: ctx.org.id, + env: ctx.env, }); sub = await cusProductToSub({ @@ -87,17 +112,16 @@ describe(`${chalk.yellowBright("cancel1: Testing cancel for trial products")}`, const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, - productId: products.pro.id, + product: proProd, isCanceled: true, }); expectProductAttached({ customer, - productId: products.free.id, + product: freeProd, status: CusProductStatus.Scheduled, }); }); - return; it("should renew pro produce through stripe CLI and have it update correctly", async () => { await stripeCli.subscriptions.update(sub!.id, { @@ -109,10 +133,10 @@ describe(`${chalk.yellowBright("cancel1: Testing cancel for trial products")}`, const customer = await autumn.customers.get(customerId); expectProductAttached({ customer, - productId: products.pro.id, + product: proProd, status: CusProductStatus.Active, }); - expect(customer.products.length).to.equal(1); + expect(customer.products.length).toBe(1); }); }); diff --git a/server/tests/core/cancel/mergedCancel1.test.ts b/server/tests/core/cancel/mergedCancel1.test.ts index b12a961a8..af5839903 100644 --- a/server/tests/core/cancel/mergedCancel1.test.ts +++ b/server/tests/core/cancel/mergedCancel1.test.ts @@ -1,3 +1,4 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, AttachScenario, @@ -5,20 +6,18 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -76,39 +75,26 @@ describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -124,7 +110,7 @@ describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -148,7 +134,7 @@ describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { } }); - it("should track usage cancel, advance test clock and have correct invoice", async () => { + test("should track usage cancel, advance test clock and have correct invoice", async () => { for (const cancel of cancels) { await autumn.cancel({ customer_id: customerId, @@ -167,7 +153,7 @@ describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { } }); - it("should renew both entities", async () => { + test("should renew both entities", async () => { for (const renewal of renewals) { const checkout = await autumn.checkout({ customer_id: customerId, @@ -175,8 +161,8 @@ describe(`${chalk.yellowBright("mergedCancel1: Merged cancel")}`, () => { entity_id: renewal.entityId, }); - expect(checkout.product.scenario).to.equal(AttachScenario.Renew); - expect(checkout.total).to.equal(0); + expect(checkout.product.scenario).toBe(AttachScenario.Renew); + expect(checkout.total).toBe(0); const attach = await autumn.attach({ customer_id: customerId, diff --git a/server/tests/core/cancel/mergedCancel2.test.ts b/server/tests/core/cancel/mergedCancel2.test.ts index ab9bef16b..66699d133 100644 --- a/server/tests/core/cancel/mergedCancel2.test.ts +++ b/server/tests/core/cancel/mergedCancel2.test.ts @@ -1,22 +1,16 @@ -import { - type AppEnv, - CusProductStatus, - LegacyVersion, - type Organization, -} from "@autumn/shared"; +import { beforeAll, describe, it } from "bun:test"; +import { CusProductStatus, LegacyVersion } from "@autumn/shared"; +import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; // Premium, Premium // Cancel End, Cancel Immediately @@ -60,45 +54,23 @@ describe(`${chalk.yellowBright("mergedCancel2: Testing cancel immediately")}`, ( const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; - let testClockId: string; - let curUnix: number; - let db: DrizzleCli; - let org: Organization; - let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: false, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; }); const entities = [ @@ -125,9 +97,9 @@ describe(`${chalk.yellowBright("mergedCancel2: Testing cancel immediately")}`, ( customerId, product: op.product, stripeCli, - db, - org, - env, + db: ctx.db, + org: ctx.org, + env: ctx.env, entityId: op.entityId, }); } catch (error) { @@ -147,10 +119,10 @@ describe(`${chalk.yellowBright("mergedCancel2: Testing cancel immediately")}`, ( }); await expectSubToBeCorrect({ - db, + db: ctx.db, customerId, - org, - env, + org: ctx.org, + env: ctx.env, shouldBeCanceled: cancel.shouldBeCanceled, }); } diff --git a/server/tests/core/cancel/mergedCancel3.test.ts b/server/tests/core/cancel/mergedCancel3.test.ts index bdaf55d0b..f4d65598c 100644 --- a/server/tests/core/cancel/mergedCancel3.test.ts +++ b/server/tests/core/cancel/mergedCancel3.test.ts @@ -1,22 +1,16 @@ -import { - type AppEnv, - CusProductStatus, - LegacyVersion, - type Organization, -} from "@autumn/shared"; +import { beforeAll, describe, it } from "bun:test"; +import { CusProductStatus, LegacyVersion } from "@autumn/shared"; +import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; // Premium, Premium // Cancel Immediately, Cancel Immediately @@ -62,45 +56,23 @@ describe(`${chalk.yellowBright("mergedCancel3: Testing cancel immediately")}`, ( const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); let stripeCli: Stripe; - let testClockId: string; - let curUnix: number; - let db: DrizzleCli; - let org: Organization; - let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: false, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; }); const entities = [ @@ -127,9 +99,9 @@ describe(`${chalk.yellowBright("mergedCancel3: Testing cancel immediately")}`, ( customerId, product: op.product, stripeCli, - db, - org, - env, + db: ctx.db, + org: ctx.org, + env: ctx.env, entityId: op.entityId, }); } catch (error) { @@ -151,10 +123,10 @@ describe(`${chalk.yellowBright("mergedCancel3: Testing cancel immediately")}`, ( if (cancel.skipSubCheck) continue; await expectSubToBeCorrect({ - db, + db: ctx.db, customerId, - org, - env, + org: ctx.org, + env: ctx.env, shouldBeCanceled: cancel.shouldBeCanceled, }); } diff --git a/server/tests/core/multiAttach/multiAttach1.test.ts b/server/tests/core/multiAttach/multiAttach1.test.ts index 205426f6c..532d2ecfa 100644 --- a/server/tests/core/multiAttach/multiAttach1.test.ts +++ b/server/tests/core/multiAttach/multiAttach1.test.ts @@ -1,23 +1,23 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectMultiAttachCorrect } from "@tests/utils/expectUtils/expectMultiAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const growth = constructProduct({ id: "growth", @@ -76,42 +76,28 @@ describe(`${chalk.yellowBright("multiAttach1: Testing multi attach for trial pro let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium, growth], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium, growth], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, - // attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -143,7 +129,7 @@ describe(`${chalk.yellowBright("multiAttach1: Testing multi attach for trial pro }); }); - it("should advance clock and update premium & growth while trialing", async () => { + test("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 6a3a01c05..aef235152 100644 --- a/server/tests/core/multiAttach/multiAttach2.test.ts +++ b/server/tests/core/multiAttach/multiAttach2.test.ts @@ -1,23 +1,23 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectMultiAttachCorrect } from "@tests/utils/expectUtils/expectMultiAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const growth = constructProduct({ id: "growth", @@ -73,42 +73,29 @@ describe(`${chalk.yellowBright("multiAttach2: Testing multi attach for trial pro let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium, growth], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium, growth], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -140,7 +127,7 @@ describe(`${chalk.yellowBright("multiAttach2: Testing multi attach for trial pro }); }); - it("should advance clock and update premium & growth while trialing", async () => { + test("should advance clock and update premium & growth while trialing", async () => { const newProducts = [ { product_id: premium.id, diff --git a/server/tests/core/multiAttach/multiAttach3.test.ts b/server/tests/core/multiAttach/multiAttach3.test.ts index d5a582600..618efa53a 100644 --- a/server/tests/core/multiAttach/multiAttach3.test.ts +++ b/server/tests/core/multiAttach/multiAttach3.test.ts @@ -1,31 +1,28 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -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 { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import { expectMultiAttachCorrect, expectResultsCorrect, -} from "tests/utils/expectUtils/expectMultiAttach.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/expectUtils/expectMultiAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import { addDays } from "date-fns"; +import type { Stripe } from "stripe"; 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 { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -63,42 +60,29 @@ describe(`${chalk.yellowBright("multiAttach3: Testing multi attach for trial pro let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -162,7 +146,7 @@ describe(`${chalk.yellowBright("multiAttach3: Testing multi attach for trial pro }, ]; - it("should transfer to entity and have correct sub", async () => { + test("should transfer to entity and have correct sub", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -188,7 +172,7 @@ describe(`${chalk.yellowBright("multiAttach3: Testing multi attach for trial pro }); }); - it("should cancel one entity's sub at end of cycle and have correct schedule...", async () => { + test("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, @@ -203,7 +187,7 @@ describe(`${chalk.yellowBright("multiAttach3: Testing multi attach for trial pro }); }); - it("should cancel one entity's sub immediately", async () => { + test("should cancel one entity's sub immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: premium.id, @@ -221,7 +205,7 @@ describe(`${chalk.yellowBright("multiAttach3: Testing multi attach for trial pro }); }); - it("should advance test clock to end of trial and have correct sub", async () => { + test("should advance test clock to end of trial and have correct sub", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -244,7 +228,7 @@ describe(`${chalk.yellowBright("multiAttach3: Testing multi attach for trial pro getBasePrice({ product: pro }) * 4 + getBasePrice({ product: premium }) * 2; - expect(invoiceTotal).to.equal(latestInvoice.total); + expect(invoiceTotal).toBe(latestInvoice.total); await expectSubToBeCorrect({ db, diff --git a/server/tests/core/multiAttach/multiAttach4.test.ts b/server/tests/core/multiAttach/multiAttach4.test.ts index bc811366b..33d305e9d 100644 --- a/server/tests/core/multiAttach/multiAttach4.test.ts +++ b/server/tests/core/multiAttach/multiAttach4.test.ts @@ -1,31 +1,28 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -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 { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import { expectMultiAttachCorrect, expectResultsCorrect, -} from "tests/utils/expectUtils/expectMultiAttach.js"; -import { createProducts } from "tests/utils/productUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { - addPrefixToProducts, - getBasePrice, -} from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/expectUtils/expectMultiAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; +import chalk from "chalk"; +import { addDays } from "date-fns"; +import type { Stripe } from "stripe"; 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 { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -69,42 +66,29 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium, proAnnual], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium, proAnnual], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -176,7 +160,7 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr }, ]; - it("should transfer to entity and have correct sub", async () => { + test("should transfer to entity and have correct sub", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -201,7 +185,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 () => { + test("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,7 +200,7 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr }); }); - it("should cancel one entity's sub immediately", async () => { + test("should cancel one entity's sub immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: premium.id, @@ -234,7 +218,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 () => { + test("should advance test clock to end of trial and have correct sub", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -257,7 +241,7 @@ describe(`${chalk.yellowBright("multiAttach4: Testing multi attach for annual pr getBasePrice({ product: pro }) * 4 + getBasePrice({ product: premium }) * 2; - expect(invoiceTotal).to.equal(latestInvoice.total); + expect(invoiceTotal).toBe(latestInvoice.total); await expectSubToBeCorrect({ db, diff --git a/server/tests/core/multiAttach/multiAttach5.test.ts b/server/tests/core/multiAttach/multiAttach5.test.ts index a0c90b867..028657241 100644 --- a/server/tests/core/multiAttach/multiAttach5.test.ts +++ b/server/tests/core/multiAttach/multiAttach5.test.ts @@ -1,29 +1,29 @@ +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; 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 { 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 { 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 { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/expectUtils/expectMultiAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { OrgService } from "@/internal/orgs/OrgService.js"; import { CacheManager } from "@/utils/cacheUtils/CacheManager.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -56,53 +56,40 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - + beforeAll(async () => { await OrgService.update({ - db, - orgId: org.id, + db: ctx.db, + orgId: ctx.org.id, updates: { config: { - ...org.config, + ...ctx.org.config, entity_product: true, }, }, }); - addPrefixToProducts({ + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -141,7 +128,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }, ]; - it("should transfer to entity 1 and 2", async () => { + test("should transfer to entity 1 and 2", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -207,7 +194,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 () => { + test("should try to reduce quantity of pro to less than number of entities and fail", async () => { await expectAutumnError({ func: async () => { await autumn.attach({ @@ -223,7 +210,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }); }); - it("should update pro product quantity and have correct amount", async () => { + test("should update pro product quantity and have correct amount", async () => { await expectMultiAttachCorrect({ customerId, products: [ @@ -257,7 +244,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }); }); - it("should decrease pro product quantity and have correct amount", async () => { + test("should decrease pro product quantity and have correct amount", async () => { await expectMultiAttachCorrect({ customerId, products: [ @@ -291,7 +278,7 @@ describe(`${chalk.yellowBright("multiAttach5: Testing multi attach and get custo }); }); - after(async () => { + afterAll(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 88fa6f58d..71a185c49 100644 --- a/server/tests/core/multiAttach/multiAttach6.test.ts +++ b/server/tests/core/multiAttach/multiAttach6.test.ts @@ -1,3 +1,4 @@ +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, @@ -6,18 +7,15 @@ import { nullish, 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 { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { TestFeature } from "tests/setup/v2Features.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 { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/expectUtils/expectMultiAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; @@ -25,7 +23,8 @@ import { OrgService } from "@/internal/orgs/OrgService.js"; import { CacheManager } from "@/utils/cacheUtils/CacheManager.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -58,53 +57,40 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - + beforeAll(async () => { await OrgService.update({ - db, - orgId: org.id, + db: ctx.db, + orgId: ctx.org.id, updates: { config: { - ...org.config, + ...ctx.org.config, entity_product: true, }, }, }); - addPrefixToProducts({ + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -143,7 +129,7 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo }, ]; - it("should transfer to entity 1 and 2", async () => { + test("should transfer to entity 1 and 2", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -198,7 +184,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 () => { + test("should try to reduce quantity of pro to 0 and have no top level cus product...", async () => { await autumn.attach({ customer_id: customerId, products: [ @@ -245,10 +231,10 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo (p: FullCusProduct) => p.product_id === pro.id && nullish(p.internal_entity_id), ); - expect(proProduct).to.be.undefined; + expect(proProduct).toBeUndefined(); }); - it("should increase pro product quantity and have correct amount", async () => { + test("should increase pro product quantity and have correct amount", async () => { await autumn.attach({ customer_id: customerId, products: [ @@ -260,7 +246,7 @@ describe(`${chalk.yellowBright("multiAttach6: Testing multi attach and get custo }); }); - after(async () => { + afterAll(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 3fca956dc..9ea2eb5ac 100644 --- a/server/tests/core/multiAttach/multiInvoice/multiInvoice1.test.ts +++ b/server/tests/core/multiAttach/multiInvoice/multiInvoice1.test.ts @@ -1,21 +1,21 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectMultiAttachCorrect } from "@tests/utils/expectUtils/expectMultiAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -50,42 +50,28 @@ describe(`${chalk.yellowBright("multiInvoice1: Testing multi attach through invo let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, - // attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through invoice checkout flow", async () => { + test("should run multi attach through invoice checkout flow", async () => { const productsList = [ { product_id: pro.id, @@ -115,7 +101,7 @@ describe(`${chalk.yellowBright("multiInvoice1: Testing multi attach through invo }); }); - it("should update premium & pro while trialing", async () => { + test("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 019a60c24..5402c178e 100644 --- a/server/tests/core/multiAttach/multiReward/multiReward1.test.ts +++ b/server/tests/core/multiAttach/multiReward/multiReward1.test.ts @@ -1,16 +1,17 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { expectMultiAttachCorrect } from "@tests/utils/expectUtils/expectMultiAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import { multiRewardPremium, multiRewardPro, @@ -31,48 +32,28 @@ describe(`${chalk.yellowBright("multiReward1: Testing multi attach with rewards" let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + beforeAll(async () => { + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; + await setupMultiRewardBefore({ orgId: org.id, db, env, }); - - // addPrefixToProducts({ - // products: [pro, premium, growth], - // prefix: testCase, - // }); - - // await createProducts({ - // autumn: autumnJs, - // products: [pro, premium, growth], - // db, - // orgId: org.id, - // env, - // customerId, - // }); - - testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("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 3cebff26c..73de7c03a 100644 --- a/server/tests/core/multiAttach/multiReward/multiReward2.test.ts +++ b/server/tests/core/multiAttach/multiReward/multiReward2.test.ts @@ -1,18 +1,19 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { expectMultiAttachCorrect } from "@tests/utils/expectUtils/expectMultiAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import { multiRewardPremium, multiRewardPro, @@ -33,34 +34,28 @@ describe(`${chalk.yellowBright("multiReward2: Testing multi attach with rewards let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + beforeAll(async () => { + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; + await setupMultiRewardBefore({ orgId: org.id, db, env, }); - - testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: multiRewardPro.id, @@ -87,7 +82,7 @@ describe(`${chalk.yellowBright("multiReward2: Testing multi attach with rewards }); }); - it("should delete discounts from subscription and prorate correctly", async () => { + test("should delete discounts from subscription and prorate correctly", async () => { const fullCus = await CusService.getFull({ db, orgId: org.id, @@ -105,7 +100,7 @@ describe(`${chalk.yellowBright("multiReward2: Testing multi attach with rewards }); }); - it("should update pro quantity and have correct checkout amount", async () => { + test("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 6709404ce..7b9b0cab1 100644 --- a/server/tests/core/multiAttach/multiReward/multiReward3.test.ts +++ b/server/tests/core/multiAttach/multiReward/multiReward3.test.ts @@ -1,22 +1,22 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +import { expectMultiAttachCorrect } from "@tests/utils/expectUtils/expectMultiAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; 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 { 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 { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; import { premiumReward, premiumTrial, @@ -37,34 +37,28 @@ describe(`${chalk.yellowBright("multiReward3: Testing multi attach with rewards let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + beforeAll(async () => { + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; + await setupMultiRewardBefore({ orgId: org.id, db, env, }); - - testClockId = testClockId1!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: proTrial.id, @@ -93,7 +87,7 @@ describe(`${chalk.yellowBright("multiReward3: Testing multi attach with rewards let checkoutRes: any; - it("should advance clock and update pro quantity", async () => { + test("should advance clock and update pro quantity", async () => { const productsList = [ { product_id: proTrial.id, @@ -129,7 +123,7 @@ describe(`${chalk.yellowBright("multiReward3: Testing multi attach with rewards checkoutRes = res.checkoutRes; }); - it("should advance to trial end and have correct quantity", async () => { + test("should advance to trial end and have correct quantity", async () => { await advanceTestClock({ stripeCli, testClockId, @@ -158,7 +152,7 @@ describe(`${chalk.yellowBright("multiReward3: Testing multi attach with rewards console.log("Premium price: ", premiumPrice); console.log("Checkout next cycle total: ", checkoutNextCycleTotal); - expect(latestInvoice.total).to.equal( + expect(latestInvoice.total).toBe( checkoutRes.next_cycle?.total + premiumPrice, ); }); diff --git a/server/tests/core/multiAttach/multiReward/multiRewardUtils.test.ts b/server/tests/core/multiAttach/multiReward/multiRewardUtils.test.ts index d6ce9ada4..cc8e36c76 100644 --- a/server/tests/core/multiAttach/multiReward/multiRewardUtils.test.ts +++ b/server/tests/core/multiAttach/multiReward/multiRewardUtils.test.ts @@ -5,7 +5,7 @@ import { LegacyVersion, RewardType, } from "@autumn/shared"; -import { TestFeature } from "tests/setup/v2Features.js"; +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"; diff --git a/server/tests/core/multiAttach/multiUpgrade/multiUpgrade1.test.ts b/server/tests/core/multiAttach/multiUpgrade/multiUpgrade1.test.ts index e407d3123..9118ed1e7 100644 --- a/server/tests/core/multiAttach/multiUpgrade/multiUpgrade1.test.ts +++ b/server/tests/core/multiAttach/multiUpgrade/multiUpgrade1.test.ts @@ -1,26 +1,25 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, 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 { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { TestFeature } from "tests/setup/v2Features.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 { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/expectUtils/expectMultiAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -56,43 +55,29 @@ describe(`${chalk.yellowBright("multiUpgrade1: Testing multi attach and upgrade" let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -146,7 +131,7 @@ describe(`${chalk.yellowBright("multiUpgrade1: Testing multi attach and upgrade" }, ]; - it("should transfer to entity and have correct sub", async () => { + test("should transfer to entity and have correct sub", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -168,7 +153,7 @@ describe(`${chalk.yellowBright("multiUpgrade1: Testing multi attach and upgrade" }); }); - it("should upgrade entity's sub to premium", async () => { + test("should upgrade entity's sub to premium", async () => { const checkoutRes = await autumn.checkout({ customer_id: customerId, product_id: premium.id, @@ -184,7 +169,7 @@ describe(`${chalk.yellowBright("multiUpgrade1: Testing multi attach and upgrade" const entity = await autumn.entities.get(customerId, "1"); const invoices = entity.invoices[0]; - expect(invoices.total).to.equal(checkoutRes.total); + expect(invoices.total).toBe(checkoutRes.total); await expectSubToBeCorrect({ db, diff --git a/server/tests/core/multiAttach/multiUpgrade/multiUpgrade2.test.ts b/server/tests/core/multiAttach/multiUpgrade/multiUpgrade2.test.ts index cf1c46076..8789c161e 100644 --- a/server/tests/core/multiAttach/multiUpgrade/multiUpgrade2.test.ts +++ b/server/tests/core/multiAttach/multiUpgrade/multiUpgrade2.test.ts @@ -1,25 +1,25 @@ +import { beforeAll, describe, expect, test } from "bun:test"; 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 { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { TestFeature } from "tests/setup/v2Features.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 { createProducts } from "tests/utils/productUtils.js"; -import { addPrefixToProducts } from "tests/utils/testProductUtils/testProductUtils.js"; +} from "@tests/utils/expectUtils/expectMultiAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import chalk from "chalk"; +import type { Stripe } from "stripe"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -55,42 +55,29 @@ describe(`${chalk.yellowBright("multiUpgrade2: Testing multi attach and update q let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); - it("should run multi attach through checkout and have correct sub", async () => { + test("should run multi attach through checkout and have correct sub", async () => { const productsList = [ { product_id: pro.id, @@ -144,7 +131,7 @@ describe(`${chalk.yellowBright("multiUpgrade2: Testing multi attach and update q }, ]; - it("should transfer to entity and have correct sub", async () => { + test("should transfer to entity and have correct sub", async () => { await autumn.entities.create(customerId, entities); await autumn.transfer(customerId, { @@ -166,7 +153,7 @@ describe(`${chalk.yellowBright("multiUpgrade2: Testing multi attach and update q }); }); - it("should update premium and pro quantities downward", async () => { + test("should update premium and pro quantities downward", async () => { const productsList = [ { product_id: pro.id, diff --git a/server/tests/core/reset1.backup.ts b/server/tests/core/reset1.backup.ts deleted file mode 100644 index f22aba0cb..000000000 --- a/server/tests/core/reset1.backup.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { - type AppEnv, - type Customer, - LegacyVersion, - type LimitedItem, - type Organization, - ProductItemInterval, -} from "@autumn/shared"; -import { expect } from "chai"; -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, - includedUsage: 400, - interval: ProductItemInterval.Day, - intervalCount: 3, -}) as LimitedItem; - -const wordsItem = constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 100, - interval: ProductItemInterval.Month, - intervalCount: 4, -}) as LimitedItem; - -export const free = constructProduct({ - items: [messagesItem, wordsItem], - type: "free", - isDefault: false, -}); - -const testCase = "reset1"; - -describe(`${chalk.yellowBright(`${testCase}: Testing custom reset intervals`)}`, () => { - 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; - const curUnix = new Date().getTime(); - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [free], - prefix: testCase, - }); - - await createProducts({ - autumn, - products: [free], - customerId, - db, - orgId: org.id, - env, - }); - - const res = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = res.testClockId!; - customer = res.customer; - }); - - it("should attach free product", async () => { - await autumn.attach({ - customer_id: customerId, - product_id: free.id, - }); - }); - - const messageUsage = 250; - const curBalance = messagesItem.included_usage; - - it("should reset messages feature and have correct next reset at", async () => { - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: messageUsage, - }); - - await timeout(3000); - - await resetAndGetCusEnt({ - db, - customer, - productGroup: free.group, - featureId: TestFeature.Messages, - }); - - const cus = await autumn.customers.get(customerId); - const msgesFeature = cus.features[TestFeature.Messages]; - expect(msgesFeature.next_reset_at).to.exist; - expect(msgesFeature.next_reset_at).to.approximately( - addDays(new Date(), 3).getTime(), - 1000 * 30, - ); - }); - - it("should reset words feature and have correct next reset at", async () => { - await resetAndGetCusEnt({ - db, - customer, - productGroup: free.group, - featureId: TestFeature.Words, - }); - - const cus = await autumn.customers.get(customerId); - const wordsFeature = cus.features[TestFeature.Words]; - expect(wordsFeature.next_reset_at).to.exist; - expect(wordsFeature.next_reset_at).to.approximately( - addMonths(new Date(), 4).getTime(), - 1000 * 30 * 60, // account for timezone differences - ); - }); -}); diff --git a/server/tests/core/reset1.test.ts b/server/tests/core/reset1.test.ts index 0a02c73a8..6c96ae0e4 100644 --- a/server/tests/core/reset1.test.ts +++ b/server/tests/core/reset1.test.ts @@ -7,13 +7,13 @@ import { type Organization, ProductItemInterval, } from "@autumn/shared"; +import { resetAndGetCusEnt } from "@tests/advanced/rollovers/rolloverTestUtils.js"; +import { addPrefixToProducts } from "@tests/attach/utils.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; 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 { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; @@ -104,7 +104,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom reset intervals`)}`, await resetAndGetCusEnt({ db, customer, - productGroup: free.group, + productGroup: free.group || "", featureId: TestFeature.Messages, }); @@ -121,7 +121,7 @@ describe(`${chalk.yellowBright(`${testCase}: Testing custom reset intervals`)}`, await resetAndGetCusEnt({ db, customer, - productGroup: free.group, + productGroup: free.group || "", featureId: TestFeature.Words, }); diff --git a/server/tests/core/reset1.ts b/server/tests/core/reset1.ts deleted file mode 100644 index f22aba0cb..000000000 --- a/server/tests/core/reset1.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { - type AppEnv, - type Customer, - LegacyVersion, - type LimitedItem, - type Organization, - ProductItemInterval, -} from "@autumn/shared"; -import { expect } from "chai"; -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, - includedUsage: 400, - interval: ProductItemInterval.Day, - intervalCount: 3, -}) as LimitedItem; - -const wordsItem = constructFeatureItem({ - featureId: TestFeature.Words, - includedUsage: 100, - interval: ProductItemInterval.Month, - intervalCount: 4, -}) as LimitedItem; - -export const free = constructProduct({ - items: [messagesItem, wordsItem], - type: "free", - isDefault: false, -}); - -const testCase = "reset1"; - -describe(`${chalk.yellowBright(`${testCase}: Testing custom reset intervals`)}`, () => { - 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; - const curUnix = new Date().getTime(); - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [free], - prefix: testCase, - }); - - await createProducts({ - autumn, - products: [free], - customerId, - db, - orgId: org.id, - env, - }); - - const res = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = res.testClockId!; - customer = res.customer; - }); - - it("should attach free product", async () => { - await autumn.attach({ - customer_id: customerId, - product_id: free.id, - }); - }); - - const messageUsage = 250; - const curBalance = messagesItem.included_usage; - - it("should reset messages feature and have correct next reset at", async () => { - await autumn.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: messageUsage, - }); - - await timeout(3000); - - await resetAndGetCusEnt({ - db, - customer, - productGroup: free.group, - featureId: TestFeature.Messages, - }); - - const cus = await autumn.customers.get(customerId); - const msgesFeature = cus.features[TestFeature.Messages]; - expect(msgesFeature.next_reset_at).to.exist; - expect(msgesFeature.next_reset_at).to.approximately( - addDays(new Date(), 3).getTime(), - 1000 * 30, - ); - }); - - it("should reset words feature and have correct next reset at", async () => { - await resetAndGetCusEnt({ - db, - customer, - productGroup: free.group, - featureId: TestFeature.Words, - }); - - const cus = await autumn.customers.get(customerId); - const wordsFeature = cus.features[TestFeature.Words]; - expect(wordsFeature.next_reset_at).to.exist; - expect(wordsFeature.next_reset_at).to.approximately( - addMonths(new Date(), 4).getTime(), - 1000 * 30 * 60, // account for timezone differences - ); - }); -}); diff --git a/server/tests/crud/customers/create-customer1.test.ts b/server/tests/crud/customers/create-customer1.test.ts index b0c9eecb9..2aed9879f 100644 --- a/server/tests/crud/customers/create-customer1.test.ts +++ b/server/tests/crud/customers/create-customer1.test.ts @@ -1,7 +1,7 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { ApiVersion, CusExpand } from "@autumn/shared"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; const testCase = "create-customer1"; diff --git a/server/tests/customers/get-cus-feature1.test.ts b/server/tests/customers/get-cus-feature1.test.ts deleted file mode 100644 index 017c73eed..000000000 --- a/server/tests/customers/get-cus-feature1.test.ts +++ /dev/null @@ -1,147 +0,0 @@ -import { beforeAll, describe, expect, test } from "bun:test"; -import { - type ApiCusFeature, - ApiVersion, - type LimitedItem, -} from "@autumn/shared"; -import chalk from "chalk"; -import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; -import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; -import type { ApiCusFeatureV3 } from "../../../shared/api/customers/cusFeatures/previousVersions/apiCusFeatureV3.js"; -import { timeout } from "../utils/genUtils.js"; - -const messagesFeature = constructFeatureItem({ - featureId: TestFeature.Messages, - includedUsage: 1000, -}) as LimitedItem; - -const freeProd = constructProduct({ - type: "free", - isDefault: false, - items: [messagesFeature], -}); - -const testCase = "get-cus-feature1"; - -describe(`${chalk.yellowBright("get-cus-feature1: testing current balance + usage")}`, () => { - const customerId = testCase; - const autumnV1: AutumnInt = new AutumnInt({ version: ApiVersion.V1_2 }); - const autumnV2: AutumnInt = new AutumnInt({ version: ApiVersion.V2_0 }); - - const usage = 20.132; - - beforeAll(async () => { - await initCustomerV3({ - ctx, - customerId, - withTestClock: false, - }); - - await initProductsV0({ - ctx, - products: [freeProd], - prefix: testCase, - }); - - await autumnV1.attach({ - customer_id: customerId, - product_id: freeProd.id, - }); - }); - - test("should track usage and have correct v1 / v2 api cus feature", async () => { - await autumnV2.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: usage, - }); - - await timeout(2000); - const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - const currentBalance = new Decimal(messagesFeature.included_usage) - .minus(usage) - .toNumber(); - - expect(feature).toMatchObject({ - granted_balance: messagesFeature.included_usage, - purchased_balance: 0, - current_balance: currentBalance, - usage, - }); - - const customerV1 = await autumnV1.customers.get(customerId); - const featureV1 = customerV1.features[ - TestFeature.Messages - ] as unknown as ApiCusFeatureV3; - - expect(featureV1).toMatchObject({ - included_usage: messagesFeature.included_usage, - balance: currentBalance, - usage, - }); - expect(featureV1.next_reset_at).toBeDefined(); - }); - return; - - test("should update balance and have correct v2 api cus feature", async () => { - // await autumnV2.balances.update({ - // customer_id: customerId, - // feature_id: TestFeature.Messages, - // current_balance: 1000, - // }); - // await timeout(2000); - // const cusEnt = await getCusEntByFeature({ - // db: ctx.db, - // org: ctx.org, - // env: ctx.env, - // customerId, - // featureId: TestFeature.Messages, - // }); - // await autumnV2.updateCusEnt({ - // customerId, - // customerEntitlementId: cusEnt.id, - // updates: { - // balance: 1000, - // }, - // }); - }); - - test("should have correct v2 api cus feature", async () => { - const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - expect(feature).toMatchObject({ - granted_balance: messagesFeature.included_usage, - purchased_balance: 0, - current_balance: 1000, - usage, - }); - expect(feature.resets_at).toBeDefined(); - }); - - test("should have correct v1 api cus feature", async () => { - const customer = await autumnV1.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeatureV3; - - expect(feature).toMatchObject({ - included_usage: messagesFeature.included_usage, - balance: 1000, - usage, - }); - expect(feature.next_reset_at).toBeDefined(); - }); -}); diff --git a/server/tests/customers/get-cus-feature2.test.ts b/server/tests/customers/get-cus-feature2.test.ts deleted file mode 100644 index edce1ada2..000000000 --- a/server/tests/customers/get-cus-feature2.test.ts +++ /dev/null @@ -1,155 +0,0 @@ -import { beforeAll, describe, expect, test } from "bun:test"; -import { - type ApiCusFeature, - type ApiCusFeatureV3, - ApiVersion, - type LimitedItem, -} from "@autumn/shared"; -import chalk from "chalk"; -import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; -import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; -import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; -import { updateFeatureBalance } from "../utils/cusProductUtils/updateCusEntBalance.js"; -import { timeout } from "../utils/genUtils.js"; - -const messagesFeature = constructArrearItem({ - featureId: TestFeature.Messages, - price: 0.5, - billingUnits: 1, - includedUsage: 1000, -}) as LimitedItem; - -const freeProd = constructProduct({ - type: "free", - id: "usage-based", - isDefault: false, - items: [messagesFeature], -}); - -const testCase = "get-cus-feature2"; - -describe(`${chalk.yellowBright("get-cus-feature2: testing arrear feature")}`, () => { - const customerId = testCase; - const autumnV1: AutumnInt = new AutumnInt({ version: ApiVersion.V1_2 }); - const autumnV2: AutumnInt = new AutumnInt({ version: ApiVersion.V2_0 }); - - const usage = 20.132; - - beforeAll(async () => { - await initCustomerV3({ - ctx, - customerId, - withTestClock: false, - attachPm: "success", - }); - - await initProductsV0({ - ctx, - products: [freeProd], - prefix: testCase, - }); - - await autumnV1.attach({ - customer_id: customerId, - product_id: freeProd.id, - }); - }); - - const usageAmount = 20.132; - test("should track usage and have correct v1 / v2 api cus feature", async () => { - await autumnV2.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: usageAmount, - }); - - await timeout(2000); - - const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - expect(feature).toMatchObject({ - granted_balance: messagesFeature.included_usage, - purchased_balance: 0, - current_balance: messagesFeature.included_usage - usageAmount, - usage: usageAmount, - }); - - const customerV1 = await autumnV1.customers.get(customerId); - const featureV1 = customerV1.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - expect(featureV1).toMatchObject({ - included_usage: messagesFeature.included_usage, - balance: messagesFeature.included_usage - usageAmount, - usage: usageAmount, - }); - }); - - const usageAmount2 = 1231.131; - const totalUsage = new Decimal(usageAmount).add(usageAmount2).toNumber(); - test("should track into overage and have correct v1 / v2 api cus feature", async () => { - await autumnV2.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: usageAmount2, - }); - - await timeout(2000); - - const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[TestFeature.Messages]; - - expect(feature).toMatchObject({ - granted_balance: messagesFeature.included_usage, - purchased_balance: new Decimal(totalUsage) - .sub(messagesFeature.included_usage) - .toNumber(), - current_balance: 0, - usage: totalUsage, - }); - - const customerV1 = await autumnV1.customers.get(customerId); - const featureV1 = customerV1.features[ - TestFeature.Messages - ] as unknown as ApiCusFeatureV3; - - expect(featureV1).toMatchObject({ - included_usage: messagesFeature.included_usage, - balance: new Decimal(messagesFeature.included_usage) - .sub(new Decimal(totalUsage)) - .toNumber(), - usage: totalUsage, - }); - }); - - const newBalance = -101.523; - test("should update balance and have correct v1 / v2 api cus feature", async () => { - await updateFeatureBalance({ - ctx, - customerId, - featureId: TestFeature.Messages, - balance: newBalance, - }); - - await timeout(2000); - - const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[TestFeature.Messages]; - - expect(feature).toMatchObject({ - granted_balance: messagesFeature.included_usage, - purchased_balance: newBalance, - current_balance: 0, - usage: usageAmount2, - }); - }); -}); diff --git a/server/tests/customers/get-cus-feature3.test.ts b/server/tests/customers/get-cus-feature3.test.ts deleted file mode 100644 index b6d8f2e87..000000000 --- a/server/tests/customers/get-cus-feature3.test.ts +++ /dev/null @@ -1,163 +0,0 @@ -import { beforeAll, describe, expect, test } from "bun:test"; -import { - type ApiCusFeature, - ApiVersion, - type LimitedItem, -} from "@autumn/shared"; -import chalk from "chalk"; -import { Decimal } from "decimal.js"; -import { TestFeature } from "tests/setup/v2Features.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; -import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; -import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; -import { constructProduct } from "../../src/utils/scriptUtils/createTestProducts.js"; -import { timeout } from "../utils/genUtils.js"; - -const userFeature = constructFeatureItem({ - featureId: TestFeature.Users, - includedUsage: 10, -}) as LimitedItem; - -const proProd = constructProduct({ - items: [userFeature], - type: "free", - isDefault: false, -}); - -const testCase = "get-cus-feature3"; - -describe(`${chalk.yellowBright("get-cus-feature3: testing arrear feature")}`, () => { - const customerId = testCase; - const autumnV1: AutumnInt = new AutumnInt({ version: ApiVersion.V1_2 }); - const autumnV2: AutumnInt = new AutumnInt({ version: ApiVersion.V2_0 }); - - const usage = 20.132; - - beforeAll(async () => { - await initCustomerV3({ - ctx, - customerId, - withTestClock: false, - attachPm: "success", - }); - - await initProductsV0({ - ctx, - products: [proProd], - prefix: testCase, - }); - - await autumnV1.attach({ - customer_id: customerId, - product_id: proProd.id, - }); - }); - - test("should attach pro product to customer", async () => { - await autumnV1.attach({ - customer_id: customerId, - product_id: proProd.id, - }); - }); - - return; - - const usageAmount = 20.132; - test("should track usage and have correct v1 / v2 api cus feature", async () => { - await autumnV2.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: usageAmount, - }); - - await timeout(2000); - - const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - expect(feature).toMatchObject({ - granted_balance: messagesFeature.included_usage, - purchased_balance: 0, - current_balance: 1000, - usage: usageAmount, - }); - - const customerV1 = await autumnV1.customers.get(customerId); - const featureV1 = customerV1.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - expect(featureV1).toMatchObject({ - included_usage: messagesFeature.included_usage, - balance: 1000, - usage: usageAmount, - }); - }); - - const usageAmount2 = 1231.131; - const totalUsage = new Decimal(usageAmount).add(usageAmount2).toNumber(); - test("should track into overage and have correct v1 / v2 api cus feature", async () => { - await autumnV2.track({ - customer_id: customerId, - feature_id: TestFeature.Messages, - value: usageAmount2, - }); - - await timeout(2000); - - const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - expect(feature).toMatchObject({ - granted_balance: messagesFeature.included_usage, - purchased_balance: new Decimal(totalUsage) - .sub(messagesFeature.included_usage) - .toNumber(), - current_balance: 0, - usage: totalUsage, - }); - - // const customerV1 = await autumnV1.customers.get(customerId); - // const featureV1 = customerV1.features[ - // TestFeature.Messages - // ] as unknown as ApiCusFeatureV3; - - // expect(featureV1).toMatchObject({ - // included_usage: messagesFeature.included_usage, - // balance: 0, - // usage: totalUsage, - }); - - test("should have correct v2 api cus feature", async () => { - const customer = await autumnV2.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - expect(feature).toMatchObject({ - granted_balance: messagesFeature.included_usage, - purchased_balance: 0, - current_balance: 1000, - usage, - }); - }); - - test("should have correct v1 api cus feature", async () => { - const customer = await autumnV1.customers.get(customerId); - const feature = customer.features[ - TestFeature.Messages - ] as unknown as ApiCusFeature; - - expect(feature).toMatchObject({ - included_usage: messagesFeature.included_usage, - balance: 1000, - usage, - }); - }); -}); diff --git a/server/tests/interval/multiSub/multiSubInterval1.test.ts b/server/tests/interval/multiSub/multiSubInterval1.test.ts index 442410bae..786bdf1a5 100644 --- a/server/tests/interval/multiSub/multiSubInterval1.test.ts +++ b/server/tests/interval/multiSub/multiSubInterval1.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addMonths, addWeeks } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/interval/multiSub/multiSubInterval2.test.ts b/server/tests/interval/multiSub/multiSubInterval2.test.ts index d1898d796..e6461e037 100644 --- a/server/tests/interval/multiSub/multiSubInterval2.test.ts +++ b/server/tests/interval/multiSub/multiSubInterval2.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addMonths, addYears, differenceInDays } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/interval/multiSub/multiSubInterval3.test.ts b/server/tests/interval/multiSub/multiSubInterval3.test.ts index 82e6c5df7..29b71eee3 100644 --- a/server/tests/interval/multiSub/multiSubInterval3.test.ts +++ b/server/tests/interval/multiSub/multiSubInterval3.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addMonths, addYears, differenceInDays } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem, diff --git a/server/tests/interval/upgrade/interval1.test.ts b/server/tests/interval/upgrade/interval1.test.ts index f2d850eba..6c470ff03 100644 --- a/server/tests/interval/upgrade/interval1.test.ts +++ b/server/tests/interval/upgrade/interval1.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addWeeks, addYears } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/interval/upgrade/interval2.test.ts b/server/tests/interval/upgrade/interval2.test.ts index c024d800a..6c5f6bfeb 100644 --- a/server/tests/interval/upgrade/interval2.test.ts +++ b/server/tests/interval/upgrade/interval2.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addMonths, addWeeks, addYears } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/interval/upgrade/interval3.test.ts b/server/tests/interval/upgrade/interval3.test.ts index 46ddfd19f..17c34a425 100644 --- a/server/tests/interval/upgrade/interval3.test.ts +++ b/server/tests/interval/upgrade/interval3.test.ts @@ -2,10 +2,10 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { LegacyVersion } from "@autumn/shared"; import chalk from "chalk"; import { addDays } from "date-fns"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; diff --git a/server/tests/merged/add/mergedAdd1.test.ts b/server/tests/merged/add/mergedAdd1.test.ts index 490a1d4aa..db5070b4c 100644 --- a/server/tests/merged/add/mergedAdd1.test.ts +++ b/server/tests/merged/add/mergedAdd1.test.ts @@ -2,12 +2,12 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { getAttachPreviewTotal } from "tests/utils/testAttachUtils/getAttachPreviewTotal.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; -import { getBasePrice } from "tests/utils/testProductUtils/testProductUtils.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { getAttachPreviewTotal } from "@tests/utils/testAttachUtils/getAttachPreviewTotal.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } 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"; diff --git a/server/tests/merged/add/mergedAdd3.test.ts b/server/tests/merged/add/mergedAdd3.test.ts index b3a68cfb5..3b593fd36 100644 --- a/server/tests/merged/add/mergedAdd3.test.ts +++ b/server/tests/merged/add/mergedAdd3.test.ts @@ -7,10 +7,10 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type { 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 ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/addOn/mergedAddOn1.test.ts b/server/tests/merged/addOn/mergedAddOn1.test.ts index 8058c3569..a51dc9de2 100644 --- a/server/tests/merged/addOn/mergedAddOn1.test.ts +++ b/server/tests/merged/addOn/mergedAddOn1.test.ts @@ -1,19 +1,17 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { @@ -25,7 +23,8 @@ import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; // UNCOMMENT FROM HERE @@ -102,39 +101,26 @@ describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, addOn], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, addOn], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -150,7 +136,7 @@ describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -180,7 +166,7 @@ describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { } }); - it("should cancel add on product and have correct sub items", async () => { + test("should cancel add on product and have correct sub items", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, @@ -208,8 +194,7 @@ describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { }); }); - // return; - it("should advance to next invoice and have no add on product", async () => { + test("should advance to next invoice and have no add on product", async () => { await advanceToNextInvoice({ stripeCli, testClockId, @@ -222,6 +207,6 @@ describe(`${chalk.yellowBright("mergedAddOn1: Adding an add on")}`, () => { status: CusProductStatus.Active, }); const products = customer.products.filter((p) => p.group === addOn.group); - expect(products.length).to.equal(1); + expect(products.length).toBe(1); }); }); diff --git a/server/tests/merged/addOn/mergedAddOn2.test.ts b/server/tests/merged/addOn/mergedAddOn2.test.ts index 1e541acf3..b00deeb97 100644 --- a/server/tests/merged/addOn/mergedAddOn2.test.ts +++ b/server/tests/merged/addOn/mergedAddOn2.test.ts @@ -1,17 +1,16 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { @@ -22,7 +21,8 @@ import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const pro = constructProduct({ id: "pro", @@ -114,39 +114,26 @@ describe(`${chalk.yellowBright("mergedAddOn2: testing add ons between multiple e let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, addOn], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, addOn], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -162,7 +149,7 @@ describe(`${chalk.yellowBright("mergedAddOn2: testing add ons between multiple e }, ]; - it("should run operations", async () => { + test("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 9c3db6779..83dc40c77 100644 --- a/server/tests/merged/addOn/mergedAddOn3.test.ts +++ b/server/tests/merged/addOn/mergedAddOn3.test.ts @@ -1,18 +1,16 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; @@ -24,7 +22,8 @@ import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; const pro = constructProduct({ @@ -102,39 +101,26 @@ describe(`${chalk.yellowBright("mergedAddOn3: testing add ons between multiple e let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, addOn], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, addOn], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -150,7 +136,7 @@ describe(`${chalk.yellowBright("mergedAddOn3: testing add ons between multiple e }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -181,7 +167,7 @@ describe(`${chalk.yellowBright("mergedAddOn3: testing add ons between multiple e } }); - it("should cancel add on product immediately", async () => { + test("should cancel add on product immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, @@ -197,7 +183,7 @@ describe(`${chalk.yellowBright("mergedAddOn3: testing add ons between multiple e }); const products = customer.products.filter((p) => p.group === addOn.group); - expect(products.length).to.equal(1); + expect(products.length).toBe(1); await expectSubToBeCorrect({ customerId, diff --git a/server/tests/merged/addOn/mergedAddOn4.test.ts b/server/tests/merged/addOn/mergedAddOn4.test.ts index 4dfdeac37..8ed0a58f0 100644 --- a/server/tests/merged/addOn/mergedAddOn4.test.ts +++ b/server/tests/merged/addOn/mergedAddOn4.test.ts @@ -1,18 +1,16 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; @@ -24,7 +22,8 @@ import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; const premium = constructProduct({ @@ -98,39 +97,26 @@ describe(`${chalk.yellowBright("mergedAddOn4: testing cancelling add on immediat let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, addOn, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, addOn, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -146,7 +132,7 @@ describe(`${chalk.yellowBright("mergedAddOn4: testing cancelling add on immediat }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -177,7 +163,7 @@ describe(`${chalk.yellowBright("mergedAddOn4: testing cancelling add on immediat } }); - it("should cancel add on product immediately", async () => { + test("should cancel add on product immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, @@ -198,7 +184,7 @@ describe(`${chalk.yellowBright("mergedAddOn4: testing cancelling add on immediat }); const products = customer.products.filter((p) => p.group === addOn.group); - expect(products.length).to.equal(2); + expect(products.length).toBe(2); await expectSubToBeCorrect({ customerId, diff --git a/server/tests/merged/addOn/mergedAddOn5.test.ts b/server/tests/merged/addOn/mergedAddOn5.test.ts index d298885a7..fbb474709 100644 --- a/server/tests/merged/addOn/mergedAddOn5.test.ts +++ b/server/tests/merged/addOn/mergedAddOn5.test.ts @@ -1,19 +1,17 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { @@ -24,7 +22,8 @@ import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; const premium = constructProduct({ @@ -98,39 +97,26 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, addOn, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, addOn, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -146,7 +132,7 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -177,11 +163,12 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat } }); - it("should cancel add on product immediately", async () => { + test("should cancel add on product immediately", async () => { await autumn.cancel({ customer_id: customerId, product_id: addOn.id, entity_id: "1", + cancel_immediately: true, }); const customer = await autumn.customers.get(customerId); @@ -195,13 +182,8 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat product: premium, }); - expectProductAttached({ - customer, - product: addOn, - }); - const products = customer.products.filter((p) => p.group === addOn.group); - expect(products.length).to.equal(3); + expect(products.length).toBe(2); await expectSubToBeCorrect({ customerId, @@ -211,7 +193,7 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat }); }); - it("should advance test clock and have correct products / sub", async () => { + test("should advance test clock and have correct products / sub", async () => { await advanceToNextInvoice({ stripeCli, testClockId, @@ -225,7 +207,7 @@ describe(`${chalk.yellowBright("mergedAddOn5: testing cancelling add on immediat }); const products = customer.products.filter((p) => p.group === addOn.group); - expect(products.length).to.equal(1); + expect(products.length).toBe(1); await expectSubToBeCorrect({ customerId, diff --git a/server/tests/merged/addOn/mergedAddOn6.test.ts b/server/tests/merged/addOn/mergedAddOn6.test.ts index b2ee9dc78..ce10d9a67 100644 --- a/server/tests/merged/addOn/mergedAddOn6.test.ts +++ b/server/tests/merged/addOn/mergedAddOn6.test.ts @@ -1,17 +1,16 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { @@ -22,7 +21,8 @@ import { constructProduct, constructRawProduct, } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -140,39 +140,26 @@ describe(`${chalk.yellowBright("mergedAddOn6: testing update add on quantities o let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, addOn, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, addOn, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -193,7 +180,7 @@ describe(`${chalk.yellowBright("mergedAddOn6: testing update add on quantities o }, ]; - it("should run operations", async () => { + test("should run operations", async () => { await autumn.entities.create(customerId, entities); for (let index = 0; index < ops.length; index++) { @@ -223,9 +210,7 @@ describe(`${chalk.yellowBright("mergedAddOn6: testing update add on quantities o } } }); - return; - - it("should update prepaid quantity for entity 1 and 2", async () => { + test("should update prepaid quantity for entity 1 and 2", async () => { await attachAndExpectCorrect({ autumn, customerId, diff --git a/server/tests/merged/downgrade/mergedDowngrade1.test.ts b/server/tests/merged/downgrade/mergedDowngrade1.test.ts index eed192a02..668bee80e 100644 --- a/server/tests/merged/downgrade/mergedDowngrade1.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade1.test.ts @@ -7,9 +7,9 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/downgrade/mergedDowngrade2.test.ts b/server/tests/merged/downgrade/mergedDowngrade2.test.ts index 714e00a9f..514cb9309 100644 --- a/server/tests/merged/downgrade/mergedDowngrade2.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade2.test.ts @@ -7,11 +7,11 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type { 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 { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { diff --git a/server/tests/merged/downgrade/mergedDowngrade3.test.ts b/server/tests/merged/downgrade/mergedDowngrade3.test.ts index 75b143e06..4d80f7e50 100644 --- a/server/tests/merged/downgrade/mergedDowngrade3.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade3.test.ts @@ -5,11 +5,11 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { diff --git a/server/tests/merged/downgrade/mergedDowngrade4.test.ts b/server/tests/merged/downgrade/mergedDowngrade4.test.ts index 81479dc29..566365881 100644 --- a/server/tests/merged/downgrade/mergedDowngrade4.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade4.test.ts @@ -5,12 +5,12 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/downgrade/mergedDowngrade5.test.ts b/server/tests/merged/downgrade/mergedDowngrade5.test.ts index 02939a0fe..d75f6399a 100644 --- a/server/tests/merged/downgrade/mergedDowngrade5.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade5.test.ts @@ -5,12 +5,12 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { 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 ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { diff --git a/server/tests/merged/downgrade/mergedDowngrade6.test.ts b/server/tests/merged/downgrade/mergedDowngrade6.test.ts index e01e603aa..27e3aa3b1 100644 --- a/server/tests/merged/downgrade/mergedDowngrade6.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade6.test.ts @@ -7,10 +7,10 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type { 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 ctx from "tests/utils/testInitUtils/createTestContext.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 ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/downgrade/mergedDowngrade8.test.ts b/server/tests/merged/downgrade/mergedDowngrade8.test.ts index 7529b3d0d..a20fd4720 100644 --- a/server/tests/merged/downgrade/mergedDowngrade8.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade8.test.ts @@ -7,9 +7,9 @@ import { } from "@autumn/shared"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { expectProductAttached } from "tests/utils/expectUtils/expectProductAttached.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/downgrade/mergedDowngrade9.test.ts b/server/tests/merged/downgrade/mergedDowngrade9.test.ts index 60c3f33a2..8a929f6b1 100644 --- a/server/tests/merged/downgrade/mergedDowngrade9.test.ts +++ b/server/tests/merged/downgrade/mergedDowngrade9.test.ts @@ -5,13 +5,13 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { 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 { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/group/mergedGroup1.test.ts b/server/tests/merged/group/mergedGroup1.test.ts index b4ff4e5d5..fc33082af 100644 --- a/server/tests/merged/group/mergedGroup1.test.ts +++ b/server/tests/merged/group/mergedGroup1.test.ts @@ -5,12 +5,12 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { 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 ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/group/mergedGroup2.test.ts b/server/tests/merged/group/mergedGroup2.test.ts index ad8b56935..a8c1d7976 100644 --- a/server/tests/merged/group/mergedGroup2.test.ts +++ b/server/tests/merged/group/mergedGroup2.test.ts @@ -5,12 +5,12 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { 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 ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/mergeUtils/expectSubCorrect.backup.ts b/server/tests/merged/mergeUtils/expectSubCorrect.backup.ts index b79838341..c4a53f9b5 100644 --- a/server/tests/merged/mergeUtils/expectSubCorrect.backup.ts +++ b/server/tests/merged/mergeUtils/expectSubCorrect.backup.ts @@ -10,7 +10,7 @@ import { import { notNullish } from "@shared/utils/utils.js"; import { expect } from "chai"; import type Stripe from "stripe"; -import { defaultApiVersion } from "tests/constants.js"; +import { defaultApiVersion } from "@tests/constants.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { createStripeCli } from "@/external/connect/createStripeCli.js"; import { priceToStripeItem } from "@/external/stripe/priceToStripeItem/priceToStripeItem.js"; diff --git a/server/tests/merged/mergeUtils/expectSubCorrect.ts b/server/tests/merged/mergeUtils/expectSubCorrect.ts index d2446fa8a..70c2fb9c5 100644 --- a/server/tests/merged/mergeUtils/expectSubCorrect.ts +++ b/server/tests/merged/mergeUtils/expectSubCorrect.ts @@ -10,7 +10,7 @@ import { } from "@autumn/shared"; import { notNullish } from "@shared/utils/utils.js"; import type Stripe from "stripe"; -import { defaultApiVersion } from "tests/constants.js"; +import { defaultApiVersion } from "@tests/constants.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { createStripeCli } from "@/external/connect/createStripeCli.js"; import { priceToStripeItem } from "@/external/stripe/priceToStripeItem/priceToStripeItem.js"; diff --git a/server/tests/merged/prepaid/mergedPrepaid1.backup.ts b/server/tests/merged/prepaid/mergedPrepaid1.backup.ts deleted file mode 100644 index b0c3aa5bb..000000000 --- a/server/tests/merged/prepaid/mergedPrepaid1.backup.ts +++ /dev/null @@ -1,175 +0,0 @@ -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 { 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({ - featureId: TestFeature.Credits, - includedUsage: 100, - price: 10, - billingUnits, -}); - -const premium = constructProduct({ - id: "premium", - items: [creditItem], - type: "premium", -}); - -const pro = constructProduct({ - id: "pro", - items: [creditItem], - type: "pro", -}); - -const ops = [ - { - entityId: "1", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 4, - }, - ], - }, - { - entityId: "2", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 3, - }, - ], - }, - - // Update prepaid quantity (increase) - { - entityId: "1", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 5, - }, - ], - }, - // Update prepaid quantity (decrease) - { - entityId: "2", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 1, - }, - ], - }, -]; - -const testCase = "mergedPrepaid1"; -describe(`${chalk.yellowBright("mergedPrepaid1: Testing merged subs, upgrade 1 & 2 to pro, add premium 2")}`, () => { - const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - - let stripeCli: Stripe; - let testClockId: string; - let curUnix: number; - let db: DrizzleCli; - let org: Organization; - let env: AppEnv; - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [pro, premium], - prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, - customerId, - }); - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = testClockId1!; - }); - - const entities = [ - { - id: "1", - name: "Entity 1", - feature_id: TestFeature.Users, - }, - { - id: "2", - name: "Entity 2", - feature_id: TestFeature.Users, - }, - ]; - - it("should run operations", async () => { - await autumn.entities.create(customerId, entities); - - for (let index = 0; index < ops.length; index++) { - const op = ops[index]; - try { - await attachAndExpectCorrect({ - autumn, - customerId, - product: op.product, - stripeCli, - db, - org, - env, - entityId: op.entityId, - options: op.options, - }); - } catch (error) { - console.log( - `Operation failed: ${op.entityId} ${op.product.id}, index: ${index}`, - ); - throw error; - } - } - }); -}); diff --git a/server/tests/merged/prepaid/mergedPrepaid1.test.ts b/server/tests/merged/prepaid/mergedPrepaid1.test.ts index acf990bcf..5719dd8a6 100644 --- a/server/tests/merged/prepaid/mergedPrepaid1.test.ts +++ b/server/tests/merged/prepaid/mergedPrepaid1.test.ts @@ -5,11 +5,11 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructPrepaidItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/prepaid/mergedPrepaid2.backup.ts b/server/tests/merged/prepaid/mergedPrepaid2.backup.ts deleted file mode 100644 index 9c630682a..000000000 --- a/server/tests/merged/prepaid/mergedPrepaid2.backup.ts +++ /dev/null @@ -1,200 +0,0 @@ -import { - type AppEnv, - CusProductStatus, - LegacyVersion, - OnDecrease, - OnIncrease, - 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 { 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({ - featureId: TestFeature.Credits, - includedUsage: 100, - price: 10, - billingUnits, - config: { - on_increase: OnIncrease.ProrateImmediately, - on_decrease: OnDecrease.None, - }, -}); - -const premium = constructProduct({ - id: "premium", - items: [creditItem], - type: "premium", -}); - -const pro = constructProduct({ - id: "pro", - items: [creditItem], - type: "pro", -}); - -const ops = [ - { - entityId: "1", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 4, - }, - ], - }, - { - entityId: "2", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 3, - }, - ], - }, - - // Update prepaid quantity (increase) - { - entityId: "1", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 2, - }, - ], - }, - { - entityId: "2", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 1, - }, - ], - }, - // // Update prepaid quantity (decrease) - // { - // entityId: "2", - // product: pro, - // results: [{ product: pro, status: CusProductStatus.Active }], - // options: [ - // { - // feature_id: TestFeature.Credits, - // quantity: billingUnits * 1, - // }, - // ], - // }, -]; - -const testCase = "mergedPrepaid2"; -describe(`${chalk.yellowBright("mergedPrepaid2: Testing merged subs, upgrade 1 & 2 to pro, add premium 2")}`, () => { - const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - - let stripeCli: Stripe; - let testClockId: string; - let curUnix: number; - let db: DrizzleCli; - let org: Organization; - let env: AppEnv; - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [pro, premium], - prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, - customerId, - }); - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = testClockId1!; - }); - - const entities = [ - { - id: "1", - name: "Entity 1", - feature_id: TestFeature.Users, - }, - { - id: "2", - name: "Entity 2", - feature_id: TestFeature.Users, - }, - ]; - - it("should run operations", async () => { - await autumn.entities.create(customerId, entities); - - for (let index = 0; index < ops.length; index++) { - const op = ops[index]; - try { - await attachAndExpectCorrect({ - autumn, - customerId, - product: op.product, - stripeCli, - db, - org, - env, - entityId: op.entityId, - options: op.options, - }); - } catch (error) { - console.log( - `Operation failed: ${op.entityId} ${op.product.id}, index: ${index}`, - ); - throw error; - } - } - }); - - it("should have correct balances after update", async () => { - await advanceToNextInvoice({ - stripeCli, - testClockId, - }); - }); -}); diff --git a/server/tests/merged/prepaid/mergedPrepaid2.test.ts b/server/tests/merged/prepaid/mergedPrepaid2.test.ts index b11a127af..f9569e71e 100644 --- a/server/tests/merged/prepaid/mergedPrepaid2.test.ts +++ b/server/tests/merged/prepaid/mergedPrepaid2.test.ts @@ -1,3 +1,4 @@ +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, @@ -6,14 +7,13 @@ import { OnIncrease, type Organization, } from "@autumn/shared"; -import { beforeAll, describe, expect, test } from "bun:test"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { addPrefixToProducts } from "@tests/utils/testProductUtils/testProductUtils.js"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { 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"; diff --git a/server/tests/merged/prepaid/mergedPrepaid3.backup.ts b/server/tests/merged/prepaid/mergedPrepaid3.backup.ts deleted file mode 100644 index f7cb0221c..000000000 --- a/server/tests/merged/prepaid/mergedPrepaid3.backup.ts +++ /dev/null @@ -1,195 +0,0 @@ -// PREPAID WITH DOWNGRADE (SCHEDULED...) - -import { - type AppEnv, - CusProductStatus, - LegacyVersion, - OnDecrease, - OnIncrease, - 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 { 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; -const creditItem = constructPrepaidItem({ - featureId: TestFeature.Credits, - includedUsage: 100, - price: 10, - billingUnits, - config: { - on_increase: OnIncrease.ProrateImmediately, - on_decrease: OnDecrease.ProrateImmediately, - }, -}); - -const premium = constructProduct({ - id: "premium", - items: [creditItem], - type: "premium", -}); - -const pro = constructProduct({ - id: "pro", - items: [creditItem], - type: "pro", -}); - -const ops = [ - { - entityId: "1", - product: premium, - results: [{ product: premium, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 4, - }, - ], - }, - { - entityId: "2", - product: premium, - results: [{ product: premium, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 3, - }, - ], - }, - - // Update prepaid quantity (increase) - { - entityId: "1", - product: pro, - results: [{ product: pro, status: CusProductStatus.Active }], - options: [ - { - feature_id: TestFeature.Credits, - quantity: billingUnits * 2, - }, - ], - }, -]; - -const testCase = "mergedPrepaid3"; -describe(`${chalk.yellowBright("mergedPrepaid3: Testing merged subs, upgrade 1 & 2 to premium, downgrade 1 to pro")}`, () => { - const customerId = testCase; - const autumn: AutumnInt = new AutumnInt({ version: LegacyVersion.v1_4 }); - - let stripeCli: Stripe; - let testClockId: string; - let curUnix: number; - let db: DrizzleCli; - let org: Organization; - let env: AppEnv; - - before(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ - products: [pro, premium], - prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, - customerId, - }); - - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, - customerId, - db, - org, - env, - attachPm: "success", - }); - - testClockId = testClockId1!; - }); - - const entities = [ - { - id: "1", - name: "Entity 1", - feature_id: TestFeature.Users, - }, - { - id: "2", - name: "Entity 2", - feature_id: TestFeature.Users, - }, - ]; - - it("should run operations", async () => { - await autumn.entities.create(customerId, entities); - - for (let index = 0; index < ops.length; index++) { - const op = ops[index]; - try { - await attachAndExpectCorrect({ - autumn, - customerId, - product: op.product, - stripeCli, - db, - org, - env, - entityId: op.entityId, - options: op.options, - }); - } catch (error) { - console.log( - `Operation failed: ${op.entityId} ${op.product.id}, index: ${index}`, - ); - throw error; - } - } - }); - - it("should have correct products after update", async () => { - await advanceToNextInvoice({ - stripeCli, - testClockId, - }); - - const entity1 = await autumn.entities.get(customerId, "1"); - expectProductAttached({ - customer: entity1, - product: pro, - entityId: "1", - }); - - await expectSubToBeCorrect({ - db, - customerId, - org, - env, - }); - }); -}); diff --git a/server/tests/merged/prepaid/mergedPrepaid3.test.ts b/server/tests/merged/prepaid/mergedPrepaid3.test.ts index 0a7d7317e..69bfcee95 100644 --- a/server/tests/merged/prepaid/mergedPrepaid3.test.ts +++ b/server/tests/merged/prepaid/mergedPrepaid3.test.ts @@ -1,5 +1,6 @@ // PREPAID WITH DOWNGRADE (SCHEDULED...) +import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, CusProductStatus, @@ -8,15 +9,14 @@ import { OnIncrease, type Organization, } from "@autumn/shared"; -import { beforeAll, describe, expect, test } from "bun:test"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { addPrefixToProducts } from "@tests/utils/testProductUtils/testProductUtils.js"; import chalk from "chalk"; import type { Stripe } from "stripe"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { 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"; diff --git a/server/tests/merged/separate/separate1.test.ts b/server/tests/merged/separate/separate1.test.ts index cb63e9a27..131b96f70 100644 --- a/server/tests/merged/separate/separate1.test.ts +++ b/server/tests/merged/separate/separate1.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { completeInvoiceCheckout } from "tests/utils/stripeUtils/completeInvoiceCheckout.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { completeInvoiceCheckout } from "@tests/utils/stripeUtils/completeInvoiceCheckout.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/merged/separate/separate2.test.ts b/server/tests/merged/separate/separate2.test.ts index c70b7a268..2b4b3aed8 100644 --- a/server/tests/merged/separate/separate2.test.ts +++ b/server/tests/merged/separate/separate2.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { type AppEnv, LegacyVersion, type Organization } from "@autumn/shared"; import chalk from "chalk"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { completeCheckoutForm } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { completeCheckoutForm } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { CusService } from "@/internal/customers/CusService.js"; diff --git a/server/tests/merged/trial/mergedTrial1.test.ts b/server/tests/merged/trial/mergedTrial1.test.ts index 5ddf84f89..9c2ba2981 100644 --- a/server/tests/merged/trial/mergedTrial1.test.ts +++ b/server/tests/merged/trial/mergedTrial1.test.ts @@ -1,23 +1,22 @@ +import { beforeAll, describe, expect, it } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; // Premium, Premium // Cancel End, Cancel Immediately @@ -42,39 +41,26 @@ describe(`${chalk.yellowBright("mergedTrial1: Testing trial")}`, () => { let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -106,7 +92,7 @@ describe(`${chalk.yellowBright("mergedTrial1: Testing trial")}`, () => { }); const entity1 = await autumn.entities.get(customerId, "1"); - const premium1 = entity1.products.find((p: any) => p.id == premium.id); + const premium1 = entity1.products.find((p: any) => p.id === premium.id); const checkout = await autumn.checkout({ customer_id: customerId, @@ -115,11 +101,12 @@ describe(`${chalk.yellowBright("mergedTrial1: Testing trial")}`, () => { }); const nextCycle = checkout.next_cycle; - expect(nextCycle?.starts_at); - expect(nextCycle?.starts_at).to.approximately( - premium1?.current_period_end, - 60000, - ); // 1 min + expect(nextCycle?.starts_at).toBeDefined(); + expect( + Math.abs( + (nextCycle?.starts_at ?? 0) - (premium1?.current_period_end ?? 0), + ), + ).toBeLessThanOrEqual(60000); // 1 min await autumn.attach({ customer_id: customerId, @@ -128,11 +115,13 @@ describe(`${chalk.yellowBright("mergedTrial1: Testing trial")}`, () => { }); const entity2 = await autumn.entities.get(customerId, "2"); - const premium2 = entity2.products.find((p: any) => p.id == premium.id); - expect(premium2?.status).to.equal(CusProductStatus.Trialing); - expect(premium2?.current_period_end).to.approximately( - premium1?.current_period_end, - 60000, - ); // 1 min + const premium2 = entity2.products.find((p: any) => p.id === premium.id); + expect(premium2?.status).toBe(CusProductStatus.Trialing); + expect( + Math.abs( + (premium2?.current_period_end ?? 0) - + (premium1?.current_period_end ?? 0), + ), + ).toBeLessThanOrEqual(60000); // 1 min }); }); diff --git a/server/tests/merged/trial/mergedTrial2.test.ts b/server/tests/merged/trial/mergedTrial2.test.ts index 72dd7e133..2b63e6567 100644 --- a/server/tests/merged/trial/mergedTrial2.test.ts +++ b/server/tests/merged/trial/mergedTrial2.test.ts @@ -1,23 +1,23 @@ +import { beforeAll, describe, it } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -51,39 +51,26 @@ describe(`${chalk.yellowBright("mergedTrial2: Testing add second trial product a let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ diff --git a/server/tests/merged/trial/mergedTrial3.test.ts b/server/tests/merged/trial/mergedTrial3.test.ts index c7be3d0e4..73111de43 100644 --- a/server/tests/merged/trial/mergedTrial3.test.ts +++ b/server/tests/merged/trial/mergedTrial3.test.ts @@ -1,23 +1,23 @@ +import { beforeAll, describe, it } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; const premium = constructProduct({ id: "premium", @@ -58,39 +58,26 @@ describe(`${chalk.yellowBright("mergedTrial3: Testing upgrade to product with tr let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ diff --git a/server/tests/merged/trial/mergedTrial4.test.ts b/server/tests/merged/trial/mergedTrial4.test.ts index 03b8e1b88..a7a1575b0 100644 --- a/server/tests/merged/trial/mergedTrial4.test.ts +++ b/server/tests/merged/trial/mergedTrial4.test.ts @@ -1,21 +1,21 @@ +import { beforeAll, describe, it } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; const premium = constructProduct({ @@ -57,39 +57,26 @@ describe(`${chalk.yellowBright("mergedTrial4: Testing cancel immediately on merg let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ diff --git a/server/tests/merged/trial/mergedTrial5.test.ts b/server/tests/merged/trial/mergedTrial5.test.ts index d6e8d0653..5de47c04c 100644 --- a/server/tests/merged/trial/mergedTrial5.test.ts +++ b/server/tests/merged/trial/mergedTrial5.test.ts @@ -1,21 +1,21 @@ +import { beforeAll, describe, it } from "bun:test"; import { type AppEnv, CusProductStatus, LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; import { constructProduct } from "@/utils/scriptUtils/createTestProducts.js"; -import { initCustomer } from "@/utils/scriptUtils/initCustomer.js"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; import { expectSubToBeCorrect } from "../mergeUtils/expectSubCorrect.js"; const premium = constructProduct({ @@ -62,39 +62,26 @@ describe(`${chalk.yellowBright("mergedTrial5: Testing cancel at end of cycle and let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro, premium], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro, premium], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); const entities = [ @@ -115,7 +102,7 @@ describe(`${chalk.yellowBright("mergedTrial5: Testing cancel at end of cycle and }, ]; - it("should attach pro trial for entity 1 and entity 2", async () => { + it("should attach pro trial for 3 entities", async () => { await autumn.entities.create(customerId, entities); for (const op of ops) { diff --git a/server/tests/merged/trial/trial1.test.ts b/server/tests/merged/trial/trial1.test.ts index 1c7988cbd..99bcbce9d 100644 --- a/server/tests/merged/trial/trial1.test.ts +++ b/server/tests/merged/trial/trial1.test.ts @@ -9,12 +9,12 @@ import { import chalk from "chalk"; import { addDays } from "date-fns"; import type { Stripe } from "stripe"; -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 { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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 { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructArrearItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/trial/trial2.test.ts b/server/tests/merged/trial/trial2.test.ts index 71a71bb45..baa3dddbb 100644 --- a/server/tests/merged/trial/trial2.test.ts +++ b/server/tests/merged/trial/trial2.test.ts @@ -6,16 +6,16 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +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 { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import { addDays } from "date-fns"; import { Decimal } from "decimal.js"; import type { Stripe } from "stripe"; -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 { advanceTestClock } from "tests/utils/stripeUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { timeout } from "@/utils/genUtils.js"; diff --git a/server/tests/merged/trial/trial3.test.ts b/server/tests/merged/trial/trial3.test.ts index d198929ba..1b97a0bca 100644 --- a/server/tests/merged/trial/trial3.test.ts +++ b/server/tests/merged/trial/trial3.test.ts @@ -1,3 +1,4 @@ +import { beforeAll, describe, expect, it } from "bun:test"; import { type AppEnv, CusProductStatus, @@ -5,22 +6,20 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; -import { expect } from "chai"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.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 { 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"; +import { initCustomerV3 } from "@/utils/scriptUtils/testUtils/initCustomerV3.js"; +import { initProductsV0 } from "@/utils/scriptUtils/testUtils/initProductsV0.js"; // Pro Trial // Trial Finishes @@ -64,39 +63,26 @@ describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => let org: Organization; let env: AppEnv; - beforeAll(async function () { - await setupBefore(this); - const { autumnJs } = this; - db = this.db; - org = this.org; - env = this.env; - - stripeCli = this.stripeCli; - - addPrefixToProducts({ + beforeAll(async () => { + await initProductsV0({ + ctx, products: [pro], prefix: testCase, - }); - - await createProducts({ - autumn: autumnJs, - products: [pro], - db, - orgId: org.id, - env, customerId, }); - const { testClockId: testClockId1 } = await initCustomer({ - autumn: autumnJs, + const res = await initCustomerV3({ + ctx, customerId, - db, - org, - env, attachPm: "success", + withTestClock: true, }); - testClockId = testClockId1!; + stripeCli = ctx.stripeCli; + db = ctx.db; + org = ctx.org; + env = ctx.env; + testClockId = res.testClockId!; }); it("should attach first trial, and advance clock past trial", async () => { @@ -146,7 +132,7 @@ describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => // console.log(`cancel at: ${sub?.cancel_at}`); // console.log(`canceled at: ${sub?.canceled_at}`); const canceled = sub?.canceled_at || sub?.cancel_at; - expect(canceled).to.exist; + expect(canceled).toBeDefined(); }); it("should have sub not canceled if renew product", async () => { @@ -159,7 +145,7 @@ describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => cusProduct, stripeCli, }); - expect(sub?.cancel_at_period_end).to.equal(false); + expect(sub?.cancel_at_period_end).toBe(false); }); it("should be canceled completely", async () => { await autumn.cancel({ @@ -169,13 +155,13 @@ describe(`${chalk.yellowBright("trial3: Testing cancel trial product")}`, () => }); const customer = await autumn.customers.get(customerId); - const proProduct = customer.products.find((p) => p.id === pro.id)!; - expect(proProduct).to.not.exist; + const proProduct = customer.products.find((p) => p.id === pro.id); + expect(proProduct).toBeUndefined(); const sub = await cusProductToSub({ cusProduct, stripeCli, }); - expect(sub?.status).to.equal("canceled"); + expect(sub?.status).toBe("canceled"); }); }); diff --git a/server/tests/merged/upgrade/mergedUpgrade1.test.ts b/server/tests/merged/upgrade/mergedUpgrade1.test.ts index 97a30f235..23dfc1c8d 100644 --- a/server/tests/merged/upgrade/mergedUpgrade1.test.ts +++ b/server/tests/merged/upgrade/mergedUpgrade1.test.ts @@ -5,16 +5,16 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { getExpectedInvoiceTotal } from "@tests/utils/expectUtils/expectInvoiceUtils.js"; +import { advanceTestClock } from "@tests/utils/stripeUtils.js"; +import { advanceToNextInvoice } from "@tests/utils/testAttachUtils/testAttachUtils.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; +import { getBasePrice } from "@tests/utils/testProductUtils/testProductUtils.js"; import chalk from "chalk"; import { addWeeks } from "date-fns"; import type { Stripe } from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; -import { attachAndExpectCorrect } from "tests/utils/expectUtils/expectAttach.js"; -import { getExpectedInvoiceTotal } from "tests/utils/expectUtils/expectInvoiceUtils.js"; -import { advanceTestClock } from "tests/utils/stripeUtils.js"; -import { advanceToNextInvoice } from "tests/utils/testAttachUtils/testAttachUtils.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.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"; diff --git a/server/tests/merged/upgrade/mergedUpgrade2.test.ts b/server/tests/merged/upgrade/mergedUpgrade2.test.ts index 0da26a440..bd5ab43c5 100644 --- a/server/tests/merged/upgrade/mergedUpgrade2.test.ts +++ b/server/tests/merged/upgrade/mergedUpgrade2.test.ts @@ -5,12 +5,12 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { 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 ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/upgrade/mergedUpgrade3.test.ts b/server/tests/merged/upgrade/mergedUpgrade3.test.ts index 04d9e8a85..6b4448fbd 100644 --- a/server/tests/merged/upgrade/mergedUpgrade3.test.ts +++ b/server/tests/merged/upgrade/mergedUpgrade3.test.ts @@ -5,12 +5,12 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { 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 ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/merged/upgrade/mergedUpgrade4.test.ts b/server/tests/merged/upgrade/mergedUpgrade4.test.ts index 4a0a9ed68..787bc234d 100644 --- a/server/tests/merged/upgrade/mergedUpgrade4.test.ts +++ b/server/tests/merged/upgrade/mergedUpgrade4.test.ts @@ -5,12 +5,12 @@ import { LegacyVersion, type Organization, } from "@autumn/shared"; +import { TestFeature } from "@tests/setup/v2Features.js"; +import { attachAndExpectCorrect } from "@tests/utils/expectUtils/expectAttach.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import chalk from "chalk"; import type { 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 ctx from "tests/utils/testInitUtils/createTestContext.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnInt } from "@/external/autumn/autumnCli.js"; import { constructFeatureItem } from "@/utils/scriptUtils/constructItem.js"; diff --git a/server/tests/plan-schema/01-basic-create.test.ts b/server/tests/plan-schema/01-basic-create.test.ts index 9f091f958..e6f1c16df 100644 --- a/server/tests/plan-schema/01-basic-create.test.ts +++ b/server/tests/plan-schema/01-basic-create.test.ts @@ -6,10 +6,10 @@ import { ResetInterval, UsageModel, } from "@autumn/shared"; +import { setupBefore } from "@tests/before.js"; +import { features } from "@tests/global.js"; import { expect } from "chai"; import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { features } from "tests/global.js"; import { AutumnCliV2 } from "@/external/autumn/autumnCliV2.js"; describe(chalk.yellowBright("Plan V2 - Basic CREATE Tests"), () => { diff --git a/server/tests/plan-schema/02-mutual-exclusivity.test.ts b/server/tests/plan-schema/02-mutual-exclusivity.test.ts index 6b0c579a3..77c7cd994 100644 --- a/server/tests/plan-schema/02-mutual-exclusivity.test.ts +++ b/server/tests/plan-schema/02-mutual-exclusivity.test.ts @@ -6,8 +6,8 @@ import { } from "@autumn/shared"; import { expect } from "chai"; import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { features } from "tests/global.js"; +import { setupBefore } from "@tests/before.js"; +import { features } from "@tests/global.js"; import { AutumnCliV2 } from "@/external/autumn/autumnCliV2.js"; describe(chalk.yellowBright("Plan V2 - Mutual Exclusivity Validation"), () => { diff --git a/server/tests/plan-schema/03-advanced-update.test.ts b/server/tests/plan-schema/03-advanced-update.test.ts index 9a8ae7a56..ea45090d2 100644 --- a/server/tests/plan-schema/03-advanced-update.test.ts +++ b/server/tests/plan-schema/03-advanced-update.test.ts @@ -8,8 +8,8 @@ import { } from "@autumn/shared"; import { expect } from "chai"; import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { features } from "tests/global.js"; +import { setupBefore } from "@tests/before.js"; +import { features } from "@tests/global.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import { AutumnCliV2 } from "@/external/autumn/autumnCliV2.js"; import { ProductService } from "@/internal/products/ProductService.js"; diff --git a/server/tests/plan-schema/04-cross-version.test.ts b/server/tests/plan-schema/04-cross-version.test.ts index d06ad12ac..4f028b7df 100644 --- a/server/tests/plan-schema/04-cross-version.test.ts +++ b/server/tests/plan-schema/04-cross-version.test.ts @@ -10,8 +10,8 @@ import { } from "@autumn/shared"; import { expect } from "chai"; import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { features } from "tests/global.js"; +import { setupBefore } from "@tests/before.js"; +import { features } from "@tests/global.js"; import { AutumnCliV2 } from "@/external/autumn/autumnCliV2.js"; describe(chalk.yellowBright("Plan V2 - Cross-Version Consistency"), () => { diff --git a/server/tests/plan-schema/05-complex-scenarios.test.ts b/server/tests/plan-schema/05-complex-scenarios.test.ts index 29ed08980..34e1dfe54 100644 --- a/server/tests/plan-schema/05-complex-scenarios.test.ts +++ b/server/tests/plan-schema/05-complex-scenarios.test.ts @@ -9,10 +9,11 @@ import { TierInfinite, UsageModel, } from "@autumn/shared"; + +import { setupBefore } from "@tests/before.js"; +import { features } from "@tests/global.js"; import { expect } from "chai"; import chalk from "chalk"; -import { setupBefore } from "tests/before.js"; -import { features } from "tests/global.js"; import { AutumnCliV2 } from "@/external/autumn/autumnCliV2.js"; describe(chalk.yellowBright("Plan V2 - Complex Real-World Scenarios"), () => { diff --git a/server/tests/setupMain.ts b/server/tests/setupMain.ts index a0323ab41..943587a5e 100644 --- a/server/tests/setupMain.ts +++ b/server/tests/setupMain.ts @@ -3,7 +3,7 @@ import dotenv from "dotenv"; dotenv.config(); import { AppEnv } from "@autumn/shared"; -import { setupOrg } from "tests/utils/setupUtils/setupOrg.js"; +import { setupOrg } from "@tests/utils/setupUtils/setupOrg.js"; import { initDrizzle } from "@/db/initDrizzle.js"; import { OrgService } from "@/internal/orgs/OrgService.js"; diff --git a/server/tests/template.ts b/server/tests/template.ts index 032393b40..a995175fd 100644 --- a/server/tests/template.ts +++ b/server/tests/template.ts @@ -4,15 +4,15 @@ // 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 { 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 { TestFeature } from "@tests/setup/v2Features.js"; // export let pro = constructProduct({ // items: [ diff --git a/server/tests/testRunner/outputParser.ts b/server/tests/testRunner/outputParser.ts index ccf0256b4..0cdadbdf0 100644 --- a/server/tests/testRunner/outputParser.ts +++ b/server/tests/testRunner/outputParser.ts @@ -69,13 +69,13 @@ export function parseTestOutput(output: string): TestSummary { // Extract failure details let currentTestFile = ""; - let inFailureSection = false; + const inFailureSection = false; for (let i = 0; i < lines.length; i++) { const line = lines[i]; // Detect test file being processed - const fileMatch = line.match(/tests\/[\w\/.-]+\.test\.ts:/); + const fileMatch = line.match(/tests\/[\w/.-]+\.test\.ts:/); if (fileMatch) { currentTestFile = fileMatch[0].replace(":", ""); } diff --git a/server/tests/utils/advancedUsageUtils.ts b/server/tests/utils/advancedUsageUtils.ts index b38666519..ed6823b58 100644 --- a/server/tests/utils/advancedUsageUtils.ts +++ b/server/tests/utils/advancedUsageUtils.ts @@ -1,9 +1,9 @@ import type { Feature, ProductV2 } from "@autumn/shared"; import assert from "assert"; import { Decimal } from "decimal.js"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { creditSystems, features } from "tests/global.js"; -import ctx from "tests/utils/testInitUtils/createTestContext.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { creditSystems, features } from "@tests/global.js"; +import ctx from "@tests/utils/testInitUtils/createTestContext.js"; import { getPriceForOverage } from "@/internal/products/prices/priceUtils.js"; import { convertProductV2ToV1 } from "@/internal/products/productUtils/productV2Utils/convertProductV2ToV1.js"; import { timeout } from "./genUtils.js"; diff --git a/server/tests/utils/autumnUtils.ts b/server/tests/utils/autumnUtils.ts index 3323d86c2..aae645493 100644 --- a/server/tests/utils/autumnUtils.ts +++ b/server/tests/utils/autumnUtils.ts @@ -1,5 +1,6 @@ -import { Autumn } from "@/external/autumn/autumnCli.js"; +import type { ApiCustomerV1 } from "@shared/api/customers/previousVersions/apiCustomerV1"; import { expect } from "chai"; +import type { AutumnInt } from "@/external/autumn/autumnCli.js"; export const checkBalance = async ({ autumn, @@ -7,13 +8,15 @@ export const checkBalance = async ({ customerId, expectedBalance, }: { - autumn: Autumn; + autumn: AutumnInt; featureId: string; customerId: string; expectedBalance: number; }) => { - let { entitlements } = await autumn.customers.get(customerId); - let entitlement = entitlements.find((e: any) => e.feature_id == featureId); + const { entitlements } = (await autumn.customers.get( + customerId, + )) as unknown as ApiCustomerV1; + const entitlement = entitlements.find((e: any) => e.feature_id === featureId); - expect(entitlement.balance).to.equal(expectedBalance); + expect(entitlement?.balance).to.equal(expectedBalance); }; diff --git a/server/tests/utils/compare.ts b/server/tests/utils/compare.ts index 949a7063c..4c750ca4b 100644 --- a/server/tests/utils/compare.ts +++ b/server/tests/utils/compare.ts @@ -11,8 +11,8 @@ import { import type { ApiCustomerV1 } from "@shared/api/customers/previousVersions/apiCustomerV1.js"; // import { expect } from "chai"; import { Decimal } from "decimal.js"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; -import { creditSystems } from "tests/global.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; +import { creditSystems } from "@tests/global.js"; export const checkProductIsScheduled = ({ cusRes, diff --git a/server/tests/utils/expectUtils/expectAttach.ts b/server/tests/utils/expectUtils/expectAttach.ts index 7b83c091e..b46f462e7 100644 --- a/server/tests/utils/expectUtils/expectAttach.ts +++ b/server/tests/utils/expectUtils/expectAttach.ts @@ -11,13 +11,13 @@ import type { AttachParams, Customer } from "autumn-js"; import { expect } from "chai"; import { Decimal } from "decimal.js"; import type Stripe from "stripe"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; -import { expectFeaturesCorrect } from "tests/utils/expectUtils/expectFeaturesCorrect.js"; +import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +import { expectFeaturesCorrect } from "@tests/utils/expectUtils/expectFeaturesCorrect.js"; import { expectInvoicesCorrect, expectProductAttached, -} from "tests/utils/expectUtils/expectProductAttached.js"; -import { getCurrentOptions } from "tests/utils/testAttachUtils/testAttachUtils.js"; +} from "@tests/utils/expectUtils/expectProductAttached.js"; +import { getCurrentOptions } from "@tests/utils/testAttachUtils/testAttachUtils.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import type { AutumnInt } from "@/external/autumn/autumnCli.js"; import { isFreeProductV2 } from "@/internal/products/productUtils/classifyProduct.js"; diff --git a/server/tests/utils/expectUtils/expectContUseUtils.ts b/server/tests/utils/expectUtils/expectContUseUtils.ts index 83143c708..7b86fa543 100644 --- a/server/tests/utils/expectUtils/expectContUseUtils.ts +++ b/server/tests/utils/expectUtils/expectContUseUtils.ts @@ -6,7 +6,7 @@ import { } from "@autumn/shared"; import { expect } from "chai"; import type Stripe from "stripe"; -import { TestFeature } from "tests/setup/v2Features.js"; +import { TestFeature } from "@tests/setup/v2Features.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import type { AutumnInt } from "@/external/autumn/autumnCli.js"; import { subToPeriodStartEnd } from "@/external/stripe/stripeSubUtils/convertSubUtils.js"; diff --git a/server/tests/utils/expectUtils/expectMultiAttach.ts b/server/tests/utils/expectUtils/expectMultiAttach.ts index f8280d20c..02f21b172 100644 --- a/server/tests/utils/expectUtils/expectMultiAttach.ts +++ b/server/tests/utils/expectUtils/expectMultiAttach.ts @@ -6,10 +6,10 @@ import { type ProductOptions, type ProductV2, } from "@autumn/shared"; +import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; +import { expectProductAttached } from "@tests/utils/expectUtils/expectProductAttached.js"; import type { Customer, Entity } from "autumn-js"; import { expect } from "chai"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.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"; @@ -51,7 +51,6 @@ export const expectMultiAttachCorrect = async ({ customer_id: customerId, products: products, entity_id: entityId, - // @ts-expect-error reward: rewards, ...attachParams, }); @@ -60,7 +59,6 @@ export const expectMultiAttachCorrect = async ({ customer_id: customerId, products: products, entity_id: entityId, - // @ts-expect-error reward: rewards, ...attachParams, }); diff --git a/server/tests/utils/expectUtils/expectScheduleUtils.ts b/server/tests/utils/expectUtils/expectScheduleUtils.ts index 80682ebfe..d767ce23e 100644 --- a/server/tests/utils/expectUtils/expectScheduleUtils.ts +++ b/server/tests/utils/expectUtils/expectScheduleUtils.ts @@ -12,7 +12,7 @@ import { import { expect } from "chai"; import { addHours } from "date-fns"; import type Stripe from "stripe"; -import { expectSubToBeCorrect } from "tests/merged/mergeUtils/expectSubCorrect.js"; +import { expectSubToBeCorrect } from "@tests/merged/mergeUtils/expectSubCorrect.js"; import type { DrizzleCli } from "@/db/initDrizzle.js"; import type { AutumnInt } from "@/external/autumn/autumnCli.js"; import { findStripePriceFromPrices } from "@/external/stripe/stripeSubUtils/stripeSubItemUtils.js"; diff --git a/server/tests/utils/genUtils.ts b/server/tests/utils/genUtils.ts index bee65d3f3..4cb06ee6a 100644 --- a/server/tests/utils/genUtils.ts +++ b/server/tests/utils/genUtils.ts @@ -4,7 +4,7 @@ import { FullCusProduct, UsagePriceConfig, } from "@autumn/shared"; -import { AutumnCli } from "tests/cli/AutumnCli.js"; +import { AutumnCli } from "@tests/cli/AutumnCli.js"; export const timeout = (ms: number) => { return new Promise((resolve) => setTimeout(resolve, ms)); diff --git a/server/tests/utils/setupUtils/setupOrg.ts b/server/tests/utils/setupUtils/setupOrg.ts index 2b90b85a1..81e1db688 100644 --- a/server/tests/utils/setupUtils/setupOrg.ts +++ b/server/tests/utils/setupUtils/setupOrg.ts @@ -1,6 +1,6 @@ import type { AppEnv } from "@autumn/shared"; import axios from "axios"; -import { getFeatures } from "tests/setup/v2Features.js"; +import { getFeatures } from "@tests/setup/v2Features.js"; import { initDrizzle } from "@/db/initDrizzle.js"; import { FeatureService } from "@/internal/features/FeatureService.js"; import { OrgService } from "@/internal/orgs/OrgService.js"; diff --git a/server/tests/utils/testAttachUtils/trialAttachUtils.ts b/server/tests/utils/testAttachUtils/trialAttachUtils.ts deleted file mode 100644 index 078d3bce2..000000000 --- a/server/tests/utils/testAttachUtils/trialAttachUtils.ts +++ /dev/null @@ -1,237 +0,0 @@ -import { type AppEnv, ProcessorType } from "@autumn/shared"; -import type Stripe from "stripe"; -import type { DrizzleCli } from "@/db/initDrizzle.js"; -import type { AutumnInt } from "@/external/autumn/autumnCli.js"; -import { attachPmToCus } from "@/external/stripe/stripeCusUtils.js"; -import { handleAddProduct } from "@/internal/customers/attach/attachFunctions/addProductFlow/handleAddProduct.js"; -import { newCusToAttachParams } from "@/internal/customers/attach/attachUtils/attachParams/convertToParams.js"; -import { CusService } from "@/internal/customers/CusService.js"; -import { ProductService } from "@/internal/products/ProductService.js"; -import { isDefaultTrialFullProduct } from "@/internal/products/productUtils/classifyProduct.js"; -import { generateId } from "@/utils/genUtils.js"; - -export async function manuallyAttachDefaultTrial({ - customerId, - stripeCli, - autumn, - db, - org, - env, - testClockID, - autumnJs, - attachPm = "", - group, -}: { - customerId: string; - stripeCli: Stripe; - autumn: AutumnInt; - db: DrizzleCli; - org: any; - env: AppEnv; - testClockID?: string; - autumnJs: any; - attachPm?: "success" | "fail" | ""; - group?: string; -}) { - try { - const existingCustomer = await CusService.get({ - db, - idOrInternalId: customerId, - orgId: org.id, - env, - }); - if (existingCustomer) { - // Delete via API to clean up properly - await autumnJs.customers.delete(customerId); - } - } catch (error) { - // Ignore if customer doesn't exist - console.log("Customer doesn't exist, skipping delete", error); - } - - // Step 2: Manually create customer in DB (following createNewCustomer.ts logic) - const customerData = { - id: customerId, - name: customerId, - email: `${customerId}@example.com`, - metadata: {}, - internal_id: generateId("cus"), - org_id: org.id, - created_at: Date.now(), - env, - }; - - const newCustomer = await CusService.insert({ - db, - data: customerData, - }); - - if (!newCustomer) { - throw new Error("Failed to create customer"); - } - - // Step 3: Get default products (following createNewCustomer.ts logic) - const allDefaultProds = await ProductService.listDefault({ - db, - orgId: org.id, - env, - }); - - // Filter by group if specified - const defaultProds = group - ? allDefaultProds.filter((p) => p.group === group) - : allDefaultProds; - - const defaultPaidTrialProd = defaultProds.find((p) => - isDefaultTrialFullProduct({ product: p }), - ); - - let customer = newCustomer; - - if (defaultPaidTrialProd) { - // Step 4: Create Stripe customer with test clock - const stripeCustomer = await stripeCli.customers.create({ - email: `${customerId}@example.com`, - test_clock: testClockID ? testClockID : undefined, - }); - - // Step 5: Update customer with Stripe processor info (BEFORE attachPmToCus) - await CusService.update({ - db, - internalCusId: newCustomer.internal_id, - update: { - processor: { - type: ProcessorType.Stripe, - id: stripeCustomer.id, - }, - }, - }); - - // Update local customer object - customer = { - ...newCustomer, - processor: { - id: stripeCustomer.id, - type: "stripe", - }, - } as any; - - if (attachPm && testClockID) { - await attachPmToCus({ - customer: customer, - org: org, - env: env, - db: db, - testClockId: testClockID, - willFail: attachPm === "fail", - }); - } - - // Step 6: Manually attach the default trial product (following createNewCustomer.ts logic) - const req = { - db, - org, - env, - orgId: org.id, - logger: console, - } as any; - - await handleAddProduct({ - req, - attachParams: newCusToAttachParams({ - req, - newCus: customer as any, - products: [defaultPaidTrialProd], - stripeCli, - freeTrial: defaultPaidTrialProd.free_trial || null, - }), - }); - - return customer; - } -} - -export async function cleanupQueueAndCache() { - try { - const { QueueManager } = await import("@/queue/QueueManager.js"); - const queueInstance = await QueueManager.getInstance(); - - // Access private properties to close connections - if ((queueInstance as any).queue) { - await (queueInstance as any).queue.close(); - } - if ((queueInstance as any).backupQueue) { - await (queueInstance as any).backupQueue.close(); - } - if ((queueInstance as any).mainConnection) { - await (queueInstance as any).mainConnection.quit(); - } - if ((queueInstance as any).backupConnection) { - await (queueInstance as any).backupConnection.quit(); - } - } catch (error) { - // Ignore cleanup errors - } - - try { - const { CacheManager } = await import("@/utils/cacheUtils/CacheManager.js"); - const cacheInstance = await CacheManager.getInstance(); - if ((cacheInstance as any).connection) { - await (cacheInstance as any).connection.quit(); - } - } catch (error) { - // Ignore cleanup errors - } -} - -export async function flipDefaultState({ - id, - autumn, - state, -}: { - id: string; - autumn: AutumnInt; - state: boolean; -}) { - try { - const productExists = await autumn.products.get(id); - if (productExists) { - await autumn.products.update(id, { - is_default: state, - }); - } - } catch (error) { - console.log(`Product ${id} doesn't exist, skipping update`); - } -} - -export async function flipDefaultStates({ - currentCase, - autumn, -}: { - currentCase: number; - autumn: AutumnInt; -}) { - const total = 4; - - // Now flip all products from 0 to total-1, only current case should be true - for (let i = 0; i < total; i++) { - const id = `defaultTrial${i}_pro`; - const state = i === currentCase; // Only the current case is true - await flipDefaultState({ - id, - autumn, - state, - }); - } - - for (let i = 0; i < total; i++) { - const id = `defaultTrial${i}_free`; - const state = i === currentCase; // Only the current case is true - await flipDefaultState({ - id, - autumn, - state, - }); - } -} diff --git a/server/tsconfig.json b/server/tsconfig.json index 746db577e..64c5c0a90 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -5,13 +5,12 @@ }, "compilerOptions": { "target": "ES2020", - "moduleResolution": "NodeNext", - "module": "NodeNext", + "moduleResolution": "bundler", + "module": "Preserve", // "declaration": true, "jsx": "react-jsx", "rootDir": ".", - "baseUrl": ".", "outDir": "./dist", "strict": true, "esModuleInterop": true, @@ -19,18 +18,22 @@ "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "paths": { - "@/*": ["src/*"], + "@/*": ["./src/*"], "@shared/*": ["../shared/*"], - "@emails/*": ["emails/*"], - "@scripts/*": ["scripts/*"], - "@lua/*": ["src/_luaScripts/*"], + "@emails/*": ["./emails/*"], + "@scripts/*": ["./scripts/*"], + "@lua/*": ["./src/_luaScripts/*"], + "@tests/*": ["./tests/*"], + + + // From shared package? + "@autumn/shared": ["../shared/index.ts"], + "@autumn/shared/*": ["../shared/*"], + "@api/*": ["../shared/api/*"], + "@models/*": ["../shared/models/*"], + "@utils/*": ["../shared/utils/*"], } }, "include": ["src", "tests", "scripts", "emails", "experiments"], - "references": [ - { - "path": "../shared" - } - ], - "exclude": ["node_modules", "dist"] + "exclude": ["node_modules", "dist", "tests/archives"] } diff --git a/shared/api/balances/check/checkParams.ts b/shared/api/balances/check/checkParams.ts index 00d4a2b86..566b13cc4 100644 --- a/shared/api/balances/check/checkParams.ts +++ b/shared/api/balances/check/checkParams.ts @@ -51,3 +51,5 @@ export const CheckParamsSchema = ExtCheckParamsSchema.extend({ ); export type CheckParams = z.infer; + +export type CheckQuery = z.infer; diff --git a/shared/api/customers/apiCustomer.ts b/shared/api/customers/apiCustomer.ts index 460df5788..52ad7e6d0 100644 --- a/shared/api/customers/apiCustomer.ts +++ b/shared/api/customers/apiCustomer.ts @@ -5,15 +5,10 @@ import { AppEnv } from "@models/genModels/genEnums.js"; import { z } from "zod/v4"; import { ApiCusReferralSchema } from "./components/apiCusReferral.js"; import { ApiCusUpcomingInvoiceSchema } from "./components/apiCusUpcomingInvoice.js"; +import { ApiTrialsUsedSchema } from "./components/apiTrialsUsed.js"; import { ApiBalanceSchema } from "./cusFeatures/apiBalance.js"; import { ApiSubscriptionSchema } from "./cusPlans/apiSubscription.js"; -export const ApiTrialsUsedSchema = z.object({ - product_id: z.string(), - customer_id: z.string(), - fingerprint: z.string().nullish(), -}); - export const ApiCusExpandSchema = z.object({ invoices: z.array(ApiInvoiceSchema).optional(), entities: z.array(ApiBaseEntitySchema).optional(), diff --git a/shared/api/customers/components/apiTrialsUsed.ts b/shared/api/customers/components/apiTrialsUsed.ts new file mode 100644 index 000000000..3a4fc6724 --- /dev/null +++ b/shared/api/customers/components/apiTrialsUsed.ts @@ -0,0 +1,9 @@ +import { z } from "zod/v4"; + +export const ApiTrialsUsedSchema = z.object({ + product_id: z.string(), + customer_id: z.string(), + fingerprint: z.string().nullish(), +}); + +export type ApiTrialsUsed = z.infer; diff --git a/shared/api/customers/customerOpModels.ts b/shared/api/customers/customerOpModels.ts index b3ece3917..cb1230529 100644 --- a/shared/api/customers/customerOpModels.ts +++ b/shared/api/customers/customerOpModels.ts @@ -71,7 +71,7 @@ export const CreateCustomerParamsSchema = z.object({ example: "fp_123abc", }), - metadata: z.record(z.string(), z.any()).default({}).meta({ + metadata: z.record(z.string(), z.any()).nullish().meta({ description: "Additional metadata for the customer", }), diff --git a/shared/api/customers/previousVersions/apiCustomerV0.ts b/shared/api/customers/previousVersions/apiCustomerV0.ts index 46feb6433..b85450f91 100644 --- a/shared/api/customers/previousVersions/apiCustomerV0.ts +++ b/shared/api/customers/previousVersions/apiCustomerV0.ts @@ -3,7 +3,7 @@ import { ApiCusProductV0Schema } from "@api/customers/cusPlans/previousVersions/ import { ApiInvoiceSchema } from "@api/others/apiInvoice.js"; import { AppEnv } from "@models/genModels/genEnums.js"; import { z } from "zod/v4"; -import { ApiTrialsUsedSchema } from "./apiCustomerV3.js"; +import { ApiTrialsUsedSchema } from "../components/apiTrialsUsed.js"; /** * ApiCustomerV0Schema - Customer response format for API V0_1 diff --git a/shared/api/customers/previousVersions/apiCustomerV1.ts b/shared/api/customers/previousVersions/apiCustomerV1.ts index bfb9ca820..d12765264 100644 --- a/shared/api/customers/previousVersions/apiCustomerV1.ts +++ b/shared/api/customers/previousVersions/apiCustomerV1.ts @@ -2,8 +2,8 @@ import { ApiCusFeatureV1Schema } from "@api/customers/cusFeatures/previousVersio import { ApiInvoiceSchema } from "@api/others/apiInvoice.js"; import { AppEnv } from "@models/genModels/genEnums.js"; import { z } from "zod/v4"; +import { ApiTrialsUsedSchema } from "../components/apiTrialsUsed.js"; import { ApiCusProductV1Schema } from "../cusPlans/previousVersions/apiCusProductV1.js"; -import { ApiTrialsUsedSchema } from "./apiCustomerV3.js"; /** * ApiCustomerV1Schema - Customer response format for API V0_2/V1_0/V1_1 (pre V1_2) diff --git a/shared/api/customers/previousVersions/apiCustomerV2.ts b/shared/api/customers/previousVersions/apiCustomerV2.ts index 204a4fadd..d3ec6a044 100644 --- a/shared/api/customers/previousVersions/apiCustomerV2.ts +++ b/shared/api/customers/previousVersions/apiCustomerV2.ts @@ -1,5 +1,6 @@ import { ApiCusReferralSchema } from "@api/customers/components/apiCusReferral.js"; import { ApiCusUpcomingInvoiceSchema } from "@api/customers/components/apiCusUpcomingInvoice.js"; +import { ApiTrialsUsedSchema } from "@api/customers/components/apiTrialsUsed.js"; import { ApiCusFeatureV2Schema } from "@api/customers/cusFeatures/previousVersions/apiCusFeatureV2.js"; import { ApiCusProductV2Schema } from "@api/customers/cusPlans/previousVersions/apiCusProductV2.js"; import { ApiEntitySchema } from "@api/entities/apiEntity.js"; @@ -8,12 +9,6 @@ import { ApiInvoiceSchema } from "@api/others/apiInvoice.js"; import { AppEnv } from "@models/genModels/genEnums.js"; import { z } from "zod/v4"; -export const ApiTrialsUsedV2Schema = z.object({ - product_id: z.string(), - customer_id: z.string(), - fingerprint: z.string().nullish(), -}); - /** * ApiCustomerV2Schema - Customer response format for API V1.1+ (merged format) * @@ -49,7 +44,7 @@ export const ApiCustomerV2Schema = z.object({ products: z.array(ApiCusProductV2Schema), features: z.array(ApiCusFeatureV2Schema), invoices: z.array(ApiInvoiceSchema).optional(), - trials_used: z.array(ApiTrialsUsedV2Schema).optional(), + trials_used: z.array(ApiTrialsUsedSchema).optional(), rewards: ApiCusRewardsSchema.nullish(), metadata: z.record(z.any(), z.any()).default({}), diff --git a/shared/api/customers/previousVersions/apiCustomerV3.ts b/shared/api/customers/previousVersions/apiCustomerV3.ts index d0f2e07f4..0c2e9d76d 100644 --- a/shared/api/customers/previousVersions/apiCustomerV3.ts +++ b/shared/api/customers/previousVersions/apiCustomerV3.ts @@ -1,19 +1,14 @@ import { ApiCusReferralSchema } from "@api/customers/components/apiCusReferral.js"; +import { ApiCusUpcomingInvoiceSchema } from "@api/customers/components/apiCusUpcomingInvoice.js"; +import { ApiTrialsUsedSchema } from "@api/customers/components/apiTrialsUsed.js"; import { ApiBaseEntitySchema } from "@api/entities/apiEntity.js"; import { ApiCusRewardsSchema } from "@api/others/apiDiscount.js"; import { ApiInvoiceSchema } from "@api/others/apiInvoice.js"; import { AppEnv } from "@models/genModels/genEnums.js"; import { z } from "zod/v4"; -import { ApiCusUpcomingInvoiceSchema } from "../components/apiCusUpcomingInvoice.js"; import { ApiCusFeatureV3Schema } from "../cusFeatures/previousVersions/apiCusFeatureV3.js"; import { ApiCusProductV3Schema } from "../cusPlans/previousVersions/apiCusProductV3.js"; -export const ApiTrialsUsedSchema = z.object({ - product_id: z.string(), - customer_id: z.string(), - fingerprint: z.string().nullish(), -}); - export const ApiCusExpandV3Schema = z.object({ invoices: z.array(ApiInvoiceSchema).optional(), entities: z.array(ApiBaseEntitySchema).optional(), diff --git a/shared/api/models.ts b/shared/api/models.ts index 1af34fed7..a1023e39e 100644 --- a/shared/api/models.ts +++ b/shared/api/models.ts @@ -24,6 +24,7 @@ export * from "./customers/cusPlans/cusProductLegacyData.js"; export * from "./customers/customerLegacyData.js"; export * from "./customers/customerOpModels.js"; export * from "./customers/previousVersions/apiCustomerV2.js"; +export * from "./customers/previousVersions/apiCustomerV3.js"; // NOTE: customersOpenApi.js is NOT exported here - it's only imported by openapi.ts for spec generation @@ -76,6 +77,7 @@ export * from "./balances/usageModels.js"; export * from "./common/customerData.js"; export * from "./common/entityData.js"; export * from "./customers/cusFeatures/cusFeatureLegacyData.js"; +export * from "./customers/cusPlans/previousVersions/apiCusProductV3.js"; // Errors export * from "./errors/index.js"; // Models diff --git a/shared/api/operations.ts b/shared/api/operations.ts deleted file mode 100644 index c5fa30373..000000000 --- a/shared/api/operations.ts +++ /dev/null @@ -1 +0,0 @@ -// export * from "./features/updateFeatureParams.js"; diff --git a/shared/api/referrals/referralsOpenApi.ts b/shared/api/referrals/referralsOpenApi.ts index 05018eeda..e2ef40520 100644 --- a/shared/api/referrals/referralsOpenApi.ts +++ b/shared/api/referrals/referralsOpenApi.ts @@ -1,3 +1,4 @@ +import type { ZodOpenApiPathsObject } from "zod-openapi"; import { CreateReferralCodeResponseSchema, RedeemReferralCodeResponseSchema, @@ -7,7 +8,7 @@ import { RedeemReferralCodeParamsSchema, } from "./referralOpModels.js"; -export const referralOps = { +export const referralOps: ZodOpenApiPathsObject = { "/referrals/code": { post: { summary: "Create a referral code", diff --git a/shared/api/versionUtils/versionChangeUtils/VersionChangeRegistryClass.ts b/shared/api/versionUtils/versionChangeUtils/VersionChangeRegistryClass.ts index e973142e1..9ae41d294 100644 --- a/shared/api/versionUtils/versionChangeUtils/VersionChangeRegistryClass.ts +++ b/shared/api/versionUtils/versionChangeUtils/VersionChangeRegistryClass.ts @@ -10,7 +10,19 @@ import type { */ const changes = new Map(); -export const VersionChangeRegistryClass = { +export const VersionChangeRegistryClass: { + register(args: { + version: ApiVersion; + changes: VersionChangeConstructor[]; + }): void; + getChangesForVersion(args: { version: ApiVersion }): VersionChange[]; + getRegisteredVersions(): ApiVersion[]; + isChangeActive(args: { + targetVersion: ApiVersion; + changeClass: VersionChangeConstructor; + }): boolean; + clear(): void; +} = { register({ version, changes: versionChanges, diff --git a/shared/api/versionUtils/versionChangeUtils/applyVersionChanges.ts b/shared/api/versionUtils/versionChangeUtils/applyVersionChanges.ts index e0a08daf0..66205fb5c 100644 --- a/shared/api/versionUtils/versionChangeUtils/applyVersionChanges.ts +++ b/shared/api/versionUtils/versionChangeUtils/applyVersionChanges.ts @@ -6,6 +6,7 @@ import { } from "../versionRegistryUtils.js"; import type { AffectedResource, + VersionChange, VersionChangeConstructor, } from "./VersionChange.js"; import { VersionChangeRegistryClass } from "./VersionChangeRegistryClass.js"; @@ -298,7 +299,7 @@ export function getChangesForResource({ currentVersion: ApiVersion; targetVersion: ApiVersion; resource: AffectedResource; -}) { +}): VersionChange[] { const versionsToApply = getVersionsBetween({ from: targetVersion, to: currentVersion, diff --git a/shared/index.ts b/shared/index.ts index 36947d006..fa1256a1c 100644 --- a/shared/index.ts +++ b/shared/index.ts @@ -5,7 +5,6 @@ export { schemas }; export * from "./api/apiUtils.js"; // API MODELS export * from "./api/models.js"; -export * from "./api/operations.js"; // API VERSIONING SYSTEM export * from "./api/versionUtils/versionUtils.js"; @@ -24,7 +23,6 @@ export * from "./enums/WebhookEventType.js"; // ANALYTICS MODELS export * from "./models/analyticsModels/actionEnums.js"; export * from "./models/analyticsModels/actionTable.js"; -export * from "./models/attachModels/attachBody.js"; export * from "./models/attachModels/attachEnums/AttachBranch.js"; export * from "./models/attachModels/attachEnums/AttachConfig.js"; export * from "./models/attachModels/attachEnums/AttachFunction.js"; @@ -48,7 +46,6 @@ export * from "./models/cusModels/cusModels.js"; export * from "./models/cusModels/cusTable.js"; export * from "./models/cusModels/entityModels/entityExpand.js"; export * from "./models/cusModels/entityModels/entityModels.js"; -export * from "./models/cusModels/entityModels/entityResModels.js"; export * from "./models/cusModels/entityModels/entityTable.js"; export * from "./models/cusModels/fullCusModel.js"; export * from "./models/cusModels/invoiceModels/invoiceModels.js"; diff --git a/shared/models/attachModels/attachBody.ts b/shared/models/attachModels/attachBody.ts deleted file mode 100644 index bebcf2d64..000000000 --- a/shared/models/attachModels/attachBody.ts +++ /dev/null @@ -1,126 +0,0 @@ -// import { z } from "zod/v4"; -// import { notNullish } from "../../utils/utils.js"; -// import { FeatureOptionsSchema } from "../cusProductModels/cusProductModels.js"; -// import { CreateFreeTrialSchema } from "../productModels/freeTrialModels/freeTrialModels.js"; -// import { ProductItemSchema } from "../productV2Models/productItemModels/productItemModels.js"; - -// export const ProductOptions = z.object({ -// product_id: z.string(), -// quantity: z.number().nullish(), -// entity_id: z.string().nullish(), -// options: z.array(FeatureOptionsSchema).nullish(), -// }); - -// export const AttachBodySchema = z -// .object({ -// // Customer Info -// customer_id: z -// .string() -// .describe("ID of the customer to attach the product to"), - -// customer_data: z -// .any() -// .nullish() -// .describe("Customer data if using attach to auto create customer"), - -// // Entity Info -// entity_id: z.string().nullish(), -// entity_data: z.any().nullish(), - -// // Product Info -// product_id: z.string().nullish(), -// product_ids: z.array(z.string()).min(1).nullish(), -// options: z.array(FeatureOptionsSchema).nullish(), - -// products: z.array(ProductOptions).nullish(), - -// // Custom Product -// is_custom: z.boolean().optional(), -// items: z.array(ProductItemSchema).optional(), -// free_trial: CreateFreeTrialSchema.or(z.boolean()).optional(), - -// // New Version -// version: z.number().optional(), - -// // Others -// success_url: z.string().optional(), -// force_checkout: z.boolean().optional(), -// invoice_only: z.boolean().optional(), -// metadata: z.any().optional(), -// billing_cycle_anchor: z.number().optional(), -// checkout_session_params: z.any().optional(), -// reward: z.string().or(z.array(z.string())).optional(), -// invoice: z.boolean().optional(), -// enable_product_immediately: z.boolean().optional(), -// finalize_invoice: z.boolean().optional(), - -// // Checkout params -// skip_checkout: z.boolean().optional(), -// setup_payment: z.boolean().optional(), -// }) -// .refine( -// (data) => { -// if (!data.product_id && !data.product_ids && !data.products) { -// return false; -// } - -// return true; -// }, -// { -// message: "`product_id` is not provided", -// }, -// ) -// .refine( -// (data) => { -// if (data.product_id && data.product_ids) { -// return false; -// } - -// return true; -// }, -// { -// message: "provide either one `product_id` or `product_ids`", -// }, -// ) -// .refine( -// (data) => { -// if ( -// notNullish(data.product_ids) && -// new Set(data.product_ids).size !== data.product_ids!.length -// ) { -// return false; -// } - -// return true; -// }, -// { -// message: "Can't pass in duplicate product_ids", -// }, -// ) -// .refine( -// (data) => { -// if (data.product_ids && data.is_custom) { -// return false; -// } - -// return true; -// }, -// { -// message: "Can't pass in product_ids if is_custom is true", -// }, -// ) -// .refine( -// (data) => { -// if (data.items && !data.is_custom) { -// return false; -// } - -// return true; -// }, -// { -// message: "Can't pass in items if is_custom is false", -// }, -// ); - -// export type AttachBody = z.infer; -// export type ProductOptions = z.infer; diff --git a/shared/models/cusModels/entityModels/entityResModels.ts b/shared/models/cusModels/entityModels/entityResModels.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/shared/models/cusModels/entityModels/entityTable.ts b/shared/models/cusModels/entityModels/entityTable.ts index 9b0d1745d..05f692194 100644 --- a/shared/models/cusModels/entityModels/entityTable.ts +++ b/shared/models/cusModels/entityModels/entityTable.ts @@ -3,12 +3,12 @@ import { foreignKey, numeric, pgTable, + text, unique, } from "drizzle-orm/pg-core"; -import { text } from "drizzle-orm/pg-core"; -import { customers } from "../cusTable.js"; import { features } from "../../featureModels/featureTable.js"; import { organizations } from "../../orgModels/orgTable.js"; +import { customers } from "../cusTable.js"; export const entities = pgTable( "entities", diff --git a/shared/package.json b/shared/package.json index 6c3d77251..e8374814d 100644 --- a/shared/package.json +++ b/shared/package.json @@ -2,28 +2,27 @@ "name": "@autumn/shared", "type": "module", "version": "1.0.0", - "main": "./dist/index.js", - "types": "./dist/index.d.ts", + "main": "./index.ts", + "types": "./index.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.js", - "default": "./dist/index.js" + "types": "./index.ts", + "import": "./index.ts", + "default": "./index.ts" } }, "author": "Recase Inc.", "license": "Apache-2.0", "scripts": { "api": "bun api/openapi.ts", - "build": "tsc --emitDeclarationOnly --outDir dist && bun build ./index.ts --outdir dist --format esm --target bun --external zod", - "dev": "bunx nodemon --ext ts --ignore dist --exec \"tsc --emitDeclarationOnly --outDir dist && bun build ./index.ts --outdir dist --format esm --target bun --external zod\"", - "dev:watch": "bun scripts/watch.js", + "ts": "bunx tsgo --build --noEmit", "db:push": "bun db:generate && bun db:migrate", "db:generate": "cross-env NODE_OPTIONS=\"--import tsx\" bunx drizzle-kit generate --config drizzle.config.ts", "db:migrate": "cross-env NODE_OPTIONS=\"--import tsx\" bunx drizzle-kit migrate --config drizzle.config.ts", "db:studio": "cross-env NODE_OPTIONS=\"--import tsx\" bunx drizzle-kit studio --config drizzle.config.ts" }, "dependencies": { + "stripe": "catalog:", "date-fns": "^4.1.0", "decimal.js": "^10.5.0", "dotenv": "^16.5.0", diff --git a/shared/utils/cusProductUtils/productIdToCusProduct.ts b/shared/utils/cusProductUtils/productIdToCusProduct.ts index 6b13fed59..c7e295815 100644 --- a/shared/utils/cusProductUtils/productIdToCusProduct.ts +++ b/shared/utils/cusProductUtils/productIdToCusProduct.ts @@ -30,17 +30,19 @@ export const productToCusProduct = ({ ? cusProduct.internal_entity_id === internalEntityId : nullish(cusProduct.internal_entity_id); - const statusMatch = inStatuses - ? inStatuses.includes(cusProduct.status) - : true; + // const statusMatch = inStatuses + // ? inStatuses.includes(cusProduct.status) + // : true; - return ( - cusProductIdMatch && - versionMatch && - prodIdMatch && - entityMatch && - statusMatch - ); + // if (cusProductIdMatch) { + // console.log(`Cus Product ID Match: ${cusProductIdMatch}`); + // console.log(`Version Match: ${versionMatch}`); + // console.log(`Prod ID Match: ${prodIdMatch}`); + // console.log(`Entity Match: ${entityMatch}`); + // console.log(`--------------------------------`); + // } + + return cusProductIdMatch && versionMatch && prodIdMatch && entityMatch; }); } diff --git a/shared/utils/displayUtils.ts b/shared/utils/displayUtils.ts index 64e66ec3a..fe94e9773 100644 --- a/shared/utils/displayUtils.ts +++ b/shared/utils/displayUtils.ts @@ -49,7 +49,10 @@ export const getFeatureName = ({ } if (capitalize) { - featureName = featureName.charAt(0).toUpperCase() + featureName.slice(1); + featureName = featureName + .split(" ") + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(" "); } return featureName; diff --git a/shared/utils/productV2Utils/productItemUtils/getProductItemRes.ts b/shared/utils/productV2Utils/productItemUtils/getProductItemRes.ts index 305138e37..30ad330d1 100644 --- a/shared/utils/productV2Utils/productItemUtils/getProductItemRes.ts +++ b/shared/utils/productV2Utils/productItemUtils/getProductItemRes.ts @@ -1,5 +1,4 @@ import { ApiProductItemSchema } from "@api/products/planFeature/previousVersions/apiProductItem.js"; -import { Decimal } from "decimal.js"; import type { FeatureOptions } from "@models/cusProductModels/cusProductModels.js"; import type { Feature } from "@models/featureModels/featureModels.js"; import { @@ -10,6 +9,7 @@ import { import { toApiFeature } from "@utils/featureUtils.js"; import { getProductItemDisplay } from "@utils/productDisplayUtils.js"; import { notNullish } from "@utils/utils.js"; +import { Decimal } from "decimal.js"; import { getItemType } from "./getItemType.js"; export const calculateProrationAmount = ({ diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..a1ac21c11 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,31 @@ +{ + "files": [], + "compilerOptions": { + // Environment setup & latest features + "lib": ["ESNext"], + "target": "ESNext", + "module": "Preserve", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + }, + "exclude": ["node_modules", "**/node_modules", "**/.bun"] +} diff --git a/vite/package.json b/vite/package.json index 36d494ebf..c1dcd34b4 100644 --- a/vite/package.json +++ b/vite/package.json @@ -100,6 +100,7 @@ "@types/react": "^18.3.18", "@types/react-dom": "^18.3.5", "@types/react-router-dom": "^5.3.3", + "@typescript/native-preview": "^7.0.0-dev.20251111.1", "@vitejs/plugin-react": "^4.3.4", "eslint": "^9.21.0", "eslint-plugin-react-hooks": "^5.1.0", @@ -107,6 +108,7 @@ "globals": "^15.15.0", "typescript": "~5.7.2", "typescript-eslint": "^8.24.1", - "vite": "^6.2.0" + "vite": "^6.2.0", + "vite-tsconfig-paths": "^5.1.4" } } diff --git a/vite/public/auth-key.png b/vite/public/auth-key.png new file mode 100644 index 000000000..a3f17697b Binary files /dev/null and b/vite/public/auth-key.png differ diff --git a/vite/public/frameworks/nodejs.svg b/vite/public/frameworks/nodejs.svg new file mode 100644 index 000000000..abf449bce --- /dev/null +++ b/vite/public/frameworks/nodejs.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/vite/src/main.tsx b/vite/src/main.tsx index 91834b7fd..4e5aa40c4 100644 --- a/vite/src/main.tsx +++ b/vite/src/main.tsx @@ -14,7 +14,11 @@ import { createRoot } from "react-dom/client"; import App from "./App"; const queryClient = new QueryClient({ - defaultOptions: {}, + defaultOptions: { + queries: { + refetchOnWindowFocus: false, + }, + }, }); const shouldInitializePostHog = process.env.NODE_ENV === "production"; diff --git a/vite/src/views/customers/customer/product/components/AttachModal.tsx b/vite/src/views/customers/customer/product/components/AttachModal.tsx index db194808c..8f42be3d0 100644 --- a/vite/src/views/customers/customer/product/components/AttachModal.tsx +++ b/vite/src/views/customers/customer/product/components/AttachModal.tsx @@ -158,7 +158,10 @@ export const AttachModal = ({ entityId, product, optionsInput: - preview?.branch !== AttachBranch.NewVersion ? options : undefined, + preview?.branch !== AttachBranch.NewVersion && + preview?.branch !== AttachBranch.SameCustomEnts + ? options + : undefined, attachState, useInvoice, enableProductImmediately, @@ -199,7 +202,7 @@ export const AttachModal = ({ } else { toast.error(getBackendErr(error, "Error creating plan")); } - } finally{ + } finally { setLoading(false); } }; @@ -216,9 +219,7 @@ export const AttachModal = ({ className={`p-6 pb-2 flex flex-col gap-4 ${mainWidth} rounded-sm`} > - - Attach plan - + Attach plan
diff --git a/vite/src/views/onboarding3/components/integration-step/FrontendSection.tsx b/vite/src/views/onboarding3/components/integration-step/FrontendSection.tsx index 14c7d6d7f..1bbe504c7 100644 --- a/vite/src/views/onboarding3/components/integration-step/FrontendSection.tsx +++ b/vite/src/views/onboarding3/components/integration-step/FrontendSection.tsx @@ -23,13 +23,7 @@ export const FrontendSection = () => { Wrap your React app in {""} } - description={ -

- {"autumnHandler"} mounts routes on the{" "} - {"/api/autumn/*"} paths which allows our React - hooks and components to interact with the Autumn API directly. -

- } + description="This allows you to use our React hooks and components in your app. If your server URL is different to your client, you will need to pass in the backend URL as a prop." />
diff --git a/vite/src/views/onboarding3/components/integration-step/PricingTableSection.tsx b/vite/src/views/onboarding3/components/integration-step/PricingTableSection.tsx index db4b1bd8d..acccb88f5 100644 --- a/vite/src/views/onboarding3/components/integration-step/PricingTableSection.tsx +++ b/vite/src/views/onboarding3/components/integration-step/PricingTableSection.tsx @@ -10,21 +10,13 @@ import { CodeSpan } from "@/views/onboarding2/integrate/components/CodeSpan"; import { SectionHeader } from "./SectionHeader"; export const PricingTableSection = () => { - const snippet = `import { AutumnProvider } from "autumn-js/react"; + const snippet = `import { PricingTable } from "autumn-js/react"; -export default function RootLayout({ - children, -}: { - children: React.ReactNode, -}) { +export default function Home() { return ( - - - - {children} - - - +
+ +
); }`; @@ -37,7 +29,7 @@ export default function RootLayout({ Drop in {""} } - description="This allows you to use our React hooks and components in your app. If your server URL is different to your client, you will need to pass in the backend URL as a prop." + description="This will display your pricing plans in a table format. You can customize the table by passing in the product details as a prop." />
diff --git a/vite/src/views/onboarding3/components/integration-step/StackSelectionSection.tsx b/vite/src/views/onboarding3/components/integration-step/StackSelectionSection.tsx index e7c689f62..43822c121 100644 --- a/vite/src/views/onboarding3/components/integration-step/StackSelectionSection.tsx +++ b/vite/src/views/onboarding3/components/integration-step/StackSelectionSection.tsx @@ -41,7 +41,7 @@ const BACKEND_OPTIONS: StackOption[] = [ { value: "hono", label: "Hono", asset: "/frameworks/hono.png" }, { value: "express", label: "Express", asset: "/frameworks/express.png" }, { value: "elysia", label: "Elysia", asset: "/frameworks/elysia.png" }, - { value: "general", label: "Other", asset: "/frameworks/react.png" }, + { value: "general", label: "Other", asset: "/frameworks/nodejs.svg" }, ]; const AUTH_OPTIONS: StackOption[] = [ @@ -52,7 +52,7 @@ const AUTH_OPTIONS: StackOption[] = [ }, { value: "supabase", label: "Supabase", asset: "/frameworks/supabase.png" }, { value: "clerk", label: "Clerk", asset: "/frameworks/clerk.png" }, - { value: "other", label: "Other", asset: "/frameworks/react.png" }, + { value: "other", label: "Other", asset: "/auth-key.png" }, ]; const CUSTOMER_TYPE_OPTIONS: StackOption[] = [ diff --git a/vite/src/views/products/plan/components/EditPlanHeader.tsx b/vite/src/views/products/plan/components/EditPlanHeader.tsx index e15ab7bca..50b3e69a9 100644 --- a/vite/src/views/products/plan/components/EditPlanHeader.tsx +++ b/vite/src/views/products/plan/components/EditPlanHeader.tsx @@ -28,7 +28,9 @@ import { PlanToolbar } from "./PlanToolbar.tsx"; export const EditPlanHeader = () => { const { product, numVersions } = useProductQuery(); - const { counts } = useProductCountsQuery(); + const { counts } = useProductCountsQuery( + product.version ? { version: product.version } : {}, + ); const { refetch: refetchMigrations } = useMigrationsQuery(); const { queryStates, setQueryStates } = useProductQueryState(); const axiosInstance = useAxiosInstance(); diff --git a/vite/src/views/products/plan/components/edit-plan-feature/BillingType.tsx b/vite/src/views/products/plan/components/edit-plan-feature/BillingType.tsx index fcf33e26f..6f40b104d 100644 --- a/vite/src/views/products/plan/components/edit-plan-feature/BillingType.tsx +++ b/vite/src/views/products/plan/components/edit-plan-feature/BillingType.tsx @@ -45,30 +45,25 @@ export function BillingType() { }; if (type === "included") { - // Only switch if not already included - if (isFeaturePrice) { - // Remove tiers to switch to included - setItem({ - ...item, - tiers: null, - billing_units: undefined, - usage_model: undefined, - interval: isContUseItem({ item, features }) ? null : item.interval, - }); - } + // Remove tiers to switch to included + setItem({ + ...item, + tiers: null, + billing_units: undefined, + usage_model: undefined, + included_usage: item.included_usage ?? 0, + interval: isContUseItem({ item, features }) ? null : item.interval, + }); } else { - // Only switch if not already priced - if (!isFeaturePrice) { - // Add initial tier to switch to priced - setItem({ - ...item, - tiers: [{ to: Infinite, amount: 0 }], - billing_units: 1, - included_usage: - item.included_usage === Infinite ? 0 : item.included_usage || 0, - interval: getPricedInterval(), - }); - } + // Add initial tier to switch to priced + setItem({ + ...item, + tiers: [{ to: Infinite, amount: 0 }], + billing_units: 1, + included_usage: + item.included_usage === Infinite ? 0 : item.included_usage || 0, + interval: getPricedInterval(), + }); } }; diff --git a/vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx b/vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx index b902e7f12..da9549bdc 100644 --- a/vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx +++ b/vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx @@ -26,6 +26,11 @@ export function EditPlanFeatureSheet({ const feature = getFeature(item?.feature_id ?? "", features); const isFeaturePrice = isFeaturePriceItem(item); + // Check if user has explicitly chosen a billing type + const hasChosenBillingType = + isFeaturePrice || // Has tiers (priced) + (item.included_usage !== undefined && item.included_usage !== null); // Has included usage set + return (
- - - + {hasChosenBillingType && ( + <> + + + - {isFeaturePrice && ( - - - - - + {isFeaturePrice && ( + + + + + + )} + + + )} - - )} diff --git a/vite/src/views/products/product/hooks/queries/useProductCountsQuery.tsx b/vite/src/views/products/product/hooks/queries/useProductCountsQuery.tsx index d8476d435..809108025 100644 --- a/vite/src/views/products/product/hooks/queries/useProductCountsQuery.tsx +++ b/vite/src/views/products/product/hooks/queries/useProductCountsQuery.tsx @@ -1,10 +1,14 @@ import { useQuery } from "@tanstack/react-query"; import { useParams } from "react-router-dom"; -import { useAxiosInstance } from "@/services/useAxiosInstance"; import { useProductStore } from "@/hooks/stores/useProductStore"; +import { useAxiosInstance } from "@/services/useAxiosInstance"; import { useProductQueryState } from "../useProductQuery"; -export const useProductCountsQuery = () => { +export const useProductCountsQuery = ({ + version, +}: { + version?: number; +} = {}) => { const axiosInstance = useAxiosInstance(); const { product_id } = useParams(); const { queryStates } = useProductQueryState(); @@ -17,12 +21,14 @@ export const useProductCountsQuery = () => { if (!productId) return null; // Always get counts for the latest version (don't pass version param) // This ensures we check if the CURRENT version has customers, not older versions - const { data } = await axiosInstance.get(`/products/${productId}/count`); + const { data } = await axiosInstance.get(`/products/${productId}/count`, { + ...(version ? { params: { version } } : {}), + }); return data; }; const { data, isLoading, error, refetch } = useQuery({ - queryKey: ["product_counts", productId], + queryKey: ["product_counts", productId, version], queryFn: fetchProductCounts, retry: false, // Don't retry on error (e.g., product not found) enabled: !!productId, // Only run query if productId exists diff --git a/vite/vite.config.ts b/vite/vite.config.ts index 77d4170f6..aac71f6df 100644 --- a/vite/vite.config.ts +++ b/vite/vite.config.ts @@ -2,10 +2,15 @@ import path from "node:path"; import tailwindcss from "@tailwindcss/vite"; import react from "@vitejs/plugin-react"; import { defineConfig } from "vite"; +import tsconfigPaths from "vite-tsconfig-paths"; // https://vite.dev/config/ export default defineConfig({ - plugins: [react(), tailwindcss()], + plugins: [ + react(), + tailwindcss(), + tsconfigPaths(), // Automatically reads paths from tsconfig.json + ], resolve: { alias: { "@": path.resolve(__dirname, "./src"),