Skip to content

Commit

Permalink
Add back test for asymmetric object with string API
Browse files Browse the repository at this point in the history
  • Loading branch information
dacharyc committed Jan 8, 2024
1 parent 3f411a6 commit c8ded95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
7 changes: 6 additions & 1 deletion examples/cpp/asymmetric/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/realm/realm-cpp.git
GIT_TAG 8eba9728ea535a6cd78beaef37ed6d22b73fe889
)
FetchContent_Declare(
json
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
)

FetchContent_MakeAvailable(Catch2 cpprealm)
FetchContent_MakeAvailable(Catch2 cpprealm json)

add_executable(examples-asymmetric
asymmetric-sync.cpp
)

target_link_libraries(examples-asymmetric PRIVATE Catch2::Catch2WithMain)
target_link_libraries(examples-asymmetric PRIVATE cpprealm)
target_link_libraries(examples-asymmetric PRIVATE nlohmann_json::nlohmann_json)
36 changes: 10 additions & 26 deletions examples/cpp/asymmetric/asymmetric-sync.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <catch2/catch_test_macros.hpp>
#include <cpprealm/sdk.hpp>
#include <nlohmann/json.hpp>

static const std::string APP_ID = "cpp-tester-uliix";

Expand Down Expand Up @@ -43,38 +44,21 @@ TEST_CASE("Asymmetric object example", "[write][sync]") {
// :snippet-end:
realm.get_sync_session()->wait_for_upload_completion().get();

// This test is currently commented out because the SDK has removed the
// exposed Core headers that gave it access to a BSON library.
// See PR https://github.com/realm/realm-cpp/pull/123/
// Per Lee, a separate project will create a C++ SDK BSON library, but in
// the meantime, I'll need to use some other library to make this test work.
// I need to figure out how to create BSON strings in C++ and pass them
// instead of using realm::bson::Bson for the params.
// TODO: Figure out what library to use and how to make this test/example work.
#if 0
SECTION("Test asymmetric object has persisted") {
// Check that the asymmetric data got inserted
// Because we don't have MongoClient, we have to use a function
nlohmann::json jsonOid;
jsonOid.push_back(oid.to_string());
std::string jsonOidString = jsonOid.dump();
auto getAsymmetricDataResult =
user.call_function("getAsymmetricSyncDataBeta",
realm::bson::BsonArray({realm::bson::BsonDocument{
{"_id", oid.to_string()}}}))
.get();
user.call_function("getAsymmetricSyncData", jsonOidString).get();
CHECK(getAsymmetricDataResult);
auto asymmetricDataBsonArray =
realm::bson::BsonArray(*getAsymmetricDataResult);
CHECK(asymmetricDataBsonArray.size() == 1);
CHECK(realm::bson::BsonDocument(asymmetricDataBsonArray[0])["_id"]
.
operator realm::ObjectId()
.to_string() == oid.to_string());
// Delete the asymmetric data to clean up after the test
auto asymmetricDataObject =
nlohmann::json::parse(getAsymmetricDataResult.value());
CHECK(asymmetricDataObject[0]["_id"]["$oid"] == oid.to_string());
// Delete the asymmetric data to clean up after the test
auto deleteAsymmetricDataResult =
user.call_function("deleteAsymmetricSyncDataBeta",
realm::bson::BsonArray({realm::bson::BsonDocument{
{"_id", oid.to_string()}}}))
.get();
user.call_function("deleteAsymmetricSyncData", jsonOidString).get();
CHECK(deleteAsymmetricDataResult);
}
#endif
}

0 comments on commit c8ded95

Please sign in to comment.