polymech pages
This commit is contained in:
parent
faa8554035
commit
4c5d8ad717
9
packages/polymech/CMakeLists.txt
Normal file
9
packages/polymech/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
add_library(polymech STATIC
|
||||
src/polymech.cpp
|
||||
)
|
||||
|
||||
target_include_directories(polymech
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(polymech PUBLIC postgres logger)
|
||||
16
packages/polymech/include/polymech/polymech.h
Normal file
16
packages/polymech/include/polymech/polymech.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace polymech {
|
||||
|
||||
/// Fetch all rows from the "pages" table.
|
||||
/// Returns raw JSON array string from Supabase.
|
||||
std::string fetch_pages();
|
||||
|
||||
/// Fetch pages with a specific select clause and optional filter.
|
||||
std::string fetch_pages(const std::string &select,
|
||||
const std::string &filter = "", int limit = 0);
|
||||
|
||||
} // namespace polymech
|
||||
17
packages/polymech/src/polymech.cpp
Normal file
17
packages/polymech/src/polymech.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "polymech/polymech.h"
|
||||
#include "logger/logger.h"
|
||||
#include "postgres/postgres.h"
|
||||
|
||||
|
||||
namespace polymech {
|
||||
|
||||
std::string fetch_pages() { return fetch_pages("*"); }
|
||||
|
||||
std::string fetch_pages(const std::string &select, const std::string &filter,
|
||||
int limit) {
|
||||
logger::debug("polymech::fetch_pages → select=" + select +
|
||||
" filter=" + filter + " limit=" + std::to_string(limit));
|
||||
return postgres::query("pages", select, filter, limit);
|
||||
}
|
||||
|
||||
} // namespace polymech
|
||||
34
tests/e2e/test_polymech_e2e.cpp
Normal file
34
tests/e2e/test_polymech_e2e.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <toml++/toml.hpp>
|
||||
|
||||
#include "logger/logger.h"
|
||||
#include "polymech/polymech.h"
|
||||
#include "postgres/postgres.h"
|
||||
#include "json/json.h"
|
||||
|
||||
// ── E2E: fetch pages from live Supabase ─────────────────────────────────
|
||||
|
||||
TEST_CASE("E2E: fetch all pages", "[e2e]") {
|
||||
logger::init("e2e-polymech");
|
||||
|
||||
// Load config
|
||||
auto cfg = toml::parse_file("config/postgres.toml");
|
||||
postgres::Config pg_cfg;
|
||||
pg_cfg.supabase_url = cfg["supabase"]["url"].value_or(std::string(""));
|
||||
pg_cfg.supabase_key =
|
||||
cfg["supabase"]["publishable_key"].value_or(std::string(""));
|
||||
|
||||
REQUIRE(!pg_cfg.supabase_url.empty());
|
||||
REQUIRE(!pg_cfg.supabase_key.empty());
|
||||
|
||||
postgres::init(pg_cfg);
|
||||
|
||||
auto result = polymech::fetch_pages();
|
||||
|
||||
// Should return valid JSON
|
||||
REQUIRE(json::is_valid(result));
|
||||
|
||||
// Should be an array (even if empty)
|
||||
REQUIRE(result.front() == '[');
|
||||
REQUIRE(result.back() == ']');
|
||||
}
|
||||
10
tests/unit/test_polymech.cpp
Normal file
10
tests/unit/test_polymech.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "polymech/polymech.h"
|
||||
#include "postgres/postgres.h"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
|
||||
// Unit test — no network required
|
||||
TEST_CASE("polymech::fetch_pages throws without init", "[polymech]") {
|
||||
// postgres::init has not been called, so fetch_pages should throw
|
||||
REQUIRE_THROWS(polymech::fetch_pages());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user