-
-
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
1 parent
47fc7cc
commit b3faf0a
Showing
8 changed files
with
436 additions
and
34 deletions.
There are no files selected for viewing
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
235 changes: 208 additions & 27 deletions
235
packages/usage/src/prisma/prisma-idb/prisma-idb-client.ts
Large diffs are not rendered by default.
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
77 changes: 77 additions & 0 deletions
77
packages/usage/tests/schema/ReferentialActions/cascade.spec.ts
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,77 @@ | ||
import { test } from "../../fixtures"; | ||
import { expectQueryToSucceed } from "../../queryRunnerHelper"; | ||
|
||
test("cascade_DeleteParentRecord_DeletesChildRecords", async ({ page }) => { | ||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { data: { name: "John", posts: { create: [{ title: "Post1" }, { title: "Post2" }] } } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "delete", | ||
query: { where: { id: 1 } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "post", | ||
operation: "findMany", | ||
query: { where: { authorId: 1 } }, | ||
}); | ||
}); | ||
|
||
test("cascade_DeleteParentRecordWithNoChildren_Success", async ({ page }) => { | ||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { data: { name: "Alice" } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "delete", | ||
query: { where: { id: 1 } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "findMany", | ||
}); | ||
}); | ||
|
||
test("cascade_DeleteParentRecordWithMixedChildren_DeletesOnlyRelatedChildren", async ({ page }) => { | ||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { data: { name: "John", posts: { create: [{ title: "Post1" }, { title: "Post2" }] } } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { data: { name: "Alice", posts: { create: [{ title: "Post3" }] } } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "delete", | ||
query: { where: { id: 1 } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "post", | ||
operation: "findMany", | ||
query: { where: { authorId: 2 } }, | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
packages/usage/tests/schema/ReferentialActions/restrict.spec.ts
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,55 @@ | ||
import { test } from "../../fixtures"; | ||
import { expectQueryToFail, expectQueryToSucceed } from "../../queryRunnerHelper"; | ||
|
||
test("restrict_DeleteUserWithGroups_ThrowsError", async ({ page }) => { | ||
await expectQueryToSucceed({ | ||
page, | ||
model: "group", | ||
operation: "create", | ||
query: { data: { name: "Admins" } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { data: { name: "John Doe" } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "userGroup", | ||
operation: "create", | ||
query: { data: { userId: 1, groupId: 1, joinedOn: new Date() } }, | ||
}); | ||
|
||
await expectQueryToFail({ | ||
page, | ||
model: "user", | ||
operation: "delete", | ||
query: { where: { id: 1 } }, | ||
errorMessage: "Cannot delete record, other records depend on it", | ||
}); | ||
}); | ||
|
||
test("restrict_DeleteUserWithoutComments_SuccessfullyDeletesUser", async ({ page }) => { | ||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { data: { name: "Alice Smith" } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "delete", | ||
query: { where: { id: 1 } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "findMany", | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
packages/usage/tests/schema/ReferentialActions/setDefault.spec.ts
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,60 @@ | ||
import { test } from "../../fixtures"; | ||
import { expectQueryToFail, expectQueryToSucceed } from "../../queryRunnerHelper"; | ||
|
||
test("setDefault_DeleteUserWithPosts_ThrowsErrorIfNoDefaultUserIdExists", async ({ page }) => { | ||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { | ||
data: { | ||
name: "John Doe", | ||
posts: { create: { title: "Post1", comments: { create: { text: "comment1", userId: 1 } } } }, | ||
}, | ||
}, | ||
}); | ||
|
||
await expectQueryToFail({ | ||
page, | ||
model: "user", | ||
operation: "delete", | ||
query: { where: { id: 1 } }, | ||
errorMessage: "Related record not found", | ||
}); | ||
}); | ||
|
||
test("setDefault_DeleteUserWithPosts_SuccessIfDefaultUserIdExists", async ({ page }) => { | ||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { data: { id: 0, name: "Anonymous" } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { | ||
data: { | ||
name: "Alice", | ||
id: 1, | ||
posts: { create: { title: "Post1", comments: { create: { text: "comment1", userId: 1 } } } }, | ||
}, | ||
}, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "delete", | ||
query: { where: { id: 1 } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "findMany", | ||
query: { include: { posts: { include: { comments: true } } } }, | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/usage/tests/schema/ReferentialActions/setNull.spec.ts
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,25 @@ | ||
import { test } from "../../fixtures"; | ||
import { expectQueryToSucceed } from "../../queryRunnerHelper"; | ||
|
||
test("setNull_DeleteUserWithPosts_SetsUserIdToNull", async ({ page }) => { | ||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "create", | ||
query: { data: { name: "John Doe", posts: { create: { title: "Post1" } } } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "user", | ||
operation: "delete", | ||
query: { where: { id: 1 } }, | ||
}); | ||
|
||
await expectQueryToSucceed({ | ||
page, | ||
model: "post", | ||
operation: "findMany", | ||
query: { where: { authorId: null } }, | ||
}); | ||
}); |