Skip to content

Commit

Permalink
Merge pull request #84 from polybase/eng-538-required-array-should-er…
Browse files Browse the repository at this point in the history
…ror-if-not

Add test for unassigned required field in constructor
  • Loading branch information
calummoore authored Apr 7, 2023
2 parents ea5ca89 + ab38a15 commit ab97687
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 ab97687

Please sign in to comment.