Skip to content

Commit

Permalink
RJS-2846: Fix path configuration when using sync (#6753)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik authored Jun 25, 2024
1 parent 1b24533 commit 65af392
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* None

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None
* `path` option in the Realm configuration not being set when using a synced Realm. ([#6754](https://github.com/realm/realm-js/issues/6754), since v12.8.0). Note: if you have been using a custom path configuration with your synced Realm, this fix will lead to a re-download of its data in the custom path.

### Compatibility
* React Native >= v0.71.4
Expand Down
54 changes: 39 additions & 15 deletions integration-tests/tests/src/tests/sync/realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2111,21 +2111,45 @@ describe("Realmtest", () => {
describe("with sync", () => {
importAppBefore(buildAppConfig("with-anon").anonAuth().partitionBasedSync());

it("data is deleted on realm with custom path", function (this: RealmContext & AppContext) {
return this.app.logIn(Realm.Credentials.anonymous()).then(async (user) => {
const config = {
schema: [TestObjectWithPkSchema],
sync: { user, partitionValue: '"Lolo"' },
};
const realm = new Realm(config);
const path = realm.path;
realm.close();
const pathExistBeforeDelete = await fs.exists(path);
expect(pathExistBeforeDelete).to.be.true;
Realm.deleteFile(config);
const pathExistAfterDelete = await fs.exists(path);
expect(pathExistAfterDelete).to.be.false;
});
it("custom path gets correctly set", async function (this: RealmContext & AppContext) {
const user = await this.app.logIn(Realm.Credentials.anonymous());
const testPath = "custom_path.realm";
const pathSeparator = "/";
const defaultDir =
Realm.defaultPath.substring(0, Realm.defaultPath.lastIndexOf(pathSeparator) + 1) +
"mongodb-realm" +
pathSeparator +
this.app.id +
pathSeparator +
user.id +
pathSeparator;

const realm = await Realm.open({
path: testPath,
schema: [TestObjectWithPkSchema],
sync: { user, partitionValue: '"Lolo"' },
});
expect(realm.path).equals(defaultDir + testPath);
const path = realm.path;
realm.close();
const pathExistAfterInitialization = await fs.exists(path);
expect(pathExistAfterInitialization).to.be.true;
});

it("data is deleted on realm with custom path", async function (this: RealmContext & AppContext) {
const user = await this.app.logIn(Realm.Credentials.anonymous());
const config = {
schema: [TestObjectWithPkSchema],
sync: { user, partitionValue: '"Lolo"' },
};
const realm = new Realm(config);
const path = realm.path;
realm.close();
const pathExistBeforeDelete = await fs.exists(path);
expect(pathExistBeforeDelete).to.be.true;
Realm.deleteFile(config);
const pathExistAfterDelete = await fs.exists(path);
expect(pathExistAfterDelete).to.be.false;
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/realm/src/Realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export class Realm {
return Realm.normalizePath(config.path);
} else {
const bindingSyncConfig = toBindingSyncConfig(config.sync);
return config.sync.user.internal.pathForRealm(bindingSyncConfig, undefined);
return config.sync.user.internal.pathForRealm(bindingSyncConfig, config.path);
}
} else {
return Realm.normalizePath(config.path);
Expand Down

0 comments on commit 65af392

Please sign in to comment.