add missing test to sdk config

pull/365/head
basdewachter 2016-10-04 15:36:36 +02:00
rodzic 6cd0202b41
commit b7e2142d2a
1 zmienionych plików z 122 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,122 @@
#!/usr/bin/env node
"use strict";
"use server";
require("c9/inline-mocha")(module);
if (typeof define === "undefined") {
require("amd-loader");
}
var sinon = require("sinon");
var assert = require("assert");
var vfsServer = require("./vfs.server");
var mockDb = {};
var mockCache = {
remove: sinon.stub()
};
var mockApi = {
section: sinon.stub().returns({
registerType: sinon.stub(),
post: sinon.stub(),
get: sinon.stub(),
delete: sinon.stub(),
all: sinon.stub()
}),
use: sinon.stub(),
ensureAdmin: sinon.stub(),
get: sinon.stub(),
authenticate: sinon.stub()
};
var mockRender = {
setTemplatePath: sinon.stub()
};
var mockConnect = {
getModule: sinon.stub().returns({
compress: sinon.stub()
})
};
describe(__filename, function() {
var server;
beforeEach(function (done) {
vfsServer({testing: true}, {
"db": mockDb,
"vfs.cache": mockCache,
"api": mockApi,
"connect.render": mockRender,
"connect": mockConnect,
}, function (err, _server) {
if (err) return done(err);
server = _server["vfs.server"];
done();
});
});
describe("handlePublish", function() {
beforeEach(function() {
mockCache.remove = sinon.stub();
});
describe("remove_member", function() {
it("Should kill the removed members VFS connection", function (done) {
var vfs = {
id: "9c123",
uid: "123"
};
var message = JSON.stringify({
action: "remove_member",
body: {
uid: "123"
}
});
server.handlePublish(vfs, message);
setTimeout(function() {
assert(mockCache.remove.calledWith(vfs.id));
done();
}, 150);
});
it("Should not kill the other members VFS connection", function (done) {
var vfs = {
id: "9c123",
uid: "456"
};
var message = JSON.stringify({
action: "remove_member",
body: {
uid: "123"
}
});
server.handlePublish(vfs, message);
setTimeout(function() {
assert.equal(mockCache.remove.callCount, 0);
done();
}, 150);
});
});
describe("update_member_access", function() {
it("Should kill the members VFS connection so they rejoin with the new access level", function (done) {
var vfs = {
id: "9c123",
uid: "123"
};
var message = JSON.stringify({
action: "update_member_access",
body: {
uid: "123"
}
});
server.handlePublish(vfs, message);
setTimeout(function() {
assert(mockCache.remove.calledWith(vfs.id));
done();
}, 150);
});
});
});
});