realm-object-server
Version:
89 lines • 4.3 kB
JavaScript
;
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 TestServer_1 = require("../TestServer");
const uuid = require("uuid");
const path = require("path");
const shared_1 = require("../shared");
describe("Server Open Realm Tests", function () {
let server;
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
server = new TestServer_1.TestServer();
yield server.start();
}));
afterEach(() => __awaiter(this, void 0, void 0, function* () {
if (server) {
yield server.shutdown();
}
}));
it("should be able to open a realm", () => __awaiter(this, void 0, void 0, function* () {
const realm = yield server.openRealm("/__admin");
chai_1.expect(realm.schema).to.not.be.empty;
realm.close();
}));
it("should be able to open a realm with admin is true", () => __awaiter(this, void 0, void 0, function* () {
const realm = yield server.openRealm("/__admin");
chai_1.expect(realm.syncSession.user.isAdmin).to.be.true;
realm.close();
}));
it("should be able to open non-existent realm", () => __awaiter(this, void 0, void 0, function* () {
const realm = yield server.openRealm(uuid.v4());
chai_1.expect(realm).to.be.ok;
chai_1.expect(realm.schema).to.be.empty;
realm.close();
}));
describe("local location tests", () => {
const openAndCheckLocation = (remotePath, expected, localPath = undefined) => __awaiter(this, void 0, void 0, function* () {
let realm;
try {
realm = yield server.openRealm({
remotePath,
localPath,
schema: []
});
chai_1.expect(realm.path).to.equal(path.join(server.dataPath, "realms", expected));
}
finally {
if (realm) {
realm.close();
}
}
});
describe("when local path is specified", () => {
it("stores in root location", () => __awaiter(this, void 0, void 0, function* () {
yield openAndCheckLocation(uuid.v4(), "foo-bar", "foo-bar");
}));
});
describe("when local path is not specified", () => {
it("stores in root location when localPath is not specified", () => __awaiter(this, void 0, void 0, function* () {
const remotePath = uuid.v4();
yield openAndCheckLocation(remotePath, remotePath + ".realm");
}));
it("trims leading slash when local path is not specified", () => __awaiter(this, void 0, void 0, function* () {
const remotePath = uuid.v4();
yield openAndCheckLocation("/" + remotePath, remotePath + ".realm");
}));
it("escapes inner slashes when local path is not specified", () => __awaiter(this, void 0, void 0, function* () {
const remotePath = uuid.v4() + "/foo/bar/something";
yield openAndCheckLocation(remotePath, remotePath.replace(/\//g, "%2F") + ".realm");
}));
});
});
describe("on client reset", () => {
it.skip("should close the Realm and not crash the server", () => __awaiter(this, void 0, void 0, function* () {
const realm = yield server.openRealm(uuid.v4());
yield shared_1.delay(100);
realm.syncSession._simulateError(211, "ClientReset");
yield shared_1.waitAsync(() => realm.isClosed);
}));
});
});
//# sourceMappingURL=server-open-realm-tests.spec.js.map