Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas794 committed Oct 9, 2024
1 parent 487370f commit 87c3d0e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
31 changes: 31 additions & 0 deletions tests/integration_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,34 @@ fn integration_delete_whole_database_query() -> Result<(), Tperrors> {

Ok(())
}

#[test]
fn integration_delete_expanded_query_with_column_as_condition() -> Result<(), Tperrors> {
// We are gonna try to simulate a
// DELETE FROM clientes WHERE (Id>=2 AND Edad>=30 AND 1=1);"
// this is gonna return rows with id 1,2, 5, 8 according sandboxSQL.

let file_name = String::from("delete_expanded_query_with_column_as_condition");
let delete = Delete;
let mut table = Table::<Cursor<&[u8]>>::mock(file_name, common::csv_data_as_bytes());
let condition = Some("Id>=2 AND Edad>=30 AND 1=1");

match delete.execute_delete_mock(&mut table, condition) {
Ok(mocked_file) => {
let expected_output_vectors = vec![
"Id,Nombre,Apellido,Edad,Correo electronico,Profesion", // ofc we are gonna have the header.
"1,Juan,Perez,32,jperez@gmail.com,medico",
"2,Maria,Gomez,28,mgomez@gmail.com,abogado",
"5,Luis,Martínez,29,lmartinez@gmail.com,profesor",
"8,Lucía,Ramos,26,lramos@gmail.com,psicóloga",
];

for (i, line_read) in mocked_file.lines().enumerate() {
let line = line_read.unwrap();
assert_eq!(line, expected_output_vectors[i]);
}
}
Err(e) => return Err(e),
}
Ok(())
}
45 changes: 44 additions & 1 deletion tests/integration_select.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::io::Cursor;
use std::{io::Cursor, vec};

use tp_individual::{
consults::select::Select, errors::tperrors::Tperrors, handler_tables::table::Table,
sorter::sort::SortMethod,
};

pub mod common;
Expand Down Expand Up @@ -211,3 +212,45 @@ fn integration_select_advanced_query_with_nested_conditions_and_spaced_condition

Ok(())
}

#[test]
fn integration_select_advanced_query_sorting_with_columns_not_present_on_the_query(
) -> Result<(), Tperrors> {
// the idea is to simulate a
// SELECT Nombre, Apellido FROM clientes WHERE Id>8 ORDER BY Edad;
// this should return the following rows: Paula Hernandez, Andres Garcia and Diego Navarro

let file_name =
String::from("query_select_advanced_query_sorting_with_columns_not_present_on_the_query");
let select = Select;
let mut table = Table::<Cursor<&[u8]>>::mock(file_name, common::csv_data_as_bytes());

let columns: Vec<String> = Vec::from(vec!["Nombre".to_string(), "Apellido".to_string()]);
let condition = Some("Id>8");
let sort_method = Some(vec![SortMethod {
by_column: "Edad".to_string(),
ascending: true,
}]);

match select.execute_select_mock(&mut table, columns, condition, sort_method) {
Ok(vector_of_lines) => {
let expected_output = vec![
vec!["Nombre", "Apellido"],
vec!["Paula", "Hernández"],
vec!["Diego", "Navarro"],
];

for (i, row) in vector_of_lines.iter().enumerate() {
let expected_row = &expected_output[i];

for (j, cell) in row.iter().enumerate() {
assert_eq!(cell, &expected_row[j]);
}
}
}
Err(e) => {
return Err(e);
}
}
Ok(())
}

0 comments on commit 87c3d0e

Please sign in to comment.