@better-auth/test-utils 1.5.5 → 1.5.7-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter.d.mts +7 -1
- package/dist/adapter.mjs +8 -2
- package/dist/create-test-suite.mjs +1 -2
- package/dist/create-test-suite.mjs.map +1 -1
- package/dist/suites/auth-flow.d.mts +30 -0
- package/dist/suites/auth-flow.mjs +140 -0
- package/dist/suites/auth-flow.mjs.map +1 -0
- package/dist/suites/basic.d.mts +210 -0
- package/dist/suites/basic.mjs +2923 -0
- package/dist/suites/basic.mjs.map +1 -0
- package/dist/suites/index.d.mts +6 -0
- package/dist/suites/index.mjs +7 -0
- package/dist/suites/joins.d.mts +25 -0
- package/dist/suites/joins.mjs +21 -0
- package/dist/suites/joins.mjs.map +1 -0
- package/dist/suites/number-id.d.mts +25 -0
- package/dist/suites/number-id.mjs +32 -0
- package/dist/suites/number-id.mjs.map +1 -0
- package/dist/suites/transactions.d.mts +28 -0
- package/dist/suites/transactions.mjs +30 -0
- package/dist/suites/transactions.mjs.map +1 -0
- package/dist/suites/uuid.d.mts +25 -0
- package/dist/suites/uuid.mjs +54 -0
- package/dist/suites/uuid.mjs.map +1 -0
- package/dist/test-adapter.mjs +1 -2
- package/dist/test-adapter.mjs.map +1 -1
- package/package.json +7 -7
package/dist/adapter.d.mts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { Logger, testAdapter } from "./test-adapter.mjs";
|
|
2
2
|
import { InsertRandomFn, TestEntry, TestSuiteStats, createTestSuite } from "./create-test-suite.mjs";
|
|
3
|
-
|
|
3
|
+
import { authFlowTestSuite } from "./suites/auth-flow.mjs";
|
|
4
|
+
import { enableJoinTests, getNormalTestSuiteTests, normalTestSuite } from "./suites/basic.mjs";
|
|
5
|
+
import { joinsTestSuite } from "./suites/joins.mjs";
|
|
6
|
+
import { numberIdTestSuite } from "./suites/number-id.mjs";
|
|
7
|
+
import { transactionsTestSuite } from "./suites/transactions.mjs";
|
|
8
|
+
import { uuidTestSuite } from "./suites/uuid.mjs";
|
|
9
|
+
export { type InsertRandomFn, type Logger, type TestEntry, type TestSuiteStats, authFlowTestSuite, createTestSuite, enableJoinTests, getNormalTestSuiteTests, joinsTestSuite, normalTestSuite, numberIdTestSuite, testAdapter, transactionsTestSuite, uuidTestSuite };
|
package/dist/adapter.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { createTestSuite } from "./create-test-suite.mjs";
|
|
2
|
+
import { authFlowTestSuite } from "./suites/auth-flow.mjs";
|
|
3
|
+
import { enableJoinTests, getNormalTestSuiteTests, normalTestSuite } from "./suites/basic.mjs";
|
|
4
|
+
import { joinsTestSuite } from "./suites/joins.mjs";
|
|
5
|
+
import { numberIdTestSuite } from "./suites/number-id.mjs";
|
|
6
|
+
import { transactionsTestSuite } from "./suites/transactions.mjs";
|
|
7
|
+
import { uuidTestSuite } from "./suites/uuid.mjs";
|
|
8
|
+
import "./suites/index.mjs";
|
|
2
9
|
import { testAdapter } from "./test-adapter.mjs";
|
|
3
|
-
|
|
4
|
-
export { createTestSuite, testAdapter };
|
|
10
|
+
export { authFlowTestSuite, createTestSuite, enableJoinTests, getNormalTestSuiteTests, joinsTestSuite, normalTestSuite, numberIdTestSuite, testAdapter, transactionsTestSuite, uuidTestSuite };
|
|
@@ -4,7 +4,6 @@ import { TTY_COLORS } from "@better-auth/core/env";
|
|
|
4
4
|
import { generateId } from "@better-auth/core/utils/id";
|
|
5
5
|
import { betterAuth } from "better-auth";
|
|
6
6
|
import { test } from "vitest";
|
|
7
|
-
|
|
8
7
|
//#region src/adapter/create-test-suite.ts
|
|
9
8
|
/**
|
|
10
9
|
* Deep equality comparison for BetterAuthOptions.
|
|
@@ -456,7 +455,7 @@ const createTestSuite = (suiteName, config, tests) => {
|
|
|
456
455
|
};
|
|
457
456
|
};
|
|
458
457
|
};
|
|
459
|
-
|
|
460
458
|
//#endregion
|
|
461
459
|
export { createTestSuite };
|
|
460
|
+
|
|
462
461
|
//# sourceMappingURL=create-test-suite.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-suite.mjs","names":[],"sources":["../src/adapter/create-test-suite.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"@better-auth/core\";\nimport type {\n\tAccount,\n\tSession,\n\tUser,\n\tVerification,\n} from \"@better-auth/core/db\";\nimport { getAuthTables } from \"@better-auth/core/db\";\nimport type { DBAdapter } from \"@better-auth/core/db/adapter\";\nimport {\n\tcreateAdapterFactory,\n\tdeepmerge,\n\tinitGetDefaultModelName,\n} from \"@better-auth/core/db/adapter\";\nimport { TTY_COLORS } from \"@better-auth/core/env\";\nimport { generateId } from \"@better-auth/core/utils/id\";\nimport type { Auth } from \"better-auth\";\nimport { betterAuth } from \"better-auth\";\nimport { test } from \"vitest\";\nimport type { Logger } from \"./test-adapter\";\n\n/**\n * Test entry type that supports both callback and object formats.\n * Object format allows specifying migration options that will be applied before the test runs.\n */\nexport type TestEntry =\n\t| ((context: {\n\t\t\treadonly skip: {\n\t\t\t\t(note?: string | undefined): never;\n\t\t\t\t(condition: boolean, note?: string | undefined): void;\n\t\t\t};\n\t }) => Promise<void>)\n\t| {\n\t\t\tmigrateBetterAuth?: BetterAuthOptions;\n\t\t\ttest: (context: {\n\t\t\t\treadonly skip: {\n\t\t\t\t\t(note?: string | undefined): never;\n\t\t\t\t\t(condition: boolean, note?: string | undefined): void;\n\t\t\t\t};\n\t\t\t}) => Promise<void>;\n\t };\n\n/**\n * Deep equality comparison for BetterAuthOptions.\n * Handles nested objects, arrays, and primitive values.\n */\nfunction deepEqual(a: any, b: any): boolean {\n\tif (a === b) return true;\n\tif (a == null || b == null) return a === b;\n\tif (typeof a !== typeof b) return false;\n\n\tif (typeof a === \"object\") {\n\t\tif (Array.isArray(a) !== Array.isArray(b)) return false;\n\n\t\tif (Array.isArray(a)) {\n\t\t\tif (a.length !== b.length) return false;\n\t\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\t\tif (!deepEqual(a[i], b[i])) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tconst keysA = Object.keys(a);\n\t\tconst keysB = Object.keys(b);\n\n\t\tif (keysA.length !== keysB.length) return false;\n\n\t\tfor (const key of keysA) {\n\t\t\tif (!keysB.includes(key)) return false;\n\t\t\tif (!deepEqual(a[key], b[key])) return false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n/**\n * Statistics tracking for test suites.\n */\nexport type TestSuiteStats = {\n\tmigrationCount: number;\n\ttotalMigrationTime: number;\n\ttestCount: number;\n\tsuiteStartTime: number;\n\tsuiteDuration: number;\n\tsuiteName: string;\n\tgroupingStats?: {\n\t\ttotalGroups: number;\n\t\taverageTestsPerGroup: number;\n\t\tlargestGroupSize: number;\n\t\tsmallestGroupSize: number;\n\t\tgroupsWithMultipleTests: number;\n\t\ttotalTestsInGroups: number;\n\t};\n};\n\ntype GenerateFn = <M extends \"user\" | \"session\" | \"verification\" | \"account\">(\n\tModel: M,\n) => Promise<\n\tM extends \"user\"\n\t\t? User\n\t\t: M extends \"session\"\n\t\t\t? Session\n\t\t\t: M extends \"verification\"\n\t\t\t\t? Verification\n\t\t\t\t: M extends \"account\"\n\t\t\t\t\t? Account\n\t\t\t\t\t: undefined\n>;\n\ntype Success<T> = {\n\tdata: T;\n\terror: null;\n};\n\ntype Failure<E> = {\n\tdata: null;\n\terror: E;\n};\n\ntype Result<T, E = Error> = Success<T> | Failure<E>;\n\nasync function tryCatch<T, E = Error>(\n\tpromise: Promise<T>,\n): Promise<Result<T, E>> {\n\ttry {\n\t\tconst data = await promise;\n\t\treturn { data, error: null };\n\t} catch (error) {\n\t\treturn { data: null, error: error as E };\n\t}\n}\n\nexport type InsertRandomFn = <\n\tM extends \"user\" | \"session\" | \"verification\" | \"account\",\n\tCount extends number = 1,\n>(\n\tmodel: M,\n\tcount?: Count | undefined,\n) => Promise<\n\tCount extends 1\n\t\t? M extends \"user\"\n\t\t\t? [User]\n\t\t\t: M extends \"session\"\n\t\t\t\t? [User, Session]\n\t\t\t\t: M extends \"verification\"\n\t\t\t\t\t? [Verification]\n\t\t\t\t\t: M extends \"account\"\n\t\t\t\t\t\t? [User, Account]\n\t\t\t\t\t\t: [undefined]\n\t\t: Array<\n\t\t\t\tM extends \"user\"\n\t\t\t\t\t? [User]\n\t\t\t\t\t: M extends \"session\"\n\t\t\t\t\t\t? [User, Session]\n\t\t\t\t\t\t: M extends \"verification\"\n\t\t\t\t\t\t\t? [Verification]\n\t\t\t\t\t\t\t: M extends \"account\"\n\t\t\t\t\t\t\t\t? [User, Account]\n\t\t\t\t\t\t\t\t: [undefined]\n\t\t\t>\n>;\n\nexport const createTestSuite = <\n\tTests extends Record<string, TestEntry>,\n\tAdditionalOptions extends Record<string, any> = {},\n>(\n\tsuiteName: string,\n\tconfig: {\n\t\tdefaultBetterAuthOptions?: BetterAuthOptions | undefined;\n\t\t/**\n\t\t * Helpful if the default better auth options require migrations to be run.\n\t\t */\n\t\talwaysMigrate?: boolean | undefined;\n\t\tprefixTests?: string | undefined;\n\t\tcustomIdGenerator?: () => any | Promise<any> | undefined;\n\t},\n\ttests: (\n\t\thelpers: {\n\t\t\tadapter: DBAdapter;\n\t\t\tlog: Logger;\n\t\t\tgenerate: GenerateFn;\n\t\t\tinsertRandom: InsertRandomFn;\n\t\t\t/**\n\t\t\t * A light cleanup function that will only delete rows it knows about.\n\t\t\t */\n\t\t\tcleanup: () => Promise<void>;\n\t\t\t/**\n\t\t\t * A hard cleanup function that will delete all rows from the database.\n\t\t\t */\n\t\t\thardCleanup: () => Promise<void>;\n\t\t\tmodifyBetterAuthOptions: (\n\t\t\t\toptions: BetterAuthOptions,\n\t\t\t\tshouldRunMigrations: boolean,\n\t\t\t) => Promise<BetterAuthOptions>;\n\t\t\tgetBetterAuthOptions: () => BetterAuthOptions;\n\t\t\tsortModels: (\n\t\t\t\tmodels: Array<\n\t\t\t\t\tRecord<string, any> & {\n\t\t\t\t\t\tid: string;\n\t\t\t\t\t}\n\t\t\t\t>,\n\t\t\t\tby?: (\"id\" | \"createdAt\") | undefined,\n\t\t\t) => (Record<string, any> & {\n\t\t\t\tid: string;\n\t\t\t})[];\n\t\t\tgetAuth: () => Promise<Auth>;\n\t\t\ttryCatch<T, E = Error>(promise: Promise<T>): Promise<Result<T, E>>;\n\t\t\tcustomIdGenerator?: () => any | Promise<any> | undefined;\n\t\t\ttransformIdOutput?: (id: any) => string | undefined;\n\t\t\t/**\n\t\t\t * Some adapters may change the ID type, this function allows you to pass the entire model\n\t\t\t * data and it will return the correct better-auth-expected transformed data.\n\t\t\t *\n\t\t\t * Eg:\n\t\t\t * MongoDB uses ObjectId for IDs, but it's possible the user can disable that option in the adapter config.\n\t\t\t * Because of this, the expected data would be a string.\n\t\t\t * These sorts of conversions will cause issues with the test when you use the `generate` function.\n\t\t\t * This is because the `generate` function will return the raw data expected to be saved in DB, not the excpected BA output.\n\t\t\t */\n\t\t\ttransformGeneratedModel: (\n\t\t\t\tdata: Record<string, any>,\n\t\t\t) => Record<string, any>;\n\t\t},\n\t\tadditionalOptions?: AdditionalOptions | undefined,\n\t) => Tests,\n) => {\n\treturn (\n\t\toptions?:\n\t\t\t| ({\n\t\t\t\t\tdisableTests?: Partial<\n\t\t\t\t\t\tRecord<keyof Tests, boolean> & { ALL?: boolean }\n\t\t\t\t\t>;\n\t\t\t } & AdditionalOptions)\n\t\t\t| undefined,\n\t) => {\n\t\treturn async (helpers: {\n\t\t\tadapter: () => Promise<DBAdapter<BetterAuthOptions>>;\n\t\t\tlog: Logger;\n\t\t\tadapterDisplayName: string;\n\t\t\tgetBetterAuthOptions: () => BetterAuthOptions;\n\t\t\tmodifyBetterAuthOptions: (\n\t\t\t\toptions: BetterAuthOptions,\n\t\t\t) => Promise<BetterAuthOptions>;\n\t\t\tcleanup: () => Promise<void>;\n\t\t\trunMigrations: () => Promise<void>;\n\t\t\tprefixTests?: string | undefined;\n\t\t\tonTestFinish: (stats: TestSuiteStats) => Promise<void>;\n\t\t\tcustomIdGenerator?: () => any | Promise<any> | undefined;\n\t\t\ttransformIdOutput?: (id: any) => string | undefined;\n\t\t}) => {\n\t\t\tconst createdRows: Record<string, any[]> = {};\n\n\t\t\tlet adapter = await helpers.adapter();\n\t\t\tconst wrapperAdapter = (\n\t\t\t\toverrideOptions?: BetterAuthOptions | undefined,\n\t\t\t) => {\n\t\t\t\tconst options = deepmerge(\n\t\t\t\t\tdeepmerge(\n\t\t\t\t\t\thelpers.getBetterAuthOptions(),\n\t\t\t\t\t\tconfig?.defaultBetterAuthOptions || {},\n\t\t\t\t\t),\n\t\t\t\t\toverrideOptions || {},\n\t\t\t\t);\n\t\t\t\tconst adapterConfig = {\n\t\t\t\t\tadapterId: helpers.adapterDisplayName,\n\t\t\t\t\t...(adapter.options?.adapterConfig || {}),\n\t\t\t\t\tadapterName: `Wrapped ${adapter.options?.adapterConfig.adapterName}`,\n\t\t\t\t\tdisableTransformOutput: true,\n\t\t\t\t\tdisableTransformInput: true,\n\t\t\t\t\tdisableTransformJoin: true,\n\t\t\t\t};\n\t\t\t\tconst adapterCreator = (\n\t\t\t\t\toptions: BetterAuthOptions,\n\t\t\t\t): DBAdapter<BetterAuthOptions> =>\n\t\t\t\t\tcreateAdapterFactory({\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\t...adapterConfig,\n\t\t\t\t\t\t\ttransaction: adapter.transaction,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tadapter: ({ getDefaultModelName }) => {\n\t\t\t\t\t\t\tadapter.transaction = undefined as any;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tcount: async (args: any) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.count(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdeleteMany: async (args: any) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.deleteMany(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdelete: async (args: any) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.delete(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tfindOne: async (args) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.findOne(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tfindMany: async (args) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.findMany(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tupdate: async (args: any) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.update(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tupdateMany: async (args) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.updateMany(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tcreateSchema: adapter.createSchema as any,\n\t\t\t\t\t\t\t\tasync create({ data, model, select }) {\n\t\t\t\t\t\t\t\t\tconst defaultModelName = getDefaultModelName(model);\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.create({\n\t\t\t\t\t\t\t\t\t\tdata: data,\n\t\t\t\t\t\t\t\t\t\tmodel: defaultModelName,\n\t\t\t\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tcreatedRows[model] = [...(createdRows[model] || []), res];\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\toptions: adapter.options,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t},\n\t\t\t\t\t})(options);\n\n\t\t\t\treturn adapterCreator(options);\n\t\t\t};\n\n\t\t\tconst resetDebugLogs = () => {\n\t\t\t\t//@ts-expect-error\n\t\t\t\twrapperAdapter()?.adapterTestDebugLogs?.resetDebugLogs();\n\t\t\t};\n\n\t\t\tconst printDebugLogs = () => {\n\t\t\t\t//@ts-expect-error\n\t\t\t\twrapperAdapter()?.adapterTestDebugLogs?.printDebugLogs();\n\t\t\t};\n\n\t\t\tconst cleanupCreatedRows = async () => {\n\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\tfor (const model of Object.keys(createdRows)) {\n\t\t\t\t\tfor (const row of createdRows[model]!) {\n\t\t\t\t\t\tconst schema = getAuthTables(helpers.getBetterAuthOptions());\n\t\t\t\t\t\tconst getDefaultModelName = initGetDefaultModelName({\n\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\tusePlural: adapter.options?.adapterConfig.usePlural,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tlet defaultModelName: string;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tdefaultModelName = getDefaultModelName(model);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!schema[defaultModelName]) continue; // model doesn't exist in the schema anymore, so we skip it\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait adapter.delete({\n\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\twhere: [{ field: \"id\", value: row.id }],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// We ignore any failed attempts to delete the created rows.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (createdRows[model]!.length === 1) {\n\t\t\t\t\t\t\tdelete createdRows[model];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Track current applied BetterAuth options state\n\t\t\tlet currentAppliedOptions: BetterAuthOptions | null = null;\n\n\t\t\t// Statistics tracking\n\t\t\tconst stats: TestSuiteStats = {\n\t\t\t\tmigrationCount: 0,\n\t\t\t\ttotalMigrationTime: 0,\n\t\t\t\ttestCount: 0,\n\t\t\t\tsuiteStartTime: performance.now(),\n\t\t\t\tsuiteDuration: 0,\n\t\t\t\tsuiteName,\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Apply BetterAuth options and run migrations if needed.\n\t\t\t * Tracks migration statistics.\n\t\t\t */\n\t\t\tconst applyOptionsAndMigrate = async (\n\t\t\t\toptions: BetterAuthOptions | Partial<BetterAuthOptions>,\n\t\t\t\tforceMigrate: boolean = false,\n\t\t\t): Promise<BetterAuthOptions> => {\n\t\t\t\tconst finalOptions = deepmerge(\n\t\t\t\t\tconfig?.defaultBetterAuthOptions || {},\n\t\t\t\t\toptions || {},\n\t\t\t\t);\n\n\t\t\t\t// Check if options have changed\n\t\t\t\tconst optionsChanged = !deepEqual(currentAppliedOptions, finalOptions);\n\n\t\t\t\tif (optionsChanged || forceMigrate) {\n\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\tawait helpers.modifyBetterAuthOptions(finalOptions);\n\n\t\t\t\t\tif (config.alwaysMigrate || forceMigrate) {\n\t\t\t\t\t\tconst migrationStart = performance.now();\n\t\t\t\t\t\tawait helpers.runMigrations();\n\t\t\t\t\t\tconst migrationTime = performance.now() - migrationStart;\n\n\t\t\t\t\t\tstats.migrationCount++;\n\t\t\t\t\t\tstats.totalMigrationTime += migrationTime;\n\n\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t}\n\n\t\t\t\t\tcurrentAppliedOptions = finalOptions;\n\t\t\t\t} else {\n\t\t\t\t\t// Options haven't changed, just update the reference\n\t\t\t\t\tcurrentAppliedOptions = finalOptions;\n\t\t\t\t}\n\n\t\t\t\treturn finalOptions;\n\t\t\t};\n\n\t\t\tconst transformGeneratedModel = (data: Record<string, any>) => {\n\t\t\t\tconst newData = { ...data };\n\t\t\t\tif (helpers.transformIdOutput) {\n\t\t\t\t\tnewData.id = helpers.transformIdOutput(newData.id);\n\t\t\t\t}\n\t\t\t\treturn newData;\n\t\t\t};\n\n\t\t\tconst idGenerator = async () => {\n\t\t\t\tif (config.customIdGenerator) {\n\t\t\t\t\treturn config.customIdGenerator();\n\t\t\t\t}\n\t\t\t\tif (helpers.customIdGenerator) {\n\t\t\t\t\treturn helpers.customIdGenerator();\n\t\t\t\t}\n\t\t\t\treturn generateId();\n\t\t\t};\n\n\t\t\tconst generateModel: GenerateFn = async (model: string) => {\n\t\t\t\tconst id = await idGenerator();\n\t\t\t\tconst randomDate = new Date(\n\t\t\t\t\tDate.now() - Math.random() * 1000 * 60 * 60 * 24 * 365,\n\t\t\t\t);\n\t\t\t\tif (model === \"user\") {\n\t\t\t\t\tconst user: User = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcreatedAt: randomDate,\n\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\temail:\n\t\t\t\t\t\t\t`user-${helpers.transformIdOutput?.(id) ?? id}@email.com`.toLowerCase(),\n\t\t\t\t\t\temailVerified: true,\n\t\t\t\t\t\tname: `user-${helpers.transformIdOutput?.(id) ?? id}`,\n\t\t\t\t\t\timage: null,\n\t\t\t\t\t};\n\t\t\t\t\treturn user as any;\n\t\t\t\t}\n\t\t\t\tif (model === \"session\") {\n\t\t\t\t\tconst session: Session = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcreatedAt: randomDate,\n\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\texpiresAt: new Date(),\n\t\t\t\t\t\ttoken: generateId(32),\n\t\t\t\t\t\tuserId: generateId(),\n\t\t\t\t\t\tipAddress: \"127.0.0.1\",\n\t\t\t\t\t\tuserAgent: \"Some User Agent\",\n\t\t\t\t\t};\n\t\t\t\t\treturn session as any;\n\t\t\t\t}\n\t\t\t\tif (model === \"verification\") {\n\t\t\t\t\tconst verification: Verification = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcreatedAt: randomDate,\n\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\texpiresAt: new Date(),\n\t\t\t\t\t\tidentifier: `test:${generateId()}`,\n\t\t\t\t\t\tvalue: generateId(),\n\t\t\t\t\t};\n\t\t\t\t\treturn verification as any;\n\t\t\t\t}\n\t\t\t\tif (model === \"account\") {\n\t\t\t\t\tconst account: Account = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcreatedAt: randomDate,\n\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\taccountId: generateId(),\n\t\t\t\t\t\tproviderId: \"test\",\n\t\t\t\t\t\tuserId: generateId(),\n\t\t\t\t\t\taccessToken: generateId(),\n\t\t\t\t\t\trefreshToken: generateId(),\n\t\t\t\t\t\tidToken: generateId(),\n\t\t\t\t\t\taccessTokenExpiresAt: new Date(),\n\t\t\t\t\t\trefreshTokenExpiresAt: new Date(),\n\t\t\t\t\t\tscope: \"test\",\n\t\t\t\t\t};\n\t\t\t\t\treturn account as any;\n\t\t\t\t}\n\t\t\t\t// This should never happen given the type constraints, but TypeScript needs an exhaustive check\n\t\t\t\tthrow new Error(`Unknown model type: ${model}`);\n\t\t\t};\n\n\t\t\tconst insertRandom: InsertRandomFn = async <\n\t\t\t\tM extends \"user\" | \"session\" | \"verification\" | \"account\",\n\t\t\t\tCount extends number = 1,\n\t\t\t>(\n\t\t\t\tmodel: M,\n\t\t\t\tcount: Count = 1 as Count,\n\t\t\t) => {\n\t\t\t\tconst res: any[] = [];\n\t\t\t\tconst a = wrapperAdapter();\n\n\t\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\t\tconst modelResults = [];\n\n\t\t\t\t\tif (model === \"user\") {\n\t\t\t\t\t\tconst user = await generateModel(\"user\");\n\t\t\t\t\t\tmodelResults.push(\n\t\t\t\t\t\t\tawait a.create({\n\t\t\t\t\t\t\t\tdata: user,\n\t\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (model === \"session\") {\n\t\t\t\t\t\tconst user = await generateModel(\"user\");\n\t\t\t\t\t\tconst userRes = await a.create({\n\t\t\t\t\t\t\tdata: user,\n\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst session = await generateModel(\"session\");\n\t\t\t\t\t\tsession.userId = userRes.id;\n\t\t\t\t\t\tconst sessionRes = await a.create({\n\t\t\t\t\t\t\tdata: session,\n\t\t\t\t\t\t\tmodel: \"session\",\n\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tmodelResults.push(userRes, sessionRes);\n\t\t\t\t\t}\n\t\t\t\t\tif (model === \"verification\") {\n\t\t\t\t\t\tconst verification = await generateModel(\"verification\");\n\t\t\t\t\t\tmodelResults.push(\n\t\t\t\t\t\t\tawait a.create({\n\t\t\t\t\t\t\t\tdata: verification,\n\t\t\t\t\t\t\t\tmodel: \"verification\",\n\t\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (model === \"account\") {\n\t\t\t\t\t\tconst user = await generateModel(\"user\");\n\t\t\t\t\t\tconst account = await generateModel(\"account\");\n\t\t\t\t\t\tconst userRes = await a.create({\n\t\t\t\t\t\t\tdata: user,\n\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\taccount.userId = userRes.id;\n\t\t\t\t\t\tconst accRes = await a.create({\n\t\t\t\t\t\t\tdata: account,\n\t\t\t\t\t\t\tmodel: \"account\",\n\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tmodelResults.push(userRes, accRes);\n\t\t\t\t\t}\n\t\t\t\t\tres.push(modelResults);\n\t\t\t\t}\n\t\t\t\treturn res.length === 1 ? res[0] : (res as any);\n\t\t\t};\n\n\t\t\tconst sortModels = (\n\t\t\t\tmodels: Array<Record<string, any> & { id: string }>,\n\t\t\t\tby: \"id\" | \"createdAt\" = \"id\",\n\t\t\t) => {\n\t\t\t\treturn models.sort((a, b) => {\n\t\t\t\t\tif (by === \"createdAt\") {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tnew Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn a.id.localeCompare(b.id);\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst modifyBetterAuthOptions = async (\n\t\t\t\topts: BetterAuthOptions,\n\t\t\t\tshouldRunMigrations: boolean,\n\t\t\t) => {\n\t\t\t\treturn await applyOptionsAndMigrate(opts, shouldRunMigrations);\n\t\t\t};\n\n\t\t\tconst additionalOptions = { ...options };\n\t\t\tadditionalOptions.disableTests = undefined;\n\n\t\t\tconst fullTests = tests(\n\t\t\t\t{\n\t\t\t\t\tadapter: new Proxy({} as any, {\n\t\t\t\t\t\tget(target, prop) {\n\t\t\t\t\t\t\tconst adapter = wrapperAdapter();\n\t\t\t\t\t\t\tif (prop === \"transaction\") {\n\t\t\t\t\t\t\t\treturn adapter.transaction;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst value = adapter[prop as keyof typeof adapter];\n\t\t\t\t\t\t\tif (typeof value === \"function\") {\n\t\t\t\t\t\t\t\treturn value.bind(adapter);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t\tgetAuth: async () => {\n\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\tconst auth = betterAuth({\n\t\t\t\t\t\t\t...helpers.getBetterAuthOptions(),\n\t\t\t\t\t\t\t...(config?.defaultBetterAuthOptions || {}),\n\t\t\t\t\t\t\tdatabase: (options: BetterAuthOptions) => {\n\t\t\t\t\t\t\t\tconst adapter = wrapperAdapter(options);\n\t\t\t\t\t\t\t\treturn adapter;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} as BetterAuthOptions);\n\t\t\t\t\t\treturn auth;\n\t\t\t\t\t},\n\t\t\t\t\tlog: helpers.log,\n\t\t\t\t\tgenerate: generateModel,\n\t\t\t\t\tcleanup: cleanupCreatedRows,\n\t\t\t\t\thardCleanup: helpers.cleanup,\n\t\t\t\t\tinsertRandom,\n\t\t\t\t\tmodifyBetterAuthOptions,\n\t\t\t\t\tgetBetterAuthOptions: helpers.getBetterAuthOptions,\n\t\t\t\t\tsortModels,\n\t\t\t\t\ttryCatch,\n\t\t\t\t\tcustomIdGenerator: helpers.customIdGenerator,\n\t\t\t\t\ttransformGeneratedModel,\n\t\t\t\t\ttransformIdOutput: helpers.transformIdOutput,\n\t\t\t\t},\n\t\t\t\tadditionalOptions as AdditionalOptions,\n\t\t\t);\n\n\t\t\tconst dash = `─`;\n\t\t\tconst allDisabled: boolean = options?.disableTests?.ALL ?? false;\n\n\t\t\t// Here to display a label in the tests showing the suite name\n\t\t\ttest(`\\n${TTY_COLORS.fg.white}${\" \".repeat(3)}${dash.repeat(35)} [${TTY_COLORS.fg.magenta}${suiteName}${TTY_COLORS.fg.white}] ${dash.repeat(35)}`, async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait helpers.cleanup();\n\t\t\t\t} catch {}\n\t\t\t\tif (config.defaultBetterAuthOptions && !allDisabled) {\n\t\t\t\t\tawait applyOptionsAndMigrate(\n\t\t\t\t\t\tconfig.defaultBetterAuthOptions,\n\t\t\t\t\t\tconfig.alwaysMigrate,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * Extract test function and migration options from a test entry.\n\t\t\t */\n\t\t\tconst extractTestEntry = (\n\t\t\t\tentry: TestEntry,\n\t\t\t): {\n\t\t\t\ttestFn: (context: {\n\t\t\t\t\treadonly skip: {\n\t\t\t\t\t\t(note?: string | undefined): never;\n\t\t\t\t\t\t(condition: boolean, note?: string | undefined): void;\n\t\t\t\t\t};\n\t\t\t\t}) => Promise<void>;\n\t\t\t\tmigrateBetterAuth?: BetterAuthOptions;\n\t\t\t} => {\n\t\t\t\tif (typeof entry === \"function\") {\n\t\t\t\t\treturn { testFn: entry };\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\ttestFn: entry.test,\n\t\t\t\t\tmigrateBetterAuth: entry.migrateBetterAuth,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\t// Convert test entries to array with migration info (moved before onFinish for access)\n\t\t\tconst testEntries = Object.entries(fullTests).map(([name, entry]) => {\n\t\t\t\tconst { testFn, migrateBetterAuth } = extractTestEntry(\n\t\t\t\t\tentry as TestEntry,\n\t\t\t\t);\n\t\t\t\treturn { name, testFn, migrateBetterAuth };\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * Group tests by their migrateBetterAuth options.\n\t\t\t * Tests with equal migration options are grouped together.\n\t\t\t */\n\t\t\ttype TestGroup = {\n\t\t\t\tmigrationOptions: BetterAuthOptions | null | undefined;\n\t\t\t\ttestIndices: number[];\n\t\t\t};\n\n\t\t\tconst groupTestsByMigrationOptions = (): TestGroup[] => {\n\t\t\t\tconst groups: TestGroup[] = [];\n\t\t\t\tlet currentGroup: TestGroup | null = null;\n\n\t\t\t\tfor (let i = 0; i < testEntries.length; i++) {\n\t\t\t\t\tconst { migrateBetterAuth } = testEntries[i]!;\n\t\t\t\t\tconst isSkipped =\n\t\t\t\t\t\t(allDisabled &&\n\t\t\t\t\t\t\toptions?.disableTests?.[testEntries[i]!.name] !== false) ||\n\t\t\t\t\t\t(options?.disableTests?.[testEntries[i]!.name] ?? false);\n\n\t\t\t\t\t// Skip grouping for skipped tests - they'll be handled individually\n\t\t\t\t\tif (isSkipped) {\n\t\t\t\t\t\tif (currentGroup) {\n\t\t\t\t\t\t\tgroups.push(currentGroup);\n\t\t\t\t\t\t\tcurrentGroup = null;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tgroups.push({\n\t\t\t\t\t\t\tmigrationOptions: migrateBetterAuth,\n\t\t\t\t\t\t\ttestIndices: [i],\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Check if this test belongs to the current group\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrentGroup &&\n\t\t\t\t\t\tdeepEqual(currentGroup.migrationOptions, migrateBetterAuth)\n\t\t\t\t\t) {\n\t\t\t\t\t\tcurrentGroup.testIndices.push(i);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Start a new group\n\t\t\t\t\t\tif (currentGroup) {\n\t\t\t\t\t\t\tgroups.push(currentGroup);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentGroup = {\n\t\t\t\t\t\t\tmigrationOptions: migrateBetterAuth,\n\t\t\t\t\t\t\ttestIndices: [i],\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Add the last group if it exists\n\t\t\t\tif (currentGroup) {\n\t\t\t\t\tgroups.push(currentGroup);\n\t\t\t\t}\n\n\t\t\t\treturn groups;\n\t\t\t};\n\n\t\t\tconst testGroups = groupTestsByMigrationOptions();\n\n\t\t\t// Calculate grouping statistics\n\t\t\tconst calculateGroupingStats = () => {\n\t\t\t\tconst nonSkippedGroups = testGroups.filter(\n\t\t\t\t\t(group) => group.testIndices.length > 0,\n\t\t\t\t);\n\t\t\t\tconst groupSizes = nonSkippedGroups.map(\n\t\t\t\t\t(group) => group.testIndices.length,\n\t\t\t\t);\n\n\t\t\t\tif (groupSizes.length === 0) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttotalGroups: 0,\n\t\t\t\t\t\taverageTestsPerGroup: 0,\n\t\t\t\t\t\tlargestGroupSize: 0,\n\t\t\t\t\t\tsmallestGroupSize: 0,\n\t\t\t\t\t\tgroupsWithMultipleTests: 0,\n\t\t\t\t\t\ttotalTestsInGroups: 0,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst totalTestsInGroups = groupSizes.reduce(\n\t\t\t\t\t(sum, size) => sum + size,\n\t\t\t\t\t0,\n\t\t\t\t);\n\t\t\t\tconst groupsWithMultipleTests = groupSizes.filter(\n\t\t\t\t\t(size) => size > 1,\n\t\t\t\t).length;\n\n\t\t\t\treturn {\n\t\t\t\t\ttotalGroups: nonSkippedGroups.length,\n\t\t\t\t\taverageTestsPerGroup: totalTestsInGroups / nonSkippedGroups.length,\n\t\t\t\t\tlargestGroupSize: Math.max(...groupSizes),\n\t\t\t\t\tsmallestGroupSize: Math.min(...groupSizes),\n\t\t\t\t\tgroupsWithMultipleTests,\n\t\t\t\t\ttotalTestsInGroups,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tconst onFinish = async (testName: string) => {\n\t\t\t\tawait cleanupCreatedRows();\n\n\t\t\t\tconst currentTestIndex = testEntries.findIndex(\n\t\t\t\t\t({ name }) => name === testName,\n\t\t\t\t);\n\t\t\t\tconst isLastTest = currentTestIndex === testEntries.length - 1;\n\n\t\t\t\tif (isLastTest) {\n\t\t\t\t\tstats.suiteDuration = performance.now() - stats.suiteStartTime;\n\t\t\t\t\tstats.groupingStats = calculateGroupingStats();\n\t\t\t\t\tawait helpers.onTestFinish(stats);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Track the current group's migration options\n\t\t\tlet currentGroupMigrationOptions: BetterAuthOptions | null | undefined =\n\t\t\t\tnull;\n\n\t\t\tfor (let i = 0; i < testEntries.length; i++) {\n\t\t\t\tconst { name: testName, testFn, migrateBetterAuth } = testEntries[i]!;\n\n\t\t\t\t// Find which group this test belongs to\n\t\t\t\tconst testGroup = testGroups.find((group) =>\n\t\t\t\t\tgroup.testIndices.includes(i),\n\t\t\t\t);\n\t\t\t\tconst isFirstInGroup = testGroup && testGroup.testIndices[0] === i;\n\n\t\t\t\tconst shouldSkip =\n\t\t\t\t\t(allDisabled && options?.disableTests?.[testName] !== false) ||\n\t\t\t\t\t(options?.disableTests?.[testName] ?? false);\n\n\t\t\t\tlet displayName = testName.replace(\n\t\t\t\t\t\" - \",\n\t\t\t\t\t` ${TTY_COLORS.dim}${dash}${TTY_COLORS.undim} `,\n\t\t\t\t);\n\t\t\t\tif (config.prefixTests) {\n\t\t\t\t\tdisplayName = `${config.prefixTests} ${TTY_COLORS.dim}>${TTY_COLORS.undim} ${displayName}`;\n\t\t\t\t}\n\t\t\t\tif (helpers.prefixTests) {\n\t\t\t\t\tdisplayName = `[${TTY_COLORS.dim}${helpers.prefixTests}${TTY_COLORS.undim}] ${displayName}`;\n\t\t\t\t}\n\n\t\t\t\ttest.skipIf(shouldSkip)(\n\t\t\t\t\tdisplayName,\n\t\t\t\t\t{ timeout: 30000 },\n\t\t\t\t\tasync ({ onTestFailed, skip }) => {\n\t\t\t\t\t\tresetDebugLogs();\n\n\t\t\t\t\t\t// Apply migration options before test runs\n\t\t\t\t\t\tawait (async () => {\n\t\t\t\t\t\t\tif (shouldSkip) return;\n\n\t\t\t\t\t\t\tconst thisMigration = deepmerge(\n\t\t\t\t\t\t\t\tconfig.defaultBetterAuthOptions || {},\n\t\t\t\t\t\t\t\tmigrateBetterAuth || {},\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// If this is the first test in a group, migrate to the group's options\n\t\t\t\t\t\t\tif (isFirstInGroup && testGroup) {\n\t\t\t\t\t\t\t\tconst groupMigrationOptions = testGroup.migrationOptions;\n\t\t\t\t\t\t\t\tconst groupFinalOptions = deepmerge(\n\t\t\t\t\t\t\t\t\tconfig.defaultBetterAuthOptions || {},\n\t\t\t\t\t\t\t\t\tgroupMigrationOptions || {},\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Only migrate if the group's options are different from current state\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t!deepEqual(\n\t\t\t\t\t\t\t\t\t\tcurrentGroupMigrationOptions,\n\t\t\t\t\t\t\t\t\t\tgroupMigrationOptions,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tawait applyOptionsAndMigrate(groupFinalOptions, true);\n\t\t\t\t\t\t\t\t\tcurrentGroupMigrationOptions = groupMigrationOptions;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// If this test is not in a group or not first in group, check if migration is needed\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\t!deepEqual(currentGroupMigrationOptions, migrateBetterAuth)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tawait applyOptionsAndMigrate(thisMigration, true);\n\t\t\t\t\t\t\t\tcurrentGroupMigrationOptions = migrateBetterAuth;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})();\n\n\t\t\t\t\t\tstats.testCount++;\n\n\t\t\t\t\t\tonTestFailed(async () => {\n\t\t\t\t\t\t\tprintDebugLogs();\n\t\t\t\t\t\t\tawait onFinish(testName);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait testFn({ skip });\n\t\t\t\t\t\tawait onFinish(testName);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t};\n};\n"],"mappings":";;;;;;;;;;;;AA8CA,SAAS,UAAU,GAAQ,GAAiB;AAC3C,KAAI,MAAM,EAAG,QAAO;AACpB,KAAI,KAAK,QAAQ,KAA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AO,4BAA4B,EAAE,EACrC,qBAAqB,EAAE,CACvB;AAGD,UAAI,kBAAkB,WAAW;OAChC,MAAM,wBAAwB,UAAU;OACxC,MAAM,oBAAoB,UACzB,OAAO,4BAA4B,EAAE,EACrC,yBAAyB,EAAE,CAC3B;AAGD,WACC,CAAC,UACA,8BACA,sBACA,EACA;AACD,cAAM,uBAAuB,mBAAmB,KAAK;AACrD,uCAA+B;;iBAKhC,CAAC,UAAU,8BAA8B,kBAAkB,EAC1D;AACD,aAAM,uBAAuB,eAAe,KAAK;AACjD,sCAA+B;;SAE7B;AAEJ,WAAM;AAEN,kBAAa,YAAY;AACxB,sBAAgB;AAChB,YAAM,SAAS,SAAS;OACvB;AACF,WAAM,OAAO,EAAE,MAAM,CAAC;AACtB,WAAM,SAAS,SAAS;MAEzB"}
|
|
1
|
+
{"version":3,"file":"create-test-suite.mjs","names":[],"sources":["../src/adapter/create-test-suite.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"@better-auth/core\";\nimport type {\n\tAccount,\n\tSession,\n\tUser,\n\tVerification,\n} from \"@better-auth/core/db\";\nimport { getAuthTables } from \"@better-auth/core/db\";\nimport type { DBAdapter } from \"@better-auth/core/db/adapter\";\nimport {\n\tcreateAdapterFactory,\n\tdeepmerge,\n\tinitGetDefaultModelName,\n} from \"@better-auth/core/db/adapter\";\nimport { TTY_COLORS } from \"@better-auth/core/env\";\nimport { generateId } from \"@better-auth/core/utils/id\";\nimport type { Auth } from \"better-auth\";\nimport { betterAuth } from \"better-auth\";\nimport { test } from \"vitest\";\nimport type { Logger } from \"./test-adapter\";\n\n/**\n * Test entry type that supports both callback and object formats.\n * Object format allows specifying migration options that will be applied before the test runs.\n */\nexport type TestEntry =\n\t| ((context: {\n\t\t\treadonly skip: {\n\t\t\t\t(note?: string | undefined): never;\n\t\t\t\t(condition: boolean, note?: string | undefined): void;\n\t\t\t};\n\t }) => Promise<void>)\n\t| {\n\t\t\tmigrateBetterAuth?: BetterAuthOptions;\n\t\t\ttest: (context: {\n\t\t\t\treadonly skip: {\n\t\t\t\t\t(note?: string | undefined): never;\n\t\t\t\t\t(condition: boolean, note?: string | undefined): void;\n\t\t\t\t};\n\t\t\t}) => Promise<void>;\n\t };\n\n/**\n * Deep equality comparison for BetterAuthOptions.\n * Handles nested objects, arrays, and primitive values.\n */\nfunction deepEqual(a: any, b: any): boolean {\n\tif (a === b) return true;\n\tif (a == null || b == null) return a === b;\n\tif (typeof a !== typeof b) return false;\n\n\tif (typeof a === \"object\") {\n\t\tif (Array.isArray(a) !== Array.isArray(b)) return false;\n\n\t\tif (Array.isArray(a)) {\n\t\t\tif (a.length !== b.length) return false;\n\t\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\t\tif (!deepEqual(a[i], b[i])) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tconst keysA = Object.keys(a);\n\t\tconst keysB = Object.keys(b);\n\n\t\tif (keysA.length !== keysB.length) return false;\n\n\t\tfor (const key of keysA) {\n\t\t\tif (!keysB.includes(key)) return false;\n\t\t\tif (!deepEqual(a[key], b[key])) return false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n/**\n * Statistics tracking for test suites.\n */\nexport type TestSuiteStats = {\n\tmigrationCount: number;\n\ttotalMigrationTime: number;\n\ttestCount: number;\n\tsuiteStartTime: number;\n\tsuiteDuration: number;\n\tsuiteName: string;\n\tgroupingStats?: {\n\t\ttotalGroups: number;\n\t\taverageTestsPerGroup: number;\n\t\tlargestGroupSize: number;\n\t\tsmallestGroupSize: number;\n\t\tgroupsWithMultipleTests: number;\n\t\ttotalTestsInGroups: number;\n\t};\n};\n\ntype GenerateFn = <M extends \"user\" | \"session\" | \"verification\" | \"account\">(\n\tModel: M,\n) => Promise<\n\tM extends \"user\"\n\t\t? User\n\t\t: M extends \"session\"\n\t\t\t? Session\n\t\t\t: M extends \"verification\"\n\t\t\t\t? Verification\n\t\t\t\t: M extends \"account\"\n\t\t\t\t\t? Account\n\t\t\t\t\t: undefined\n>;\n\ntype Success<T> = {\n\tdata: T;\n\terror: null;\n};\n\ntype Failure<E> = {\n\tdata: null;\n\terror: E;\n};\n\ntype Result<T, E = Error> = Success<T> | Failure<E>;\n\nasync function tryCatch<T, E = Error>(\n\tpromise: Promise<T>,\n): Promise<Result<T, E>> {\n\ttry {\n\t\tconst data = await promise;\n\t\treturn { data, error: null };\n\t} catch (error) {\n\t\treturn { data: null, error: error as E };\n\t}\n}\n\nexport type InsertRandomFn = <\n\tM extends \"user\" | \"session\" | \"verification\" | \"account\",\n\tCount extends number = 1,\n>(\n\tmodel: M,\n\tcount?: Count | undefined,\n) => Promise<\n\tCount extends 1\n\t\t? M extends \"user\"\n\t\t\t? [User]\n\t\t\t: M extends \"session\"\n\t\t\t\t? [User, Session]\n\t\t\t\t: M extends \"verification\"\n\t\t\t\t\t? [Verification]\n\t\t\t\t\t: M extends \"account\"\n\t\t\t\t\t\t? [User, Account]\n\t\t\t\t\t\t: [undefined]\n\t\t: Array<\n\t\t\t\tM extends \"user\"\n\t\t\t\t\t? [User]\n\t\t\t\t\t: M extends \"session\"\n\t\t\t\t\t\t? [User, Session]\n\t\t\t\t\t\t: M extends \"verification\"\n\t\t\t\t\t\t\t? [Verification]\n\t\t\t\t\t\t\t: M extends \"account\"\n\t\t\t\t\t\t\t\t? [User, Account]\n\t\t\t\t\t\t\t\t: [undefined]\n\t\t\t>\n>;\n\nexport const createTestSuite = <\n\tTests extends Record<string, TestEntry>,\n\tAdditionalOptions extends Record<string, any> = {},\n>(\n\tsuiteName: string,\n\tconfig: {\n\t\tdefaultBetterAuthOptions?: BetterAuthOptions | undefined;\n\t\t/**\n\t\t * Helpful if the default better auth options require migrations to be run.\n\t\t */\n\t\talwaysMigrate?: boolean | undefined;\n\t\tprefixTests?: string | undefined;\n\t\tcustomIdGenerator?: () => any | Promise<any> | undefined;\n\t},\n\ttests: (\n\t\thelpers: {\n\t\t\tadapter: DBAdapter;\n\t\t\tlog: Logger;\n\t\t\tgenerate: GenerateFn;\n\t\t\tinsertRandom: InsertRandomFn;\n\t\t\t/**\n\t\t\t * A light cleanup function that will only delete rows it knows about.\n\t\t\t */\n\t\t\tcleanup: () => Promise<void>;\n\t\t\t/**\n\t\t\t * A hard cleanup function that will delete all rows from the database.\n\t\t\t */\n\t\t\thardCleanup: () => Promise<void>;\n\t\t\tmodifyBetterAuthOptions: (\n\t\t\t\toptions: BetterAuthOptions,\n\t\t\t\tshouldRunMigrations: boolean,\n\t\t\t) => Promise<BetterAuthOptions>;\n\t\t\tgetBetterAuthOptions: () => BetterAuthOptions;\n\t\t\tsortModels: (\n\t\t\t\tmodels: Array<\n\t\t\t\t\tRecord<string, any> & {\n\t\t\t\t\t\tid: string;\n\t\t\t\t\t}\n\t\t\t\t>,\n\t\t\t\tby?: (\"id\" | \"createdAt\") | undefined,\n\t\t\t) => (Record<string, any> & {\n\t\t\t\tid: string;\n\t\t\t})[];\n\t\t\tgetAuth: () => Promise<Auth>;\n\t\t\ttryCatch<T, E = Error>(promise: Promise<T>): Promise<Result<T, E>>;\n\t\t\tcustomIdGenerator?: () => any | Promise<any> | undefined;\n\t\t\ttransformIdOutput?: (id: any) => string | undefined;\n\t\t\t/**\n\t\t\t * Some adapters may change the ID type, this function allows you to pass the entire model\n\t\t\t * data and it will return the correct better-auth-expected transformed data.\n\t\t\t *\n\t\t\t * Eg:\n\t\t\t * MongoDB uses ObjectId for IDs, but it's possible the user can disable that option in the adapter config.\n\t\t\t * Because of this, the expected data would be a string.\n\t\t\t * These sorts of conversions will cause issues with the test when you use the `generate` function.\n\t\t\t * This is because the `generate` function will return the raw data expected to be saved in DB, not the excpected BA output.\n\t\t\t */\n\t\t\ttransformGeneratedModel: (\n\t\t\t\tdata: Record<string, any>,\n\t\t\t) => Record<string, any>;\n\t\t},\n\t\tadditionalOptions?: AdditionalOptions | undefined,\n\t) => Tests,\n) => {\n\treturn (\n\t\toptions?:\n\t\t\t| ({\n\t\t\t\t\tdisableTests?: Partial<\n\t\t\t\t\t\tRecord<keyof Tests, boolean> & { ALL?: boolean }\n\t\t\t\t\t>;\n\t\t\t } & AdditionalOptions)\n\t\t\t| undefined,\n\t) => {\n\t\treturn async (helpers: {\n\t\t\tadapter: () => Promise<DBAdapter<BetterAuthOptions>>;\n\t\t\tlog: Logger;\n\t\t\tadapterDisplayName: string;\n\t\t\tgetBetterAuthOptions: () => BetterAuthOptions;\n\t\t\tmodifyBetterAuthOptions: (\n\t\t\t\toptions: BetterAuthOptions,\n\t\t\t) => Promise<BetterAuthOptions>;\n\t\t\tcleanup: () => Promise<void>;\n\t\t\trunMigrations: () => Promise<void>;\n\t\t\tprefixTests?: string | undefined;\n\t\t\tonTestFinish: (stats: TestSuiteStats) => Promise<void>;\n\t\t\tcustomIdGenerator?: () => any | Promise<any> | undefined;\n\t\t\ttransformIdOutput?: (id: any) => string | undefined;\n\t\t}) => {\n\t\t\tconst createdRows: Record<string, any[]> = {};\n\n\t\t\tlet adapter = await helpers.adapter();\n\t\t\tconst wrapperAdapter = (\n\t\t\t\toverrideOptions?: BetterAuthOptions | undefined,\n\t\t\t) => {\n\t\t\t\tconst options = deepmerge(\n\t\t\t\t\tdeepmerge(\n\t\t\t\t\t\thelpers.getBetterAuthOptions(),\n\t\t\t\t\t\tconfig?.defaultBetterAuthOptions || {},\n\t\t\t\t\t),\n\t\t\t\t\toverrideOptions || {},\n\t\t\t\t);\n\t\t\t\tconst adapterConfig = {\n\t\t\t\t\tadapterId: helpers.adapterDisplayName,\n\t\t\t\t\t...(adapter.options?.adapterConfig || {}),\n\t\t\t\t\tadapterName: `Wrapped ${adapter.options?.adapterConfig.adapterName}`,\n\t\t\t\t\tdisableTransformOutput: true,\n\t\t\t\t\tdisableTransformInput: true,\n\t\t\t\t\tdisableTransformJoin: true,\n\t\t\t\t};\n\t\t\t\tconst adapterCreator = (\n\t\t\t\t\toptions: BetterAuthOptions,\n\t\t\t\t): DBAdapter<BetterAuthOptions> =>\n\t\t\t\t\tcreateAdapterFactory({\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\t...adapterConfig,\n\t\t\t\t\t\t\ttransaction: adapter.transaction,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tadapter: ({ getDefaultModelName }) => {\n\t\t\t\t\t\t\tadapter.transaction = undefined as any;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tcount: async (args: any) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.count(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdeleteMany: async (args: any) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.deleteMany(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdelete: async (args: any) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.delete(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tfindOne: async (args) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.findOne(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tfindMany: async (args) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.findMany(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tupdate: async (args: any) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.update(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tupdateMany: async (args) => {\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.updateMany(args);\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tcreateSchema: adapter.createSchema as any,\n\t\t\t\t\t\t\t\tasync create({ data, model, select }) {\n\t\t\t\t\t\t\t\t\tconst defaultModelName = getDefaultModelName(model);\n\t\t\t\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\t\t\t\tconst res = await adapter.create({\n\t\t\t\t\t\t\t\t\t\tdata: data,\n\t\t\t\t\t\t\t\t\t\tmodel: defaultModelName,\n\t\t\t\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tcreatedRows[model] = [...(createdRows[model] || []), res];\n\t\t\t\t\t\t\t\t\treturn res as any;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\toptions: adapter.options,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t},\n\t\t\t\t\t})(options);\n\n\t\t\t\treturn adapterCreator(options);\n\t\t\t};\n\n\t\t\tconst resetDebugLogs = () => {\n\t\t\t\t//@ts-expect-error\n\t\t\t\twrapperAdapter()?.adapterTestDebugLogs?.resetDebugLogs();\n\t\t\t};\n\n\t\t\tconst printDebugLogs = () => {\n\t\t\t\t//@ts-expect-error\n\t\t\t\twrapperAdapter()?.adapterTestDebugLogs?.printDebugLogs();\n\t\t\t};\n\n\t\t\tconst cleanupCreatedRows = async () => {\n\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\tfor (const model of Object.keys(createdRows)) {\n\t\t\t\t\tfor (const row of createdRows[model]!) {\n\t\t\t\t\t\tconst schema = getAuthTables(helpers.getBetterAuthOptions());\n\t\t\t\t\t\tconst getDefaultModelName = initGetDefaultModelName({\n\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\tusePlural: adapter.options?.adapterConfig.usePlural,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tlet defaultModelName: string;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tdefaultModelName = getDefaultModelName(model);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!schema[defaultModelName]) continue; // model doesn't exist in the schema anymore, so we skip it\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait adapter.delete({\n\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\twhere: [{ field: \"id\", value: row.id }],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// We ignore any failed attempts to delete the created rows.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (createdRows[model]!.length === 1) {\n\t\t\t\t\t\t\tdelete createdRows[model];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Track current applied BetterAuth options state\n\t\t\tlet currentAppliedOptions: BetterAuthOptions | null = null;\n\n\t\t\t// Statistics tracking\n\t\t\tconst stats: TestSuiteStats = {\n\t\t\t\tmigrationCount: 0,\n\t\t\t\ttotalMigrationTime: 0,\n\t\t\t\ttestCount: 0,\n\t\t\t\tsuiteStartTime: performance.now(),\n\t\t\t\tsuiteDuration: 0,\n\t\t\t\tsuiteName,\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Apply BetterAuth options and run migrations if needed.\n\t\t\t * Tracks migration statistics.\n\t\t\t */\n\t\t\tconst applyOptionsAndMigrate = async (\n\t\t\t\toptions: BetterAuthOptions | Partial<BetterAuthOptions>,\n\t\t\t\tforceMigrate: boolean = false,\n\t\t\t): Promise<BetterAuthOptions> => {\n\t\t\t\tconst finalOptions = deepmerge(\n\t\t\t\t\tconfig?.defaultBetterAuthOptions || {},\n\t\t\t\t\toptions || {},\n\t\t\t\t);\n\n\t\t\t\t// Check if options have changed\n\t\t\t\tconst optionsChanged = !deepEqual(currentAppliedOptions, finalOptions);\n\n\t\t\t\tif (optionsChanged || forceMigrate) {\n\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\tawait helpers.modifyBetterAuthOptions(finalOptions);\n\n\t\t\t\t\tif (config.alwaysMigrate || forceMigrate) {\n\t\t\t\t\t\tconst migrationStart = performance.now();\n\t\t\t\t\t\tawait helpers.runMigrations();\n\t\t\t\t\t\tconst migrationTime = performance.now() - migrationStart;\n\n\t\t\t\t\t\tstats.migrationCount++;\n\t\t\t\t\t\tstats.totalMigrationTime += migrationTime;\n\n\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t}\n\n\t\t\t\t\tcurrentAppliedOptions = finalOptions;\n\t\t\t\t} else {\n\t\t\t\t\t// Options haven't changed, just update the reference\n\t\t\t\t\tcurrentAppliedOptions = finalOptions;\n\t\t\t\t}\n\n\t\t\t\treturn finalOptions;\n\t\t\t};\n\n\t\t\tconst transformGeneratedModel = (data: Record<string, any>) => {\n\t\t\t\tconst newData = { ...data };\n\t\t\t\tif (helpers.transformIdOutput) {\n\t\t\t\t\tnewData.id = helpers.transformIdOutput(newData.id);\n\t\t\t\t}\n\t\t\t\treturn newData;\n\t\t\t};\n\n\t\t\tconst idGenerator = async () => {\n\t\t\t\tif (config.customIdGenerator) {\n\t\t\t\t\treturn config.customIdGenerator();\n\t\t\t\t}\n\t\t\t\tif (helpers.customIdGenerator) {\n\t\t\t\t\treturn helpers.customIdGenerator();\n\t\t\t\t}\n\t\t\t\treturn generateId();\n\t\t\t};\n\n\t\t\tconst generateModel: GenerateFn = async (model: string) => {\n\t\t\t\tconst id = await idGenerator();\n\t\t\t\tconst randomDate = new Date(\n\t\t\t\t\tDate.now() - Math.random() * 1000 * 60 * 60 * 24 * 365,\n\t\t\t\t);\n\t\t\t\tif (model === \"user\") {\n\t\t\t\t\tconst user: User = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcreatedAt: randomDate,\n\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\temail:\n\t\t\t\t\t\t\t`user-${helpers.transformIdOutput?.(id) ?? id}@email.com`.toLowerCase(),\n\t\t\t\t\t\temailVerified: true,\n\t\t\t\t\t\tname: `user-${helpers.transformIdOutput?.(id) ?? id}`,\n\t\t\t\t\t\timage: null,\n\t\t\t\t\t};\n\t\t\t\t\treturn user as any;\n\t\t\t\t}\n\t\t\t\tif (model === \"session\") {\n\t\t\t\t\tconst session: Session = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcreatedAt: randomDate,\n\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\texpiresAt: new Date(),\n\t\t\t\t\t\ttoken: generateId(32),\n\t\t\t\t\t\tuserId: generateId(),\n\t\t\t\t\t\tipAddress: \"127.0.0.1\",\n\t\t\t\t\t\tuserAgent: \"Some User Agent\",\n\t\t\t\t\t};\n\t\t\t\t\treturn session as any;\n\t\t\t\t}\n\t\t\t\tif (model === \"verification\") {\n\t\t\t\t\tconst verification: Verification = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcreatedAt: randomDate,\n\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\texpiresAt: new Date(),\n\t\t\t\t\t\tidentifier: `test:${generateId()}`,\n\t\t\t\t\t\tvalue: generateId(),\n\t\t\t\t\t};\n\t\t\t\t\treturn verification as any;\n\t\t\t\t}\n\t\t\t\tif (model === \"account\") {\n\t\t\t\t\tconst account: Account = {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcreatedAt: randomDate,\n\t\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t\t\taccountId: generateId(),\n\t\t\t\t\t\tproviderId: \"test\",\n\t\t\t\t\t\tuserId: generateId(),\n\t\t\t\t\t\taccessToken: generateId(),\n\t\t\t\t\t\trefreshToken: generateId(),\n\t\t\t\t\t\tidToken: generateId(),\n\t\t\t\t\t\taccessTokenExpiresAt: new Date(),\n\t\t\t\t\t\trefreshTokenExpiresAt: new Date(),\n\t\t\t\t\t\tscope: \"test\",\n\t\t\t\t\t};\n\t\t\t\t\treturn account as any;\n\t\t\t\t}\n\t\t\t\t// This should never happen given the type constraints, but TypeScript needs an exhaustive check\n\t\t\t\tthrow new Error(`Unknown model type: ${model}`);\n\t\t\t};\n\n\t\t\tconst insertRandom: InsertRandomFn = async <\n\t\t\t\tM extends \"user\" | \"session\" | \"verification\" | \"account\",\n\t\t\t\tCount extends number = 1,\n\t\t\t>(\n\t\t\t\tmodel: M,\n\t\t\t\tcount: Count = 1 as Count,\n\t\t\t) => {\n\t\t\t\tconst res: any[] = [];\n\t\t\t\tconst a = wrapperAdapter();\n\n\t\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\t\tconst modelResults = [];\n\n\t\t\t\t\tif (model === \"user\") {\n\t\t\t\t\t\tconst user = await generateModel(\"user\");\n\t\t\t\t\t\tmodelResults.push(\n\t\t\t\t\t\t\tawait a.create({\n\t\t\t\t\t\t\t\tdata: user,\n\t\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (model === \"session\") {\n\t\t\t\t\t\tconst user = await generateModel(\"user\");\n\t\t\t\t\t\tconst userRes = await a.create({\n\t\t\t\t\t\t\tdata: user,\n\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst session = await generateModel(\"session\");\n\t\t\t\t\t\tsession.userId = userRes.id;\n\t\t\t\t\t\tconst sessionRes = await a.create({\n\t\t\t\t\t\t\tdata: session,\n\t\t\t\t\t\t\tmodel: \"session\",\n\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tmodelResults.push(userRes, sessionRes);\n\t\t\t\t\t}\n\t\t\t\t\tif (model === \"verification\") {\n\t\t\t\t\t\tconst verification = await generateModel(\"verification\");\n\t\t\t\t\t\tmodelResults.push(\n\t\t\t\t\t\t\tawait a.create({\n\t\t\t\t\t\t\t\tdata: verification,\n\t\t\t\t\t\t\t\tmodel: \"verification\",\n\t\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (model === \"account\") {\n\t\t\t\t\t\tconst user = await generateModel(\"user\");\n\t\t\t\t\t\tconst account = await generateModel(\"account\");\n\t\t\t\t\t\tconst userRes = await a.create({\n\t\t\t\t\t\t\tdata: user,\n\t\t\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\taccount.userId = userRes.id;\n\t\t\t\t\t\tconst accRes = await a.create({\n\t\t\t\t\t\t\tdata: account,\n\t\t\t\t\t\t\tmodel: \"account\",\n\t\t\t\t\t\t\tforceAllowId: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tmodelResults.push(userRes, accRes);\n\t\t\t\t\t}\n\t\t\t\t\tres.push(modelResults);\n\t\t\t\t}\n\t\t\t\treturn res.length === 1 ? res[0] : (res as any);\n\t\t\t};\n\n\t\t\tconst sortModels = (\n\t\t\t\tmodels: Array<Record<string, any> & { id: string }>,\n\t\t\t\tby: \"id\" | \"createdAt\" = \"id\",\n\t\t\t) => {\n\t\t\t\treturn models.sort((a, b) => {\n\t\t\t\t\tif (by === \"createdAt\") {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tnew Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn a.id.localeCompare(b.id);\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst modifyBetterAuthOptions = async (\n\t\t\t\topts: BetterAuthOptions,\n\t\t\t\tshouldRunMigrations: boolean,\n\t\t\t) => {\n\t\t\t\treturn await applyOptionsAndMigrate(opts, shouldRunMigrations);\n\t\t\t};\n\n\t\t\tconst additionalOptions = { ...options };\n\t\t\tadditionalOptions.disableTests = undefined;\n\n\t\t\tconst fullTests = tests(\n\t\t\t\t{\n\t\t\t\t\tadapter: new Proxy({} as any, {\n\t\t\t\t\t\tget(target, prop) {\n\t\t\t\t\t\t\tconst adapter = wrapperAdapter();\n\t\t\t\t\t\t\tif (prop === \"transaction\") {\n\t\t\t\t\t\t\t\treturn adapter.transaction;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst value = adapter[prop as keyof typeof adapter];\n\t\t\t\t\t\t\tif (typeof value === \"function\") {\n\t\t\t\t\t\t\t\treturn value.bind(adapter);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t\tgetAuth: async () => {\n\t\t\t\t\t\tadapter = await helpers.adapter();\n\t\t\t\t\t\tconst auth = betterAuth({\n\t\t\t\t\t\t\t...helpers.getBetterAuthOptions(),\n\t\t\t\t\t\t\t...(config?.defaultBetterAuthOptions || {}),\n\t\t\t\t\t\t\tdatabase: (options: BetterAuthOptions) => {\n\t\t\t\t\t\t\t\tconst adapter = wrapperAdapter(options);\n\t\t\t\t\t\t\t\treturn adapter;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} as BetterAuthOptions);\n\t\t\t\t\t\treturn auth;\n\t\t\t\t\t},\n\t\t\t\t\tlog: helpers.log,\n\t\t\t\t\tgenerate: generateModel,\n\t\t\t\t\tcleanup: cleanupCreatedRows,\n\t\t\t\t\thardCleanup: helpers.cleanup,\n\t\t\t\t\tinsertRandom,\n\t\t\t\t\tmodifyBetterAuthOptions,\n\t\t\t\t\tgetBetterAuthOptions: helpers.getBetterAuthOptions,\n\t\t\t\t\tsortModels,\n\t\t\t\t\ttryCatch,\n\t\t\t\t\tcustomIdGenerator: helpers.customIdGenerator,\n\t\t\t\t\ttransformGeneratedModel,\n\t\t\t\t\ttransformIdOutput: helpers.transformIdOutput,\n\t\t\t\t},\n\t\t\t\tadditionalOptions as AdditionalOptions,\n\t\t\t);\n\n\t\t\tconst dash = `─`;\n\t\t\tconst allDisabled: boolean = options?.disableTests?.ALL ?? false;\n\n\t\t\t// Here to display a label in the tests showing the suite name\n\t\t\ttest(`\\n${TTY_COLORS.fg.white}${\" \".repeat(3)}${dash.repeat(35)} [${TTY_COLORS.fg.magenta}${suiteName}${TTY_COLORS.fg.white}] ${dash.repeat(35)}`, async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait helpers.cleanup();\n\t\t\t\t} catch {}\n\t\t\t\tif (config.defaultBetterAuthOptions && !allDisabled) {\n\t\t\t\t\tawait applyOptionsAndMigrate(\n\t\t\t\t\t\tconfig.defaultBetterAuthOptions,\n\t\t\t\t\t\tconfig.alwaysMigrate,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * Extract test function and migration options from a test entry.\n\t\t\t */\n\t\t\tconst extractTestEntry = (\n\t\t\t\tentry: TestEntry,\n\t\t\t): {\n\t\t\t\ttestFn: (context: {\n\t\t\t\t\treadonly skip: {\n\t\t\t\t\t\t(note?: string | undefined): never;\n\t\t\t\t\t\t(condition: boolean, note?: string | undefined): void;\n\t\t\t\t\t};\n\t\t\t\t}) => Promise<void>;\n\t\t\t\tmigrateBetterAuth?: BetterAuthOptions;\n\t\t\t} => {\n\t\t\t\tif (typeof entry === \"function\") {\n\t\t\t\t\treturn { testFn: entry };\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\ttestFn: entry.test,\n\t\t\t\t\tmigrateBetterAuth: entry.migrateBetterAuth,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\t// Convert test entries to array with migration info (moved before onFinish for access)\n\t\t\tconst testEntries = Object.entries(fullTests).map(([name, entry]) => {\n\t\t\t\tconst { testFn, migrateBetterAuth } = extractTestEntry(\n\t\t\t\t\tentry as TestEntry,\n\t\t\t\t);\n\t\t\t\treturn { name, testFn, migrateBetterAuth };\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * Group tests by their migrateBetterAuth options.\n\t\t\t * Tests with equal migration options are grouped together.\n\t\t\t */\n\t\t\ttype TestGroup = {\n\t\t\t\tmigrationOptions: BetterAuthOptions | null | undefined;\n\t\t\t\ttestIndices: number[];\n\t\t\t};\n\n\t\t\tconst groupTestsByMigrationOptions = (): TestGroup[] => {\n\t\t\t\tconst groups: TestGroup[] = [];\n\t\t\t\tlet currentGroup: TestGroup | null = null;\n\n\t\t\t\tfor (let i = 0; i < testEntries.length; i++) {\n\t\t\t\t\tconst { migrateBetterAuth } = testEntries[i]!;\n\t\t\t\t\tconst isSkipped =\n\t\t\t\t\t\t(allDisabled &&\n\t\t\t\t\t\t\toptions?.disableTests?.[testEntries[i]!.name] !== false) ||\n\t\t\t\t\t\t(options?.disableTests?.[testEntries[i]!.name] ?? false);\n\n\t\t\t\t\t// Skip grouping for skipped tests - they'll be handled individually\n\t\t\t\t\tif (isSkipped) {\n\t\t\t\t\t\tif (currentGroup) {\n\t\t\t\t\t\t\tgroups.push(currentGroup);\n\t\t\t\t\t\t\tcurrentGroup = null;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tgroups.push({\n\t\t\t\t\t\t\tmigrationOptions: migrateBetterAuth,\n\t\t\t\t\t\t\ttestIndices: [i],\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Check if this test belongs to the current group\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrentGroup &&\n\t\t\t\t\t\tdeepEqual(currentGroup.migrationOptions, migrateBetterAuth)\n\t\t\t\t\t) {\n\t\t\t\t\t\tcurrentGroup.testIndices.push(i);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Start a new group\n\t\t\t\t\t\tif (currentGroup) {\n\t\t\t\t\t\t\tgroups.push(currentGroup);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentGroup = {\n\t\t\t\t\t\t\tmigrationOptions: migrateBetterAuth,\n\t\t\t\t\t\t\ttestIndices: [i],\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Add the last group if it exists\n\t\t\t\tif (currentGroup) {\n\t\t\t\t\tgroups.push(currentGroup);\n\t\t\t\t}\n\n\t\t\t\treturn groups;\n\t\t\t};\n\n\t\t\tconst testGroups = groupTestsByMigrationOptions();\n\n\t\t\t// Calculate grouping statistics\n\t\t\tconst calculateGroupingStats = () => {\n\t\t\t\tconst nonSkippedGroups = testGroups.filter(\n\t\t\t\t\t(group) => group.testIndices.length > 0,\n\t\t\t\t);\n\t\t\t\tconst groupSizes = nonSkippedGroups.map(\n\t\t\t\t\t(group) => group.testIndices.length,\n\t\t\t\t);\n\n\t\t\t\tif (groupSizes.length === 0) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttotalGroups: 0,\n\t\t\t\t\t\taverageTestsPerGroup: 0,\n\t\t\t\t\t\tlargestGroupSize: 0,\n\t\t\t\t\t\tsmallestGroupSize: 0,\n\t\t\t\t\t\tgroupsWithMultipleTests: 0,\n\t\t\t\t\t\ttotalTestsInGroups: 0,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst totalTestsInGroups = groupSizes.reduce(\n\t\t\t\t\t(sum, size) => sum + size,\n\t\t\t\t\t0,\n\t\t\t\t);\n\t\t\t\tconst groupsWithMultipleTests = groupSizes.filter(\n\t\t\t\t\t(size) => size > 1,\n\t\t\t\t).length;\n\n\t\t\t\treturn {\n\t\t\t\t\ttotalGroups: nonSkippedGroups.length,\n\t\t\t\t\taverageTestsPerGroup: totalTestsInGroups / nonSkippedGroups.length,\n\t\t\t\t\tlargestGroupSize: Math.max(...groupSizes),\n\t\t\t\t\tsmallestGroupSize: Math.min(...groupSizes),\n\t\t\t\t\tgroupsWithMultipleTests,\n\t\t\t\t\ttotalTestsInGroups,\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tconst onFinish = async (testName: string) => {\n\t\t\t\tawait cleanupCreatedRows();\n\n\t\t\t\tconst currentTestIndex = testEntries.findIndex(\n\t\t\t\t\t({ name }) => name === testName,\n\t\t\t\t);\n\t\t\t\tconst isLastTest = currentTestIndex === testEntries.length - 1;\n\n\t\t\t\tif (isLastTest) {\n\t\t\t\t\tstats.suiteDuration = performance.now() - stats.suiteStartTime;\n\t\t\t\t\tstats.groupingStats = calculateGroupingStats();\n\t\t\t\t\tawait helpers.onTestFinish(stats);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Track the current group's migration options\n\t\t\tlet currentGroupMigrationOptions: BetterAuthOptions | null | undefined =\n\t\t\t\tnull;\n\n\t\t\tfor (let i = 0; i < testEntries.length; i++) {\n\t\t\t\tconst { name: testName, testFn, migrateBetterAuth } = testEntries[i]!;\n\n\t\t\t\t// Find which group this test belongs to\n\t\t\t\tconst testGroup = testGroups.find((group) =>\n\t\t\t\t\tgroup.testIndices.includes(i),\n\t\t\t\t);\n\t\t\t\tconst isFirstInGroup = testGroup && testGroup.testIndices[0] === i;\n\n\t\t\t\tconst shouldSkip =\n\t\t\t\t\t(allDisabled && options?.disableTests?.[testName] !== false) ||\n\t\t\t\t\t(options?.disableTests?.[testName] ?? false);\n\n\t\t\t\tlet displayName = testName.replace(\n\t\t\t\t\t\" - \",\n\t\t\t\t\t` ${TTY_COLORS.dim}${dash}${TTY_COLORS.undim} `,\n\t\t\t\t);\n\t\t\t\tif (config.prefixTests) {\n\t\t\t\t\tdisplayName = `${config.prefixTests} ${TTY_COLORS.dim}>${TTY_COLORS.undim} ${displayName}`;\n\t\t\t\t}\n\t\t\t\tif (helpers.prefixTests) {\n\t\t\t\t\tdisplayName = `[${TTY_COLORS.dim}${helpers.prefixTests}${TTY_COLORS.undim}] ${displayName}`;\n\t\t\t\t}\n\n\t\t\t\ttest.skipIf(shouldSkip)(\n\t\t\t\t\tdisplayName,\n\t\t\t\t\t{ timeout: 30000 },\n\t\t\t\t\tasync ({ onTestFailed, skip }) => {\n\t\t\t\t\t\tresetDebugLogs();\n\n\t\t\t\t\t\t// Apply migration options before test runs\n\t\t\t\t\t\tawait (async () => {\n\t\t\t\t\t\t\tif (shouldSkip) return;\n\n\t\t\t\t\t\t\tconst thisMigration = deepmerge(\n\t\t\t\t\t\t\t\tconfig.defaultBetterAuthOptions || {},\n\t\t\t\t\t\t\t\tmigrateBetterAuth || {},\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// If this is the first test in a group, migrate to the group's options\n\t\t\t\t\t\t\tif (isFirstInGroup && testGroup) {\n\t\t\t\t\t\t\t\tconst groupMigrationOptions = testGroup.migrationOptions;\n\t\t\t\t\t\t\t\tconst groupFinalOptions = deepmerge(\n\t\t\t\t\t\t\t\t\tconfig.defaultBetterAuthOptions || {},\n\t\t\t\t\t\t\t\t\tgroupMigrationOptions || {},\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Only migrate if the group's options are different from current state\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t!deepEqual(\n\t\t\t\t\t\t\t\t\t\tcurrentGroupMigrationOptions,\n\t\t\t\t\t\t\t\t\t\tgroupMigrationOptions,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tawait applyOptionsAndMigrate(groupFinalOptions, true);\n\t\t\t\t\t\t\t\t\tcurrentGroupMigrationOptions = groupMigrationOptions;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// If this test is not in a group or not first in group, check if migration is needed\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\t!deepEqual(currentGroupMigrationOptions, migrateBetterAuth)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tawait applyOptionsAndMigrate(thisMigration, true);\n\t\t\t\t\t\t\t\tcurrentGroupMigrationOptions = migrateBetter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AS,eAAe,aAAa;IAEvC,IAAI,cAAc,SAAS,QAC1B,OACA,IAAI,WAAW,MAAM,OAAO,WAAW,MAAM,GAC7C;AACD,QAAI,OAAO,YACV,eAAc,GAAG,OAAO,YAAY,GAAG,WAAW,IAAI,GAAG,WAAW,MAAM,GAAG;AAE9E,QAAI,QAAQ,YACX,eAAc,IAAI,WAAW,MAAM,QAAQ,cAAc,WAAW,MAAM,IAAI;AAG/E,SAAK,OAAO,WAAW,CACtB,aACA,EAAE,SAAS,KAAO,EAClB,OAAO,EAAE,cAAc,WAAW;AACjC,qBAAgB;AAGhB,YAAO,YAAY;AAClB,UAAI,WAAY;MAEhB,MAAM,gBAAgB,UACrB,OAAO,4BAA4B,EAAE,EACrC,qBAAqB,EAAE,CACvB;AAGD,UAAI,kBAAkB,WAAW;OAChC,MAAM,wBAAwB,UAAU;OACxC,MAAM,oBAAoB,UACzB,OAAO,4BAA4B,EAAE,EACrC,yBAAyB,EAAE,CAC3B;AAGD,WACC,CAAC,UACA,8BACA,sBACA,EACA;AACD,cAAM,uBAAuB,mBAAmB,KAAK;AACrD,uCAA+B;;iBAKhC,CAAC,UAAU,8BAA8B,kBAAkB,EAC1D;AACD,aAAM,uBAAuB,eAAe,KAAK;AACjD,sCAA+B;;SAE7B;AAEJ,WAAM;AAEN,kBAAa,YAAY;AACxB,sBAAgB;AAChB,YAAM,SAAS,SAAS;OACvB;AACF,WAAM,OAAO,EAAE,MAAM,CAAC;AACtB,WAAM,SAAS,SAAS;MAEzB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Logger } from "../test-adapter.mjs";
|
|
2
|
+
import { TestSuiteStats } from "../create-test-suite.mjs";
|
|
3
|
+
import * as better_auth0 from "better-auth";
|
|
4
|
+
|
|
5
|
+
//#region src/adapter/suites/auth-flow.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* This test suite tests basic authentication flow using the adapter.
|
|
8
|
+
*/
|
|
9
|
+
declare const authFlowTestSuite: (options?: ({
|
|
10
|
+
disableTests?: Partial<Record<"should successfully sign up" | "should successfully sign in" | "should successfully get session" | "should not sign in with invalid email" | "should store and retrieve timestamps correctly across timezones" | "should sign up with additional fields", boolean> & {
|
|
11
|
+
ALL?: boolean;
|
|
12
|
+
}> | undefined;
|
|
13
|
+
} & {
|
|
14
|
+
showDB?: () => Promise<void>;
|
|
15
|
+
}) | undefined) => (helpers: {
|
|
16
|
+
adapter: () => Promise<better_auth0.DBAdapter<better_auth0.BetterAuthOptions>>;
|
|
17
|
+
log: Logger;
|
|
18
|
+
adapterDisplayName: string;
|
|
19
|
+
getBetterAuthOptions: () => better_auth0.BetterAuthOptions;
|
|
20
|
+
modifyBetterAuthOptions: (options: better_auth0.BetterAuthOptions) => Promise<better_auth0.BetterAuthOptions>;
|
|
21
|
+
cleanup: () => Promise<void>;
|
|
22
|
+
runMigrations: () => Promise<void>;
|
|
23
|
+
prefixTests?: string | undefined;
|
|
24
|
+
onTestFinish: (stats: TestSuiteStats) => Promise<void>;
|
|
25
|
+
customIdGenerator?: (() => any | Promise<any> | undefined) | undefined;
|
|
26
|
+
transformIdOutput?: ((id: any) => string | undefined) | undefined;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { authFlowTestSuite };
|
|
30
|
+
//# sourceMappingURL=auth-flow.d.mts.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createTestSuite } from "../create-test-suite.mjs";
|
|
2
|
+
import { expect } from "vitest";
|
|
3
|
+
import { setCookieToHeader } from "better-auth/cookies";
|
|
4
|
+
//#region src/adapter/suites/auth-flow.ts
|
|
5
|
+
/**
|
|
6
|
+
* This test suite tests basic authentication flow using the adapter.
|
|
7
|
+
*/
|
|
8
|
+
const authFlowTestSuite = createTestSuite("auth-flow", { defaultBetterAuthOptions: { emailAndPassword: {
|
|
9
|
+
enabled: true,
|
|
10
|
+
password: {
|
|
11
|
+
hash: async (password) => password,
|
|
12
|
+
async verify(data) {
|
|
13
|
+
return data.hash === data.password;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
} } }, ({ generate, getAuth, modifyBetterAuthOptions, tryCatch, getBetterAuthOptions }, debug) => ({
|
|
17
|
+
"should successfully sign up": async () => {
|
|
18
|
+
const auth = await getAuth();
|
|
19
|
+
const user = await generate("user");
|
|
20
|
+
const start = Date.now();
|
|
21
|
+
const result = await auth.api.signUpEmail({ body: {
|
|
22
|
+
email: user.email,
|
|
23
|
+
password: crypto.randomUUID(),
|
|
24
|
+
name: user.name,
|
|
25
|
+
image: user.image || ""
|
|
26
|
+
} });
|
|
27
|
+
const end = Date.now();
|
|
28
|
+
console.log(`signUpEmail took ${end - start}ms (without hashing)`);
|
|
29
|
+
expect(result.user).toBeDefined();
|
|
30
|
+
expect(result.user.email).toBe(user.email);
|
|
31
|
+
expect(result.user.name).toBe(user.name);
|
|
32
|
+
expect(result.user.image).toBe(user.image || "");
|
|
33
|
+
expect(result.user.emailVerified).toBe(false);
|
|
34
|
+
expect(result.user.createdAt).toBeDefined();
|
|
35
|
+
expect(result.user.updatedAt).toBeDefined();
|
|
36
|
+
},
|
|
37
|
+
"should successfully sign in": async () => {
|
|
38
|
+
const auth = await getAuth();
|
|
39
|
+
const user = await generate("user");
|
|
40
|
+
const password = crypto.randomUUID();
|
|
41
|
+
const signUpResult = await auth.api.signUpEmail({ body: {
|
|
42
|
+
email: user.email,
|
|
43
|
+
password,
|
|
44
|
+
name: user.name,
|
|
45
|
+
image: user.image || ""
|
|
46
|
+
} });
|
|
47
|
+
const start = Date.now();
|
|
48
|
+
const result = await auth.api.signInEmail({ body: {
|
|
49
|
+
email: user.email,
|
|
50
|
+
password
|
|
51
|
+
} });
|
|
52
|
+
const end = Date.now();
|
|
53
|
+
console.log(`signInEmail took ${end - start}ms (without hashing)`);
|
|
54
|
+
expect(result.user).toBeDefined();
|
|
55
|
+
expect(result.user.id).toBe(signUpResult.user.id);
|
|
56
|
+
},
|
|
57
|
+
"should successfully get session": async () => {
|
|
58
|
+
const auth = await getAuth();
|
|
59
|
+
const user = await generate("user");
|
|
60
|
+
const password = crypto.randomUUID();
|
|
61
|
+
const response = await auth.api.signUpEmail({
|
|
62
|
+
body: {
|
|
63
|
+
email: user.email,
|
|
64
|
+
password,
|
|
65
|
+
name: user.name,
|
|
66
|
+
image: user.image || ""
|
|
67
|
+
},
|
|
68
|
+
asResponse: true
|
|
69
|
+
});
|
|
70
|
+
const headers = new Headers();
|
|
71
|
+
setCookieToHeader(headers)({ response });
|
|
72
|
+
const start = Date.now();
|
|
73
|
+
const result = await auth.api.getSession({ headers });
|
|
74
|
+
const end = Date.now();
|
|
75
|
+
console.log(`getSession took ${end - start}ms`);
|
|
76
|
+
const signUpResult = await response.json();
|
|
77
|
+
signUpResult.user.createdAt = new Date(signUpResult.user.createdAt);
|
|
78
|
+
signUpResult.user.updatedAt = new Date(signUpResult.user.updatedAt);
|
|
79
|
+
expect(result?.user).toBeDefined();
|
|
80
|
+
expect(result?.user).toStrictEqual(signUpResult.user);
|
|
81
|
+
expect(result?.session).toBeDefined();
|
|
82
|
+
},
|
|
83
|
+
"should not sign in with invalid email": async () => {
|
|
84
|
+
const auth = await getAuth();
|
|
85
|
+
const user = await generate("user");
|
|
86
|
+
const { data, error } = await tryCatch(auth.api.signInEmail({ body: {
|
|
87
|
+
email: user.email,
|
|
88
|
+
password: crypto.randomUUID()
|
|
89
|
+
} }));
|
|
90
|
+
expect(data).toBeNull();
|
|
91
|
+
expect(error).toBeDefined();
|
|
92
|
+
},
|
|
93
|
+
"should store and retrieve timestamps correctly across timezones": async () => {
|
|
94
|
+
using _ = recoverProcessTZ();
|
|
95
|
+
const auth = await getAuth();
|
|
96
|
+
const user = await generate("user");
|
|
97
|
+
const password = crypto.randomUUID();
|
|
98
|
+
const userSignUp = await auth.api.signUpEmail({ body: {
|
|
99
|
+
email: user.email,
|
|
100
|
+
password,
|
|
101
|
+
name: user.name,
|
|
102
|
+
image: user.image || ""
|
|
103
|
+
} });
|
|
104
|
+
process.env.TZ = "Europe/London";
|
|
105
|
+
const userSignIn = await auth.api.signInEmail({ body: {
|
|
106
|
+
email: user.email,
|
|
107
|
+
password
|
|
108
|
+
} });
|
|
109
|
+
process.env.TZ = "America/Los_Angeles";
|
|
110
|
+
expect(userSignUp.user.createdAt.toISOString()).toStrictEqual(userSignIn.user.createdAt.toISOString());
|
|
111
|
+
},
|
|
112
|
+
"should sign up with additional fields": async () => {
|
|
113
|
+
await modifyBetterAuthOptions({ user: { additionalFields: { dateField: { type: "date" } } } }, true);
|
|
114
|
+
const auth = await getAuth();
|
|
115
|
+
const user = await generate("user");
|
|
116
|
+
const dateField = /* @__PURE__ */ new Date();
|
|
117
|
+
const response = await auth.api.signUpEmail({
|
|
118
|
+
body: {
|
|
119
|
+
email: user.email,
|
|
120
|
+
name: user.name,
|
|
121
|
+
password: crypto.randomUUID(),
|
|
122
|
+
dateField: dateField.toISOString()
|
|
123
|
+
},
|
|
124
|
+
asResponse: true
|
|
125
|
+
});
|
|
126
|
+
const headers = new Headers();
|
|
127
|
+
setCookieToHeader(headers)({ response });
|
|
128
|
+
expect((await auth.api.getSession({ headers }))?.user.dateField).toStrictEqual(dateField);
|
|
129
|
+
}
|
|
130
|
+
}));
|
|
131
|
+
function recoverProcessTZ() {
|
|
132
|
+
const originalTZ = process.env.TZ;
|
|
133
|
+
return { [Symbol.dispose]: () => {
|
|
134
|
+
process.env.TZ = originalTZ;
|
|
135
|
+
} };
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { authFlowTestSuite };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=auth-flow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-flow.mjs","names":[],"sources":["../../src/adapter/suites/auth-flow.ts"],"sourcesContent":["import type { Session, User } from \"@better-auth/core/db\";\nimport { setCookieToHeader } from \"better-auth/cookies\";\nimport { expect } from \"vitest\";\nimport { createTestSuite } from \"../create-test-suite\";\n\n/**\n * This test suite tests basic authentication flow using the adapter.\n */\nexport const authFlowTestSuite = createTestSuite(\n\t\"auth-flow\",\n\t{\n\t\tdefaultBetterAuthOptions: {\n\t\t\temailAndPassword: {\n\t\t\t\tenabled: true,\n\t\t\t\tpassword: {\n\t\t\t\t\thash: async (password) => password,\n\t\t\t\t\tasync verify(data) {\n\t\t\t\t\t\treturn data.hash === data.password;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n\t(\n\t\t{\n\t\t\tgenerate,\n\t\t\tgetAuth,\n\t\t\tmodifyBetterAuthOptions,\n\t\t\ttryCatch,\n\t\t\tgetBetterAuthOptions,\n\t\t},\n\t\tdebug?: { showDB?: () => Promise<void> } | undefined,\n\t) => ({\n\t\t\"should successfully sign up\": async () => {\n\t\t\tconst auth = await getAuth();\n\t\t\tconst user = await generate(\"user\");\n\t\t\tconst start = Date.now();\n\t\t\tconst result = await auth.api.signUpEmail({\n\t\t\t\tbody: {\n\t\t\t\t\temail: user.email,\n\t\t\t\t\tpassword: crypto.randomUUID(),\n\t\t\t\t\tname: user.name,\n\t\t\t\t\timage: user.image || \"\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst end = Date.now();\n\t\t\tconsole.log(`signUpEmail took ${end - start}ms (without hashing)`);\n\t\t\texpect(result.user).toBeDefined();\n\t\t\texpect(result.user.email).toBe(user.email);\n\t\t\texpect(result.user.name).toBe(user.name);\n\t\t\texpect(result.user.image).toBe(user.image || \"\");\n\t\t\texpect(result.user.emailVerified).toBe(false);\n\t\t\texpect(result.user.createdAt).toBeDefined();\n\t\t\texpect(result.user.updatedAt).toBeDefined();\n\t\t},\n\t\t\"should successfully sign in\": async () => {\n\t\t\tconst auth = await getAuth();\n\t\t\tconst user = await generate(\"user\");\n\t\t\tconst password = crypto.randomUUID();\n\t\t\tconst signUpResult = await auth.api.signUpEmail({\n\t\t\t\tbody: {\n\t\t\t\t\temail: user.email,\n\t\t\t\t\tpassword: password,\n\t\t\t\t\tname: user.name,\n\t\t\t\t\timage: user.image || \"\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst start = Date.now();\n\t\t\tconst result = await auth.api.signInEmail({\n\t\t\t\tbody: { email: user.email, password: password },\n\t\t\t});\n\t\t\tconst end = Date.now();\n\t\t\tconsole.log(`signInEmail took ${end - start}ms (without hashing)`);\n\t\t\texpect(result.user).toBeDefined();\n\t\t\texpect(result.user.id).toBe(signUpResult.user.id);\n\t\t},\n\t\t\"should successfully get session\": async () => {\n\t\t\tconst auth = await getAuth();\n\t\t\tconst user = await generate(\"user\");\n\t\t\tconst password = crypto.randomUUID();\n\t\t\tconst response = await auth.api.signUpEmail({\n\t\t\t\tbody: {\n\t\t\t\t\temail: user.email,\n\t\t\t\t\tpassword: password,\n\t\t\t\t\tname: user.name,\n\t\t\t\t\timage: user.image || \"\",\n\t\t\t\t},\n\t\t\t\tasResponse: true,\n\t\t\t});\n\t\t\tconst headers = new Headers();\n\t\t\tsetCookieToHeader(headers)({ response });\n\t\t\tconst start = Date.now();\n\t\t\tconst result = await auth.api.getSession({\n\t\t\t\theaders,\n\t\t\t});\n\t\t\tconst end = Date.now();\n\t\t\tconsole.log(`getSession took ${end - start}ms`);\n\t\t\tconst signUpResult = (await response.json()) as {\n\t\t\t\tuser: User;\n\t\t\t\tsession: Session;\n\t\t\t};\n\t\t\tsignUpResult.user.createdAt = new Date(signUpResult.user.createdAt);\n\t\t\tsignUpResult.user.updatedAt = new Date(signUpResult.user.updatedAt);\n\t\t\texpect(result?.user).toBeDefined();\n\t\t\texpect(result?.user).toStrictEqual(signUpResult.user);\n\t\t\texpect(result?.session).toBeDefined();\n\t\t},\n\t\t\"should not sign in with invalid email\": async () => {\n\t\t\tconst auth = await getAuth();\n\t\t\tconst user = await generate(\"user\");\n\t\t\tconst { data, error } = await tryCatch(\n\t\t\t\tauth.api.signInEmail({\n\t\t\t\t\tbody: { email: user.email, password: crypto.randomUUID() },\n\t\t\t\t}),\n\t\t\t);\n\t\t\texpect(data).toBeNull();\n\t\t\texpect(error).toBeDefined();\n\t\t},\n\t\t\"should store and retrieve timestamps correctly across timezones\":\n\t\t\tasync () => {\n\t\t\t\tusing _ = recoverProcessTZ();\n\t\t\t\tconst auth = await getAuth();\n\t\t\t\tconst user = await generate(\"user\");\n\t\t\t\tconst password = crypto.randomUUID();\n\t\t\t\tconst userSignUp = await auth.api.signUpEmail({\n\t\t\t\t\tbody: {\n\t\t\t\t\t\temail: user.email,\n\t\t\t\t\t\tpassword: password,\n\t\t\t\t\t\tname: user.name,\n\t\t\t\t\t\timage: user.image || \"\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tprocess.env.TZ = \"Europe/London\";\n\t\t\t\tconst userSignIn = await auth.api.signInEmail({\n\t\t\t\t\tbody: { email: user.email, password: password },\n\t\t\t\t});\n\t\t\t\tprocess.env.TZ = \"America/Los_Angeles\";\n\t\t\t\texpect(userSignUp.user.createdAt.toISOString()).toStrictEqual(\n\t\t\t\t\tuserSignIn.user.createdAt.toISOString(),\n\t\t\t\t);\n\t\t\t},\n\t\t\"should sign up with additional fields\": async () => {\n\t\t\tawait modifyBetterAuthOptions(\n\t\t\t\t{ user: { additionalFields: { dateField: { type: \"date\" } } } },\n\t\t\t\ttrue,\n\t\t\t);\n\t\t\tconst auth = await getAuth();\n\t\t\tconst user = await generate(\"user\");\n\t\t\tconst dateField = new Date();\n\t\t\tconst response = await auth.api.signUpEmail({\n\t\t\t\tbody: {\n\t\t\t\t\temail: user.email,\n\t\t\t\t\tname: user.name,\n\t\t\t\t\tpassword: crypto.randomUUID(),\n\t\t\t\t\t//@ts-expect-error - we are testing with additional fields\n\t\t\t\t\tdateField: dateField.toISOString(), // using iso string to simulate client to server communication (this should be converted back to Date)\n\t\t\t\t},\n\t\t\t\tasResponse: true,\n\t\t\t});\n\t\t\tconst headers = new Headers();\n\t\t\tsetCookieToHeader(headers)({ response });\n\t\t\tconst result = await auth.api.getSession({\n\t\t\t\theaders,\n\t\t\t});\n\t\t\t//@ts-expect-error - we are testing with additional fields\n\t\t\texpect(result?.user.dateField).toStrictEqual(dateField);\n\t\t},\n\t}),\n);\n\nfunction recoverProcessTZ() {\n\tconst originalTZ = process.env.TZ;\n\treturn {\n\t\t[Symbol.dispose]: () => {\n\t\t\tprocess.env.TZ = originalTZ;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAQA,MAAa,oBAAoB,gBAChC,aACA,EACC,0BAA0B,EACzB,kBAAkB;CACjB,SAAS;CACT,UAAU;EACT,MAAM,OAAO,aAAa;EAC1B,MAAM,OAAO,MAAM;AAClB,UAAO,KAAK,SAAS,KAAK;;EAE3B;CACD,EACD,EACD,GAEA,EACC,UACA,SACA,yBACA,UACA,wBAED,WACK;CACL,+BAA+B,YAAY;EAC1C,MAAM,OAAO,MAAM,SAAS;EAC5B,MAAM,OAAO,MAAM,SAAS,OAAO;EACnC,MAAM,QAAQ,KAAK,KAAK;EACxB,MAAM,SAAS,MAAM,KAAK,IAAI,YAAY,EACzC,MAAM;GACL,OAAO,KAAK;GACZ,UAAU,OAAO,YAAY;GAC7B,MAAM,KAAK;GACX,OAAO,KAAK,SAAS;GACrB,EACD,CAAC;EACF,MAAM,MAAM,KAAK,KAAK;AACtB,UAAQ,IAAI,oBAAoB,MAAM,MAAM,sBAAsB;AAClE,SAAO,OAAO,KAAK,CAAC,aAAa;AACjC,SAAO,OAAO,KAAK,MAAM,CAAC,KAAK,KAAK,MAAM;AAC1C,SAAO,OAAO,KAAK,KAAK,CAAC,KAAK,KAAK,KAAK;AACxC,SAAO,OAAO,KAAK,MAAM,CAAC,KAAK,KAAK,SAAS,GAAG;AAChD,SAAO,OAAO,KAAK,cAAc,CAAC,KAAK,MAAM;AAC7C,SAAO,OAAO,KAAK,UAAU,CAAC,aAAa;AAC3C,SAAO,OAAO,KAAK,UAAU,CAAC,aAAa;;CAE5C,+BAA+B,YAAY;EAC1C,MAAM,OAAO,MAAM,SAAS;EAC5B,MAAM,OAAO,MAAM,SAAS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