UNPKG

realm-object-server

Version:

Realm Object Server

88 lines 4.31 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const realms_1 = require("../realms"); const Logger_1 = require("../shared/Logger"); const TestServer_1 = require("../TestServer"); const Constants_1 = require("../shared/Constants"); describe("Server starting, shutting down and restarting", function () { const uploadAndClose = (realm) => __awaiter(this, void 0, void 0, function* () { yield realm.syncSession.uploadAllLocalChanges(); realm.close(); }); const server = new TestServer_1.TestServer(); after(() => __awaiter(this, void 0, void 0, function* () { if (server && server.started) { yield server.shutdown(); } })); const params = { logger: new Logger_1.ThrowingLogger(), defaultProviders: [{ type: "PasswordAuthProvider" }, { type: "AnonymousAuthProvider" }] }; it("should start without logging warnings or errors", () => __awaiter(this, void 0, void 0, function* () { yield server.start(params); })); it("should support opening the admin Realm from the inside", () => __awaiter(this, void 0, void 0, function* () { const adminRealm = yield server.openRealm(realms_1.AdminRealm); const users = adminRealm.objects("User"); chai_1.expect(users.length).to.be.at.least(1); const firstUser = users[0]; chai_1.expect(firstUser.userId).to.equal(Constants_1.Constants.AdminUserId); yield uploadAndClose(adminRealm); })); let regularUser; it("should support creating a user and opening a Realm from the outside", () => __awaiter(this, void 0, void 0, function* () { regularUser = yield Realm.Sync.User.login(server.url, Realm.Sync.Credentials.anonymous()); const url = (server.url + "/~/test-realm").replace("http://", "realm://"); const testRealm = yield Realm.open({ schema: [{ name: "TestClass", properties: {}, }], sync: { user: regularUser, fullSynchronization: true, url, } }); const objects = testRealm.objects("TestClass"); chai_1.expect(objects.length).to.be.equal(0); yield uploadAndClose(testRealm); })); it("should support opening the admin Realm from the outside", () => __awaiter(this, void 0, void 0, function* () { const adminCredentials = Realm.Sync.Credentials.adminToken(server.adminToken); const adminUser = Realm.Sync.User.login(server.url, adminCredentials); const url = (server.url + "/__admin").replace("http://", "realm://"); const adminRealm = yield Realm.open({ sync: { user: adminUser, fullSynchronization: true, url, } }); const users = adminRealm.objects("User"); chai_1.expect(users.length).to.be.at.least(1); const lastUser = users[users.length - 1]; chai_1.expect(lastUser.userId).to.equal(regularUser.identity); yield uploadAndClose(adminRealm); })); it("should shutdown without logging warnings or errors", () => __awaiter(this, void 0, void 0, function* () { yield server.shutdown(); })); it("should restart without logging warnings or errors", () => __awaiter(this, void 0, void 0, function* () { yield server.start(params); })); it("should shutdown again without logging warnings or errors", () => __awaiter(this, void 0, void 0, function* () { yield server.shutdown(); })); }); //# sourceMappingURL=server-shutdown-start-tests.spec.js.map