TwoToc code
[YouAndWeb_TwoToc] / server / api / category / index.spec.js
1 'use strict';
2
3 var proxyquire = require('proxyquire').noPreserveCache();
4
5 var categoryCtrlStub = {
6   index: 'categoryCtrl.index',
7   show: 'categoryCtrl.show',
8   create: 'categoryCtrl.create',
9   update: 'categoryCtrl.update',
10   destroy: 'categoryCtrl.destroy'
11 };
12
13 var routerStub = {
14   get: sinon.spy(),
15   put: sinon.spy(),
16   patch: sinon.spy(),
17   post: sinon.spy(),
18   delete: sinon.spy()
19 };
20
21 // require the index with our stubbed out modules
22 var categoryIndex = proxyquire('./index.js', {
23   'express': {
24     Router: function() {
25       return routerStub;
26     }
27   },
28   './category.controller': categoryCtrlStub
29 });
30
31 describe('Category API Router:', function() {
32
33   it('should return an express router instance', function() {
34     categoryIndex.should.equal(routerStub);
35   });
36
37   describe('GET /api/categories', function() {
38
39     it('should route to category.controller.index', function() {
40       routerStub.get
41         .withArgs('/', 'categoryCtrl.index')
42         .should.have.been.calledOnce;
43     });
44
45   });
46
47   describe('GET /api/categories/:id', function() {
48
49     it('should route to category.controller.show', function() {
50       routerStub.get
51         .withArgs('/:id', 'categoryCtrl.show')
52         .should.have.been.calledOnce;
53     });
54
55   });
56
57   describe('POST /api/categories', function() {
58
59     it('should route to category.controller.create', function() {
60       routerStub.post
61         .withArgs('/', 'categoryCtrl.create')
62         .should.have.been.calledOnce;
63     });
64
65   });
66
67   describe('PUT /api/categories/:id', function() {
68
69     it('should route to category.controller.update', function() {
70       routerStub.put
71         .withArgs('/:id', 'categoryCtrl.update')
72         .should.have.been.calledOnce;
73     });
74
75   });
76
77   describe('PATCH /api/categories/:id', function() {
78
79     it('should route to category.controller.update', function() {
80       routerStub.patch
81         .withArgs('/:id', 'categoryCtrl.update')
82         .should.have.been.calledOnce;
83     });
84
85   });
86
87   describe('DELETE /api/categories/:id', function() {
88
89     it('should route to category.controller.destroy', function() {
90       routerStub.delete
91         .withArgs('/:id', 'categoryCtrl.destroy')
92         .should.have.been.calledOnce;
93     });
94
95   });
96
97 });