From ab38a15c15cd49e503b1ffd5a8117d2b13ddbc35 Mon Sep 17 00:00:00 2001 From: Cal Date: Tue, 4 Apr 2023 20:34:39 +0100 Subject: [PATCH] Add test for unassigned required field in constructor --- gateway/src/lib.rs | 3 +++ polybase/tests/api/errors.rs | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index 6c667864..9f5487ae 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -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)] diff --git a/polybase/tests/api/errors.rs b/polybase/tests/api/errors.rs index 05e5e8b6..03ff2c16 100644 --- a/polybase/tests/api/errors.rs +++ b/polybase/tests/api/errors.rs @@ -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;