TwoToc code
[YouAndWeb_TwoToc] / server / api / category / index.spec.js
diff --git a/server/api/category/index.spec.js b/server/api/category/index.spec.js
new file mode 100755 (executable)
index 0000000..a3f61ca
--- /dev/null
@@ -0,0 +1,97 @@
+'use strict';
+
+var proxyquire = require('proxyquire').noPreserveCache();
+
+var categoryCtrlStub = {
+  index: 'categoryCtrl.index',
+  show: 'categoryCtrl.show',
+  create: 'categoryCtrl.create',
+  update: 'categoryCtrl.update',
+  destroy: 'categoryCtrl.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 categoryIndex = proxyquire('./index.js', {
+  'express': {
+    Router: function() {
+      return routerStub;
+    }
+  },
+  './category.controller': categoryCtrlStub
+});
+
+describe('Category API Router:', function() {
+
+  it('should return an express router instance', function() {
+    categoryIndex.should.equal(routerStub);
+  });
+
+  describe('GET /api/categories', function() {
+
+    it('should route to category.controller.index', function() {
+      routerStub.get
+        .withArgs('/', 'categoryCtrl.index')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('GET /api/categories/:id', function() {
+
+    it('should route to category.controller.show', function() {
+      routerStub.get
+        .withArgs('/:id', 'categoryCtrl.show')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('POST /api/categories', function() {
+
+    it('should route to category.controller.create', function() {
+      routerStub.post
+        .withArgs('/', 'categoryCtrl.create')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('PUT /api/categories/:id', function() {
+
+    it('should route to category.controller.update', function() {
+      routerStub.put
+        .withArgs('/:id', 'categoryCtrl.update')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('PATCH /api/categories/:id', function() {
+
+    it('should route to category.controller.update', function() {
+      routerStub.patch
+        .withArgs('/:id', 'categoryCtrl.update')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+  describe('DELETE /api/categories/:id', function() {
+
+    it('should route to category.controller.destroy', function() {
+      routerStub.delete
+        .withArgs('/:id', 'categoryCtrl.destroy')
+        .should.have.been.calledOnce;
+    });
+
+  });
+
+});