test: adapter schema gen

This commit is contained in:
Bereket Engida
2024-09-30 19:11:18 +03:00
parent 456afc94c9
commit 9175fb3238
6 changed files with 121 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`adapter test > should create schema > __snapshots__/adapter.drizzle 1`] = `
"import {
pgTable,
text,
integer,
timestamp,
boolean,
} from "drizzle-orm/pg-core";
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("emailVerified").notNull(),
image: text("image"),
createdAt: timestamp("createdAt").notNull(),
updatedAt: timestamp("updatedAt").notNull(),
});
export const session = pgTable("session", {
id: text("id").primaryKey(),
expiresAt: timestamp("expiresAt").notNull(),
ipAddress: text("ipAddress"),
userAgent: text("userAgent"),
userId: text("userId")
.notNull()
.references(() => user.id),
});
export const account = pgTable("account", {
id: text("id").primaryKey(),
accountId: text("accountId").notNull(),
providerId: text("providerId").notNull(),
userId: text("userId")
.notNull()
.references(() => user.id),
accessToken: text("accessToken"),
refreshToken: text("refreshToken"),
idToken: text("idToken"),
expiresAt: timestamp("expiresAt"),
password: text("password"),
});
"
`;

View File

@@ -1,5 +1,5 @@
import fs from "fs/promises";
import { afterAll, beforeAll, beforeEach, describe, it } from "vitest";
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { user } from "./schema";
import { runAdapterTest } from "../../test";
@@ -38,6 +38,16 @@ describe("adapter test", async () => {
provider: "pg",
});
it("should create schema", async () => {
const res = await adapter.createSchema!({
database: {
provider: "sqlite",
url: ":memory:",
},
});
expect(res.code).toMatchSnapshot("__snapshots__/adapter.drizzle");
});
await runAdapterTest({
adapter,
});

View File

@@ -0,0 +1,9 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`adapter test > should create schema > __snapshots__/adapter.drizzle 1`] = `
"create table "user" ("id" text primary key, "name" text not null, "email" text not null unique, "emailVerified" boolean not null, "image" text, "createdAt" date not null, "updatedAt" date not null);
create table "session" ("id" text primary key, "expiresAt" date not null, "ipAddress" text, "userAgent" text, "userId" text not null references "user" ("id"));
create table "account" ("id" text primary key, "accountId" text not null, "providerId" text not null, "userId" text not null references "user" ("id"), "accessToken" text, "refreshToken" text, "idToken" text, "expiresAt" date, "password" text)"
`;

View File

@@ -0,0 +1,53 @@
import fs from "fs/promises";
import { afterAll, beforeEach, describe, expect, it } from "vitest";
import { runAdapterTest } from "../../test";
import { getMigrations } from "../../../cli/utils/get-migration";
import path from "path";
import { drizzle } from "drizzle-orm/better-sqlite3";
import Database from "better-sqlite3";
import { kyselyAdapter } from "..";
import { Kysely, SqliteDialect } from "kysely";
describe("adapter test", async () => {
beforeEach(async () => {
const { runMigrations } = await getMigrations({
database: {
provider: "sqlite",
url: path.join(__dirname, "test.db"),
},
});
await runMigrations();
});
afterAll(async () => {
await fs.unlink(path.join(__dirname, "test.db"));
});
const sqlite = new Database(path.join(__dirname, "test.db"));
const db = new Kysely({
dialect: new SqliteDialect({
database: sqlite,
}),
});
const adapter = kyselyAdapter(db, {
transform: {
schema: {},
boolean: true,
date: true,
},
});
it("should create schema", async () => {
const res = await adapter.createSchema!({
database: {
provider: "sqlite",
url: ":memory:",
},
});
expect(res.code).toMatchSnapshot("__snapshots__/adapter.drizzle");
});
await runAdapterTest({
adapter,
});
});

View File

@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`adapter test > should match > __snapshots__/adapter.prisma 1`] = `
exports[`adapter test > should create schema > __snapshots__/adapter.prisma 1`] = `
"
generator client {
provider = "prisma-client-js"

View File

@@ -13,7 +13,7 @@ describe("adapter test", async () => {
provider: "sqlite",
});
it("should match", async () => {
it("should create schema", async () => {
const res = await adapter.createSchema!({
database: {
provider: "sqlite",