Skip to content

Commit

Permalink
Reintroduce query-specific tests for UUID (with necessary addition to…
Browse files Browse the repository at this point in the history
… get_type_of).
  • Loading branch information
steffenagger committed Jan 14, 2021
1 parent 9fe66ec commit 40073c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/js_object_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
41 changes: 21 additions & 20 deletions tests/js/realm-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]});
Expand Down

0 comments on commit 40073c2

Please sign in to comment.