nothing changed, still 3/6
This commit is contained in:
@@ -4,8 +4,9 @@ use tonic;
|
|||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
use common::proto::multieko2::tables_data::GetTableDataCountRequest;
|
use common::proto::multieko2::tables_data::GetTableDataCountRequest;
|
||||||
use server::tables_data::handlers::get_table_data_count;
|
use server::tables_data::handlers::get_table_data_count;
|
||||||
|
|
||||||
use crate::common::setup_test_db;
|
use crate::common::setup_test_db;
|
||||||
|
use chrono::Utc;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
#[fixture]
|
#[fixture]
|
||||||
async fn pool() -> PgPool {
|
async fn pool() -> PgPool {
|
||||||
@@ -25,17 +26,30 @@ async fn test_returns_correct_count(#[future] pool: PgPool) {
|
|||||||
let pool = pool.await;
|
let pool = pool.await;
|
||||||
let mut tx = pool.begin().await.unwrap();
|
let mut tx = pool.begin().await.unwrap();
|
||||||
|
|
||||||
|
// Clean up existing profiles
|
||||||
|
sqlx::query!("DELETE FROM profiles WHERE name LIKE 'test_profile%'")
|
||||||
|
.execute(&mut *tx)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Setup profile and table definition
|
// Setup profile and table definition
|
||||||
|
let profile_name = format!("test_profile_{}", Utc::now().timestamp());
|
||||||
let profile_id = sqlx::query_scalar!(
|
let profile_id = sqlx::query_scalar!(
|
||||||
"INSERT INTO profiles (name) VALUES ('test_profile') RETURNING id"
|
"INSERT INTO profiles (name) VALUES ($1) RETURNING id",
|
||||||
|
profile_name
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *tx)
|
.fetch_one(&mut *tx)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO table_definitions (profile_id, table_name) VALUES ($1, 'adresar')",
|
r#"
|
||||||
profile_id
|
INSERT INTO table_definitions (profile_id, table_name, columns)
|
||||||
|
VALUES ($1, $2, $3)
|
||||||
|
"#,
|
||||||
|
profile_id,
|
||||||
|
"adresar",
|
||||||
|
json!({}) // Provide a valid JSON object for columns
|
||||||
)
|
)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await
|
.await
|
||||||
@@ -56,7 +70,7 @@ async fn test_returns_correct_count(#[future] pool: PgPool) {
|
|||||||
|
|
||||||
// Call handler
|
// Call handler
|
||||||
let request = GetTableDataCountRequest {
|
let request = GetTableDataCountRequest {
|
||||||
profile_name: "test_profile".to_string(),
|
profile_name,
|
||||||
table_name: "adresar".to_string(),
|
table_name: "adresar".to_string(),
|
||||||
};
|
};
|
||||||
let response = get_table_data_count(&pool, request).await.unwrap();
|
let response = get_table_data_count(&pool, request).await.unwrap();
|
||||||
@@ -78,16 +92,29 @@ async fn test_excludes_deleted_records(#[future] pool: PgPool) {
|
|||||||
let pool = pool.await;
|
let pool = pool.await;
|
||||||
let mut tx = pool.begin().await.unwrap();
|
let mut tx = pool.begin().await.unwrap();
|
||||||
|
|
||||||
|
// Clean up existing profiles
|
||||||
|
sqlx::query!("DELETE FROM profiles WHERE name LIKE 'test_profile%'")
|
||||||
|
.execute(&mut *tx)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let profile_name = format!("test_profile_{}", Utc::now().timestamp());
|
||||||
let profile_id = sqlx::query_scalar!(
|
let profile_id = sqlx::query_scalar!(
|
||||||
"INSERT INTO profiles (name) VALUES ('test_profile') RETURNING id"
|
"INSERT INTO profiles (name) VALUES ($1) RETURNING id",
|
||||||
|
profile_name
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *tx)
|
.fetch_one(&mut *tx)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO table_definitions (profile_id, table_name) VALUES ($1, 'adresar')",
|
r#"
|
||||||
profile_id
|
INSERT INTO table_definitions (profile_id, table_name, columns)
|
||||||
|
VALUES ($1, $2, $3)
|
||||||
|
"#,
|
||||||
|
profile_id,
|
||||||
|
"adresar",
|
||||||
|
json!({}) // Provide a valid JSON object for columns
|
||||||
)
|
)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await
|
.await
|
||||||
@@ -106,7 +133,7 @@ async fn test_excludes_deleted_records(#[future] pool: PgPool) {
|
|||||||
tx.commit().await.unwrap();
|
tx.commit().await.unwrap();
|
||||||
|
|
||||||
let request = GetTableDataCountRequest {
|
let request = GetTableDataCountRequest {
|
||||||
profile_name: "test_profile".to_string(),
|
profile_name,
|
||||||
table_name: "adresar".to_string(),
|
table_name: "adresar".to_string(),
|
||||||
};
|
};
|
||||||
let response = get_table_data_count(&pool, request).await.unwrap();
|
let response = get_table_data_count(&pool, request).await.unwrap();
|
||||||
@@ -135,8 +162,16 @@ async fn test_table_not_in_profile(#[future] pool: PgPool) {
|
|||||||
let pool = pool.await;
|
let pool = pool.await;
|
||||||
let mut tx = pool.begin().await.unwrap();
|
let mut tx = pool.begin().await.unwrap();
|
||||||
|
|
||||||
|
// Clean up existing profiles
|
||||||
|
sqlx::query!("DELETE FROM profiles WHERE name LIKE 'test_profile%'")
|
||||||
|
.execute(&mut *tx)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let profile_name = format!("test_profile_{}", Utc::now().timestamp());
|
||||||
let profile_id = sqlx::query_scalar!(
|
let profile_id = sqlx::query_scalar!(
|
||||||
"INSERT INTO profiles (name) VALUES ('test_profile') RETURNING id"
|
"INSERT INTO profiles (name) VALUES ($1) RETURNING id",
|
||||||
|
profile_name
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *tx)
|
.fetch_one(&mut *tx)
|
||||||
.await
|
.await
|
||||||
@@ -146,7 +181,7 @@ async fn test_table_not_in_profile(#[future] pool: PgPool) {
|
|||||||
tx.commit().await.unwrap();
|
tx.commit().await.unwrap();
|
||||||
|
|
||||||
let request = GetTableDataCountRequest {
|
let request = GetTableDataCountRequest {
|
||||||
profile_name: "test_profile".to_string(),
|
profile_name,
|
||||||
table_name: "adresar".to_string(),
|
table_name: "adresar".to_string(),
|
||||||
};
|
};
|
||||||
let result = get_table_data_count(&pool, request).await;
|
let result = get_table_data_count(&pool, request).await;
|
||||||
@@ -175,16 +210,29 @@ async fn test_empty_table_count(#[future] pool: PgPool) {
|
|||||||
let pool = pool.await;
|
let pool = pool.await;
|
||||||
let mut tx = pool.begin().await.unwrap();
|
let mut tx = pool.begin().await.unwrap();
|
||||||
|
|
||||||
|
// Clean up existing profiles
|
||||||
|
sqlx::query!("DELETE FROM profiles WHERE name LIKE 'empty_test%'")
|
||||||
|
.execute(&mut *tx)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let profile_name = format!("empty_test_{}", Utc::now().timestamp());
|
||||||
let profile_id = sqlx::query_scalar!(
|
let profile_id = sqlx::query_scalar!(
|
||||||
"INSERT INTO profiles (name) VALUES ('empty_test') RETURNING id"
|
"INSERT INTO profiles (name) VALUES ($1) RETURNING id",
|
||||||
|
profile_name
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *tx)
|
.fetch_one(&mut *tx)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO table_definitions (profile_id, table_name) VALUES ($1, 'adresar')",
|
r#"
|
||||||
profile_id
|
INSERT INTO table_definitions (profile_id, table_name, columns)
|
||||||
|
VALUES ($1, $2, $3)
|
||||||
|
"#,
|
||||||
|
profile_id,
|
||||||
|
"adresar",
|
||||||
|
json!({}) // Provide a valid JSON object for columns
|
||||||
)
|
)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await
|
.await
|
||||||
@@ -193,7 +241,7 @@ async fn test_empty_table_count(#[future] pool: PgPool) {
|
|||||||
tx.commit().await.unwrap();
|
tx.commit().await.unwrap();
|
||||||
|
|
||||||
let request = GetTableDataCountRequest {
|
let request = GetTableDataCountRequest {
|
||||||
profile_name: "empty_test".to_string(),
|
profile_name,
|
||||||
table_name: "adresar".to_string(),
|
table_name: "adresar".to_string(),
|
||||||
};
|
};
|
||||||
let response = get_table_data_count(&pool, request).await.unwrap();
|
let response = get_table_data_count(&pool, request).await.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user