Skip to content

Commit

Permalink
Add test for unassigned required field in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
calummoore committed Apr 4, 2023
1 parent 2da5604 commit ab38a15
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pub enum GatewayUserError {

#[error("constructor must assign id")]
ConstructorMustAssignId,

// #[error("constructor must assign required fields")]
// ConstructorMustAssignRequired,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
37 changes: 37 additions & 0 deletions polybase/tests/api/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,43 @@ collection test {
);
}

#[tokio::test]
async fn constructor_does_not_assign_required() {
let server = Server::setup_and_wait().await;

let collection = server
.create_collection_untyped(
"ns/test",
"
@public
collection test {
id: string;
arr: array[];
constructor (id: string) {
this.id = id;
}
}
",
None,
)
.await
.unwrap();

let err = collection.create(json!(["id"]), None).await.unwrap_err();

assert_eq!(
err,
Error {
error: ErrorData {
code: "invalid-argument".to_string(),
reason: "record/missing-field".to_string(),
message: "record is missing field \"arr\"".to_string(),
}
}
);
}

#[tokio::test]
async fn id_already_exists() {
let server = Server::setup_and_wait().await;
Expand Down

0 comments on commit ab38a15

Please sign in to comment.