mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-19 23:53:17 -05:00
* refactor * cleanup and more refactor * test: cli * chore: release v0.4.9-beta.12 * feat: kysley generate and orm migrations * chore: release v0.4.9-beta.13 * test: generate * test: change test snapshot file * docs * chore: lint * fix: test * chore: release v0.4.9-beta.14 * chore: release v0.4.9
92 lines
2.0 KiB
TypeScript
92 lines
2.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { migrateAction } from "../src/commands/migrate";
|
|
import * as config from "../src/utils/get-config";
|
|
import { betterAuth, type BetterAuthPlugin } from "better-auth";
|
|
import Database from "better-sqlite3";
|
|
|
|
describe("migrate base auth instance", () => {
|
|
const db = new Database(":memory:");
|
|
|
|
const auth = betterAuth({
|
|
baseURL: "http://localhost:3000",
|
|
database: db,
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
},
|
|
});
|
|
|
|
beforeEach(() => {
|
|
vi.spyOn(process, "exit").mockImplementation((code) => {
|
|
return code as never;
|
|
});
|
|
vi.spyOn(config, "getConfig").mockImplementation(async () => auth.options);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("should migrate the database and sign-up a user", async () => {
|
|
await migrateAction({
|
|
cwd: process.cwd(),
|
|
config: "test/auth.ts",
|
|
y: true,
|
|
});
|
|
const signUpRes = await auth.api.signUpEmail({
|
|
body: {
|
|
name: "test",
|
|
email: "test@email.com",
|
|
password: "password",
|
|
},
|
|
});
|
|
expect(signUpRes.user).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe("migrate auth instance with plugins", () => {
|
|
const db = new Database(":memory:");
|
|
const testPlugin = {
|
|
id: "plugin",
|
|
schema: {
|
|
plugin: {
|
|
fields: {
|
|
test: {
|
|
type: "string",
|
|
fieldName: "test",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} satisfies BetterAuthPlugin;
|
|
|
|
const auth = betterAuth({
|
|
baseURL: "http://localhost:3000",
|
|
database: db,
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
},
|
|
plugins: [testPlugin],
|
|
});
|
|
|
|
beforeEach(() => {
|
|
vi.spyOn(process, "exit").mockImplementation((code) => {
|
|
return code as never;
|
|
});
|
|
vi.spyOn(config, "getConfig").mockImplementation(async () => auth.options);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("should migrate the database and sign-up a user", async () => {
|
|
await migrateAction({
|
|
cwd: process.cwd(),
|
|
config: "test/auth.ts",
|
|
y: true,
|
|
});
|
|
const res = db.prepare("INSERT INTO plugin (test) VALUES ('test')").run();
|
|
expect(res.changes).toBe(1);
|
|
});
|
|
});
|