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 20
Expand file tree
/
Copy pathtest.js
More file actions
119 lines (110 loc) · 3.97 KB
/
test.js
File metadata and controls
119 lines (110 loc) · 3.97 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
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',
'shouldBeRejected',
'shouldNotBeFound',
'shouldBeAllowedWhenCalledAnonymously',
'shouldBeDeniedWhenCalledAnonymously',
'shouldBeAllowedWhenCalledUnauthenticated',
'shouldBeDeniedWhenCalledUnauthenticated',
'shouldBeNotFoundWhenCalledUnauthenticated',
'shouldBeAllowedWhenCalledByUser',
'shouldBeValidCreateResponse',
'shouldBeValidGetAllResponse',
'shouldBeValidGetByIdResponse',
'shouldBeValidUpdateResponse',
'shouldBeValidDeleteResponse',
'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('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);
});
});
});
});
});