some test adjustments

This commit is contained in:
Sascha Kühl 2026-02-19 22:31:51 +01:00
parent 1deaab116c
commit cfd2a9c423
2 changed files with 45 additions and 19 deletions

View File

@ -482,10 +482,8 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
select_result = query::select({r.id, r.name, ri.ingredient_id, i.name}) select_result = query::select({r.id, r.name, ri.ingredient_id, i.name})
.from(r) .from(r)
.join_left(ri) .join_left(ri).on(r.id == ri.recipe_id)
.on(r.id == ri.recipe_id) .join_left(i).on(ri.ingredient_id == i.id)
.join_left(i)
.on(ri.ingredient_id == i.id)
.fetch_all(db); .fetch_all(db);
REQUIRE(result.is_ok()); REQUIRE(result.is_ok());

View File

@ -17,9 +17,7 @@ using namespace matador::test;
TEST_CASE_METHOD(SessionFixture, "Session insert test", "[session][insert]") { TEST_CASE_METHOD(SessionFixture, "Session insert test", "[session][insert]") {
const auto result = schema.attach<airplane>("airplanes") const auto result = schema.attach<airplane>("airplanes")
.and_then([this] { .and_then([this] { return schema.create(db); } );
return schema.create(db);
} );
REQUIRE(result.is_ok()); REQUIRE(result.is_ok());
auto plane = ses.insert(make_object<airplane>(1, "Boeing", "A380")); auto plane = ses.insert(make_object<airplane>(1, "Boeing", "A380"));
@ -35,9 +33,7 @@ TEST_CASE_METHOD(SessionFixture, "Session insert test", "[session][insert]") {
TEST_CASE_METHOD(SessionFixture, "Session update test", "[session][update]") { TEST_CASE_METHOD(SessionFixture, "Session update test", "[session][update]") {
const auto res = schema.attach<airplane>("airplanes") const auto res = schema.attach<airplane>("airplanes")
.and_then([this] { .and_then([this] { return schema.create(db); } );
return schema.create(db);
} );
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
auto result = ses.insert(make_object<airplane>(1, "Boeing", "A380")); auto result = ses.insert(make_object<airplane>(1, "Boeing", "A380"));
@ -131,9 +127,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find object with id", "[session
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects", "[session][find]") { TEST_CASE_METHOD(SessionFixture, "Use session to find all objects", "[session][find]") {
const auto result = schema.attach<airplane>("airplanes") const auto result = schema.attach<airplane>("airplanes")
.and_then([this] { .and_then([this] { return schema.create(db); } );
return schema.create(db);
} );
REQUIRE(result.is_ok()); REQUIRE(result.is_ok());
std::vector planes { std::vector planes {
@ -187,7 +181,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
auto all_authors = find_result.release(); auto all_authors = find_result.release();
std::vector<object_ptr<author>> author_repo; std::vector<object_ptr<author>> author_repo;
for (auto it = all_authors.begin(); it != all_authors.end(); ++it) { for (auto it = all_authors.begin(); it != all_authors.end(); ++it) {
REQUIRE(it->books.size() == 0); REQUIRE(it->books.empty());
author_repo.emplace_back(it.optr()); author_repo.emplace_back(it.optr());
} }
REQUIRE(author_repo.size() == 2); REQUIRE(author_repo.size() == 2);
@ -240,7 +234,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
auto all_departments = find_result.release(); auto all_departments = find_result.release();
std::vector<object_ptr<department>> departments_repo; std::vector<object_ptr<department>> departments_repo;
for (auto it = all_departments.begin(); it != all_departments.end(); ++it) { for (auto it = all_departments.begin(); it != all_departments.end(); ++it) {
std::cout << "department: " << it->name << " (employees: " << it->employees.size() << ")\n"; REQUIRE(it->employees.empty());
departments_repo.emplace_back(it.optr()); departments_repo.emplace_back(it.optr());
} }
REQUIRE(departments_repo.size() == 2); REQUIRE(departments_repo.size() == 2);
@ -268,10 +262,10 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
all_departments = find_result.release(); all_departments = find_result.release();
for (auto it = all_departments.begin(); it != all_departments.end(); ++it) { for (auto it = all_departments.begin(); it != all_departments.end(); ++it) {
std::cout << "department: " << it->name << " (id: " << it->id << ", employees: " << it->employees.size() << ")\n"; REQUIRE(it->employees.size() == 5);
for (const auto& emp : it->employees) { // for (const auto& emp : it->employees) {
std::cout << "\temployee: " << emp->first_name << " " << emp->last_name << "( " << emp->id << ")\n"; // REQUIRE(emp->dep->id == it->id);
} // }
} }
} }
@ -303,6 +297,40 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with many-to-m
make_object<recipe>(3, "Pineapple Pie", std::vector{ingredients[0], ingredients[1], ingredients[2]}) make_object<recipe>(3, "Pineapple Pie", std::vector{ingredients[0], ingredients[1], ingredients[2]})
}; };
for (auto &r: recipes) {
auto res = ses.insert(r);
REQUIRE(res.is_ok());
}
}
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with many-to-many lazy relation", "[session][find][many-to-many][lazy]") {
auto result = schema.attach<recipe>("recipes")
.and_then( [this] { return schema.attach<ingredient>("ingredients"); } )
.and_then([this] {
return schema.create(db);
} );
std::vector ingredients {
make_object<ingredient>(1, "Apple"),
make_object<ingredient>(2, "Strawberry"),
make_object<ingredient>(3, "Pineapple"),
make_object<ingredient>(4, "Sugar"),
make_object<ingredient>(5, "Flour"),
make_object<ingredient>(6, "Butter"),
make_object<ingredient>(7, "Beans")
};
for (auto &i: ingredients) {
auto res = ses.insert(i);
REQUIRE(res.is_ok());
}
std::vector recipes {
make_object<recipe>(1, "Apple Pie", std::vector{ingredients[0], ingredients[3], ingredients[4]}),
make_object<recipe>(2, "Strawberry Cake", std::vector{ingredients[5], ingredients[6]}),
make_object<recipe>(3, "Pineapple Pie", std::vector{ingredients[0], ingredients[1], ingredients[2]})
};
for (auto &r: recipes) { for (auto &r: recipes) {
auto res = ses.insert(r); auto res = ses.insert(r);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());