-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathindex.spec.js
97 lines (72 loc) · 2.6 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
var proxyquire = require('proxyquire').noPreserveCache();
var <%= cameledName %>CtrlStub = {
index: '<%= cameledName %>Ctrl.index'<% if(filters.models) { %>,
show: '<%= cameledName %>Ctrl.show',
create: '<%= cameledName %>Ctrl.create',
update: '<%= cameledName %>Ctrl.update',
destroy: '<%= cameledName %>Ctrl.destroy'<% } %>
};
var routerStub = {
get: sinon.spy()<% if(filters.models) { %>,
put: sinon.spy(),
patch: sinon.spy(),
post: sinon.spy(),
delete: sinon.spy()<% } %>
};
// require the index with our stubbed out modules
var <%= cameledName %>Index = proxyquire('./index.js', {
'express': {
Router: function() {
return routerStub;
}
},
'./<%= basename %>.controller': <%= cameledName %>CtrlStub
});
describe('<%= classedName %> API Router:', function() {
it('should return an express router instance', function() {
<%= expect() %><%= cameledName %>Index<%= to() %>.equal(routerStub);
});
describe('GET <%= route %>', function() {
it('should route to <%= cameledName %>.controller.index', function() {
<%= expect() %>routerStub.get
.withArgs('/', '<%= cameledName %>Ctrl.index')
<%= to() %>.have.been.calledOnce;
});
});<% if(filters.models) { %>
describe('GET <%= route %>/:id', function() {
it('should route to <%= cameledName %>.controller.show', function() {
<%= expect() %>routerStub.get
.withArgs('/:id', '<%= cameledName %>Ctrl.show')
<%= to() %>.have.been.calledOnce;
});
});
describe('POST <%= route %>', function() {
it('should route to <%= cameledName %>.controller.create', function() {
<%= expect() %>routerStub.post
.withArgs('/', '<%= cameledName %>Ctrl.create')
<%= to() %>.have.been.calledOnce;
});
});
describe('PUT <%= route %>/:id', function() {
it('should route to <%= cameledName %>.controller.update', function() {
<%= expect() %>routerStub.put
.withArgs('/:id', '<%= cameledName %>Ctrl.update')
<%= to() %>.have.been.calledOnce;
});
});
describe('PATCH <%= route %>/:id', function() {
it('should route to <%= cameledName %>.controller.update', function() {
<%= expect() %>routerStub.patch
.withArgs('/:id', '<%= cameledName %>Ctrl.update')
<%= to() %>.have.been.calledOnce;
});
});
describe('DELETE <%= route %>/:id', function() {
it('should route to <%= cameledName %>.controller.destroy', function() {
<%= expect() %>routerStub.delete
.withArgs('/:id', '<%= cameledName %>Ctrl.destroy')
<%= to() %>.have.been.calledOnce;
});
});<% } %>
});