Skip to content

Commit

Permalink
feat: add supported status to connection model definition (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulkr authored May 30, 2024
1 parent 07e5b55 commit c22d1af
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub struct CreateRequest {
pub is_default_crud_mapping: Option<bool>,
pub mapping: Option<CrudMapping>,
pub paths: Option<ModelPaths>,
pub supported: Option<bool>,
}

impl HookExt<ConnectionModelDefinition> for CreateRequest {}
Expand Down Expand Up @@ -344,6 +345,7 @@ impl RequestExt for CreateRequest {
is_default_crud_mapping: self.is_default_crud_mapping,
mapping: self.mapping.clone(),
record_metadata: Default::default(),
supported: self.supported.unwrap_or(false),
};
record.record_metadata.version = self.version.clone();
Some(record)
Expand Down Expand Up @@ -387,6 +389,10 @@ impl RequestExt for CreateRequest {
record.extractor_config.clone_from(&self.extractor_config);
record.record_metadata.version = self.version.clone();

if let Some(supported) = self.supported {
record.supported = supported;
}

record
}

Expand Down
53 changes: 51 additions & 2 deletions integrationos-api/tests/api_tests/passthrough_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async fn test_passthrough_api() {
responses: vec![],
is_default_crud_mapping: None,
mapping: None,
supported: Some(true),
};

let create_model_definition_response = server
Expand All @@ -82,6 +83,28 @@ async fn test_passthrough_api() {

assert_eq!(create_model_definition_response.code, StatusCode::OK);

let unverified_create_model_definition_payload = CreateConnectionModelDefinitionRequest {
supported: Some(false),
path: "invoices".to_string(),
..create_model_definition_payload.clone()
};

let create_unverified_model_definition_response = server
.send_request::<Value, Value>(
"v1/connection-model-definitions",
Method::POST,
Some(&server.live_key),
Some(&serde_json::to_value(&unverified_create_model_definition_payload).unwrap()),
)
.await
.unwrap();

assert_eq!(
create_unverified_model_definition_response.code,
StatusCode::OK
);

// Test a passthrough API call for a verified connection model definition
let call_universal_api = server
.send_request_with_headers::<Value, Value>(
"v1/passthrough/customers",
Expand All @@ -101,13 +124,39 @@ async fn test_passthrough_api() {
),
)
.await
.expect("Failed to call universal API");
.expect("Failed to call passthrough API");

// assert_eq!(call_universal_api.code, StatusCode::OK);
assert_eq!(
call_universal_api.data,
serde_json::from_str::<Value>(&response_body).unwrap()
);

// Test a passthrough API call for an unverified connection model definition
let call_unverified_passthrough_endpoint = server
.send_request_with_headers::<Value, Value>(
"v1/passthrough/invoices",
Method::GET,
Some(&server.live_key),
None,
Some(
vec![
(CONTENT_TYPE.to_string(), "application/json".to_string()),
(
"x-integrationos-connection-key".to_string(),
connection.key.to_string(),
),
]
.into_iter()
.collect(),
),
)
.await
.expect("Failed to call the passthrough API");

assert_eq!(
call_unverified_passthrough_endpoint.code,
StatusCode::NOT_FOUND
);

mock.assert_async().await;
}
1 change: 1 addition & 0 deletions integrationos-api/tests/api_tests/test_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ impl TestServer {
),
to_common_model: Some("function mapCrudRequest(data) { return data; }".to_string()),
}),
supported: Some(true),
};

let res = self
Expand Down
1 change: 1 addition & 0 deletions integrationos-api/tests/api_tests/unified_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ async fn create_connection_model_definition(
responses: vec![],
is_default_crud_mapping: None,
mapping: Some(mapping.clone()),
supported: Some(true),
};

let create_model_definition_response = server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ pub struct ConnectionModelDefinition {

#[serde(flatten, default)]
pub record_metadata: RecordMetadata,

#[serde(default)]
pub supported: bool,
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)]
Expand Down
2 changes: 2 additions & 0 deletions integrationos-domain/src/service/client/caller_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ mod tests {
record_metadata: Default::default(),
is_default_crud_mapping: None,
mapping: None,
supported: true,
};

let client = Client::new();
Expand Down Expand Up @@ -244,6 +245,7 @@ mod tests {
record_metadata: Default::default(),
is_default_crud_mapping: None,
mapping: None,
supported: true,
};

let client = Client::new();
Expand Down
1 change: 1 addition & 0 deletions integrationos-event/tests/mock_destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub async fn seed_db(config: &EventCoreConfig, base_url: String) -> Id {
record_metadata: Default::default(),
is_default_crud_mapping: None,
mapping: None,
supported: true,
};

db.collection("connection-model-definitions")
Expand Down
9 changes: 8 additions & 1 deletion integrationos-unified/src/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use integrationos_domain::{
hashed_secret::HashedSecret,
id::{prefix::IdPrefix, Id},
prelude::{CryptoExt, MongoStore, TimedExt},
Connection, ErrorMeta, IntegrationOSError, Store,
ApplicationError, Connection, ErrorMeta, IntegrationOSError, Store,
};
use js_sandbox_ios::Script;
use moka::future::Cache;
Expand Down Expand Up @@ -973,6 +973,13 @@ impl UnifiedDestination {
Err(e) => Err(InternalError::connection_error(e.message().as_ref(), None)),
}?;

if !config.supported {
return Err(ApplicationError::not_found(
"Supported Connection Model Definition",
None,
));
}

let secret = self
.secrets_cache
.try_get_with_by_ref(&connection, async {
Expand Down

0 comments on commit c22d1af

Please sign in to comment.