Skip to content

Commit

Permalink
fix: add org tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikmishra356 authored and Datron committed Jan 13, 2025
1 parent 040882d commit 4bb04a1
Show file tree
Hide file tree
Showing 18 changed files with 221 additions and 41 deletions.
5 changes: 3 additions & 2 deletions crates/context_aware_config/src/api/audit_log/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use actix_web::{
};
use chrono::{Duration, Utc};
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
use service_utils::service::types::DbConnection;
use service_utils::service::types::{DbConnection, Tenant};
use superposition_types::{
database::{models::cac::EventLog, schema::event_log::dsl as event_log},
result as superposition, PaginatedResponse,
Expand All @@ -21,11 +21,12 @@ pub fn endpoints() -> Scope {
async fn get_audit_logs(
filters: Query<AuditQueryFilters>,
db_conn: DbConnection,
tenant: Tenant,
) -> superposition::Result<Json<PaginatedResponse<EventLog>>> {
let DbConnection(mut conn) = db_conn;

let query_builder = |filters: &AuditQueryFilters| {
let mut builder = event_log::event_log.into_boxed();
let mut builder = event_log::event_log.schema_name(&tenant).into_boxed();
if let Some(tables) = filters.table.clone() {
builder = builder.filter(event_log::table_name.eq_any(tables.0));
}
Expand Down
1 change: 1 addition & 0 deletions crates/context_aware_config/src/api/context/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ fn r#move(
dsl::last_modified_at.eq(Utc::now().naive_utc()),
dsl::last_modified_by.eq(user.get_email()),
))
.schema_name(tenant)
.get_result(conn);

let contruct_new_ctx_with_old_overrides = |ctx: Context| Context {
Expand Down
1 change: 1 addition & 0 deletions crates/context_aware_config/src/api/context/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub fn validate_override_with_functions(
let keys_function_array: Vec<(String, Option<String>)> = dsl::default_configs
.filter(dsl::key.eq_any(default_config_keys))
.select((dsl::key, dsl::function_name))
.schema_name(tenant)
.load(conn)?;
let new_keys_function_array: Vec<(String, String)> = keys_function_array
.into_iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ async fn delete(
.schema_name(&tenant)
.execute(transaction_conn)?;

let default_config: DefaultConfig = dsl::default_configs
.filter(dsl::key.eq(&key))
.schema_name(&tenant)
.first::<DefaultConfig>(transaction_conn)?;
let description = default_config.description;
let change_reason = format!("Context Deleted by {}", user.get_email());

let deleted_row =
diesel::delete(dsl::default_configs.filter(dsl::key.eq(&key)))
.schema_name(&tenant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ CREATE INDEX IF NOT EXISTS idx_organisation_status ON superposition.organisation
CREATE INDEX IF NOT EXISTS idx_organisation_created_at ON superposition.organisations (created_at);
CREATE INDEX IF NOT EXISTS idx_organisation_admin_email ON superposition.organisations (admin_email);


INSERT INTO superposition.organisations(id, admin_email, name, created_by, updated_by) values(
'testorg',
'[email protected]',
'testorg',
'test_user',
'test_user'
);
5 changes: 5 additions & 0 deletions postman/cac/.variable.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"key": "token",
"value": "12345678",
"type": "default"
},
{
"key": "org_id",
"value": "testorg",
"type": "default"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getConfigAndTest(key, value) {
'x-org-id': `${org_id}`
}
};

console.log(getRequest)
pm.sendRequest(getRequest, (error, response) => {
if(error) {
console.log("Failed to fetch config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"value": "12345678",
"type": "default",
"enabled": true
},
{
"key": "org_id",
"value": "testorg",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
Expand Down
Loading

0 comments on commit 4bb04a1

Please sign in to comment.