Skip to content

Commit

Permalink
Adding tests accessing app.currentUser from listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed May 2, 2024
1 parent a5e797c commit 600c23b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions integration-tests/tests/src/tests/sync/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { generatePartition } from "../../utils/generators";
import { baseUrl } from "../../hooks/import-app-before";
import { select } from "../../utils/select";
import { buildAppConfig } from "../../utils/build-app-config";
import { createPromiseHandle } from "../../utils/promise-handle";

const TestObjectSchema: Realm.ObjectSchema = {
primaryKey: "_id",
Expand Down Expand Up @@ -235,6 +236,50 @@ describe("App", () => {
expect(this.app.currentUser).to.be.null;
});

it("currentUser is available from an App listener", async function (this: Mocha.Context & AppContext & RealmContext) {

Check failure on line 239 in integration-tests/tests/src/tests/sync/app.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·AppContext·&` with `⏎······AppContext·&⏎·····`
expect(this.app.currentUser).to.be.null;

const credentials = Realm.Credentials.anonymous();

const handle = createPromiseHandle();
const listener = () => {
expect(this.app.currentUser).to.not.be.null;
this.app.removeListener(listener);
handle.resolve();
};

this.app.addListener(listener);
await this.app.logIn(credentials);

await this.app.currentUser?.logOut();
expect(this.app.currentUser).to.be.null;

await handle;
});

it.only("currentUser is available from a User listener", async function (this: Mocha.Context & AppContext & RealmContext) {

Check failure on line 260 in integration-tests/tests/src/tests/sync/app.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·AppContext·&` with `⏎······AppContext·&⏎·····`
expect(this.app.currentUser).to.be.null;

const credentials = Realm.Credentials.anonymous(false);
const user = await this.app.logIn(credentials);

const handle = createPromiseHandle();
const listener = () => {
expect(this.app.currentUser?.id).equals(user.id);
user.removeListener(listener);
handle.resolve();
};
user.addListener(listener);

// Refresh custom data to fire the listener
await user.refreshCustomData();

await user.logOut();
expect(this.app.currentUser).to.be.null;

await handle;
});

it("changeListeners works", async function (this: Mocha.Context & AppContext & RealmContext) {
let eventListenerCalls = 0;
expect(this.app).instanceOf(Realm.App);
Expand Down

0 comments on commit 600c23b

Please sign in to comment.