3 var proxyquire = require('proxyquire').noPreserveCache();
6 index: 'userCtrl.index',
7 destroy: 'userCtrl.destroy',
9 changePassword: 'userCtrl.changePassword',
10 show: 'userCtrl.show',
11 create: 'userCtrl.create'
14 var authServiceStub = {
15 isAuthenticated: function() {
16 return 'authService.isAuthenticated';
18 hasRole: function(role) {
19 return 'authService.hasRole.' + role;
30 // require the index with our stubbed out modules
31 var userIndex = proxyquire('./index', {
37 './user.controller': userCtrlStub,
38 '../../auth/auth.service': authServiceStub
41 describe('User API Router:', function() {
43 it('should return an express router instance', function() {
44 userIndex.should.equal(routerStub);
47 describe('GET /api/users', function() {
49 it('should verify admin role and route to user.controller.index', function() {
51 .withArgs('/', 'authService.hasRole.admin', 'userCtrl.index')
52 .should.have.been.calledOnce;
57 describe('DELETE /api/users/:id', function() {
59 it('should verify admin role and route to user.controller.destroy', function() {
61 .withArgs('/:id', 'authService.hasRole.admin', 'userCtrl.destroy')
62 .should.have.been.calledOnce;
67 describe('GET /api/users/me', function() {
69 it('should be authenticated and route to user.controller.me', function() {
71 .withArgs('/me', 'authService.isAuthenticated', 'userCtrl.me')
72 .should.have.been.calledOnce;
77 describe('PUT /api/users/:id/password', function() {
79 it('should be authenticated and route to user.controller.changePassword', function() {
81 .withArgs('/:id/password', 'authService.isAuthenticated', 'userCtrl.changePassword')
82 .should.have.been.calledOnce;
87 describe('GET /api/users/:id', function() {
89 it('should be authenticated and route to user.controller.show', function() {
91 .withArgs('/:id', 'authService.isAuthenticated', 'userCtrl.show')
92 .should.have.been.calledOnce;
97 describe('POST /api/users', function() {
99 it('should route to user.controller.create', function() {
101 .withArgs('/', 'userCtrl.create')
102 .should.have.been.calledOnce;