This repository was archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest.js
More file actions
132 lines (121 loc) · 4.6 KB
/
Copy pathtest.js
File metadata and controls
132 lines (121 loc) · 4.6 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var loopback = require('loopback');
var helpers = require('../');
var assert = require('assert');
describe('helpers', function () {
var testApp = loopback();
var db = testApp.dataSource('db', {connector: loopback.Memory});
var testModel = testApp.model('xxx-test-model', {dataSource: 'db'});
testApp.use(loopback.rest());
helpers.beforeEach.withApp(testApp);
describe('helpers.it', function() {
['shouldBeAllowed',
'shouldBeDenied',
'shouldNotBeFound',
'shouldBeAllowedWhenCalledAnonymously',
'shouldBeDeniedWhenCalledAnonymously',
'shouldBeAllowedWhenCalledUnauthenticated',
'shouldBeDeniedWhenCalledUnauthenticated',
'shouldBeAllowedWhenCalledByUser',
'shouldBeDeniedWhenCalledByUser']
.forEach(function(func) {
it('should have a method named ' + func, function () {
assert.equal(typeof helpers.it[func], 'function');
});
});
});
describe('helpers.describe', function() {
['staticMethod',
'instanceMethod',
'whenLoggedInAsUser',
'whenCalledByUser',
'whenCalledAnonymously',
'whenCalledUnauthenticated']
.forEach(function(func) {
it('should have a method named ' + func, function () {
assert.equal(typeof helpers.describe[func], 'function');
});
});
});
describe('helpers.beforeEach', function() {
['withArgs',
'givenModel',
'givenUser',
'givenLoggedInUser',
'givenAnUnauthenticatedToken',
'givenAnAnonymousToken']
.forEach(function(func) {
it('should have a helper method named ' + func, function () {
assert.equal(typeof helpers.beforeEach[func], 'function');
});
});
});
describe('helpers.beforeEach.givenModel', function() {
helpers.beforeEach.givenModel('xxx-test-model');
it('should have an xxx-test-model property', function () {
assert(this['xxx-test-model']);
assert(this['xxx-test-model'].id);
});
});
describe('helpers.beforeEach.givenModel should accept an object to initialise the model', function() {
helpers.beforeEach.givenModel('xxx-test-model', {name: 'name'});
it('should have an xxx-test-model property', function () {
assert(this['xxx-test-model']);
assert(this['xxx-test-model'].id);
assert(this['xxx-test-model'].name === 'name');
});
});
describe('helpers.beforeEach.givenModel should accept an object array to initialise the model', function() {
helpers.beforeEach.givenModel('xxx-test-model', [{name: 'name0'}, {name: 'name1'}]);
it('should have an xxx-test-model property', function () {
assert(this['xxx-test-model']);
assert(this['xxx-test-model'][0].id);
assert(this['xxx-test-model'][0].name === 'name0');
assert(this['xxx-test-model'][1].id);
assert(this['xxx-test-model'][1].name === 'name1');
});
});
describe('whenCalledRemotely', function() {
helpers.describe.staticMethod('create', function() {
helpers.beforeEach.withArgs({foo: 'bar'});
helpers.describe.whenCalledRemotely('POST', '/xxx-test-models', function() {
it('should call the method over rest', function () {
assert.equal(this.res.statusCode, 200);
});
});
});
helpers.describe.staticMethod('findById', function() {
helpers.beforeEach.givenModel('xxx-test-model', {foo: 'bar'});
helpers.describe.whenCalledRemotely('GET', function () {
return '/xxx-test-models/' + this['xxx-test-model'].id;
}, function() {
it('should retrieve the expected model in the first test', function () {
assert.equal(this.res.body.id, this['xxx-test-model'].id);
});
it('should retrieve the expected model in subsequent tests', function () {
assert.equal(this.res.body.id, this['xxx-test-model'].id);
});
});
});
});
describe('cleanDatasource', function() {
helpers.describe.staticMethod('create', function() {
helpers.beforeEach.withArgs({foo: 'bar'});
helpers.describe.whenCalledRemotely('POST', '/xxx-test-models', function() {
it('should call the method over rest', function () {
assert.equal(this.res.statusCode, 200);
});
});
});
helpers.describe.staticMethod('findById', function() {
helpers.beforeEach.givenModel('xxx-test-model', {foo: 'bar'});
helpers.beforeEach.cleanDatasource();
helpers.describe.whenCalledRemotely('GET', function () {
return '/xxx-test-models/' + this['xxx-test-model'].id;
}, function() {
it('should not find the given model', function () {
assert.equal(this.res.statusCode, 404);
});
});
});
});
});