Support string type integer for oracle_document_id (#1448)

Fix #1420
This commit is contained in:
cyan317
2024-06-12 10:31:32 +01:00
committed by GitHub
parent 56ab943be5
commit 49b80c7ad8
9 changed files with 246 additions and 21 deletions

View File

@@ -31,6 +31,7 @@
#include <boost/json/parse.hpp>
#include <boost/json/value.hpp>
#include <fmt/core.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <ripple/protocol/AccountID.h>
#include <ripple/protocol/ErrorCodes.h>
@@ -604,3 +605,49 @@ TEST_F(RPCBaseTest, ToLowerModifier)
ASSERT_TRUE(spec.process(passingInput4)); // empty str no problem
ASSERT_EQ(passingInput4.at("str").as_string(), "");
}
TEST_F(RPCBaseTest, ToNumberModifier)
{
auto const spec = RpcSpec{
{"str", ToNumber{}},
};
auto passingInput = json::parse(R"({ "str": [] })");
ASSERT_TRUE(spec.process(passingInput));
passingInput = json::parse(R"({ "str2": "TesT" })");
ASSERT_TRUE(spec.process(passingInput));
passingInput = json::parse(R"([])");
ASSERT_TRUE(spec.process(passingInput));
passingInput = json::parse(R"({ "str": "123" })");
ASSERT_TRUE(spec.process(passingInput));
ASSERT_EQ(passingInput.at("str").as_int64(), 123);
auto failingInput = json::parse(R"({ "str": "ok" })");
ASSERT_FALSE(spec.process(failingInput));
failingInput = json::parse(R"({ "str": "123.123" })");
ASSERT_FALSE(spec.process(failingInput));
}
TEST_F(RPCBaseTest, CustomModifier)
{
testing::StrictMock<testing::MockFunction<MaybeError(json::value & value, std::string_view)>> mockModifier;
auto const customModifier = CustomModifier{mockModifier.AsStdFunction()};
auto const spec = RpcSpec{
{"str", customModifier},
};
EXPECT_CALL(mockModifier, Call).WillOnce(testing::Return(MaybeError{}));
auto passingInput = json::parse(R"({ "str": "sss" })");
ASSERT_TRUE(spec.process(passingInput));
passingInput = json::parse(R"({ "strNotExist": 123 })");
ASSERT_TRUE(spec.process(passingInput));
// not a json object
passingInput = json::parse(R"([])");
ASSERT_TRUE(spec.process(passingInput));
}