"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var promise_utils_1 = require("../src/promise-utils");
var nodejs_1 = require("../src/nodejs");
var universal_1 = require("../src/universal");
var wamp_client_fs_1 = require("../src/wamp-client-fs");
var implementation_suite_1 = require("./implementation-suite");
describe("the wamp client filesystem implementation", function () {
    var wampServer;
    function server() {
        return nodejs_1.wampServerOverFs(new universal_1.MemoryFileSystem(undefined, [implementation_suite_1.ignoredDir, implementation_suite_1.ignoredFile]), 3000);
    }
    function getFS() {
        return Promise.resolve(new universal_1.WampClientFileSystem("ws://127.0.0.1:3000", nodejs_1.wampRealm));
    }
    function getInitedFS() {
        return getFS().then(function (fs) { return fs.init(); });
    }
    var eventMatcherOptions = {
        retries: 25,
        interval: 50,
        noExtraEventsGrace: 150,
        timeout: 1500
    };
    beforeEach(function () { return server().then(function (clientAndServer) { return wampServer = clientAndServer; }); });
    afterEach(function () {
        wampServer.router.close();
        var errMsg = "WAMP connection hasn't been closed after the previous test";
        return promise_utils_1.retryPromise(function () { return wampServer.connection.isConnected ? Promise.reject(errMsg) : Promise.resolve(); }, { interval: 100, retries: 10 });
    });
    implementation_suite_1.assertFileSystemContract(getInitedFS, eventMatcherOptions);
    describe("when not inited", function () {
        it("fails on each CRUD method", function () {
            return Promise.all([
                chai_1.expect(getFS().then(function (fs) { return fs.saveFile(implementation_suite_1.fileName, implementation_suite_1.content); })).to.eventually.be.rejectedWith(wamp_client_fs_1.noConnectionError),
                chai_1.expect(getFS().then(function (fs) { return fs.deleteFile(implementation_suite_1.fileName); })).to.eventually.be.rejectedWith(wamp_client_fs_1.noConnectionError),
                chai_1.expect(getFS().then(function (fs) { return fs.deleteDirectory(implementation_suite_1.dirName); })).to.eventually.be.rejectedWith(wamp_client_fs_1.noConnectionError),
                chai_1.expect(getFS().then(function (fs) { return fs.ensureDirectory(implementation_suite_1.dirName); })).to.eventually.be.rejectedWith(wamp_client_fs_1.noConnectionError),
                chai_1.expect(getFS().then(function (fs) { return fs.loadTextFile(implementation_suite_1.fileName); })).to.eventually.be.rejectedWith(wamp_client_fs_1.noConnectionError),
                chai_1.expect(getFS().then(function (fs) { return fs.loadDirectoryTree(); })).to.eventually.be.rejectedWith(wamp_client_fs_1.noConnectionError)
            ]);
        });
    });
});
//# sourceMappingURL=wamp-client-fs.spec.js.map