Skip to content

Commit

Permalink
Merge branch 'feat/no-action-should-be-alias-of-restrict-when-relatio…
Browse files Browse the repository at this point in the history
…n-mode-is-prisma' into integration/fix-15655
  • Loading branch information
jkomyno committed Oct 12, 2022
2 parents a810b25 + 3c03d27 commit a3da7a3
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,26 @@ mod one2one_req {
Ok(())
}

/// Deleting the parent leaves the data in a integrity-violating state.
/// Deleting the parent must fail if a child is connected.
#[connector_test(only(MongoDb))]
async fn delete_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { deleteOneParent(where: { id: 1 }) { id }}"#),
@r###"{"data":{"deleteOneParent":{"id":1}}}"###
assert_error!(
runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
run_query!(&runner, r#"query { findManyChild { parent_id }}"#),
@r###"{"data":{"findManyChild":[{"parent_id":1}]}}"###
assert_error!(
runner,
"mutation { deleteManyParent(where: { id: 1 }) { count }}",
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

Ok(())
Expand Down Expand Up @@ -145,9 +149,11 @@ mod one2one_opt {
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { deleteOneParent(where: { id: 1 }) { id }}"#),
@r###"{"data":{"deleteOneParent":{"id":1}}}"###
assert_error!(
runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand Down Expand Up @@ -237,9 +243,11 @@ mod one2many_req {
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { deleteOneParent(where: { id: 1 }) { id }}"#),
@r###"{"data":{"deleteOneParent":{"id":1}}}"###
assert_error!(
runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand Down Expand Up @@ -329,9 +337,11 @@ mod one2many_opt {
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { deleteOneParent(where: { id: 1 }) { id }}"#),
@r###"{"data":{"deleteOneParent":{"id":1}}}"###
assert_error!(
runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ mod one2one_req {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn update_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#),
@r###"{"data":{"updateOneParent":{"id":1}}}"###
assert_error!(
&runner,
r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand All @@ -69,17 +71,19 @@ mod one2one_req {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn update_many_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateManyParent(data: { uniq: "u1" }) { count }}"#),
@r###"{"data":{"updateManyParent":{"count":1}}}"###
assert_error!(
&runner,
r#"mutation { updateManyParent(data: { uniq: "u1" }) { count }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand All @@ -91,17 +95,19 @@ mod one2one_req {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn upsert_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"upsertOneParent":{"id":1}}}"###
assert_error!(
&runner,
r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand Down Expand Up @@ -201,17 +207,19 @@ mod one2one_opt {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn update_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#),
@r###"{"data":{"updateOneParent":{"id":1}}}"###
assert_error!(
&runner,
r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand All @@ -223,17 +231,19 @@ mod one2one_opt {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn update_many_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateManyParent(data: { uniq: "u1" }) { count }}"#),
@r###"{"data":{"updateManyParent":{"count":1}}}"###
assert_error!(
&runner,
r#"mutation { updateManyParent(data: { uniq: "u1" }) { count }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand All @@ -245,17 +255,19 @@ mod one2one_opt {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn upsert_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"upsertOneParent":{"id":1}}}"###
assert_error!(
&runner,
r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, uniq: "1", child: { create: { id: 1 }}}) { id }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand Down Expand Up @@ -346,9 +358,11 @@ mod one2many_req {
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#),
@r###"{"data":{"updateOneParent":{"id":1}}}"###
assert_error!(
&runner,
r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand All @@ -360,17 +374,19 @@ mod one2many_req {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn update_many_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", children: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateManyParent(data: { uniq: "u1" }) { count }}"#),
@r###"{"data":{"updateManyParent":{"count":1}}}"###
assert_error!(
&runner,
r#"mutation { updateManyParent(data: { uniq: "u1" }) { count }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand All @@ -382,17 +398,19 @@ mod one2many_req {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn upsert_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", children: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, uniq: "1", children: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"upsertOneParent":{"id":1}}}"###
assert_error!(
&runner,
r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, uniq: "1", children: { create: { id: 1 }}}) { id }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand Down Expand Up @@ -483,9 +501,11 @@ mod one2many_opt {
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#),
@r###"{"data":{"updateOneParent":{"id":1}}}"###
assert_error!(
&runner,
r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand All @@ -497,17 +517,19 @@ mod one2many_opt {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn update_many_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", children: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateManyParent(data: { uniq: "u1" }) { count }}"#),
@r###"{"data":{"updateManyParent":{"count":1}}}"###
assert_error!(
&runner,
r#"mutation { updateManyParent(data: { uniq: "u1" }) { count }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand All @@ -519,17 +541,19 @@ mod one2many_opt {
}

/// Updating the parent leaves the data in a integrity-violating state.
/// All supported dbs except mongo throw key violations.
/// All supported dbs throw key constraint violations.
#[connector_test(only(MongoDb))]
async fn upsert_parent_violation(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, uniq: "1", children: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, uniq: "1", children: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"upsertOneParent":{"id":1}}}"###
assert_error!(
&runner,
r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, uniq: "1", children: { create: { id: 1 }}}) { id }}"#,
2014,
"The change you are trying to make would violate the required relation 'ChildToParent' between the `Child` and `Parent` models."
);

insta::assert_snapshot!(
Expand Down

0 comments on commit a3da7a3

Please sign in to comment.