Skip to content

Commit

Permalink
Fix types and add a test for flexible sync client reset (#4703)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Duncalf authored Jul 4, 2022
1 parent 223178b commit 8261202
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ x.x.x Release notes (yyyy-MM-dd)
* Adding response type checking to the realm-app-importer. ([#4688](https://github.com/realm/realm-js/pull/4688))
* Updated integration test app to target Android SDK 31 ([#4686](https://github.com/realm/realm-js/pull/4686))
* Enabled debugging Realm C++ code in integration test app ([#4696](https://github.com/realm/realm-js/pull/4696))
* Fixed types for flexible sync client reset and added a test ([#4702](https://github.com/realm/realm-js/pull/4702))

10.19.3 Release notes (2022-6-27)
=============================================================
Expand Down
31 changes: 31 additions & 0 deletions integration-tests/tests/src/tests/sync/flexible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Realm, { BSON, ClientResetMode, FlexibleSyncConfiguration, SessionStopPol
import { authenticateUserBefore, importAppBefore, openRealmBeforeEach } from "../../hooks";
import { DogSchema, IPerson, PersonSchema } from "../../schemas/person-and-dog-with-object-ids";
import { closeAndReopenRealm, closeRealm } from "../../utils/close-realm";
import { expectClientResetError } from "../../utils/expect-sync-error";

const FlexiblePersonSchema = { ...PersonSchema, properties: { ...PersonSchema.properties, nonQueryable: "string?" } };

Expand Down Expand Up @@ -1637,5 +1638,35 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () {
await expect(action()).to.not.be.rejected;
});
});

describe("client reset handling", function () {
it("handles manual client resets with flexible sync enabled", async function (this: RealmContext) {
await expectClientResetError(
{
schema: [FlexiblePersonSchema, DogSchema],
sync: {
_sessionStopPolicy: SessionStopPolicy.Immediately,
flexible: true,
user: this.user,
clientReset: {
mode: ClientResetMode.Manual,
},
},
},
this.user,
(realm) => {
const session = realm.syncSession;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore calling undocumented method _simulateError
session._simulateError(211, "Simulate Client Reset", "realm::sync::ProtocolError", false); // 211 -> diverging histories
},
(error) => {
expect(error.name).to.equal("ClientReset");
expect(error.message).to.equal("Simulate Client Reset");
expect(error.code).to.equal(211);
},
);
});
});
});
});
2 changes: 1 addition & 1 deletion integration-tests/tests/src/utils/expect-sync-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { expect } from "chai";
import { openRealm } from "./open-realm";

type Error = Realm.SyncError | (Realm.ClientResetError & { message: string });
type Error = Realm.SyncError | (Realm.ClientResetError & { message: string; code: number });

/**
* Open a new Realm and perform an action, expecting a sync error to occur. Will
Expand Down
6 changes: 1 addition & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ declare namespace Realm {
validateCallback?: SSLVerifyCallback;
}

enum ClientResetModeManualOnly {
Manual = "manual",
}

enum ClientResetMode {
Manual = "manual",
DiscardLocal = "discardLocal",
Expand Down Expand Up @@ -176,7 +172,7 @@ declare namespace Realm {
interface FlexibleSyncConfiguration extends BaseSyncConfiguration {
flexible: true;
partitionValue?: never;
clientReset?: ClientResetConfiguration<ClientResetModeManualOnly>;
clientReset?: ClientResetConfiguration<ClientResetMode.Manual>;
/**
* Optional object to configure the setup of an initial set of flexible
* sync subscriptions to be used when opening the Realm. If this is specified,
Expand Down

0 comments on commit 8261202

Please sign in to comment.