query/test/orm/query/SchemaTest.cpp

42 lines
1.3 KiB
C++

#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][belongsto]") {
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");
}