Merge pull request #13 from apigee/fix-accumulate-response

fixing an issue with accumulate-response where a lack of response body will cause errors instead of a successful request response cycle.
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..e49a3ea
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+- '6.3.1'
+
diff --git a/README.md b/README.md
index 9311c2f..36f5d8b 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
 #Plugins
 
+Build Status [![Build Status](https://travis-ci.org/apigee/microgateway-plugins.svg?branch=accumulate-request-fixes)](https://travis-ci.org/apigee/microgateway-plugins)
+
 ##Overview
 This repo contains plugins for the [microgateway-core project](https://github.com/apigee/microgateway-core).  
 
@@ -55,4 +57,4 @@
 
 ```javascript 
 next([err])
-```
\ No newline at end of file
+```
diff --git a/accumulate-request/index.js b/accumulate-request/index.js
index b1e7643..d162087 100644
--- a/accumulate-request/index.js
+++ b/accumulate-request/index.js
@@ -14,7 +14,6 @@
  * should only be used when it is known that request/response bodies are small.
  */
 module.exports.init = function(config, logger, stats) {
-
   function accumulate(req, data) {
     if (!req._chunks) req._chunks = [];
     req._chunks.push(data);
@@ -29,11 +28,13 @@
 
     onend_request: function(req, res, data, next) {
       if (data && data.length > 0) accumulate(req, data);
-      var content = Buffer.concat(req._chunks);
+      var content = null;
+      if (req._chunks && req._chunks.length) {
+        content = Buffer.concat(req._chunks);
+      }
       delete req._chunks;
       next(null, content);
     }
-
   };
 
 }
diff --git a/test/accumulate-request-test.js b/test/accumulate-request-test.js
index 88f7b6d..1983c25 100644
--- a/test/accumulate-request-test.js
+++ b/test/accumulate-request-test.js
@@ -91,4 +91,17 @@
 
     plugin.ondata_request.apply(null, [req, {}, Buffer.alloc(5, 'a'), cb]);
   });
+
+  it('will call the callback with null if no data events are provided.', (done) => {
+    var onend_cb = (err, result) => {
+      assert.equal(err, null);
+      assert.equal(result, null); 
+      done();
+    } 
+
+    var req = {};
+
+    plugin.onend_request.apply(null, [req, {}, null, onend_cb]);  
+
+  });
 })
diff --git a/test/quota-test.js b/test/quota-test.js
index 92a7beb..e8a2a31 100644
--- a/test/quota-test.js
+++ b/test/quota-test.js
@@ -4,7 +4,7 @@
 var exampleConfig = { 
   EdgeMicroTestProduct: {
     allow: process.env.QUOTA_ALLOW,
-    interval: process.env.QUOTA_INTERVAL,
+    interval: Number(process.env.QUOTA_INTERVAL),
     timeUnit: process.env.QUOTA_TIMEUNIT,
     bufferSize: process.env.QUOTA_BUFFERSIZE,
     uri: process.env.QUOTA_URI,