Skip to content

Commit

Permalink
test: cover invalid enum runtime error
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-prisma committed Jan 2, 2025
1 parent 94c6c8a commit 13af2b0
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,45 @@ mod enum_type {
Ok(())
}

#[connector_test(only(Sqlite))]
async fn read_one_invalid_sqlite(runner: Runner) -> TestResult<()> {
runner
.query(r#"mutation { executeRaw(query: "INSERT INTO \"TestModel\" (id, my_enum) VALUES(1, 'D')", parameters: "[]") }"#)
.await?
.assert_success();

match runner.protocol() {
EngineProtocol::Graphql => {
let res = runner
.query(r#"{ findUniqueTestModel(where: { id: 1 }) { my_enum } }"#)
.await?;
res.assert_failure(None, Some("Value 'D' not found in enum 'MyEnum'".to_owned()));
}
EngineProtocol::Json => {
let res = runner
.query_json(
r#"{
"modelName": "TestModel",
"action": "findUnique",
"query": {
"arguments": {
"where": { "id": 1 }
},
"selection": {
"my_enum": true
}
}
}"#,
)
.await?;

res.assert_failure(None, Some("Value 'D' not found in enum 'MyEnum'".to_owned()));
}
}

Ok(())
}

async fn create_test_data(runner: &Runner) -> TestResult<()> {
create_row(runner, r#"{ id: 1, my_enum: A }"#).await?;
create_row(runner, r#"{ id: 2, my_enum: B }"#).await?;
Expand Down

0 comments on commit 13af2b0

Please sign in to comment.