diff --git a/tests/integration_delete.rs b/tests/integration_delete.rs index bc329c0..a6e71af 100644 --- a/tests/integration_delete.rs +++ b/tests/integration_delete.rs @@ -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::>::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(()) +} diff --git a/tests/integration_select.rs b/tests/integration_select.rs index 060a248..8a8174c 100644 --- a/tests/integration_select.rs +++ b/tests/integration_select.rs @@ -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; @@ -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::>::mock(file_name, common::csv_data_as_bytes()); + + let columns: Vec = 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(()) +}