-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests of support types of partition values #3671
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2021 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
'use strict'; | ||
|
||
/* global navigator, WorkerNavigator */ | ||
|
||
const require_method = require; | ||
|
||
const Realm = require("realm"); | ||
const TestCase = require("./asserts"); | ||
const AppConfig = require("./support/testConfig"); | ||
const { ObjectId, UUID } = Realm.BSON; | ||
|
||
const PvIntDog = { | ||
name: "Dog", | ||
primaryKey: "_id", | ||
properties: { | ||
_id: "objectId?", // NOTE: this needs to be changed to non-optional in the docker image. | ||
breed: "string?", | ||
name: "string", | ||
realm_id: "int?" | ||
} | ||
}; | ||
|
||
const PvStringDog = { | ||
name: "Dog", | ||
primaryKey: "_id", | ||
properties: { | ||
_id: "objectId?", // NOTE: this needs to be changed to non-optional in the docker image. | ||
breed: "string?", | ||
name: "string", | ||
realm_id: "string?" | ||
} | ||
}; | ||
|
||
const PvUuidDog = { | ||
name: "Dog", | ||
primaryKey: "_id", | ||
properties: { | ||
_id: "objectId?", // NOTE: this needs to be changed to non-optional in the docker image. | ||
breed: "string?", | ||
name: "string", | ||
realm_id: "uuid?" | ||
} | ||
}; | ||
|
||
const PvObjectidDog = { | ||
name: "Dog", | ||
primaryKey: "_id", | ||
properties: { | ||
_id: "objectId?", // NOTE: this needs to be changed to non-optional in the docker image. | ||
breed: "string?", | ||
name: "string", | ||
realm_id: "objectId?" | ||
} | ||
}; | ||
|
||
module.exports = { | ||
async testPvInt() { | ||
let app = new Realm.App(AppConfig.pvIntAppConfig); | ||
|
||
let credentials = Realm.Credentials.anonymous(); | ||
let user = await app.logIn(credentials); | ||
const realmConfig = { | ||
schema: [PvIntDog], | ||
sync: { | ||
user: user, | ||
partitionValue: 42, | ||
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() | ||
} | ||
}; | ||
|
||
Realm.deleteFile(realmConfig); | ||
let realm1 = await Realm.open(realmConfig); | ||
realm1.write(() => { | ||
realm1.create("Dog", { "_id": new ObjectId(), name: "King" }); | ||
}); | ||
|
||
await realm1.syncSession.uploadAllLocalChanges(); | ||
TestCase.assertEqual(realm1.objects("Dog").length, 1); | ||
realm1.close(); | ||
|
||
Realm.deleteFile(realmConfig); | ||
|
||
let realm2 = await Realm.open(realmConfig); | ||
await realm2.syncSession.downloadAllServerChanges(); | ||
|
||
let dogs = realm2.objects("Dog"); | ||
TestCase.assertEqual(dogs.length, 1); | ||
|
||
realm2.close(); | ||
await user.logOut(); | ||
}, | ||
|
||
async testPvString() { | ||
let app = new Realm.App(AppConfig.pvStringAppConfig); | ||
|
||
let credentials = Realm.Credentials.anonymous(); | ||
let user = await app.logIn(credentials); | ||
const realmConfig = { | ||
schema: [PvStringDog], | ||
sync: { | ||
user: user, | ||
partitionValue: "42", | ||
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() | ||
} | ||
}; | ||
|
||
Realm.deleteFile(realmConfig); | ||
let realm1 = await Realm.open(realmConfig); | ||
realm1.write(() => { | ||
realm1.create("Dog", { "_id": new ObjectId(), name: "King" }); | ||
}); | ||
|
||
await realm1.syncSession.uploadAllLocalChanges(); | ||
TestCase.assertEqual(realm1.objects("Dog").length, 1); | ||
realm1.close(); | ||
|
||
Realm.deleteFile(realmConfig); | ||
|
||
let realm2 = await Realm.open(realmConfig); | ||
await realm2.syncSession.downloadAllServerChanges(); | ||
|
||
let dogs = realm2.objects("Dog"); | ||
TestCase.assertEqual(dogs.length, 1); | ||
|
||
realm2.close(); | ||
await user.logOut(); | ||
}, | ||
|
||
/*async testUuidString() { | ||
fronck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let app = new Realm.App(AppConfig.pvUuidAppConfig); | ||
|
||
let credentials = Realm.Credentials.anonymous(); | ||
let user = await app.logIn(credentials); | ||
const realmConfig = { | ||
schema: [PvUuidDog], | ||
sync: { | ||
user: user, | ||
partitionValue: new UUID(), | ||
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() | ||
} | ||
}; | ||
|
||
Realm.deleteFile(realmConfig); | ||
let realm1 = await Realm.open(realmConfig); | ||
realm1.write(() => { | ||
realm1.create("Dog", { "_id": new ObjectId(), name: "King" }); | ||
}); | ||
|
||
await realm1.syncSession.uploadAllLocalChanges(); | ||
TestCase.assertEqual(realm1.objects("Dog").length, 1); | ||
realm1.close(); | ||
|
||
Realm.deleteFile(realmConfig); | ||
|
||
let realm2 = await Realm.open(realmConfig); | ||
await realm2.syncSession.downloadAllServerChanges(); | ||
|
||
let dogs = realm2.objects("Dog"); | ||
TestCase.assertEqual(dogs.length, 1); | ||
|
||
realm2.close(); | ||
await user.logOut(); | ||
},*/ | ||
|
||
async testObjectidString() { | ||
let app = new Realm.App(AppConfig.pvObjectidAppConfig); | ||
|
||
let credentials = Realm.Credentials.anonymous(); | ||
let user = await app.logIn(credentials); | ||
const realmConfig = { | ||
schema: [PvObjectidDog], | ||
sync: { | ||
user: user, | ||
partitionValue: new ObjectId(), | ||
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() | ||
} | ||
}; | ||
|
||
Realm.deleteFile(realmConfig); | ||
let realm1 = await Realm.open(realmConfig); | ||
realm1.write(() => { | ||
realm1.create("Dog", { "_id": new ObjectId(), name: "King" }); | ||
}); | ||
|
||
await realm1.syncSession.uploadAllLocalChanges(); | ||
TestCase.assertEqual(realm1.objects("Dog").length, 1); | ||
realm1.close(); | ||
|
||
Realm.deleteFile(realmConfig); | ||
|
||
let realm2 = await Realm.open(realmConfig); | ||
await realm2.syncSession.downloadAllServerChanges(); | ||
|
||
let dogs = realm2.objects("Dog"); | ||
TestCase.assertEqual(dogs.length, 1); | ||
|
||
realm2.close(); | ||
await user.logOut(); | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/mongodb/auth_providers/anon-user.json → ...ommon-tests/auth_providers/anon-user.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/mongodb/auth_providers/api-key.json → .../common-tests/auth_providers/api-key.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ngodb/auth_providers/custom-function.json → ...tests/auth_providers/custom-function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ongodb/auth_providers/local-userpass.json → ...-tests/auth_providers/local-userpass.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/mongodb/config.json → tests/mongodb/common-tests/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"values": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"values": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"values": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"values": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"values": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"values": {} | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/mongodb/functions/authFunc/config.json → ...mmon-tests/functions/authFunc/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"can_evaluate": {}, | ||
"id": "6037be866c917b9bd04fb551", | ||
"id": "606453b13d297b2d11f1d03e", | ||
"name": "authFunc", | ||
"private": false | ||
} |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] I'd actually really like it if we can introduce an env variable that changes the local port we forward to the Docker image (e.g., MONGODB_REALM_PORT=9091).
makeAppConfig()
seems to support this already usingprocess.env.MONGODB_REALM_PORT
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support the suggestion, but for testing on iOS/Android the task becomes less trivial, as the port would have to be passed to the test-app & Android need to have the port reversed. So I think out of scope, just now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's other places in the script files that we provide a default if the environment variable isn't set, though.