Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Unit tests for import and export.

  • Loading branch information...
commit 56386085ba4d36ae188d5149014b4bba878ec5c2 1 parent 712e38c
@phipla authored
View
4 lib/manager.js
@@ -147,6 +147,7 @@ function syncOrAsyncCall(f, args, callback) {
callback(res);
} else {
if (typeof res !== "undefined") {
+
callback(null, res);
}
}
@@ -169,7 +170,6 @@ Manager.prototype.importData = function(route, data, callback) {
}
Manager.prototype.exportData = function(route, data, callback) {
-
if (route.export) {
if (data instanceof Array) {
var l = data.length;
@@ -510,6 +510,6 @@ Manager.prototype.add = function(collection, handler, options) {
handler: handler,
validate: options && options.validate,
import: options && options.import,
- export: options && options.exportda
+ export: options && options.export
});
}
View
8 lib/store.js
@@ -25,19 +25,19 @@ var Store = module.exports = function(options) {
};
Store.prototype.read = function(req, res) {
- res.send([]);
+ res(null, []);
};
Store.prototype.insert = function(req, res) {
- res.send(req);
+ res(null, req);
};
Store.prototype.delete = function(req, res) {
- res.send(req);
+ res(null, req);
};
Store.prototype.update = function(req, res) {
- res.send(req);
+ res(null, req);
};
/**
View
4 test/unit/lib/mock.js
@@ -64,7 +64,9 @@ Socket.prototype = {
this.flags.message = message;
this.flags.data = data;
this.operations.push(this.flags);
- this.callback(null, this.flags);
+
+ if (!this.flags.broadcast)
+ this.callback(null, this.flags);
this.flags = {};
},
join: function(room) {
View
121 test/unit/manager.test.js
@@ -652,7 +652,126 @@ vows.describe("Manager")
"Socket leaves the room": function(err, message) {
assert.equal(message.leave, 'collections/Test3/"foo":1,"bar":1');
}
- }
+ },
+
+ "import, returns": {
+ topic: function() {
+ var manager = new Manager(new mock.Io);
+ manager.add("Test", new mock.Store({}, this.callback), {
+ import: function(data) {
+ return {
+ t2: data.t
+ };
+ }
+ });
+
+ var socket = new mock.Socket(this.callback);
+
+ manager.handleCollection(socket, {
+ operation: "insert",
+ collection: "Test",
+ key: 1,
+ data: { t: "Test" }
+ });
+ },
+
+ "Insert operation was called": function(err, operation) {
+ assert.equal(operation.req.operation, "insert");
+ },
+
+ "Data is OK": function(err, operation) {
+ assert.strictEqual(operation.req.data.t2, "Test");
+ }
+ },
+
+ "import, callback": {
+ topic: function() {
+ var manager = new Manager(new mock.Io);
+ manager.add("Test", new mock.Store({}, this.callback), {
+ import: function(data, callback) {
+ callback(null, {
+ t2: data.t
+ });
+ }
+ });
+
+ var socket = new mock.Socket(this.callback);
+
+ manager.handleCollection(socket, {
+ operation: "insert",
+ collection: "Test",
+ key: 1,
+ data: { t: "Test" }
+ });
+ },
+
+ "Insert operation was called": function(err, operation) {
+ assert.equal(operation.req.operation, "insert");
+ },
+
+ "Data is OK": function(err, operation) {
+ assert.strictEqual(operation.req.data.t2, "Test");
+ }
+ },
+ "export, returns": {
+ topic: function() {
+ var manager = new Manager(new mock.Io());
+ manager.add("Test", new collection.Store(), {
+ export: function(data) {
+ return {
+ t2: data.t
+ };
+ }
+ });
+
+ var socket = new mock.Socket(this.callback);
+ manager.handleCollection(socket, {
+ operation: "insert",
+ collection: "Test",
+ key: 1,
+ data: { t: "Test" }
+ });
+ },
+
+ "Insert operation was called": function(err, operation) {
+ assert.equal(operation.data.operation, "insert");
+ },
+
+ "Data is OK": function(err, operation) {
+ assert.strictEqual(operation.data.data.t2, "Test");
+ }
+ },
+
+ "export, callback": {
+ topic: function() {
+ var manager = new Manager(new mock.Io);
+ manager.add("Test", new collection.Store(), {
+ export: function(data, callback) {
+ callback(null, {
+ t2: data.t
+ });
+ }
+ });
+
+ var socket = new mock.Socket(this.callback);
+
+ manager.handleCollection(socket, {
+ operation: "insert",
+ collection: "Test",
+ key: 1,
+ data: { t: "Test" }
+ });
+ },
+
+ "Insert operation was called": function(err, operation) {
+ assert.equal(operation.data.operation, "insert");
+ },
+
+ "Data is OK": function(err, operation) {
+ assert.strictEqual(operation.data.data.t2, "Test");
+ }
+ },
+
}).export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.