@better-auth/test-utils 1.5.5 → 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.
@@ -0,0 +1,31 @@
1
+ import { createTestSuite } from "../create-test-suite.mjs";
2
+ import { expect } from "vitest";
3
+
4
+ //#region src/adapter/suites/transactions.ts
5
+ /**
6
+ * This test suite tests the transaction functionality of the adapter.
7
+ */
8
+ const transactionsTestSuite = createTestSuite("transactions", {}, ({ adapter, generate, hardCleanup }) => ({ "transaction - should rollback failing transaction": async ({ skip }) => {
9
+ if (!adapter.options?.adapterConfig.transaction) {
10
+ skip(`Skipping test: ${adapter.options?.adapterConfig.adapterName} does not support transactions`);
11
+ return;
12
+ }
13
+ const user1 = await generate("user");
14
+ await generate("user");
15
+ await expect(adapter.transaction(async (tx) => {
16
+ await tx.create({
17
+ model: "user",
18
+ data: user1,
19
+ forceAllowId: true
20
+ });
21
+ expect(await tx.findMany({ model: "user" })).toHaveLength(1);
22
+ throw new Error("Simulated failure");
23
+ })).rejects.toThrow("Simulated failure");
24
+ const result = await adapter.findMany({ model: "user" });
25
+ await hardCleanup();
26
+ expect(result.length).toBe(0);
27
+ } }));
28
+
29
+ //#endregion
30
+ export { transactionsTestSuite };
31
+ //# sourceMappingURL=transactions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactions.mjs","names":[],"sources":["../../src/adapter/suites/transactions.ts"],"sourcesContent":["import type { User } from \"better-auth/db\";\nimport { expect } from \"vitest\";\nimport { createTestSuite } from \"../create-test-suite\";\n\n/**\n * This test suite tests the transaction functionality of the adapter.\n */\nexport const transactionsTestSuite = createTestSuite(\n\t\"transactions\",\n\t{},\n\t({ adapter, generate, hardCleanup }) => ({\n\t\t\"transaction - should rollback failing transaction\": async ({ skip }) => {\n\t\t\tconst isEnabled = adapter.options?.adapterConfig.transaction;\n\t\t\tif (!isEnabled) {\n\t\t\t\tskip(\n\t\t\t\t\t`Skipping test: ${adapter.options?.adapterConfig.adapterName} does not support transactions`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst user1 = await generate(\"user\");\n\t\t\tconst user2 = await generate(\"user\");\n\t\t\tawait expect(\n\t\t\t\tadapter.transaction(async (tx) => {\n\t\t\t\t\tawait tx.create({ model: \"user\", data: user1, forceAllowId: true });\n\t\t\t\t\tconst users = await tx.findMany({ model: \"user\" });\n\t\t\t\t\texpect(users).toHaveLength(1);\n\t\t\t\t\tthrow new Error(\"Simulated failure\");\n\t\t\t\t\tawait tx.create({ model: \"user\", data: user2, forceAllowId: true });\n\t\t\t\t}),\n\t\t\t).rejects.toThrow(\"Simulated failure\");\n\t\t\tconst result = await adapter.findMany<User>({\n\t\t\t\tmodel: \"user\",\n\t\t\t});\n\t\t\t//Transactions made rows are unable to be automatically cleaned up, so we need to clean them up manually\n\t\t\tawait hardCleanup();\n\t\t\texpect(result.length).toBe(0);\n\t\t},\n\t}),\n);\n"],"mappings":";;;;;;;AAOA,MAAa,wBAAwB,gBACpC,gBACA,EAAE,GACD,EAAE,SAAS,UAAU,mBAAmB,EACxC,qDAAqD,OAAO,EAAE,WAAW;AAExE,KAAI,CADc,QAAQ,SAAS,cAAc,aACjC;AACf,OACC,kBAAkB,QAAQ,SAAS,cAAc,YAAY,gCAC7D;AACD;;CAGD,MAAM,QAAQ,MAAM,SAAS,OAAO;AACtB,OAAM,SAAS,OAAO;AACpC,OAAM,OACL,QAAQ,YAAY,OAAO,OAAO;AACjC,QAAM,GAAG,OAAO;GAAE,OAAO;GAAQ,MAAM;GAAO,cAAc;GAAM,CAAC;AAEnE,SADc,MAAM,GAAG,SAAS,EAAE,OAAO,QAAQ,CAAC,CACrC,CAAC,aAAa,EAAE;AAC7B,QAAM,IAAI,MAAM,oBAAoB;GAEnC,CACF,CAAC,QAAQ,QAAQ,oBAAoB;CACtC,MAAM,SAAS,MAAM,QAAQ,SAAe,EAC3C,OAAO,QACP,CAAC;AAEF,OAAM,aAAa;AACnB,QAAO,OAAO,OAAO,CAAC,KAAK,EAAE;GAE9B,EACD"}
@@ -0,0 +1,25 @@
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/uuid.d.ts
6
+ declare const uuidTestSuite: (options?: {
7
+ disableTests?: Partial<Record<"init - tests" | "create - should create a model" | "create - should always return an id" | "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" | "create - should return a uuid" | "findOne - should find a model using a uuid", boolean> & {
8
+ ALL?: boolean;
9
+ }> | undefined;
10
+ } | undefined) => (helpers: {
11
+ adapter: () => Promise<better_auth0.DBAdapter<better_auth0.BetterAuthOptions>>;
12
+ log: Logger;
13
+ adapterDisplayName: string;
14
+ getBetterAuthOptions: () => better_auth0.BetterAuthOptions;
15
+ modifyBetterAuthOptions: (options: better_auth0.BetterAuthOptions) => Promise<better_auth0.BetterAuthOptions>;
16
+ cleanup: () => Promise<void>;
17
+ runMigrations: () => Promise<void>;
18
+ prefixTests?: string | undefined;
19
+ onTestFinish: (stats: TestSuiteStats) => Promise<void>;
20
+ customIdGenerator?: (() => any | Promise<any> | undefined) | undefined;
21
+ transformIdOutput?: ((id: any) => string | undefined) | undefined;
22
+ }) => Promise<void>;
23
+ //#endregion
24
+ export { uuidTestSuite };
25
+ //# sourceMappingURL=uuid.d.mts.map
@@ -0,0 +1,55 @@
1
+ import { createTestSuite } from "../create-test-suite.mjs";
2
+ import { getNormalTestSuiteTests } from "./basic.mjs";
3
+ import { expect } from "vitest";
4
+
5
+ //#region src/adapter/suites/uuid.ts
6
+ const uuidTestSuite = createTestSuite("uuid", {
7
+ defaultBetterAuthOptions: { advanced: { database: { generateId: "uuid" } } },
8
+ prefixTests: "uuid",
9
+ alwaysMigrate: true,
10
+ customIdGenerator() {
11
+ return crypto.randomUUID();
12
+ }
13
+ }, (helpers) => {
14
+ const { "create - should use generateId if provided": _, ...normalTests } = getNormalTestSuiteTests(helpers);
15
+ return {
16
+ "init - tests": async () => {
17
+ expect(helpers.getBetterAuthOptions().advanced?.database?.generateId === "uuid").toBe(true);
18
+ },
19
+ "create - should return a uuid": async () => {
20
+ const user = await helpers.generate("user");
21
+ const res = await helpers.adapter.create({
22
+ model: "user",
23
+ data: {
24
+ ...user,
25
+ id: void 0
26
+ }
27
+ });
28
+ expect(res).toHaveProperty("id");
29
+ expect(typeof res.id).toBe("string");
30
+ expect(res.id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
31
+ console.log(res);
32
+ },
33
+ "findOne - should find a model using a uuid": async () => {
34
+ const { id: _, ...user } = await helpers.generate("user");
35
+ const res = await helpers.adapter.create({
36
+ model: "user",
37
+ data: user
38
+ });
39
+ const result = await helpers.adapter.findOne({
40
+ model: "user",
41
+ where: [{
42
+ field: "id",
43
+ value: res.id
44
+ }]
45
+ });
46
+ expect(result?.id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
47
+ expect(result).toEqual(res);
48
+ },
49
+ ...normalTests
50
+ };
51
+ });
52
+
53
+ //#endregion
54
+ export { uuidTestSuite };
55
+ //# sourceMappingURL=uuid.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.mjs","names":[],"sources":["../../src/adapter/suites/uuid.ts"],"sourcesContent":["import type { User } from \"@better-auth/core/db\";\nimport { expect } from \"vitest\";\nimport { createTestSuite } from \"../create-test-suite\";\nimport { getNormalTestSuiteTests } from \"./basic\";\n\nexport const uuidTestSuite = createTestSuite(\n\t\"uuid\",\n\t{\n\t\tdefaultBetterAuthOptions: {\n\t\t\tadvanced: {\n\t\t\t\tdatabase: {\n\t\t\t\t\tgenerateId: \"uuid\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tprefixTests: \"uuid\",\n\t\talwaysMigrate: true,\n\t\t// This is here to overwrite `generateId` functions to generate UUIDs instead of the default.\n\t\t// Since existing tests often use generated IDs as well as `forceAllowId` to be true, this is needed to ensure the tests pass.\n\t\tcustomIdGenerator() {\n\t\t\treturn crypto.randomUUID();\n\t\t},\n\t},\n\t(helpers) => {\n\t\tconst { \"create - should use generateId if provided\": _, ...normalTests } =\n\t\t\tgetNormalTestSuiteTests(helpers);\n\t\treturn {\n\t\t\t\"init - tests\": async () => {\n\t\t\t\tconst opts = helpers.getBetterAuthOptions();\n\t\t\t\texpect(opts.advanced?.database?.generateId === \"uuid\").toBe(true);\n\t\t\t},\n\t\t\t\"create - should return a uuid\": async () => {\n\t\t\t\tconst user = await helpers.generate(\"user\");\n\t\t\t\tconst res = await helpers.adapter.create<User>({\n\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\t...user,\n\t\t\t\t\t\t//@ts-expect-error - remove id from `user`\n\t\t\t\t\t\tid: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\texpect(res).toHaveProperty(\"id\");\n\t\t\t\texpect(typeof res.id).toBe(\"string\");\n\t\t\t\tconst uuidRegex =\n\t\t\t\t\t/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\t\t\t\texpect(res.id).toMatch(uuidRegex);\n\t\t\t\tconsole.log(res);\n\t\t\t},\n\t\t\t\"findOne - should find a model using a uuid\": async () => {\n\t\t\t\tconst { id: _, ...user } = await helpers.generate(\"user\");\n\t\t\t\tconst res = await helpers.adapter.create<User>({\n\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\tdata: user,\n\t\t\t\t});\n\n\t\t\t\tconst result = await helpers.adapter.findOne<User>({\n\t\t\t\t\tmodel: \"user\",\n\t\t\t\t\twhere: [{ field: \"id\", value: res.id }],\n\t\t\t\t});\n\t\t\t\tconst uuidRegex =\n\t\t\t\t\t/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\t\t\t\texpect(result?.id).toMatch(uuidRegex);\n\t\t\t\texpect(result).toEqual(res);\n\t\t\t},\n\t\t\t...normalTests,\n\t\t};\n\t},\n);\n"],"mappings":";;;;;AAKA,MAAa,gBAAgB,gBAC5B,QACA;CACC,0BAA0B,EACzB,UAAU,EACT,UAAU,EACT,YAAY,QACZ,EACD,EACD;CACD,aAAa;CACb,eAAe;CAGf,oBAAoB;AACnB,SAAO,OAAO,YAAY;;CAE3B,GACA,YAAY;CACZ,MAAM,EAAE,8CAA8C,GAAG,GAAG,gBAC3D,wBAAwB,QAAQ;AACjC,QAAO;EACN,gBAAgB,YAAY;AAE3B,UADa,QAAQ,sBAAsB,CAC/B,UAAU,UAAU,eAAe,OAAO,CAAC,KAAK,KAAK;;EAElE,iCAAiC,YAAY;GAC5C,MAAM,OAAO,MAAM,QAAQ,SAAS,OAAO;GAC3C,MAAM,MAAM,MAAM,QAAQ,QAAQ,OAAa;IAC9C,OAAO;IACP,MAAM;KACL,GAAG;KAEH,IAAI;KACJ;IACD,CAAC;AACF,UAAO,IAAI,CAAC,eAAe,KAAK;AAChC,UAAO,OAAO,IAAI,GAAG,CAAC,KAAK,SAAS;AAGpC,UAAO,IAAI,GAAG,CAAC,QADd,kEACgC;AACjC,WAAQ,IAAI,IAAI;;EAEjB,8CAA8C,YAAY;GACzD,MAAM,EAAE,IAAI,GAAG,GAAG,SAAS,MAAM,QAAQ,SAAS,OAAO;GACzD,MAAM,MAAM,MAAM,QAAQ,QAAQ,OAAa;IAC9C,OAAO;IACP,MAAM;IACN,CAAC;GAEF,MAAM,SAAS,MAAM,QAAQ,QAAQ,QAAc;IAClD,OAAO;IACP,OAAO,CAAC;KAAE,OAAO;KAAM,OAAO,IAAI;KAAI,CAAC;IACvC,CAAC;AAGF,UAAO,QAAQ,GAAG,CAAC,QADlB,kEACoC;AACrC,UAAO,OAAO,CAAC,QAAQ,IAAI;;EAE5B,GAAG;EACH;EAEF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/test-utils",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "Testing utilities for Better Auth adapter development",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "exports": {
26
26
  "./adapter": {
27
- "dev-source": "./src/adapter.ts",
27
+ "dev-source": "./src/adapter/index.ts",
28
28
  "default": "./dist/adapter.mjs",
29
29
  "types": "./dist/adapter.d.mts"
30
30
  }
@@ -32,13 +32,13 @@
32
32
  "devDependencies": {
33
33
  "tsdown": "0.21.0-beta.2",
34
34
  "vitest": "^4.0.18",
35
- "better-auth": "1.5.5",
36
- "@better-auth/core": "1.5.5"
35
+ "@better-auth/core": "1.5.6",
36
+ "better-auth": "1.5.6"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "vitest": "^4.0.18",
40
- "@better-auth/core": "1.5.5",
41
- "better-auth": "1.5.5"
40
+ "@better-auth/core": "1.5.6",
41
+ "better-auth": "1.5.6"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsdown",