大更新
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "adminive/adapters/nlohmann_json.hpp"
|
||||
#include "adminive/http.hpp"
|
||||
#include <cassert>
|
||||
#include "adminive_test.hpp"
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
@@ -265,39 +265,39 @@ int main() {
|
||||
using namespace safety_test;
|
||||
Root_Config root;
|
||||
auto update = adminive::apply_frontend_patch<Json>(root, Json{{"child", Json{{"editable_value", 8}}}});
|
||||
assert(update.success);
|
||||
assert(root.child.editable_value == 8);
|
||||
assert(root.child.required_value == 3);
|
||||
ADMINIVE_CHECK(update.success);
|
||||
ADMINIVE_CHECK(root.child.editable_value == 8);
|
||||
ADMINIVE_CHECK(root.child.required_value == 3);
|
||||
update = adminive::apply_frontend_patch<Json>(root, Json{{"child", Json{{"locked_value", 9}}}});
|
||||
assert(!update.success);
|
||||
assert(update.field_errors.contains("child.locked_value"));
|
||||
assert(root.child.locked_value == 2);
|
||||
ADMINIVE_CHECK(!update.success);
|
||||
ADMINIVE_CHECK(update.field_errors.contains("child.locked_value"));
|
||||
ADMINIVE_CHECK(root.child.locked_value == 2);
|
||||
Root_Config created;
|
||||
update = adminive::apply_frontend_create<Json>(created, Json{{"child", Json{{"editable_value", 5}}}});
|
||||
assert(!update.success);
|
||||
assert(update.field_errors.contains("child.required_value"));
|
||||
ADMINIVE_CHECK(!update.success);
|
||||
ADMINIVE_CHECK(update.field_errors.contains("child.required_value"));
|
||||
const auto root_form = adminive::to_amis_form_schema<Json>(root, adminive::describe_edit_view<Root_Config>());
|
||||
assert(root_form.at("body").at(0).at("body").at(2).at("visibleOn") == "${child.editable_value > 0}");
|
||||
ADMINIVE_CHECK(root_form.at("body").at(0).at("body").at(2).at("visibleOn") == "${child.editable_value > 0}");
|
||||
Numeric_Config numeric;
|
||||
update = adminive::apply_frontend_patch<Json>(numeric, Json{{"signed_value", 1.5}});
|
||||
assert(!update.success);
|
||||
ADMINIVE_CHECK(!update.success);
|
||||
update = adminive::apply_frontend_patch<Json>(numeric, Json{{"unsigned_value", -1}});
|
||||
assert(!update.success);
|
||||
ADMINIVE_CHECK(!update.success);
|
||||
update = adminive::apply_frontend_patch<Json>(numeric, Json{{"signed_value", std::numeric_limits<std::uint64_t>::max()}});
|
||||
assert(!update.success);
|
||||
ADMINIVE_CHECK(!update.success);
|
||||
Optional_Config optional;
|
||||
const auto optional_form = adminive::to_amis_form_schema<Json>(optional, adminive::describe_edit_view<Optional_Config>());
|
||||
assert(optional_form.at("body").at(0).at("clearable") == true);
|
||||
assert(optional_form.at("body").at(1).at("clearable") == true);
|
||||
ADMINIVE_CHECK(optional_form.at("body").at(0).at("clearable") == true);
|
||||
ADMINIVE_CHECK(optional_form.at("body").at(1).at("clearable") == true);
|
||||
update = adminive::apply_frontend_patch<Json>(optional, Json{{"count", nullptr}, {"note", nullptr}});
|
||||
assert(update.success);
|
||||
assert(!optional.count);
|
||||
assert(!optional.note);
|
||||
ADMINIVE_CHECK(update.success);
|
||||
ADMINIVE_CHECK(!optional.count);
|
||||
ADMINIVE_CHECK(!optional.note);
|
||||
Multi_Error_Config multi;
|
||||
update = adminive::apply_frontend_patch<Json>(multi, Json{{"first", -1}, {"second", -2}});
|
||||
assert(!update.success);
|
||||
assert(update.field_errors.contains("first"));
|
||||
assert(update.field_errors.contains("second"));
|
||||
ADMINIVE_CHECK(!update.success);
|
||||
ADMINIVE_CHECK(update.field_errors.contains("first"));
|
||||
ADMINIVE_CHECK(update.field_errors.contains("second"));
|
||||
Runtime_Config runtime;
|
||||
bool rollback_called{};
|
||||
adminive::Resource_Transaction<Runtime_Model> transaction;
|
||||
@@ -305,39 +305,39 @@ int main() {
|
||||
throw std::runtime_error("external commit failed");
|
||||
};
|
||||
transaction.rollback = [&rollback_called](const Runtime_Model& original, const adminive::Request_Context&) {
|
||||
assert(original.value == 1);
|
||||
ADMINIVE_CHECK(original.value == 1);
|
||||
rollback_called = true;
|
||||
};
|
||||
adminive::Resource_Service<Runtime_Config, Json> service(runtime, "/runtime", std::move(transaction));
|
||||
const auto response = service.update_response(R"({"value":7})");
|
||||
assert(response.status == 500);
|
||||
assert(runtime.value() == 1);
|
||||
assert(rollback_called);
|
||||
ADMINIVE_CHECK(response.status == 500);
|
||||
ADMINIVE_CHECK(runtime.value() == 1);
|
||||
ADMINIVE_CHECK(rollback_called);
|
||||
Device_Config devices;
|
||||
update = adminive::apply_frontend_patch<Json>(devices, Json{{"device", Json{{"type", "serial"}, {"baud_rate", 9600}}}});
|
||||
assert(update.success);
|
||||
assert(std::get<Serial_Device>(devices.device).port == "COM1");
|
||||
assert(std::get<Serial_Device>(devices.device).baud_rate == 9600);
|
||||
ADMINIVE_CHECK(update.success);
|
||||
ADMINIVE_CHECK(std::get<Serial_Device>(devices.device).port == "COM1");
|
||||
ADMINIVE_CHECK(std::get<Serial_Device>(devices.device).baud_rate == 9600);
|
||||
update = adminive::apply_frontend_patch<Json>(devices, Json{{"device", Json{{"type", "network"}, {"host", "10.0.0.1"}, {"port", 7000}}}});
|
||||
assert(update.success);
|
||||
assert(std::holds_alternative<Network_Device>(devices.device));
|
||||
ADMINIVE_CHECK(update.success);
|
||||
ADMINIVE_CHECK(std::holds_alternative<Network_Device>(devices.device));
|
||||
update = adminive::apply_frontend_patch<Json>(devices, Json{{"device", Json{{"type", "token"}, {"token", "abc"}}}});
|
||||
assert(update.success);
|
||||
assert(std::holds_alternative<Token_Device>(devices.device));
|
||||
assert(std::get<Token_Device>(devices.device).token == "abc");
|
||||
ADMINIVE_CHECK(update.success);
|
||||
ADMINIVE_CHECK(std::holds_alternative<Token_Device>(devices.device));
|
||||
ADMINIVE_CHECK(std::get<Token_Device>(devices.device).token == "abc");
|
||||
bool invalid_name_rejected{};
|
||||
try {
|
||||
static_cast<void>(adminive::to_descriptor_json<Json, Invalid_Name_Config>());
|
||||
} catch(const std::invalid_argument&) {
|
||||
invalid_name_rejected = true;
|
||||
}
|
||||
assert(invalid_name_rejected);
|
||||
ADMINIVE_CHECK(invalid_name_rejected);
|
||||
bool conflict_rejected{};
|
||||
try {
|
||||
static_cast<void>(adminive::to_descriptor_json<Json, Conflict_Config>());
|
||||
} catch(const std::invalid_argument&) {
|
||||
conflict_rejected = true;
|
||||
}
|
||||
assert(conflict_rejected);
|
||||
ADMINIVE_CHECK(conflict_rejected);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user