added SchemaTest, fixed bug in class shipment, added contains methods to class schema and enabled some tests

This commit is contained in:
2026-01-09 09:32:47 +01:00
parent 930b9d1aa4
commit ac53526a27
7 changed files with 102 additions and 25 deletions
+1
View File
@@ -28,6 +28,7 @@ add_executable(OrmTests
utils/auto_reset_event.cpp
utils/auto_reset_event.hpp
query/GeneratorTests.cpp
query/SchemaTest.cpp
)
target_link_libraries(OrmTests matador-orm matador-core Catch2::Catch2WithMain)
+42
View File
@@ -0,0 +1,42 @@
#include <catch2/catch_test_macros.hpp>
#include "matador/query/schema.hpp"
#include "../../models/shipment.hpp"
using namespace matador::query;
using namespace matador::test;
TEST_CASE("Test schema with belongs-to to has-many relation" "[schema][relation][belongs_to]") {
schema repo;
auto result = repo.attach<package>("packages")
.and_then( [&repo] { return repo.attach<shipment>("shipments"); } );
REQUIRE(result.is_ok());
REQUIRE(repo.size() == 2);
REQUIRE(repo.contains<shipment>());
REQUIRE(repo.contains<package>());
auto it = repo.find<shipment>();
REQUIRE(it != repo.end());
REQUIRE(it->second.name() == "shipments");
it = repo.find<package>();
REQUIRE(it != repo.end());
REQUIRE(it->second.name() == "packages");
}
TEST_CASE("Test schema with has-many to belongs-to relation" "[schema][relation][has_many]") {
schema repo;
auto result = repo.attach<shipment>("shipments")
.and_then( [&repo] { return repo.attach<package>("packages"); } );
REQUIRE(result.is_ok());
REQUIRE(repo.size() == 2);
REQUIRE(repo.contains<shipment>());
REQUIRE(repo.contains<package>());
auto it = repo.find<shipment>();
REQUIRE(it != repo.end());
REQUIRE(it->second.name() == "shipments");
it = repo.find<package>();
REQUIRE(it != repo.end());
REQUIRE(it->second.name() == "packages");
}