TwoToc code
[YouAndWeb_TwoToc] / server / api / comment / index.spec.js
diff --git a/server/api/comment/index.spec.js b/server/api/comment/index.spec.js
new file mode 100755 (executable)
index 0000000..7095c48
--- /dev/null
@@ -0,0 +1,97 @@
+'use strict';
+
+var proxyquire = require('proxyquire').noPreserveCache();
+
+var commentCtrlStub = {
+  index: 'commentCtrl.index',
+  show: 'commentCtrl.show',
+  create: 'commentCtrl.create',
+  update: 'commentCtrl.update',
+  destroy: 'commentCtrl.destroy'
+};
+
+var routerStub = {
+  get: sinon.spy(),
+  put: sinon.spy(),
+  patch: sinon.spy(),
+  post: sinon.spy(),
+  delete: sinon.spy()
+};
+
+// require the index with our stubbed out modules
+var commentIndex = proxyquire('./index.js', {
+  'express': {
+    Router: function() {
+      return routerStub;
+    }
+  },
+  './comment.controller': commentCtrlStub
+});
+
+describe('Comment API Router:', function() {
+
+  it('should return an express router instance', function() {
+    commentIndex.should.equal(routerStub);
+  });
+
+  describe('GET /api/comments', function() {
+
+    it('should route to comment.controller.index', function() {
+      routerStub.get
+        .withArgs('/', 'commentCtrl.index')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('GET /api/comments/:id', function() {
+
+    it('should route to comment.controller.show', function() {
+      routerStub.get
+        .withArgs('/:id', 'commentCtrl.show')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('POST /api/comments', function() {
+
+    it('should route to comment.controller.create', function() {
+      routerStub.post
+        .withArgs('/', 'commentCtrl.create')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('PUT /api/comments/:id', function() {
+
+    it('should route to comment.controller.update', function() {
+      routerStub.put
+        .withArgs('/:id', 'commentCtrl.update')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('PATCH /api/comments/:id', function() {
+
+    it('should route to comment.controller.update', function() {
+      routerStub.patch
+        .withArgs('/:id', 'commentCtrl.update')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('DELETE /api/comments/:id', function() {
+
+    it('should route to comment.controller.destroy', function() {
+      routerStub.delete
+        .withArgs('/:id', 'commentCtrl.destroy')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+});