-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
157 additions
and
114 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { defineUserFactory } from "./__generated__/fabbrica"; | ||
import { UserService } from "./UserService"; | ||
import { definePostFactory, defineUserFactory } from "./__generated__/fabbrica"; | ||
import { cleaner } from "../test/cleaner"; | ||
|
||
const UserFactory = defineUserFactory(); | ||
const PostFactory = definePostFactory({ | ||
defaultData: { | ||
user: UserFactory, | ||
}, | ||
}); | ||
|
||
describe("UserService", () => { | ||
const prisma = new PrismaClient().$extends( | ||
cleaner.withCleaner(), | ||
) as PrismaClient; | ||
const userService = new UserService(prisma); | ||
|
||
it("should create a new user", async () => { | ||
// this record will delete by prisma-cleaner in afterEach defined by setup.ts | ||
const user = await userService.createUser("xxx"); | ||
expect(user.name).toEqual("xxx"); | ||
await UserFactory.create(); | ||
expect(await prisma.user.count()).toEqual(2); | ||
const post = await PostFactory.create({ title: "xxx" }); | ||
expect(post.title).toEqual("xxx"); | ||
|
||
expect(await prisma.user.count()).toEqual(1); | ||
expect(await prisma.post.count()).toEqual(1); | ||
}); | ||
|
||
it("should be cleanup user table by cleaner", async () => { | ||
const count = await prisma.user.count(); | ||
expect(count).toEqual(0); | ||
expect(await prisma.user.count()).toEqual(0); | ||
expect(await prisma.post.count()).toEqual(0); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../prisma/schema.prisma |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../prisma/schema.prisma |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../prisma/schema.prisma |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../prisma/schema.prisma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters