|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var proxyquire = require('proxyquire').noPreserveCache(); |
| 4 | + |
| 5 | + /* thing.controller stub */ |
| 6 | +var thingCtrl = { |
| 7 | + index: 'thingCtrl.index'<% if(filters.mongoose) { %>, |
| 8 | + show: 'thingCtrl.show', |
| 9 | + create: 'thingCtrl.create', |
| 10 | + update: 'thingCtrl.update', |
| 11 | + destroy: 'thingCtrl.destroy'<% } %> |
| 12 | + }, |
| 13 | + /* express.Router().router stub */ |
| 14 | + router = { |
| 15 | + get: sinon.spy()<% if(filters.mongoose) { %>, |
| 16 | + put: sinon.spy(), |
| 17 | + patch: sinon.spy(), |
| 18 | + post: sinon.spy(), |
| 19 | + delete: sinon.spy()<% } %> |
| 20 | + }, |
| 21 | + /* stubbed thing router */ |
| 22 | + index = proxyquire('./index.js', { |
| 23 | + 'express': { |
| 24 | + Router: function() { |
| 25 | + return router; |
| 26 | + } |
| 27 | + }, |
| 28 | + './thing.controller': thingCtrl |
| 29 | + }); |
| 30 | + |
| 31 | +describe('Thing API Router:', function() { |
| 32 | + |
| 33 | + it('should return an express router instance', function() { |
| 34 | + index.should.equal(router); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('GET /api/things', function() { |
| 38 | + |
| 39 | + it('should route to thing.controller.index', function() { |
| 40 | + return router.get.withArgs('/', 'thingCtrl.index').should.have.been.calledOnce; |
| 41 | + }); |
| 42 | + |
| 43 | + });<% if(filters.mongoose) { %> |
| 44 | + |
| 45 | + describe('GET /api/things/:id', function() { |
| 46 | + |
| 47 | + it('should route to thing.controller.show', function() { |
| 48 | + return router.get.withArgs('/:id', 'thingCtrl.show').should.have.been.calledOnce; |
| 49 | + }); |
| 50 | + |
| 51 | + }); |
| 52 | + |
| 53 | + describe('POST /api/things', function() { |
| 54 | + |
| 55 | + it('should route to thing.controller.create', function() { |
| 56 | + return router.post.withArgs('/', 'thingCtrl.create').should.have.been.calledOnce; |
| 57 | + }); |
| 58 | + |
| 59 | + }); |
| 60 | + |
| 61 | + describe('PUT /api/things/:id', function() { |
| 62 | + |
| 63 | + it('should route to thing.controller.update', function() { |
| 64 | + return router.put.withArgs('/:id', 'thingCtrl.update').should.have.been.calledOnce; |
| 65 | + }); |
| 66 | + |
| 67 | + }); |
| 68 | + |
| 69 | + describe('PATCH /api/things/:id', function() { |
| 70 | + |
| 71 | + it('should route to thing.controller.update', function() { |
| 72 | + return router.patch.withArgs('/:id', 'thingCtrl.update').should.have.been.calledOnce; |
| 73 | + }); |
| 74 | + |
| 75 | + }); |
| 76 | + |
| 77 | + describe('DELETE /api/things/:id', function() { |
| 78 | + |
| 79 | + it('should route to thing.controller.destroy', function() { |
| 80 | + return router.delete.withArgs('/:id', 'thingCtrl.destroy').should.have.been.calledOnce; |
| 81 | + }); |
| 82 | + |
| 83 | + });<% } %> |
| 84 | + |
| 85 | +}); |
0 commit comments