From 40073c2959aa74ad089f20f30e08c87f4e859bac Mon Sep 17 00:00:00 2001 From: Steffen Agger Date: Thu, 14 Jan 2021 12:24:11 +0100 Subject: [PATCH] Reintroduce query-specific tests for UUID (with necessary addition to get_type_of). --- src/js_object_accessor.hpp | 3 +++ tests/js/realm-tests.js | 41 +++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index 39513f2c2f..ae5bcbd260 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -190,6 +190,9 @@ class NativeAccessor { if (Value::is_object_id(m_ctx, value)) { return type_ObjectId; } + if (Value::is_uuid(m_ctx, value)) { + return type_UUID; + } if (Value::is_decimal128(m_ctx, value)) { return type_Decimal; } diff --git a/tests/js/realm-tests.js b/tests/js/realm-tests.js index a9da04f8a8..3d721433d4 100644 --- a/tests/js/realm-tests.js +++ b/tests/js/realm-tests.js @@ -2086,26 +2086,27 @@ module.exports = { realm.close(); }, - // testUUIDQuery: function() { - // const realm = new Realm({schema: [schemas.UUIDObject]}); - - // const uuidStr = "7c203d29-3f00-4395-86de-2b7f9b78d8e9"; - // const uuid = new UUID(uuidStr); - // realm.write(() => { - // realm.create(schemas.UUIDObject.name, { id: new UUID }); // extra data - // realm.create(schemas.UUIDObject.name, { id: uuid }); - // realm.create(schemas.UUIDObject.name, { id: new UUID }); // extra data - // }); - // const allResults = realm.objects(schemas.UUIDObject.name); - // const filtered = allResults.filtered("id == $0", uuid); - // TestCase.assertTrue(allResults.length > 1, "Realm contains more than targeted result."); - // TestCase.assertEqual(filtered.length, 1, "Found ONE result filtered on id."); - // TestCase.assertTrue(filtered[0] instanceof UUID, "Object from query is instance of UUID."); - // TestCase.assertEqual(filtered[0].id.toString(), uuidStr, "Roundtrip string representation equals predefined input string."); - - // // "cleanup" - // realm.close(); - // }, + testUUIDQuery: function() { + const realm = new Realm({schema: [schemas.UUIDObject]}); + + const uuidStr = "7c203d29-3f00-4395-86de-2b7f9b78d8e9"; + const uuid = new UUID(uuidStr); + realm.write(() => { + realm.create(schemas.UUIDObject.name, { id: new UUID }); // padded extra data + realm.create(schemas.UUIDObject.name, { id: uuid }); // actual test data + realm.create(schemas.UUIDObject.name, { id: new UUID }); // padded extra data + }); + const allResults = realm.objects(schemas.UUIDObject.name); + const filtered = allResults.filtered("id == $0", uuid); + const obj = filtered[0]; + TestCase.assertTrue(allResults.length > 1, "Realm contains more than targeted result."); + TestCase.assertEqual(filtered.length, 1, "Found ONE result filtered on id."); + TestCase.assertTrue(obj.id instanceof UUID, "Object id from query is instance of UUID."); + TestCase.assertEqual(obj.id.toString(), uuidStr, "Roundtrip string representation equals predefined input string."); + + // "cleanup" + realm.close(); + }, testUUIDPkSingleQuery: function() { const realm = new Realm({schema: [schemas.UUIDPkObject]});