THRIFT-1967 Node.js tests don't cover all services
Patch: Henrique Mendonça

align with the tests we have for the original JS and C++ libraries
it also corrects two small bugs on the test server
and add nodejs to travis and make check
diff --git a/test/nodejs/client.js b/test/nodejs/client.js
index 8e19b88..ea2cc38 100644
--- a/test/nodejs/client.js
+++ b/test/nodejs/client.js
@@ -31,7 +31,7 @@
   assert(false, err);
 });
 
- // deepEqual doesn't work for binary64
+ // deepEqual doesn't work with fields using node-int64
 function checkRecursively(map1, map2) {
   if (typeof map1 !== 'function' && typeof map2 !== 'function') {
     if (!map1 || typeof map1 !== 'object') {
@@ -47,7 +47,7 @@
 
 client.testVoid(function(err, response) {
   assert( ! err);
-  assert.equal(undefined, response);
+  assert.equal(undefined, response); //void
 });
 
 
@@ -83,6 +83,18 @@
   assert( ! err);
   assert.equal(1, response);
 });
+client.testByte(0, function(err, response) {
+  assert( ! err);
+  assert.equal(0, response);
+});
+client.testByte(-1, function(err, response) {
+  assert( ! err);
+  assert.equal(-1, response);
+});
+client.testByte(-127, function(err, response) {
+  assert( ! err);
+  assert.equal(-127, response);
+});
 
 client.testI32(-1, function(err, response) {
   assert( ! err);
@@ -93,12 +105,10 @@
   assert( ! err);
   assert.equal(5, response);
 });
-
 client.testI64(-5, function(err, response) {
   assert( ! err);
   assert.equal(-5, response);
 });
-
 client.testI64(-34359738368, function(err, response) {
   assert( ! err);
   assert.equal(-34359738368, response);
@@ -108,7 +118,6 @@
   assert( ! err);
   assert.equal(-5.2098523, response);
 });
-
 client.testDouble(7.012052175215044, function(err, response) {
   assert( ! err);
   assert.equal(7.012052175215044, response);
@@ -126,6 +135,7 @@
   checkRecursively(out, response);
 });
 
+
 var out2 = new ttypes.Xtruct2();
 out2.byte_thing = 1;
 out2.struct_thing = out;
@@ -135,6 +145,7 @@
   checkRecursively(out2, response);
 });
 
+
 var mapout = {};
 for (var i = 0; i < 5; ++i) {
   mapout[i] = i-10;
@@ -144,27 +155,103 @@
   assert.deepEqual(mapout, response);
 });
 
-/*
- * TODO: testSet, testList, testEnum, testTypedef, testMapMap, testInsanity
- */
 
-
-client.testException('ApplicationException', function(err, response) {
-  //assert.equal('ApplicationException', err);
-  assert( ! response);
-});
-
-client.testException('Xception', function(err, response) {
-  assert.equal('Xception', err.message);
-  assert( ! response);
-});
-
-client.testException('success', function(err, response) {
+var mapTestInput = {
+  "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",
+  "longValue":stringTest, stringTest:"long key"
+};
+client.testStringMap(mapTestInput, function(err, response) {
   assert( ! err);
-  //assert.equal('success', response);
+  assert.deepEqual(mapTestInput, response);
 });
 
 
+var setTestInput = [1,2,3];
+client.testSet(setTestInput, function(err, response) {
+  assert( ! err);
+  assert.deepEqual(setTestInput, response);
+});
+client.testList(setTestInput, function(err, response) {
+  assert( ! err);
+  assert.deepEqual(setTestInput, response);
+});
+
+client.testEnum(ttypes.Numberz.ONE, function(err, response) {
+  assert( ! err);
+  assert.equal(ttypes.Numberz.ONE, response);
+});
+
+client.testTypedef(69, function(err, response) {
+  assert( ! err);
+  assert.equal(69, response);
+});
+
+
+var mapMapTest = {
+  "4": {"1":1, "2":2, "3":3, "4":4},
+  "-4": {"-4":-4, "-3":-3, "-2":-2, "-1":-1}
+};
+client.testMapMap(mapMapTest, function(err, response) {
+  assert( ! err);
+  assert.deepEqual(mapMapTest, response);
+});
+
+var crazy = new ttypes.Insanity({
+  "userMap":{ "5":5, "8":8 },
+  "xtructs":[new ttypes.Xtruct({
+      "string_thing":"Goodbye4",
+      "byte_thing":4,
+      "i32_thing":4,
+      "i64_thing":4
+    }), new ttypes.Xtruct({
+      "string_thing":"Hello2",
+      "byte_thing":2,
+      "i32_thing":2,
+      "i64_thing":2
+    })]
+});
+var insanity = {
+  "1":{ "2": crazy, "3": crazy },
+  "2":{ "6":{ "userMap":null, "xtructs":null } }
+};
+client.testInsanity(crazy, function(err, response) {
+  assert( ! err);
+  checkRecursively(insanity, response);
+});
+
+
+client.testException('TException', function(err, response) {
+  //assert(err); //BUG?
+  assert( ! response);
+});
+client.testException('Xception', function(err, response) {
+  assert( ! response);
+  assert.equal(err.errorCode, 1001);
+  assert.equal('Xception', err.message);
+});
+client.testException('no Exception', function(err, response) {
+  assert( ! err);
+  assert.equal(undefined, response); //void
+});
+
+
+client.testOneway(1, function(err, response) {
+  assert(false); //should not answer
+});
+
+/**
+ * redo a simple test after the oneway to make sure we aren't "off by one" --
+ * if the server treated oneway void like normal void, this next test will
+ * fail since it will get the void confirmation rather than the correct
+ * result. In this circumstance, the client will throw the exception:
+ *
+ *   TApplicationException: Wrong method namea
+ */
+client.testI32(-1, function(err, response) {
+  assert( ! err);
+  assert.equal(-1, response);
+});
+
 setTimeout(function() {
   console.log("Server successfully tested!");
   connection.end();