@better-auth/test-utils 1.5.4 → 1.5.6

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.
@@ -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
- export { type InsertRandomFn, type Logger, type TestEntry, type TestSuiteStats, createTestSuite, testAdapter };
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,11 @@
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
10
 
4
- export { createTestSuite, testAdapter };
11
+ export { authFlowTestSuite, createTestSuite, enableJoinTests, getNormalTestSuiteTests, joinsTestSuite, normalTestSuite, numberIdTestSuite, testAdapter, transactionsTestSuite, uuidTestSuite };
@@ -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,141 @@
1
+ import { createTestSuite } from "../create-test-suite.mjs";
2
+ import { expect } from "vitest";
3
+ import { setCookieToHeader } from "better-auth/cookies";
4
+
5
+ //#region src/adapter/suites/auth-flow.ts
6
+ /**
7
+ * This test suite tests basic authentication flow using the adapter.
8
+ */
9
+ const authFlowTestSuite = createTestSuite("auth-flow", { defaultBetterAuthOptions: { emailAndPassword: {
10
+ enabled: true,
11
+ password: {
12
+ hash: async (password) => password,
13
+ async verify(data) {
14
+ return data.hash === data.password;
15
+ }
16
+ }
17
+ } } }, ({ generate, getAuth, modifyBetterAuthOptions, tryCatch, getBetterAuthOptions }, debug) => ({
18
+ "should successfully sign up": async () => {
19
+ const auth = await getAuth();
20
+ const user = await generate("user");
21
+ const start = Date.now();
22
+ const result = await auth.api.signUpEmail({ body: {
23
+ email: user.email,
24
+ password: crypto.randomUUID(),
25
+ name: user.name,
26
+ image: user.image || ""
27
+ } });
28
+ const end = Date.now();
29
+ console.log(`signUpEmail took ${end - start}ms (without hashing)`);
30
+ expect(result.user).toBeDefined();
31
+ expect(result.user.email).toBe(user.email);
32
+ expect(result.user.name).toBe(user.name);
33
+ expect(result.user.image).toBe(user.image || "");
34
+ expect(result.user.emailVerified).toBe(false);
35
+ expect(result.user.createdAt).toBeDefined();
36
+ expect(result.user.updatedAt).toBeDefined();
37
+ },
38
+ "should successfully sign in": async () => {
39
+ const auth = await getAuth();
40
+ const user = await generate("user");
41
+ const password = crypto.randomUUID();
42
+ const signUpResult = await auth.api.signUpEmail({ body: {
43
+ email: user.email,
44
+ password,
45
+ name: user.name,
46
+ image: user.image || ""
47
+ } });
48
+ const start = Date.now();
49
+ const result = await auth.api.signInEmail({ body: {
50
+ email: user.email,
51
+ password
52
+ } });
53
+ const end = Date.now();
54
+ console.log(`signInEmail took ${end - start}ms (without hashing)`);
55
+ expect(result.user).toBeDefined();
56
+ expect(result.user.id).toBe(signUpResult.user.id);
57
+ },
58
+ "should successfully get session": async () => {
59
+ const auth = await getAuth();
60
+ const user = await generate("user");
61
+ const password = crypto.randomUUID();
62
+ const response = await auth.api.signUpEmail({
63
+ body: {
64
+ email: user.email,
65
+ password,
66
+ name: user.name,
67
+ image: user.image || ""
68
+ },
69
+ asResponse: true
70
+ });
71
+ const headers = new Headers();
72
+ setCookieToHeader(headers)({ response });
73
+ const start = Date.now();
74
+ const result = await auth.api.getSession({ headers });
75
+ const end = Date.now();
76
+ console.log(`getSession took ${end - start}ms`);
77
+ const signUpResult = await response.json();
78
+ signUpResult.user.createdAt = new Date(signUpResult.user.createdAt);
79
+ signUpResult.user.updatedAt = new Date(signUpResult.user.updatedAt);
80
+ expect(result?.user).toBeDefined();
81
+ expect(result?.user).toStrictEqual(signUpResult.user);
82
+ expect(result?.session).toBeDefined();
83
+ },
84
+ "should not sign in with invalid email": async () => {
85
+ const auth = await getAuth();
86
+ const user = await generate("user");
87
+ const { data, error } = await tryCatch(auth.api.signInEmail({ body: {
88
+ email: user.email,
89
+ password: crypto.randomUUID()
90
+ } }));
91
+ expect(data).toBeNull();
92
+ expect(error).toBeDefined();
93
+ },
94
+ "should store and retrieve timestamps correctly across timezones": async () => {
95
+ using _ = recoverProcessTZ();
96
+ const auth = await getAuth();
97
+ const user = await generate("user");
98
+ const password = crypto.randomUUID();
99
+ const userSignUp = await auth.api.signUpEmail({ body: {
100
+ email: user.email,
101
+ password,
102
+ name: user.name,
103
+ image: user.image || ""
104
+ } });
105
+ process.env.TZ = "Europe/London";
106
+ const userSignIn = await auth.api.signInEmail({ body: {
107
+ email: user.email,
108
+ password
109
+ } });
110
+ process.env.TZ = "America/Los_Angeles";
111
+ expect(userSignUp.user.createdAt.toISOString()).toStrictEqual(userSignIn.user.createdAt.toISOString());
112
+ },
113
+ "should sign up with additional fields": async () => {
114
+ await modifyBetterAuthOptions({ user: { additionalFields: { dateField: { type: "date" } } } }, true);
115
+ const auth = await getAuth();
116
+ const user = await generate("user");
117
+ const dateField = /* @__PURE__ */ new Date();
118
+ const response = await auth.api.signUpEmail({
119
+ body: {
120
+ email: user.email,
121
+ name: user.name,
122
+ password: crypto.randomUUID(),
123
+ dateField: dateField.toISOString()
124
+ },
125
+ asResponse: true
126
+ });
127
+ const headers = new Headers();
128
+ setCookieToHeader(headers)({ response });
129
+ expect((await auth.api.getSession({ headers }))?.user.dateField).toStrictEqual(dateField);
130
+ }
131
+ }));
132
+ function recoverProcessTZ() {
133
+ const originalTZ = process.env.TZ;
134
+ return { [Symbol.dispose]: () => {
135
+ process.env.TZ = originalTZ;
136
+ } };
137
+ }
138
+
139
+ //#endregion
140
+ export { authFlowTestSuite };
141
+ //# 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,KA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AS;EAC5B,MAAM,OAAO,MAAM,SAAS,OAAO;EACnC,MAAM,4BAAY,IAAI,MAAM;EAC5B,MAAM,WAAW,MAAM,KAAK,IAAI,YAAY;GAC3C,MAAM;IACL,OAAO,KAAK;IACZ,MAAM,KAAK;IACX,UAAU,OAAO,YAAY;IAE7B,WAAW,UAAU,aAAa;IAClC;GACD,YAAY;GACZ,CAAC;EACF,MAAM,UAAU,IAAI,SAAS;AAC7B,oBAAkB,QAAQ,CAAC,EAAE,UAAU,CAAC;AAKxC,UAJe,MAAM,KAAK,IAAI,WAAW,EACxC,SACA,CAAC,GAEa,KAAK,UAAU,CAAC,cAAc,UAAU;;CAExD,EACD;AAED,SAAS,mBAAmB;CAC3B,MAAM,aAAa,QAAQ,IAAI;AAC/B,QAAO,GACL,OAAO,gBAAgB;AACvB,UAAQ,IAAI,KAAK;IAElB"}
@@ -0,0 +1,206 @@
1
+ import { Logger } from "../test-adapter.mjs";
2
+ import { TestSuiteStats, createTestSuite } from "../create-test-suite.mjs";
3
+ import * as better_auth0 from "better-auth";
4
+
5
+ //#region src/adapter/suites/basic.d.ts
6
+ /**
7
+ * This test suite tests the basic CRUD operations of the adapter.
8
+ */
9
+ declare const normalTestSuite: (options?: ({
10
+ disableTests?: Partial<Record<"init - tests" | "create - should create a model" | "create - should always return an id" | "create - should use generateId if provided" | "create - should return null for nullable foreign keys" | "create - should apply default values to fields" | "findOne - should find a model" | "findOne - should not apply defaultValue if value not found" | "findOne - should find a model using a reference field" | "findOne - should not throw on record not found" | "findOne - should find a model without id" | "findOne - should find a model with join" | "findOne - should find a model with modified field name" | "findOne - should find a model with modified model name" | "findOne - should find a model with additional fields" | "findOne - should select fields" | "findOne - should select fields with one-to-many join" | "findOne - should select fields with one-to-one join" | "findOne - should select fields with multiple joins" | "findOne - should find model with date field" | "findOne - should perform backwards joins" | "findOne - should return an object for one-to-one joins" | "findOne - should return an array for one-to-many joins" | "findOne - should work with both one-to-one and one-to-many joins" | "findOne - should return null for failed base model lookup that has joins" | "findOne - should join a model with modified field name" | "findMany - should find many models" | "findMany - should find many models with date fields" | "findMany - should find many models with join" | "findMany - should find many with join and limit" | "findMany - should select fields" | "findMany - should select fields with one-to-many join" | "findMany - should select fields with one-to-one join" | "findMany - should select fields with multiple joins" | "findMany - should find many with join and offset" | "findMany - should find many with join and sortBy" | "findMany - should find many with join and where clause" | "findMany - should find many with join, where, limit, and offset" | "findMany - should find many with one-to-one join" | "findMany - should find many with both one-to-one and one-to-many joins" | "findMany - should return an empty array when no models are found" | "findMany - should return empty array when base records don't exist with joins" | "findMany - should find many models with starts_with operator" | "findMany - starts_with should not interpret regex patterns" | "findMany - ends_with should not interpret regex patterns" | "findMany - contains should not interpret regex patterns" | "findMany - should find many models with ends_with operator" | "findMany - should find many models with contains operator" | "findMany - should handle multiple where conditions with different operators" | "findMany - should find many models with contains operator (using symbol)" | "findMany - should find many models with eq operator" | "findMany - should find many models with ne operator" | "findMany - should find many models with gt operator" | "findMany - should find many models with gte operator" | "findMany - should find many models with lte operator" | "findMany - should find many models with lt operator" | "findMany - should find many models with in operator" | "findMany - should find many models with not_in operator" | "findMany - should find many models with sortBy" | "findMany - should find many models with limit" | "findMany - should find many models with offset" | "findMany - should find many models with limit and offset" | "findMany - should find many models with sortBy and offset" | "findMany - should find many models with sortBy and limit" | "findMany - should find many models with sortBy and limit and offset" | "findMany - should find many models with sortBy and limit and offset and where" | "update - should update a model" | "updateMany - should update all models when where is empty" | "updateMany - should update many models with a specific where" | "updateMany - should update many models with a multiple where" | "delete - should delete a model" | "delete - should not throw on record not found" | "delete - should delete by non-unique field" | "deleteMany - should delete many models" | "deleteMany - starts_with should not interpret regex patterns" | "deleteMany - ends_with should not interpret regex patterns" | "deleteMany - contains should not interpret regex patterns" | "deleteMany - should delete many models with numeric values" | "deleteMany - should delete many models with boolean values" | "count - should count many models" | "count - should return 0 with no rows to count" | "count - should count with where clause" | "update - should correctly return record when updating a field used in where clause" | "update - should handle updating multiple fields including where clause field" | "update - should work when updated field is not in where clause" | "findOne - backwards join should only return single record not array" | "findMany - backwards join should only return single record not array" | "findOne - backwards join with modified field name (session base, users-table join)" | "findOne - multiple joins should return result even when some joined tables have no matching rows" | "findOne - should be able to perform a limited join" | "findOne - should be able to perform a complex limited join" | "findMany - should be able to perform a limited join" | "findMany - should be able to perform a complex limited join" | "findOne - should return null for one-to-one join when joined record doesn't exist" | "findMany - should return null for one-to-one join when joined records don't exist" | "findMany - should return empty array for one-to-many join when joined records don't exist" | "findMany - should handle mixed joins correctly when some are missing" | "create - should support arrays" | "create - should support json" | "update - should support multiple where conditions under AND connector with unique field", 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
+ declare const getNormalTestSuiteTests: ({
29
+ adapter,
30
+ generate,
31
+ insertRandom,
32
+ modifyBetterAuthOptions,
33
+ sortModels,
34
+ customIdGenerator,
35
+ getBetterAuthOptions,
36
+ transformGeneratedModel,
37
+ transformIdOutput
38
+ }: Parameters<Parameters<typeof createTestSuite>[2]>[0], debugTools?: {
39
+ showDB?: () => Promise<void>;
40
+ }) => {
41
+ "create - should create a model": () => Promise<void>;
42
+ "create - should always return an id": () => Promise<void>;
43
+ "create - should use generateId if provided": () => Promise<void>;
44
+ "create - should return null for nullable foreign keys": {
45
+ migrateBetterAuth: {
46
+ plugins: {
47
+ id: "nullable-test";
48
+ schema: {
49
+ testModel: {
50
+ fields: {
51
+ nullableReference: {
52
+ type: "string";
53
+ references: {
54
+ field: string;
55
+ model: string;
56
+ };
57
+ required: false;
58
+ };
59
+ };
60
+ };
61
+ };
62
+ }[];
63
+ };
64
+ test: () => Promise<void>;
65
+ };
66
+ "create - should apply default values to fields": () => Promise<void>;
67
+ "findOne - should find a model": () => Promise<void>;
68
+ "findOne - should not apply defaultValue if value not found": () => Promise<void>;
69
+ "findOne - should find a model using a reference field": () => Promise<void>;
70
+ "findOne - should not throw on record not found": () => Promise<void>;
71
+ "findOne - should find a model without id": () => Promise<void>;
72
+ "findOne - should find a model with join": () => Promise<void>;
73
+ "findOne - should find a model with modified field name": () => Promise<void>;
74
+ "findOne - should find a model with modified model name": () => Promise<void>;
75
+ "findOne - should find a model with additional fields": () => Promise<void>;
76
+ "findOne - should select fields": () => Promise<void>;
77
+ "findOne - should select fields with one-to-many join": () => Promise<void>;
78
+ "findOne - should select fields with one-to-one join": () => Promise<void>;
79
+ "findOne - should select fields with multiple joins": () => Promise<void>;
80
+ "findOne - should find model with date field": () => Promise<void>;
81
+ "findOne - should perform backwards joins": () => Promise<void>;
82
+ "findOne - should return an object for one-to-one joins": () => Promise<void>;
83
+ "findOne - should return an array for one-to-many joins": () => Promise<void>;
84
+ "findOne - should work with both one-to-one and one-to-many joins": () => Promise<void>;
85
+ "findOne - should return null for failed base model lookup that has joins": () => Promise<void>;
86
+ "findOne - should join a model with modified field name": () => Promise<void>;
87
+ "findMany - should find many models": () => Promise<void>;
88
+ "findMany - should find many models with date fields": () => Promise<void>;
89
+ "findMany - should find many models with join": () => Promise<void>;
90
+ "findMany - should find many with join and limit": () => Promise<void>;
91
+ "findMany - should select fields": () => Promise<void>;
92
+ "findMany - should select fields with one-to-many join": () => Promise<void>;
93
+ "findMany - should select fields with one-to-one join": () => Promise<void>;
94
+ "findMany - should select fields with multiple joins": () => Promise<void>;
95
+ "findMany - should find many with join and offset": () => Promise<void>;
96
+ "findMany - should find many with join and sortBy": () => Promise<void>;
97
+ "findMany - should find many with join and where clause": () => Promise<void>;
98
+ "findMany - should find many with join, where, limit, and offset": () => Promise<void>;
99
+ "findMany - should find many with one-to-one join": () => Promise<void>;
100
+ "findMany - should find many with both one-to-one and one-to-many joins": () => Promise<void>;
101
+ "findMany - should return an empty array when no models are found": () => Promise<void>;
102
+ "findMany - should return empty array when base records don't exist with joins": () => Promise<void>;
103
+ "findMany - should find many models with starts_with operator": () => Promise<void>;
104
+ "findMany - starts_with should not interpret regex patterns": () => Promise<void>;
105
+ "findMany - ends_with should not interpret regex patterns": () => Promise<void>;
106
+ "findMany - contains should not interpret regex patterns": () => Promise<void>;
107
+ "findMany - should find many models with ends_with operator": () => Promise<void>;
108
+ "findMany - should find many models with contains operator": () => Promise<void>;
109
+ "findMany - should handle multiple where conditions with different operators": () => Promise<void>;
110
+ "findMany - should find many models with contains operator (using symbol)": () => Promise<void>;
111
+ "findMany - should find many models with eq operator": () => Promise<void>;
112
+ "findMany - should find many models with ne operator": () => Promise<void>;
113
+ "findMany - should find many models with gt operator": () => Promise<void>;
114
+ "findMany - should find many models with gte operator": () => Promise<void>;
115
+ "findMany - should find many models with lte operator": () => Promise<void>;
116
+ "findMany - should find many models with lt operator": () => Promise<void>;
117
+ "findMany - should find many models with in operator": () => Promise<void>;
118
+ "findMany - should find many models with not_in operator": () => Promise<void>;
119
+ "findMany - should find many models with sortBy": () => Promise<void>;
120
+ "findMany - should find many models with limit": () => Promise<void>;
121
+ "findMany - should find many models with offset": () => Promise<void>;
122
+ "findMany - should find many models with limit and offset": () => Promise<void>;
123
+ "findMany - should find many models with sortBy and offset": () => Promise<void>;
124
+ "findMany - should find many models with sortBy and limit": () => Promise<void>;
125
+ "findMany - should find many models with sortBy and limit and offset": () => Promise<void>;
126
+ "findMany - should find many models with sortBy and limit and offset and where": () => Promise<void>;
127
+ "update - should update a model": () => Promise<void>;
128
+ "updateMany - should update all models when where is empty": () => Promise<void>;
129
+ "updateMany - should update many models with a specific where": () => Promise<void>;
130
+ "updateMany - should update many models with a multiple where": () => Promise<void>;
131
+ "delete - should delete a model": () => Promise<void>;
132
+ "delete - should not throw on record not found": () => Promise<void>;
133
+ /**
134
+ * @see https://github.com/better-auth/better-auth/issues/8313
135
+ */
136
+ "delete - should delete by non-unique field": () => Promise<void>;
137
+ "deleteMany - should delete many models": () => Promise<void>;
138
+ "deleteMany - starts_with should not interpret regex patterns": () => Promise<void>;
139
+ "deleteMany - ends_with should not interpret regex patterns": () => Promise<void>;
140
+ "deleteMany - contains should not interpret regex patterns": () => Promise<void>;
141
+ "deleteMany - should delete many models with numeric values": () => Promise<void>;
142
+ "deleteMany - should delete many models with boolean values": () => Promise<void>;
143
+ "count - should count many models": () => Promise<void>;
144
+ "count - should return 0 with no rows to count": () => Promise<void>;
145
+ "count - should count with where clause": () => Promise<void>;
146
+ "update - should correctly return record when updating a field used in where clause": () => Promise<void>;
147
+ "update - should handle updating multiple fields including where clause field": () => Promise<void>;
148
+ "update - should work when updated field is not in where clause": () => Promise<void>;
149
+ "findOne - backwards join should only return single record not array": () => Promise<void>;
150
+ "findMany - backwards join should only return single record not array": () => Promise<void>;
151
+ "findOne - backwards join with modified field name (session base, users-table join)": () => Promise<void>;
152
+ "findOne - multiple joins should return result even when some joined tables have no matching rows": () => Promise<void>;
153
+ "findOne - should be able to perform a limited join": () => Promise<void>;
154
+ "findOne - should be able to perform a complex limited join": () => Promise<void>;
155
+ "findMany - should be able to perform a limited join": () => Promise<void>;
156
+ "findMany - should be able to perform a complex limited join": () => Promise<void>;
157
+ "findOne - should return null for one-to-one join when joined record doesn't exist": () => Promise<void>;
158
+ "findMany - should return null for one-to-one join when joined records don't exist": () => Promise<void>;
159
+ "findMany - should return empty array for one-to-many join when joined records don't exist": () => Promise<void>;
160
+ "findMany - should handle mixed joins correctly when some are missing": () => Promise<void>;
161
+ "create - should support arrays": {
162
+ migrateBetterAuth: {
163
+ plugins: {
164
+ id: "string-arrays-test";
165
+ schema: {
166
+ testModel: {
167
+ fields: {
168
+ stringArray: {
169
+ type: "string[]";
170
+ required: true;
171
+ };
172
+ numberArray: {
173
+ type: "number[]";
174
+ required: true;
175
+ };
176
+ };
177
+ };
178
+ };
179
+ }[];
180
+ };
181
+ test: () => Promise<void>;
182
+ };
183
+ "create - should support json": {
184
+ migrateBetterAuth: {
185
+ plugins: {
186
+ id: "json-test";
187
+ schema: {
188
+ testModel: {
189
+ fields: {
190
+ json: {
191
+ type: "json";
192
+ required: true;
193
+ };
194
+ };
195
+ };
196
+ };
197
+ }[];
198
+ };
199
+ test: () => Promise<void>;
200
+ };
201
+ "update - should support multiple where conditions under AND connector with unique field": () => Promise<void>;
202
+ };
203
+ declare const enableJoinTests: Partial<Record<"create - should create a model" | "create - should always return an id" | "create - should use generateId if provided" | "create - should return null for nullable foreign keys" | "create - should apply default values to fields" | "findOne - should find a model" | "findOne - should not apply defaultValue if value not found" | "findOne - should find a model using a reference field" | "findOne - should not throw on record not found" | "findOne - should find a model without id" | "findOne - should find a model with join" | "findOne - should find a model with modified field name" | "findOne - should find a model with modified model name" | "findOne - should find a model with additional fields" | "findOne - should select fields" | "findOne - should select fields with one-to-many join" | "findOne - should select fields with one-to-one join" | "findOne - should select fields with multiple joins" | "findOne - should find model with date field" | "findOne - should perform backwards joins" | "findOne - should return an object for one-to-one joins" | "findOne - should return an array for one-to-many joins" | "findOne - should work with both one-to-one and one-to-many joins" | "findOne - should return null for failed base model lookup that has joins" | "findOne - should join a model with modified field name" | "findMany - should find many models" | "findMany - should find many models with date fields" | "findMany - should find many models with join" | "findMany - should find many with join and limit" | "findMany - should select fields" | "findMany - should select fields with one-to-many join" | "findMany - should select fields with one-to-one join" | "findMany - should select fields with multiple joins" | "findMany - should find many with join and offset" | "findMany - should find many with join and sortBy" | "findMany - should find many with join and where clause" | "findMany - should find many with join, where, limit, and offset" | "findMany - should find many with one-to-one join" | "findMany - should find many with both one-to-one and one-to-many joins" | "findMany - should return an empty array when no models are found" | "findMany - should return empty array when base records don't exist with joins" | "findMany - should find many models with starts_with operator" | "findMany - starts_with should not interpret regex patterns" | "findMany - ends_with should not interpret regex patterns" | "findMany - contains should not interpret regex patterns" | "findMany - should find many models with ends_with operator" | "findMany - should find many models with contains operator" | "findMany - should handle multiple where conditions with different operators" | "findMany - should find many models with contains operator (using symbol)" | "findMany - should find many models with eq operator" | "findMany - should find many models with ne operator" | "findMany - should find many models with gt operator" | "findMany - should find many models with gte operator" | "findMany - should find many models with lte operator" | "findMany - should find many models with lt operator" | "findMany - should find many models with in operator" | "findMany - should find many models with not_in operator" | "findMany - should find many models with sortBy" | "findMany - should find many models with limit" | "findMany - should find many models with offset" | "findMany - should find many models with limit and offset" | "findMany - should find many models with sortBy and offset" | "findMany - should find many models with sortBy and limit" | "findMany - should find many models with sortBy and limit and offset" | "findMany - should find many models with sortBy and limit and offset and where" | "update - should update a model" | "updateMany - should update all models when where is empty" | "updateMany - should update many models with a specific where" | "updateMany - should update many models with a multiple where" | "delete - should delete a model" | "delete - should not throw on record not found" | "delete - should delete by non-unique field" | "deleteMany - should delete many models" | "deleteMany - starts_with should not interpret regex patterns" | "deleteMany - ends_with should not interpret regex patterns" | "deleteMany - contains should not interpret regex patterns" | "deleteMany - should delete many models with numeric values" | "deleteMany - should delete many models with boolean values" | "count - should count many models" | "count - should return 0 with no rows to count" | "count - should count with where clause" | "update - should correctly return record when updating a field used in where clause" | "update - should handle updating multiple fields including where clause field" | "update - should work when updated field is not in where clause" | "findOne - backwards join should only return single record not array" | "findMany - backwards join should only return single record not array" | "findOne - backwards join with modified field name (session base, users-table join)" | "findOne - multiple joins should return result even when some joined tables have no matching rows" | "findOne - should be able to perform a limited join" | "findOne - should be able to perform a complex limited join" | "findMany - should be able to perform a limited join" | "findMany - should be able to perform a complex limited join" | "findOne - should return null for one-to-one join when joined record doesn't exist" | "findMany - should return null for one-to-one join when joined records don't exist" | "findMany - should return empty array for one-to-many join when joined records don't exist" | "findMany - should handle mixed joins correctly when some are missing" | "create - should support arrays" | "create - should support json" | "update - should support multiple where conditions under AND connector with unique field", boolean>>;
204
+ //#endregion
205
+ export { enableJoinTests, getNormalTestSuiteTests, normalTestSuite };
206
+ //# sourceMappingURL=basic.d.mts.map