api, cli, web, tsting env and some rust fixes

This commit is contained in:
dal 2025-04-29 10:37:37 -06:00
parent 0c5c9eafff
commit 19eea365a4
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
6 changed files with 69 additions and 61 deletions

View File

@ -13,6 +13,7 @@ on:
jobs:
test:
runs-on: blacksmith-16vcpu-ubuntu-2204
environment: testing
# Service container for Redis (needed by the setup action)
services:
@ -42,9 +43,9 @@ jobs:
# Use hardcoded default values and secrets
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres
REDIS_URL: redis://localhost:6379 # Connect to the Redis service container
JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret
JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value
SUPABASE_URL: http://127.0.0.1:54321 # Default local URL
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret
SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value
RUST_LOG: debug # Or adjust as needed
# Sensitive values from Secrets

View File

@ -13,6 +13,7 @@ on:
jobs:
test:
runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested
environment: testing # Add the environment key
# Service container for Redis (needed by the setup action)
services:
@ -42,9 +43,9 @@ jobs:
# Use hardcoded default values and secrets
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres
REDIS_URL: redis://localhost:6379 # Connect to the Redis service container
JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret
JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value
SUPABASE_URL: http://127.0.0.1:54321 # Default local URL
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret
SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value
RUST_LOG: debug # Or adjust as needed
# Add any other environment variables your CLI tests might require

View File

@ -13,6 +13,7 @@ on:
jobs:
test:
runs-on: blacksmith-16vcpu-ubuntu-2204
environment: testing
# Service container for Redis (needed by the setup action and potentially API)
services:
@ -56,9 +57,9 @@ jobs:
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres
POOLER_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres # Assuming pooler uses same DB
REDIS_URL: redis://localhost:6379 # Use localhost as it runs on the runner accessing the service
JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret
JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value
SUPABASE_URL: http://127.0.0.1:54321 # Default local URL
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret
SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value
# Non-sensitive / Default values
ENVIRONMENT: development
@ -104,7 +105,7 @@ jobs:
NEXT_PUBLIC_URL: http://localhost:3000 # Assuming default URL for the app itself
# Use Supabase details - default URL and secret anon key
NEXT_PUBLIC_SUPABASE_URL: http://127.0.0.1:54321 # Default local URL
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_ANON_KEY }} # Use secret
NEXT_PUBLIC_SUPABASE_ANON_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODIzNDMwOTZ9.7UIsMFfHYKxH7bUJCRfxd6lr7CSXGF7UxtZQO10FMMo' # Use default local value
NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # Assuming WS connects to API
# Pass any other required NEXT_PUBLIC_ variables

View File

@ -3,12 +3,14 @@ use chrono::Utc;
use database::enums::{AssetPermissionRole, AssetType, Verification};
use database::models::{Chat, Collection, DashboardFile, MetricFile};
use database::schema::{chats, collections, dashboard_files, metric_files};
use database::types::metric_yml::{
BarAndLineAxis, BarLineChartConfig, BaseChartConfig, ChartConfig,
};
use database::types::{DashboardYml, MetricYml, VersionHistory};
use database::types::metric_yml::{BaseChartConfig, BarAndLineAxis, BarLineChartConfig, ChartConfig};
use diesel_async::RunQueryDsl;
use indexmap;
use uuid::Uuid;
use std::collections::HashMap;
use uuid::Uuid;
use crate::common::db::TestDb;
use crate::common::permissions::PermissionTestHelpers;
@ -18,13 +20,10 @@ pub struct AssetTestHelpers;
impl AssetTestHelpers {
/// Creates a test metric file
pub async fn create_test_metric(
test_db: &TestDb,
name: &str,
) -> Result<MetricFile> {
pub async fn create_test_metric(test_db: &TestDb, name: &str) -> Result<MetricFile> {
let mut conn = test_db.diesel_conn().await?;
let metric_id = Uuid::new_v4();
// Create a simple metric content
let content = MetricYml {
name: name.to_string(),
@ -34,11 +33,15 @@ impl AssetTestHelpers {
chart_config: create_default_chart_config(),
dataset_ids: Vec::new(),
};
let metric_file = MetricFile {
id: metric_id,
name: format!("{}-{}", test_db.test_id, name),
file_name: format!("{}-{}.yml", test_db.test_id, name.to_lowercase().replace(" ", "_")),
file_name: format!(
"{}-{}.yml",
test_db.test_id,
name.to_lowercase().replace(" ", "_")
),
content,
verification: Verification::Verified,
evaluation_obj: None,
@ -56,34 +59,35 @@ impl AssetTestHelpers {
data_metadata: None,
public_password: None,
};
diesel::insert_into(metric_files::table)
.values(&metric_file)
.execute(&mut conn)
.await?;
Ok(metric_file)
}
/// Creates a test dashboard file
pub async fn create_test_dashboard(
test_db: &TestDb,
name: &str,
) -> Result<DashboardFile> {
pub async fn create_test_dashboard(test_db: &TestDb, name: &str) -> Result<DashboardFile> {
let mut conn = test_db.diesel_conn().await?;
let dashboard_id = Uuid::new_v4();
// Create a simple dashboard content
let content = DashboardYml {
name: name.to_string(),
description: Some(format!("Test dashboard description for {}", name)),
rows: Vec::new(),
};
let dashboard_file = DashboardFile {
id: dashboard_id,
name: format!("{}-{}", test_db.test_id, name),
file_name: format!("{}-{}.yml", test_db.test_id, name.to_lowercase().replace(" ", "_")),
file_name: format!(
"{}-{}.yml",
test_db.test_id,
name.to_lowercase().replace(" ", "_")
),
content,
filter: None,
organization_id: test_db.organization_id,
@ -97,23 +101,20 @@ impl AssetTestHelpers {
version_history: VersionHistory(HashMap::new()),
public_password: None,
};
diesel::insert_into(dashboard_files::table)
.values(&dashboard_file)
.execute(&mut conn)
.await?;
Ok(dashboard_file)
}
/// Creates a test collection
pub async fn create_test_collection(
test_db: &TestDb,
name: &str,
) -> Result<Collection> {
pub async fn create_test_collection(test_db: &TestDb, name: &str) -> Result<Collection> {
let mut conn = test_db.diesel_conn().await?;
let collection_id = Uuid::new_v4();
let collection = Collection {
id: collection_id,
name: format!("{}-{}", test_db.test_id, name),
@ -125,23 +126,20 @@ impl AssetTestHelpers {
deleted_at: None,
organization_id: test_db.organization_id,
};
diesel::insert_into(collections::table)
.values(&collection)
.execute(&mut conn)
.await?;
Ok(collection)
}
/// Creates a test chat
pub async fn create_test_chat(
test_db: &TestDb,
title: &str,
) -> Result<Chat> {
pub async fn create_test_chat(test_db: &TestDb, title: &str) -> Result<Chat> {
let mut conn = test_db.diesel_conn().await?;
let chat_id = Uuid::new_v4();
let chat = Chat {
id: chat_id,
title: format!("{}-{}", test_db.test_id, title),
@ -156,16 +154,17 @@ impl AssetTestHelpers {
public_expiry_date: None,
most_recent_file_id: None,
most_recent_file_type: None,
most_recent_version_number: None,
};
diesel::insert_into(chats::table)
.values(&chat)
.execute(&mut conn)
.await?;
Ok(chat)
}
/// Creates a test metric with owner permission
pub async fn create_test_metric_with_permission(
test_db: &TestDb,
@ -174,7 +173,7 @@ impl AssetTestHelpers {
role: AssetPermissionRole,
) -> Result<MetricFile> {
let metric = Self::create_test_metric(test_db, name).await?;
// Add permission
PermissionTestHelpers::create_user_permission(
test_db,
@ -182,11 +181,12 @@ impl AssetTestHelpers {
AssetType::MetricFile,
user_id,
role,
).await?;
)
.await?;
Ok(metric)
}
/// Creates a test dashboard with owner permission
pub async fn create_test_dashboard_with_permission(
test_db: &TestDb,
@ -195,7 +195,7 @@ impl AssetTestHelpers {
role: AssetPermissionRole,
) -> Result<DashboardFile> {
let dashboard = Self::create_test_dashboard(test_db, name).await?;
// Add permission
PermissionTestHelpers::create_user_permission(
test_db,
@ -203,11 +203,12 @@ impl AssetTestHelpers {
AssetType::DashboardFile,
user_id,
role,
).await?;
)
.await?;
Ok(dashboard)
}
/// Creates a test collection with owner permission
pub async fn create_test_collection_with_permission(
test_db: &TestDb,
@ -216,7 +217,7 @@ impl AssetTestHelpers {
role: AssetPermissionRole,
) -> Result<Collection> {
let collection = Self::create_test_collection(test_db, name).await?;
// Add permission
PermissionTestHelpers::create_user_permission(
test_db,
@ -224,11 +225,12 @@ impl AssetTestHelpers {
AssetType::Collection,
user_id,
role,
).await?;
)
.await?;
Ok(collection)
}
/// Creates a test chat with owner permission
pub async fn create_test_chat_with_permission(
test_db: &TestDb,
@ -237,7 +239,7 @@ impl AssetTestHelpers {
role: AssetPermissionRole,
) -> Result<Chat> {
let chat = Self::create_test_chat(test_db, title).await?;
// Add permission
PermissionTestHelpers::create_user_permission(
test_db,
@ -245,8 +247,9 @@ impl AssetTestHelpers {
AssetType::Chat,
user_id,
role,
).await?;
)
.await?;
Ok(chat)
}
}
@ -281,4 +284,4 @@ fn create_default_chart_config() -> ChartConfig {
bar_show_total_at_top: None,
line_group_type: None,
})
}
}

View File

@ -93,6 +93,7 @@ impl TestDb {
created_at: Utc::now(),
updated_at: Utc::now(),
deleted_at: None,
payment_required: false,
};
let mut conn = self.diesel_conn().await?;

View File

@ -41,6 +41,7 @@ impl TestSetup {
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
deleted_at: None,
payment_required: false,
};
// Create user with specified role