From 0cd3db1cd836401f3b7db04f196e4bc4ba147822 Mon Sep 17 00:00:00 2001 From: Saurav Suman Date: Thu, 14 Nov 2024 16:29:18 +0530 Subject: [PATCH] feat: added description and comment columns in all existing tables and apis --- .../down.sql | 15 +++ .../up.sql | 20 ++++ .../src/api/config/handlers.rs | 16 ++++ .../src/api/context/handlers.rs | 8 ++ .../src/api/context/types.rs | 10 +- .../src/api/default_config/handlers.rs | 4 + .../src/api/default_config/types.rs | 2 + .../src/api/dimension/handlers.rs | 32 ++++--- .../src/api/dimension/types.rs | 6 ++ .../src/api/functions/handlers.rs | 4 +- .../src/api/type_templates/handlers.rs | 4 + .../src/api/type_templates/types.rs | 4 + crates/context_aware_config/src/db/models.rs | 10 +- crates/context_aware_config/src/db/schema.rs | 10 +- .../down.sql | 2 + .../up.sql | 2 + .../src/api/experiments/handlers.rs | 18 ++++ .../src/api/experiments/types.rs | 16 ++++ .../experimentation_platform/src/db/models.rs | 2 + .../experimentation_platform/src/db/schema.rs | 2 + .../tests/experimentation_tests.rs | 3 + postman/cac.postman_collection.json | 91 +++++++++++-------- .../cac/Context/Create Context/request.json | 4 +- postman/cac/Context/Get Context/event.test.js | 2 + postman/cac/Context/Move Context/request.json | 4 +- .../cac/Context/Update Context/request.json | 4 +- .../Add default-config key/event.test.js | 46 +++++++++- .../Add default-config key/request.json | 4 +- .../event.prerequest.js | 4 +- .../Dimension/Create Dimension/request.json | 4 +- .../Delete Dimension/event.prerequest.js | 4 +- .../cac/custom types/Create Type/request.json | 4 +- .../cac/custom types/Get Types/event.test.js | 10 ++ .../cac/custom types/Update Type/request.json | 4 +- .../Conclude/request.json | 4 +- .../Create Experiment 2/event.prerequest.js | 12 ++- .../Create Experiment 2/request.json | 4 +- .../Create Experiment/event.prerequest.js | 14 ++- .../Create Experiment/event.test.js | 16 +++- .../Create Experiment/request.json | 4 +- .../Ramp/request.json | 4 +- .../Update Override Keys/event.prerequest.js | 4 +- .../Update Override Keys/request.json | 4 +- 43 files changed, 350 insertions(+), 91 deletions(-) create mode 100644 crates/context_aware_config/migrations/2024-11-06-123105_add_description_and_comment_columns/down.sql create mode 100644 crates/context_aware_config/migrations/2024-11-06-123105_add_description_and_comment_columns/up.sql create mode 100644 crates/experimentation_platform/migrations/2024-11-21-103114_add_comment_and_description_in_experiments/down.sql create mode 100644 crates/experimentation_platform/migrations/2024-11-21-103114_add_comment_and_description_in_experiments/up.sql diff --git a/crates/context_aware_config/migrations/2024-11-06-123105_add_description_and_comment_columns/down.sql b/crates/context_aware_config/migrations/2024-11-06-123105_add_description_and_comment_columns/down.sql new file mode 100644 index 00000000..1186a969 --- /dev/null +++ b/crates/context_aware_config/migrations/2024-11-06-123105_add_description_and_comment_columns/down.sql @@ -0,0 +1,15 @@ +ALTER TABLE public.functions ALTER COLUMN description DROP NOT NULL; +ALTER TABLE public.functions ALTER COLUMN description DROP DEFAULT; +ALTER TABLE public.functions RENAME COLUMN description TO function_description; + +ALTER TABLE public.type_templates DROP COLUMN IF EXISTS description; +ALTER TABLE public.type_templates DROP COLUMN IF EXISTS comment; + +ALTER TABLE public.default_configs DROP COLUMN IF EXISTS description; +ALTER TABLE public.default_configs DROP COLUMN IF EXISTS comment; + +ALTER TABLE public.dimensions DROP COLUMN IF EXISTS description; +ALTER TABLE public.dimensions DROP COLUMN IF EXISTS comment; + +ALTER TABLE public.contexts DROP COLUMN IF EXISTS description; +ALTER TABLE public.contexts DROP COLUMN IF EXISTS comment; \ No newline at end of file diff --git a/crates/context_aware_config/migrations/2024-11-06-123105_add_description_and_comment_columns/up.sql b/crates/context_aware_config/migrations/2024-11-06-123105_add_description_and_comment_columns/up.sql new file mode 100644 index 00000000..e9cc59cf --- /dev/null +++ b/crates/context_aware_config/migrations/2024-11-06-123105_add_description_and_comment_columns/up.sql @@ -0,0 +1,20 @@ + +ALTER TABLE public.contexts ADD COLUMN IF NOT EXISTS description TEXT DEFAULT '' NOT NULL; +ALTER TABLE public.contexts ADD COLUMN IF NOT EXISTS comment TEXT DEFAULT '' NOT NULL; + +ALTER TABLE public.contexts ADD COLUMN IF NOT EXISTS description TEXT DEFAULT '' NOT NULL; +ALTER TABLE public.contexts ADD COLUMN IF NOT EXISTS comment TEXT DEFAULT '' NOT NULL; + +ALTER TABLE public.dimensions ADD COLUMN IF NOT EXISTS description TEXT DEFAULT '' NOT NULL; +ALTER TABLE public.dimensions ADD COLUMN IF NOT EXISTS comment TEXT DEFAULT '' NOT NULL; + +ALTER TABLE public.default_configs ADD COLUMN IF NOT EXISTS description TEXT DEFAULT '' NOT NULL; +ALTER TABLE public.default_configs ADD COLUMN IF NOT EXISTS comment TEXT DEFAULT '' NOT NULL; + +ALTER TABLE public.type_templates ADD COLUMN IF NOT EXISTS description TEXT DEFAULT '' NOT NULL; +ALTER TABLE public.type_templates ADD COLUMN IF NOT EXISTS comment TEXT DEFAULT '' NOT NULL; + +ALTER TABLE public.functions RENAME COLUMN function_description TO description; + +ALTER TABLE public.functions ALTER COLUMN description SET DEFAULT ''; +ALTER TABLE public.functions ALTER COLUMN description SET NOT NULL; \ No newline at end of file diff --git a/crates/context_aware_config/src/api/config/handlers.rs b/crates/context_aware_config/src/api/config/handlers.rs index 9fd59a01..5b7b3d15 100644 --- a/crates/context_aware_config/src/api/config/handlers.rs +++ b/crates/context_aware_config/src/api/config/handlers.rs @@ -378,9 +378,25 @@ fn construct_new_payload( }, )?; + let description = res + .get("description") + .expect("Description not present") + .as_str() + .expect("Description is not a string") + .to_string(); + + let comment = res + .get("comment") + .expect("Comment not present") + .as_str() + .expect("Comment is not a string") + .to_string(); + return Ok(web::Json(PutReq { context: context, r#override: override_, + description, + comment, })); } diff --git a/crates/context_aware_config/src/api/context/handlers.rs b/crates/context_aware_config/src/api/context/handlers.rs index 648438bb..154fd730 100644 --- a/crates/context_aware_config/src/api/context/handlers.rs +++ b/crates/context_aware_config/src/api/context/handlers.rs @@ -207,6 +207,8 @@ fn create_ctx_from_put_req( tenant_config: &TenantConfig, ) -> superposition::Result { let ctx_condition = req.context.to_owned().into_inner(); + let description = req.description.to_owned(); + let comment = req.comment.clone(); let condition_val = Value::Object(ctx_condition.clone().into()); let r_override = req.r#override.clone().into_inner(); let ctx_override = Value::Object(r_override.clone().into()); @@ -242,6 +244,8 @@ fn create_ctx_from_put_req( created_by: user.get_email(), last_modified_at: Utc::now().naive_utc(), last_modified_by: user.get_email(), + description, + comment, }) } @@ -445,6 +449,8 @@ fn r#move( ) -> superposition::Result { use contexts::dsl; let req = req.into_inner(); + let description = req.description.clone(); + let comment = req.comment.clone(); let ctx_condition = req.context.to_owned().into_inner(); let ctx_condition_value = Value::Object(ctx_condition.clone().into()); let new_ctx_id = hash(&ctx_condition_value); @@ -488,6 +494,8 @@ fn r#move( override_: ctx.override_, last_modified_at: Utc::now().naive_utc(), last_modified_by: user.get_email(), + description, + comment, }; let handle_unique_violation = diff --git a/crates/context_aware_config/src/api/context/types.rs b/crates/context_aware_config/src/api/context/types.rs index 008f01dd..be1b525e 100644 --- a/crates/context_aware_config/src/api/context/types.rs +++ b/crates/context_aware_config/src/api/context/types.rs @@ -6,12 +6,16 @@ use superposition_types::{Cac, Condition, Overrides}; pub struct PutReq { pub context: Cac, pub r#override: Cac, + pub description: String, + pub comment: String, } #[cfg_attr(test, derive(Debug, PartialEq))] // Derive traits only when running tests #[derive(Deserialize, Clone)] pub struct MoveReq { pub context: Cac, + pub description: String, + pub comment: String, } #[derive(Deserialize, Clone)] @@ -98,7 +102,9 @@ mod tests { }, "override": { "foo": "baz" - } + }, + "description": "", + "comment": "" }); let action_str = json!({ @@ -120,6 +126,8 @@ mod tests { let expected_action = ContextAction::Put(PutReq { context: context, r#override: override_, + description: "".to_string(), + comment: "".to_string(), }); let action_deserialized = diff --git a/crates/context_aware_config/src/api/default_config/handlers.rs b/crates/context_aware_config/src/api/default_config/handlers.rs index ec0307c5..1761f6d3 100644 --- a/crates/context_aware_config/src/api/default_config/handlers.rs +++ b/crates/context_aware_config/src/api/default_config/handlers.rs @@ -77,6 +77,8 @@ async fn create( )) } }; + let description = req.description.clone(); + let comment = req.comment.clone(); let result = fetch_default_key(&key, &mut conn); @@ -129,6 +131,8 @@ async fn create( created_at: created_at_val, last_modified_at: Utc::now().naive_utc(), last_modified_by: user.get_email(), + description, + comment, }; let schema_compile_result = JSONSchema::options() diff --git a/crates/context_aware_config/src/api/default_config/types.rs b/crates/context_aware_config/src/api/default_config/types.rs index 8366d00d..371c1dce 100644 --- a/crates/context_aware_config/src/api/default_config/types.rs +++ b/crates/context_aware_config/src/api/default_config/types.rs @@ -10,6 +10,8 @@ pub struct CreateReq { pub schema: Option>, #[serde(default, deserialize_with = "deserialize_option")] pub function_name: Option, + pub description: String, + pub comment: String, } #[derive(Debug, Deserialize, AsRef, Deref, DerefMut, Into)] diff --git a/crates/context_aware_config/src/api/dimension/handlers.rs b/crates/context_aware_config/src/api/dimension/handlers.rs index 946932b7..15fe2141 100644 --- a/crates/context_aware_config/src/api/dimension/handlers.rs +++ b/crates/context_aware_config/src/api/dimension/handlers.rs @@ -2,7 +2,10 @@ use crate::{ api::dimension::{types::CreateReq, utils::get_dimension_usage_context_ids}, db::{ models::Dimension, - schema::{dimensions, dimensions::dsl::*}, + schema::dimensions::dsl::{ + created_at, dimension, dimensions as dimension_table, last_modified_at, + last_modified_by, + }, }, helpers::validate_jsonschema, }; @@ -81,11 +84,13 @@ async fn create( function_name: fun_name.clone(), last_modified_at: Utc::now().naive_utc(), last_modified_by: user.get_email(), + comment: create_req.comment.into(), + description: create_req.description.into(), }; - let upsert = diesel::insert_into(dimensions) + let upsert = diesel::insert_into(dimension_table) .values(&new_dimension) - .on_conflict(dimensions::dimension) + .on_conflict(dimension) .do_update() .set(&new_dimension) .get_result::(&mut conn); @@ -129,13 +134,13 @@ async fn get( let (total_pages, total_items, result) = match filters.all { Some(true) => { - let result: Vec = dimensions.get_results(&mut conn)?; + let result: Vec = dimension_table.get_results(&mut conn)?; (1, result.len() as i64, result) } _ => { - let n_dimensions: i64 = dimensions.count().get_result(&mut conn)?; + let n_dimensions: i64 = dimension_table.count().get_result(&mut conn)?; let limit = filters.count.unwrap_or(10); - let mut builder = dimensions + let mut builder = dimension_table .into_boxed() .order(created_at.desc()) .limit(limit); @@ -173,23 +178,22 @@ async fn delete_dimension( ) -> superposition::Result { let name: String = path.into_inner().into(); let DbConnection(mut conn) = db_conn; - dimensions::dsl::dimensions - .filter(dimensions::dimension.eq(&name)) + dimension_table + .filter(dimension.eq(&name)) .select(Dimension::as_select()) .get_result(&mut conn)?; let context_ids = get_dimension_usage_context_ids(&name, &mut conn) .map_err(|_| unexpected_error!("Something went wrong"))?; if context_ids.is_empty() { conn.transaction::<_, superposition::AppError, _>(|transaction_conn| { - use dimensions::dsl; - diesel::update(dsl::dimensions) - .filter(dsl::dimension.eq(&name)) + diesel::update(dimension_table) + .filter(dimension.eq(&name)) .set(( - dsl::last_modified_at.eq(Utc::now().naive_utc()), - dsl::last_modified_by.eq(user.get_email()), + last_modified_at.eq(Utc::now().naive_utc()), + last_modified_by.eq(user.get_email()), )) .execute(transaction_conn)?; - let deleted_row = delete(dsl::dimensions.filter(dsl::dimension.eq(&name))) + let deleted_row = delete(dimension_table.filter(dimension.eq(&name))) .execute(transaction_conn); match deleted_row { Ok(0) => Err(not_found!("Dimension `{}` doesn't exists", name)), diff --git a/crates/context_aware_config/src/api/dimension/types.rs b/crates/context_aware_config/src/api/dimension/types.rs index 11adb6bb..cb774f34 100644 --- a/crates/context_aware_config/src/api/dimension/types.rs +++ b/crates/context_aware_config/src/api/dimension/types.rs @@ -13,6 +13,8 @@ pub struct CreateReq { pub schema: Value, #[serde(default, deserialize_with = "deserialize_option")] pub function_name: Option, + pub description: String, + pub comment: String, } #[derive(Debug, Deserialize, AsRef, Deref, DerefMut, Into)] @@ -72,6 +74,8 @@ pub struct DimensionWithMandatory { pub function_name: Option, pub last_modified_at: NaiveDateTime, pub last_modified_by: String, + pub description: String, + pub comment: String, pub mandatory: bool, } @@ -86,6 +90,8 @@ impl DimensionWithMandatory { function_name: value.function_name, last_modified_at: value.last_modified_at, last_modified_by: value.last_modified_by, + description: value.description, + comment: value.comment, mandatory, } } diff --git a/crates/context_aware_config/src/api/functions/handlers.rs b/crates/context_aware_config/src/api/functions/handlers.rs index 32ff7639..a24e9a7c 100644 --- a/crates/context_aware_config/src/api/functions/handlers.rs +++ b/crates/context_aware_config/src/api/functions/handlers.rs @@ -63,7 +63,7 @@ async fn create( published_at: None, published_by: None, published_runtime_version: None, - function_description: req.description, + description: req.description, last_modified_at: Utc::now().naive_utc(), last_modified_by: user.get_email(), }; @@ -136,7 +136,7 @@ async fn update( draft_runtime_version: req .runtime_version .unwrap_or(result.draft_runtime_version), - function_description: req.description.unwrap_or(result.function_description), + description: req.description.unwrap_or(result.description), draft_edited_by: user.get_email(), draft_edited_at: Utc::now().naive_utc(), published_code: result.published_code, diff --git a/crates/context_aware_config/src/api/type_templates/handlers.rs b/crates/context_aware_config/src/api/type_templates/handlers.rs index c195777c..b6c68406 100644 --- a/crates/context_aware_config/src/api/type_templates/handlers.rs +++ b/crates/context_aware_config/src/api/type_templates/handlers.rs @@ -43,12 +43,16 @@ async fn create_type( ) })?; let type_name: String = request.type_name.clone().into(); + let description = request.description.clone(); + let comment = request.comment.clone(); let type_template = diesel::insert_into(type_templates::table) .values(( type_templates::type_schema.eq(request.type_schema.clone()), type_templates::type_name.eq(type_name), type_templates::created_by.eq(user.email.clone()), type_templates::last_modified_by.eq(user.email.clone()), + type_templates::description.eq(description), + type_templates::comment.eq(comment), )) .get_result::(&mut conn) .map_err(|err| { diff --git a/crates/context_aware_config/src/api/type_templates/types.rs b/crates/context_aware_config/src/api/type_templates/types.rs index d7cbbd1f..9de68cc7 100644 --- a/crates/context_aware_config/src/api/type_templates/types.rs +++ b/crates/context_aware_config/src/api/type_templates/types.rs @@ -7,6 +7,8 @@ use superposition_types::RegexEnum; pub struct TypeTemplateRequest { pub type_schema: Value, pub type_name: TypeTemplateName, + pub description: String, + pub comment: String, } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -16,6 +18,8 @@ pub struct TypeTemplateResponse { pub created_at: String, pub last_modified: String, pub created_by: String, + pub description: String, + pub comment: String, } #[derive(Debug, Deserialize, Serialize, AsRef, Deref, DerefMut, Into, Clone)] diff --git a/crates/context_aware_config/src/db/models.rs b/crates/context_aware_config/src/db/models.rs index a0425793..9331f4e3 100644 --- a/crates/context_aware_config/src/db/models.rs +++ b/crates/context_aware_config/src/db/models.rs @@ -22,6 +22,8 @@ pub struct Context { pub override_: Overrides, pub last_modified_at: NaiveDateTime, pub last_modified_by: String, + pub description: String, + pub comment: String, } impl Contextual for Context { @@ -49,6 +51,8 @@ pub struct Dimension { pub function_name: Option, pub last_modified_at: NaiveDateTime, pub last_modified_by: String, + pub description: String, + pub comment: String, } #[derive(Queryable, Selectable, Insertable, AsChangeset, Serialize, Clone)] @@ -64,6 +68,8 @@ pub struct DefaultConfig { pub function_name: Option, pub last_modified_at: NaiveDateTime, pub last_modified_by: String, + pub description: String, + pub comment: String, } #[derive(Queryable, Selectable, Insertable, AsChangeset, Serialize, Clone, Debug)] @@ -73,7 +79,7 @@ pub struct Function { pub function_name: String, pub published_code: Option, pub draft_code: String, - pub function_description: String, + pub description: String, pub published_runtime_version: Option, pub draft_runtime_version: String, pub published_at: Option, @@ -121,4 +127,6 @@ pub struct TypeTemplates { pub created_at: NaiveDateTime, pub last_modified_at: NaiveDateTime, pub last_modified_by: String, + pub description: String, + pub comment: String, } diff --git a/crates/context_aware_config/src/db/schema.rs b/crates/context_aware_config/src/db/schema.rs index 70e80901..c9f99e2a 100644 --- a/crates/context_aware_config/src/db/schema.rs +++ b/crates/context_aware_config/src/db/schema.rs @@ -23,6 +23,8 @@ diesel::table! { last_modified_at -> Timestamp, #[max_length = 200] last_modified_by -> Varchar, + description -> Text, + comment -> Text, } } @@ -37,6 +39,8 @@ diesel::table! { last_modified_at -> Timestamp, #[max_length = 200] last_modified_by -> Varchar, + description -> Text, + comment -> Text, } } @@ -51,6 +55,8 @@ diesel::table! { last_modified_at -> Timestamp, #[max_length = 200] last_modified_by -> Varchar, + description -> Text, + comment -> Text, } } @@ -605,7 +611,7 @@ diesel::table! { function_name -> Text, published_code -> Nullable, draft_code -> Text, - function_description -> Text, + description -> Text, #[max_length = 16] published_runtime_version -> Nullable, #[max_length = 16] @@ -629,6 +635,8 @@ diesel::table! { last_modified_at -> Timestamp, #[max_length = 200] last_modified_by -> Varchar, + description -> Text, + comment -> Text, } } diff --git a/crates/experimentation_platform/migrations/2024-11-21-103114_add_comment_and_description_in_experiments/down.sql b/crates/experimentation_platform/migrations/2024-11-21-103114_add_comment_and_description_in_experiments/down.sql new file mode 100644 index 00000000..607fd6ef --- /dev/null +++ b/crates/experimentation_platform/migrations/2024-11-21-103114_add_comment_and_description_in_experiments/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE public.experiments DROP COLUMN IF EXISTS description; +ALTER TABLE public.experiments DROP COLUMN IF EXISTS comment; diff --git a/crates/experimentation_platform/migrations/2024-11-21-103114_add_comment_and_description_in_experiments/up.sql b/crates/experimentation_platform/migrations/2024-11-21-103114_add_comment_and_description_in_experiments/up.sql new file mode 100644 index 00000000..05174cf0 --- /dev/null +++ b/crates/experimentation_platform/migrations/2024-11-21-103114_add_comment_and_description_in_experiments/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE public.experiments ADD COLUMN IF NOT EXISTS description TEXT DEFAULT '' NOT NULL; +ALTER TABLE public.experiments ADD COLUMN IF NOT EXISTS comment TEXT DEFAULT '' NOT NULL; \ No newline at end of file diff --git a/crates/experimentation_platform/src/api/experiments/handlers.rs b/crates/experimentation_platform/src/api/experiments/handlers.rs index ce1698c1..ec8dda2a 100644 --- a/crates/experimentation_platform/src/api/experiments/handlers.rs +++ b/crates/experimentation_platform/src/api/experiments/handlers.rs @@ -136,6 +136,8 @@ async fn create( use crate::db::schema::experiments::dsl::experiments; let mut variants = req.variants.to_vec(); let DbConnection(mut conn) = db_conn; + let description = req.description.clone(); + let comment = req.comment.clone(); // Checking if experiment has exactly 1 control variant, and // atleast 1 experimental variant @@ -210,6 +212,8 @@ async fn create( })? .clone(), r#override: json!(variant.overrides), + description: description.clone(), + comment: comment.clone(), }; cac_operations.push(ContextAction::PUT(payload)); } @@ -279,6 +283,8 @@ async fn create( variants: Variants::new(variants), last_modified_by: user.get_email(), chosen_variant: None, + description, + comment, }; let mut inserted_experiments = diesel::insert_into(experiments) @@ -355,6 +361,8 @@ pub async fn conclude( user: User, ) -> superposition::Result<(Experiment, Option)> { use crate::db::schema::experiments::dsl; + let description = req.description.clone(); + let comment = req.comment.clone(); let winner_variant_id: String = req.chosen_variant.to_owned(); @@ -384,6 +392,8 @@ pub async fn conclude( if !experiment_context.is_empty() { let context_move_req = ContextMoveReq { context: experiment_context.clone(), + description: description.clone(), + comment: comment.clone(), }; operations.push(ContextAction::MOVE((context_id, context_move_req))); } else { @@ -630,6 +640,8 @@ async fn ramp( ) -> superposition::Result> { let DbConnection(mut conn) = db_conn; let exp_id = params.into_inner(); + let description = req.description.clone(); + let comment = req.comment.clone(); let experiment: Experiment = experiments::experiments .find(exp_id) @@ -660,6 +672,8 @@ async fn ramp( experiments::last_modified.eq(Utc::now()), experiments::last_modified_by.eq(user.get_email()), experiments::status.eq(ExperimentStatusType::INPROGRESS), + experiments::description.eq(description), + experiments::comment.eq(comment), )) .get_result(&mut conn)?; @@ -701,6 +715,8 @@ async fn update_overrides( ) -> superposition::Result { let DbConnection(mut conn) = db_conn; let experiment_id = params.into_inner(); + let description = req.description.clone(); + let comment = req.comment.clone(); let payload = req.into_inner(); let variants = payload.variants; @@ -838,6 +854,8 @@ async fn update_overrides( })? .clone(), r#override: json!(variant.overrides), + description: description.clone(), + comment: comment.clone(), }; cac_operations.push(ContextAction::PUT(payload)); } diff --git a/crates/experimentation_platform/src/api/experiments/types.rs b/crates/experimentation_platform/src/api/experiments/types.rs index 19f7586d..cc4c9456 100644 --- a/crates/experimentation_platform/src/api/experiments/types.rs +++ b/crates/experimentation_platform/src/api/experiments/types.rs @@ -15,6 +15,8 @@ pub struct ExperimentCreateRequest { pub name: String, pub context: Exp, pub variants: Vec, + pub description: String, + pub comment: String, } #[derive(Serialize)] @@ -50,6 +52,8 @@ pub struct ExperimentResponse { pub variants: Vec, pub last_modified_by: String, pub chosen_variant: Option, + pub description: String, + pub comment: String, } impl From for ExperimentResponse { @@ -69,6 +73,8 @@ impl From for ExperimentResponse { variants: experiment.variants.into_inner(), last_modified_by: experiment.last_modified_by, chosen_variant: experiment.chosen_variant, + description: experiment.description, + comment: experiment.comment, } } } @@ -85,6 +91,8 @@ pub struct ExperimentsResponse { #[derive(Deserialize, Debug)] pub struct ConcludeExperimentRequest { pub chosen_variant: String, + pub description: String, + pub comment: String, } /********** Context Bulk API Type *************/ @@ -93,6 +101,8 @@ pub struct ConcludeExperimentRequest { pub struct ContextPutReq { pub context: Map, pub r#override: Value, + pub description: String, + pub comment: String, } #[derive(Deserialize, Serialize, Clone)] @@ -175,6 +185,8 @@ pub struct ExpListFilters { #[derive(Deserialize, Debug)] pub struct RampRequest { pub traffic_percentage: u64, + pub description: String, + pub comment: String, } /********** Update API type ********/ @@ -188,11 +200,15 @@ pub struct VariantUpdateRequest { #[derive(Deserialize, Debug)] pub struct OverrideKeysUpdateRequest { pub variants: Vec, + pub description: String, + pub comment: String, } #[derive(Deserialize, Serialize, Clone)] pub struct ContextMoveReq { pub context: Map, + pub description: String, + pub comment: String, } /*********** List Audit API Filter Type **************/ diff --git a/crates/experimentation_platform/src/db/models.rs b/crates/experimentation_platform/src/db/models.rs index 7d0a3422..585ed0b1 100644 --- a/crates/experimentation_platform/src/db/models.rs +++ b/crates/experimentation_platform/src/db/models.rs @@ -79,6 +79,8 @@ pub struct Experiment { pub variants: Variants, pub last_modified_by: String, pub chosen_variant: Option, + pub description: String, + pub comment: String, } pub type Experiments = Vec; diff --git a/crates/experimentation_platform/src/db/schema.rs b/crates/experimentation_platform/src/db/schema.rs index a8676f48..7b6a6c90 100644 --- a/crates/experimentation_platform/src/db/schema.rs +++ b/crates/experimentation_platform/src/db/schema.rs @@ -569,6 +569,8 @@ diesel::table! { variants -> Json, last_modified_by -> Text, chosen_variant -> Nullable, + description -> Text, + comment -> Text, } } diff --git a/crates/experimentation_platform/tests/experimentation_tests.rs b/crates/experimentation_platform/tests/experimentation_tests.rs index 8098ab61..2a9eabfc 100644 --- a/crates/experimentation_platform/tests/experimentation_tests.rs +++ b/crates/experimentation_platform/tests/experimentation_tests.rs @@ -11,6 +11,7 @@ use superposition_types::{result as superposition, Cac, Condition, Exp, Override enum Dimensions { Os(String), Client(String), + #[allow(dead_code)] VariantIds(String), } @@ -70,6 +71,8 @@ fn experiment_gen( context: context.clone(), variants: Variants::new(variants.clone()), chosen_variant: None, + description: "".to_string(), + comment: "".to_string(), } } diff --git a/postman/cac.postman_collection.json b/postman/cac.postman_collection.json index cf507ed1..09579804 100644 --- a/postman/cac.postman_collection.json +++ b/postman/cac.postman_collection.json @@ -477,7 +477,7 @@ " \"body\": {", " \"mode\": \"raw\",", " \"raw\": JSON.stringify({", - " \"dimension\": \"dim1\",", + " \"dimension\": \"dim1\",", " \"priority\": 4,", " \"schema\": {", " \"type\": \"string\",", @@ -514,20 +514,21 @@ "})", "", "pm.test(\"404 check\", function () {", - " const deleteRequest = {", - " url: `${host}/dimension/dim1`,", - " method: 'DELETE',", - " header: {", - " 'Content-Type': 'application/json',", - " 'x-tenant': 'test',", - " 'Authorization': `Bearer ${token}`", - " }", - " };", - "", - " pm.sendRequest(deleteRequest, (error, response) => {", - " response.to.have.status(404);", - " });", - "})" + " const deleteRequest = {", + " url: `${host}/dimension/dim1`,", + " method: 'DELETE',", + " header: {", + " 'Content-Type': 'application/json',", + " 'x-tenant': 'test',", + " 'Authorization': `Bearer ${token}`", + " }", + " };", + "", + " pm.sendRequest(deleteRequest, (error, response) => {", + " response.to.have.status(404);", + " });", + "})", + "" ], "type": "text/javascript" } @@ -562,8 +563,7 @@ "dim1" ] } - }, - "response": [] + } } ] }, @@ -1002,6 +1002,8 @@ " delete response.created_by;", " delete response.last_modified_at;", " delete response.last_modified_by;", + " delete response.description;", + " delete response.comment;", "", " pm.expect(JSON.stringify(response)).to.be.eq(JSON.stringify(expected_context));", "});", @@ -1334,46 +1336,55 @@ "pm.test('expect response be 200', function () {", " pm.response.to.be.ok;", " const response = pm.response.json();", - " const modified_response = response.data.map(({ created_at, last_modified, ...rest }) => rest);", + " const modified_response = response.data.map(({ created_at, last_modified_at, last_modified_by, ...rest }) => rest);", " console.log(\"The API returned the response\", modified_response);", " pm.expect(JSON.stringify(modified_response)).to.be.eq(JSON.stringify([", " {", - " \"created_by\": \"user@superposition.io\",", - " \"type_name\": \"Number\",", + " \"type_name\": \"Pattern\",", " \"type_schema\": {", - " \"type\": \"integer\"", - " }", + " \"pattern\": \".*\",", + " \"type\": \"string\"", + " },", + " \"created_by\": \"user@superposition.io\",", + " \"description\": null,", + " \"comment\": null ", " },", " {", - " \"created_by\": \"user@superposition.io\",", - " \"type_name\": \"Decimal\",", + " \"type_name\": \"Enum\",", " \"type_schema\": {", - " \"type\": \"number\"", - " }", + " \"enum\": [\"android\", \"ios\"],", + " \"type\": \"string\"", + " },", + " \"created_by\": \"user@superposition.io\",", + " \"description\": null,", + " \"comment\": null ", " },", " {", - " \"created_by\": \"user@superposition.io\",", " \"type_name\": \"Boolean\",", " \"type_schema\": {", " \"type\": \"boolean\"", - " }", + " },", + " \"created_by\": \"user@superposition.io\",", + " \"description\": null,", + " \"comment\": null ", " },", " {", - " \"created_by\": \"user@superposition.io\",", - " \"type_name\": \"Enum\",", + " \"type_name\": \"Decimal\",", " \"type_schema\": {", - " \"enum\": [\"android\", \"ios\"],", - " \"type\": \"string\"", - " }", + " \"type\": \"number\"", + " },", + " \"created_by\": \"user@superposition.io\",", + " \"description\": null,", + " \"comment\": null ", " },", - "", " {", - " \"created_by\": \"user@superposition.io\",", - " \"type_name\": \"Pattern\",", + " \"type_name\": \"Number\",", " \"type_schema\": {", - " \"pattern\": \".*\",", - " \"type\": \"string\"", - " }", + " \"type\": \"integer\"", + " },", + " \"created_by\": \"user@superposition.io\",", + " \"description\": null,", + " \"comment\": null ", " }", " ]))", "});", @@ -1439,7 +1450,7 @@ " throw error;", " }", " const resp = response.json();", - " const modified_response = resp.map(({ created_at, last_modified, ...rest }) => rest).sort((a, b) => {", + " const modified_response = resp.map(({ created_at, last_modified_at, last_modified_by, ...rest }) => rest).sort((a, b) => {", " return a.type_name > b.type_name;", " });", " pm.expect(JSON.stringify(modified_response)).to.be.eq(JSON.stringify([", diff --git a/postman/cac/Context/Create Context/request.json b/postman/cac/Context/Create Context/request.json index 6bf6048f..93df7272 100644 --- a/postman/cac/Context/Create Context/request.json +++ b/postman/cac/Context/Create Context/request.json @@ -35,7 +35,9 @@ }, "piyaz" ] - } + }, + "description": "", + "comment": "" } }, "url": { diff --git a/postman/cac/Context/Get Context/event.test.js b/postman/cac/Context/Get Context/event.test.js index a8553581..f62918ab 100644 --- a/postman/cac/Context/Get Context/event.test.js +++ b/postman/cac/Context/Get Context/event.test.js @@ -26,6 +26,8 @@ pm.test("Context equality check", function() { delete response.created_by; delete response.last_modified_at; delete response.last_modified_by; + delete response.description; + delete response.comment; pm.expect(JSON.stringify(response)).to.be.eq(JSON.stringify(expected_context)); }); diff --git a/postman/cac/Context/Move Context/request.json b/postman/cac/Context/Move Context/request.json index c19dadef..197e443d 100644 --- a/postman/cac/Context/Move Context/request.json +++ b/postman/cac/Context/Move Context/request.json @@ -35,7 +35,9 @@ }, "tamatar" ] - } + }, + "description": "", + "comment": "" } }, "url": { diff --git a/postman/cac/Context/Update Context/request.json b/postman/cac/Context/Update Context/request.json index 8d1043f7..8a91398b 100644 --- a/postman/cac/Context/Update Context/request.json +++ b/postman/cac/Context/Update Context/request.json @@ -35,7 +35,9 @@ }, "piyaz" ] - } + }, + "description": "", + "comment": "" } }, "url": { diff --git a/postman/cac/Default Config/Add default-config key/event.test.js b/postman/cac/Default Config/Add default-config key/event.test.js index 28b30c2c..c1af6fd0 100644 --- a/postman/cac/Default Config/Add default-config key/event.test.js +++ b/postman/cac/Default Config/Add default-config key/event.test.js @@ -15,20 +15,60 @@ function getConfigAndTest(key, value) { console.log("Failed to fetch config"); throw error; } - const resp_obj = response.json(); const default_configs = resp_obj.default_configs; - + + // Original checks for key-value console.log(`Checking if key=${key} with value=${value} in default_configs`); + pm.expect(default_configs).to.have.property(key); pm.expect(default_configs[key]).to.be.eq(value); }); } +// Original test cases pm.test("201 check", function () { pm.response.to.have.status(200); -}) +}); pm.test("Check if key added to default config", function () { const key = "key1", value = "value1"; getConfigAndTest(key, value); +}); + +// New test case for description and comment fields +pm.test("Check if description and comment fields exist", function () { + const getRequest = { + url: `${host}/config`, + method: 'GET', + header: { + 'Content-Type': 'application/json', + 'x-tenant': 'test', + } + }; + + pm.sendRequest(getRequest, (error, response) => { + if(error) { + console.log("Failed to fetch config"); + throw error; + } + const resp_obj = response.json(); + console.log("Response:", JSON.stringify(resp_obj, null, 2)); + + // Verify the structure of the response + pm.expect(resp_obj).to.have.property('default_configs'); + const configItem = resp_obj.default_configs.key1; + + // If the config is returned as an object + if (typeof configItem === 'object') { + pm.expect(configItem).to.have.property('value'); + pm.expect(configItem).to.have.property('description'); + pm.expect(configItem).to.have.property('comment'); + } + // If it's just the value directly + else { + // The original format is maintained + pm.expect(resp_obj.default_configs).to.have.property('description'); + pm.expect(resp_obj.default_configs).to.have.property('comment'); + } + }); }); \ No newline at end of file diff --git a/postman/cac/Default Config/Add default-config key/request.json b/postman/cac/Default Config/Add default-config key/request.json index c5345661..0b51d211 100644 --- a/postman/cac/Default Config/Add default-config key/request.json +++ b/postman/cac/Default Config/Add default-config key/request.json @@ -29,7 +29,9 @@ "schema": { "type": "string", "pattern": ".*" - } + }, + "description": "", + "comment": "" } }, "url": { diff --git a/postman/cac/Default Config/Delete default-config key/event.prerequest.js b/postman/cac/Default Config/Delete default-config key/event.prerequest.js index 1aa1f867..3a829a84 100644 --- a/postman/cac/Default Config/Delete default-config key/event.prerequest.js +++ b/postman/cac/Default Config/Delete default-config key/event.prerequest.js @@ -15,7 +15,9 @@ function add_default_config() { "schema": { "type": "string", "pattern": ".*" - } + }, + "description": "", + "comment": "" }) } }; diff --git a/postman/cac/Dimension/Create Dimension/request.json b/postman/cac/Dimension/Create Dimension/request.json index b9b4696d..8d3ce998 100644 --- a/postman/cac/Dimension/Create Dimension/request.json +++ b/postman/cac/Dimension/Create Dimension/request.json @@ -30,7 +30,9 @@ "schema": { "type": "string", "pattern": "^[a-z0-9].*$" - } + }, + "description": "", + "comment": "" } }, "url": { diff --git a/postman/cac/Dimension/Delete Dimension/event.prerequest.js b/postman/cac/Dimension/Delete Dimension/event.prerequest.js index b9bf91ba..9a3b70be 100644 --- a/postman/cac/Dimension/Delete Dimension/event.prerequest.js +++ b/postman/cac/Dimension/Delete Dimension/event.prerequest.js @@ -16,7 +16,9 @@ function add_dimension() { "schema": { "type": "string", "pattern": ".*" - } + }, + "description": "", + "comment": "" }) } }; diff --git a/postman/cac/custom types/Create Type/request.json b/postman/cac/custom types/Create Type/request.json index 8e0c1ef3..b1c0fd0a 100644 --- a/postman/cac/custom types/Create Type/request.json +++ b/postman/cac/custom types/Create Type/request.json @@ -28,7 +28,9 @@ "type_schema": { "type": "number" }, - "type_name": "Integer" + "type_name": "Integer", + "description": "", + "comment": "" } }, "url": { diff --git a/postman/cac/custom types/Get Types/event.test.js b/postman/cac/custom types/Get Types/event.test.js index f3b58c04..7d4f6a6d 100644 --- a/postman/cac/custom types/Get Types/event.test.js +++ b/postman/cac/custom types/Get Types/event.test.js @@ -13,6 +13,8 @@ pm.test('expect response be 200', function () { "type": "string" }, "created_by": "user@superposition.io", + "description": "", + "comment": "" }, { "type_name": "Enum", @@ -21,6 +23,8 @@ pm.test('expect response be 200', function () { "type": "string" }, "created_by": "user@superposition.io", + "description": "", + "comment": "" }, { "type_name": "Boolean", @@ -28,6 +32,8 @@ pm.test('expect response be 200', function () { "type": "boolean" }, "created_by": "user@superposition.io", + "description": "", + "comment": "" }, { "type_name": "Decimal", @@ -35,6 +41,8 @@ pm.test('expect response be 200', function () { "type": "number" }, "created_by": "user@superposition.io", + "description": "", + "comment": "" }, { "type_name": "Number", @@ -42,6 +50,8 @@ pm.test('expect response be 200', function () { "type": "integer" }, "created_by": "user@superposition.io", + "description": "", + "comment": "" } ])) }); diff --git a/postman/cac/custom types/Update Type/request.json b/postman/cac/custom types/Update Type/request.json index 371124a3..de351244 100644 --- a/postman/cac/custom types/Update Type/request.json +++ b/postman/cac/custom types/Update Type/request.json @@ -28,7 +28,9 @@ "type_schema": { "type": "integer" }, - "type_name": "Integer" + "type_name": "Integer", + "description": "", + "comment": "" } }, "url": { diff --git a/postman/experimentation-platform/Conclude/request.json b/postman/experimentation-platform/Conclude/request.json index af51941a..5ab93c71 100644 --- a/postman/experimentation-platform/Conclude/request.json +++ b/postman/experimentation-platform/Conclude/request.json @@ -25,7 +25,9 @@ } }, "raw_json_formatted": { - "chosen_variant": "{{experiment_id}}-control" + "chosen_variant": "{{experiment_id}}-control", + "description": "", + "comment": "" } }, "url": { diff --git a/postman/experimentation-platform/Create Experiment 2/event.prerequest.js b/postman/experimentation-platform/Create Experiment 2/event.prerequest.js index 7433c1ce..f5c3ed91 100644 --- a/postman/experimentation-platform/Create Experiment 2/event.prerequest.js +++ b/postman/experimentation-platform/Create Experiment 2/event.prerequest.js @@ -23,7 +23,9 @@ function create_default_config_keys() { "schema": { "type": "string", "pattern": ".*" - } + }, + "description": "", + "comment": "" }) } }; @@ -41,9 +43,9 @@ function create_default_config_keys() { function create_dimensions() { const dimensions = [ - {name: "os", priority: 10, type: "STRING"}, - {name: "client", priority: 100, type: "STRING"}, - {name: "variantIds", priority: 1000, type: "STRING"} + {name: "os", priority: 10, type: "STRING", description: "", comment: ""}, + {name: "client", priority: 100, type: "STRING", description: "", comment: ""}, + {name: "variantIds", priority: 1000, type: "STRING", description: "", comment: ""} ]; for (const dimension of dimensions) { @@ -60,7 +62,7 @@ function create_dimensions() { "raw": JSON.stringify({ "dimension": dimension.name, "priority": dimension.priority, - "type": dimension.type + "type": dimension.type, }) } }; diff --git a/postman/experimentation-platform/Create Experiment 2/request.json b/postman/experimentation-platform/Create Experiment 2/request.json index d231f32d..3ec4be70 100644 --- a/postman/experimentation-platform/Create Experiment 2/request.json +++ b/postman/experimentation-platform/Create Experiment 2/request.json @@ -63,7 +63,9 @@ "pmTestKey4": "value4-test" } } - ] + ], + "description": "", + "comment": "" } }, "url": { diff --git a/postman/experimentation-platform/Create Experiment/event.prerequest.js b/postman/experimentation-platform/Create Experiment/event.prerequest.js index da93399e..ef2e0153 100644 --- a/postman/experimentation-platform/Create Experiment/event.prerequest.js +++ b/postman/experimentation-platform/Create Experiment/event.prerequest.js @@ -23,7 +23,9 @@ function create_default_config_keys() { "schema": { "type": "string", "pattern": ".*" - } + }, + "description": "", + "comment": "" }) } }; @@ -41,9 +43,9 @@ function create_default_config_keys() { function create_dimensions() { const dimensions = [ - {name: "os", priority: 10, schema: { type: "string", enum: ["android", "ios", "web"] }}, - {name: "client", priority: 100, schema: { type: "string", pattern: ".*" }}, - {name: "variantIds", priority: 1000, schema: { type: "string", pattern: ".*" }} + {name: "os", priority: 10, schema: { type: "string", enum: ["android", "ios", "web"] },"description": "", "comment":"" }, + {name: "client", priority: 100, schema: { type: "string", pattern: ".*" } ,"description": "", "comment":"" }, + {name: "variantIds", priority: 1000, schema: { type: "string", pattern: ".*" }, "description": "", "comment":""} ]; for (const dimension of dimensions) { @@ -60,7 +62,9 @@ function create_dimensions() { "raw": JSON.stringify({ "dimension": dimension.name, "priority": dimension.priority, - "schema": dimension.schema + "schema": dimension.schema, + "description": dimension.description, + "comment": dimension.comment }) } }; diff --git a/postman/experimentation-platform/Create Experiment/event.test.js b/postman/experimentation-platform/Create Experiment/event.test.js index 2acd7253..9e38bd47 100644 --- a/postman/experimentation-platform/Create Experiment/event.test.js +++ b/postman/experimentation-platform/Create Experiment/event.test.js @@ -141,7 +141,9 @@ pm.test("Test created contexts", function() { "pmTestKey1": "value1-control", "pmTestKey2": "value1-control" }, - "variant_type": "CONTROL" + "variant_type": "CONTROL", + "description": "", + "comment": "" }, { "id": `${experiment_id}-test1`, @@ -149,7 +151,9 @@ pm.test("Test created contexts", function() { "pmTestKey1": "value2-test", "pmTestKey2": "value2-test" }, - "variant_type": "EXPERIMENTAL" + "variant_type": "EXPERIMENTAL", + "description": "", + "comment": "" } ]; const expected_variant_contexts = [ @@ -181,7 +185,9 @@ pm.test("Test created contexts", function() { } ] } - ] + ], + "description": "", + "comment": "" } }, { @@ -212,7 +218,9 @@ pm.test("Test created contexts", function() { } ] } - ] + ], + "description": "", + "comment": "" } } ]; diff --git a/postman/experimentation-platform/Create Experiment/request.json b/postman/experimentation-platform/Create Experiment/request.json index 030e4c00..d42dc3b3 100644 --- a/postman/experimentation-platform/Create Experiment/request.json +++ b/postman/experimentation-platform/Create Experiment/request.json @@ -68,7 +68,9 @@ "pmTestKey2": "value2-test" } } - ] + ], + "description": "", + "comment": "" } }, "url": { diff --git a/postman/experimentation-platform/Ramp/request.json b/postman/experimentation-platform/Ramp/request.json index 9c4e4edc..efaf3d05 100644 --- a/postman/experimentation-platform/Ramp/request.json +++ b/postman/experimentation-platform/Ramp/request.json @@ -25,7 +25,9 @@ } }, "raw_json_formatted": { - "traffic_percentage": 46 + "traffic_percentage": 46, + "description": "", + "comment": "" } }, "url": { diff --git a/postman/experimentation-platform/Update Override Keys/event.prerequest.js b/postman/experimentation-platform/Update Override Keys/event.prerequest.js index 49475ab4..1b7c3429 100644 --- a/postman/experimentation-platform/Update Override Keys/event.prerequest.js +++ b/postman/experimentation-platform/Update Override Keys/event.prerequest.js @@ -23,7 +23,9 @@ function create_default_config_keys() { "schema": { "type": "string", "pattern": ".*" - } + }, + "description": "", + "comment": "" }) } }; diff --git a/postman/experimentation-platform/Update Override Keys/request.json b/postman/experimentation-platform/Update Override Keys/request.json index 145614cf..fe7f99c0 100644 --- a/postman/experimentation-platform/Update Override Keys/request.json +++ b/postman/experimentation-platform/Update Override Keys/request.json @@ -39,7 +39,9 @@ "pmTestKey1999": "value-6930-an-test" } } - ] + ], + "description": "", + "comment": "" } }, "url": {