diff --git a/README.md b/README.md index 6c651d8..5dcef6e 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@ export const prisma = new PrismaClient(); // ./src/user.ts import { prisma } from "./client"; -export function createUser(email: string) { - return prisma.user.create({ ... }); +export function createUser(data: { name: string }) { + return prisma.user.create({ data }); } ``` @@ -119,7 +119,7 @@ describe("user", () => { it("should create a new user", async () => { // this record will delete by prisma-cleaner in afterEach defined by setup.ts const created = await createUser("xxx"); - expect(created.email).toEqual("xxx"); + expect(created.name).toEqual("xxx"); expect(await prisma.user.count()).toEqual(1); }); @@ -135,7 +135,7 @@ describe("user", () => { Prisma-cleaner adds tables targeted for deletion triggered by the execution of Prisma's `create`, `createMany`, `upsert`. If added via `$executeRaw` or similar, they will not be automatically deleted, so you will need to manually delete them. ```typescript -await prisma.$executeRaw`INSERT INTO "User" (email) VALUES ('xxx')`; +await prisma.$executeRaw`INSERT INTO "User" (name) VALUES ('xxx')`; // You should delete manually. await cleaner.cleanupTables(["User"]); diff --git a/example/with-fabbrica/package.json b/example/with-fabbrica/package.json index e5f7015..69e261c 100644 --- a/example/with-fabbrica/package.json +++ b/example/with-fabbrica/package.json @@ -1,5 +1,5 @@ { - "name": "with-jest-example", + "name": "with-fabbrica-example", "private": true, "scripts": { "generate": "prisma generate", diff --git a/example/with-fabbrica/prisma/schema.prisma b/example/with-fabbrica/prisma/schema.prisma index ad58553..8cc2c58 100644 --- a/example/with-fabbrica/prisma/schema.prisma +++ b/example/with-fabbrica/prisma/schema.prisma @@ -12,17 +12,15 @@ generator fabbrica { } model User { - id Int @id @default(autoincrement()) - email String @unique - name String? + id Int @id @default(autoincrement()) + name String posts Post[] } model Post { - id Int @id @default(autoincrement()) - title String - content String? - published Boolean @default(false) - author User @relation(fields: [authorId], references: [id]) - authorId Int + id Int @id @default(autoincrement()) + title String + content String + User User? @relation(fields: [userId], references: [id]) + userId Int? } diff --git a/example/with-fabbrica/src/user.test.ts b/example/with-fabbrica/src/user.test.ts index 1196d7b..9417ef9 100644 --- a/example/with-fabbrica/src/user.test.ts +++ b/example/with-fabbrica/src/user.test.ts @@ -8,10 +8,9 @@ describe("user", () => { it("should create a new user", async () => { // this record will delete by prisma-cleaner in afterEach defined by setup.ts const created = await createUser("xxx"); - expect(created.email).toEqual("xxx"); + expect(created.name).toEqual("xxx"); - const user = await UserFactory.create(); - expect(user).toBeDefined(); + await UserFactory.create(); expect(await prisma.user.count()).toEqual(2); }); diff --git a/example/with-fabbrica/src/user.ts b/example/with-fabbrica/src/user.ts index bdb32e3..8dff16b 100644 --- a/example/with-fabbrica/src/user.ts +++ b/example/with-fabbrica/src/user.ts @@ -1,10 +1,8 @@ import { prisma } from "./client"; -export function createUser(email: string) { +export function createUser(name: string) { return prisma.user.create({ - data: { - email, - }, + data: { name }, }); } diff --git a/example/with-jest/prisma/schema.prisma b/example/with-jest/prisma/schema.prisma index 7ee0523..8f8cc17 100644 --- a/example/with-jest/prisma/schema.prisma +++ b/example/with-jest/prisma/schema.prisma @@ -8,17 +8,15 @@ datasource db { } model User { - id Int @id @default(autoincrement()) - email String @unique - name String? + id Int @id @default(autoincrement()) + name String posts Post[] } model Post { - id Int @id @default(autoincrement()) - title String - content String? - published Boolean @default(false) - author User @relation(fields: [authorId], references: [id]) - authorId Int + id Int @id @default(autoincrement()) + title String + content String + User User? @relation(fields: [userId], references: [id]) + userId Int? } diff --git a/example/with-jest/src/user.test.ts b/example/with-jest/src/user.test.ts index 8eabd28..c70dd3d 100644 --- a/example/with-jest/src/user.test.ts +++ b/example/with-jest/src/user.test.ts @@ -5,7 +5,7 @@ describe("user", () => { it("should create a new user", async () => { // this record will delete by prisma-cleaner in afterEach defined by setup.ts const created = await createUser("xxx"); - expect(created.email).toEqual("xxx"); + expect(created.name).toEqual("xxx"); expect(await prisma.user.count()).toEqual(1); }); diff --git a/example/with-jest/src/user.ts b/example/with-jest/src/user.ts index bdb32e3..8dff16b 100644 --- a/example/with-jest/src/user.ts +++ b/example/with-jest/src/user.ts @@ -1,10 +1,8 @@ import { prisma } from "./client"; -export function createUser(email: string) { +export function createUser(name: string) { return prisma.user.create({ - data: { - email, - }, + data: { name }, }); } diff --git a/example/with-vitest/prisma/schema.prisma b/example/with-vitest/prisma/schema.prisma index 7ee0523..8f8cc17 100644 --- a/example/with-vitest/prisma/schema.prisma +++ b/example/with-vitest/prisma/schema.prisma @@ -8,17 +8,15 @@ datasource db { } model User { - id Int @id @default(autoincrement()) - email String @unique - name String? + id Int @id @default(autoincrement()) + name String posts Post[] } model Post { - id Int @id @default(autoincrement()) - title String - content String? - published Boolean @default(false) - author User @relation(fields: [authorId], references: [id]) - authorId Int + id Int @id @default(autoincrement()) + title String + content String + User User? @relation(fields: [userId], references: [id]) + userId Int? } diff --git a/example/with-vitest/src/user.test.ts b/example/with-vitest/src/user.test.ts index 03fbbd3..a654f52 100644 --- a/example/with-vitest/src/user.test.ts +++ b/example/with-vitest/src/user.test.ts @@ -6,7 +6,7 @@ describe("user", () => { it("should create a new user", async () => { // this record will delete by prisma-cleaner in afterEach defined by setup.ts const created = await createUser("xxx"); - expect(created.email).toEqual("xxx"); + expect(created.name).toEqual("xxx"); expect(await prisma.user.count()).toEqual(1); }); diff --git a/example/with-vitest/src/user.ts b/example/with-vitest/src/user.ts index bdb32e3..8dff16b 100644 --- a/example/with-vitest/src/user.ts +++ b/example/with-vitest/src/user.ts @@ -1,10 +1,8 @@ import { prisma } from "./client"; -export function createUser(email: string) { +export function createUser(name: string) { return prisma.user.create({ - data: { - email, - }, + data: { name }, }); } diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7ee0523..8f8cc17 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -8,17 +8,15 @@ datasource db { } model User { - id Int @id @default(autoincrement()) - email String @unique - name String? + id Int @id @default(autoincrement()) + name String posts Post[] } model Post { - id Int @id @default(autoincrement()) - title String - content String? - published Boolean @default(false) - author User @relation(fields: [authorId], references: [id]) - authorId Int + id Int @id @default(autoincrement()) + title String + content String + User User? @relation(fields: [userId], references: [id]) + userId Int? } diff --git a/test/cleaner.test.ts b/test/cleaner.test.ts index 80dff09..298db49 100644 --- a/test/cleaner.test.ts +++ b/test/cleaner.test.ts @@ -16,7 +16,7 @@ describe("PrismaCleaner", () => { test("cleanup user table", async () => { await prisma.user.create({ data: { - email: "xxx", + name: "xxx", }, }); expect(await prisma.user.count()).toBe(1); @@ -27,7 +27,7 @@ describe("PrismaCleaner", () => { test("manually cleanup", async () => { const insert = () => - prisma.$executeRaw`insert into "User" (email) values ('xxx')`; + prisma.$executeRaw`insert into "User" (name) values ('xxx')`; await insert(); expect(await prisma.user.count()).toBe(1);