Skip to content

Commit 2395786

Browse files
author
Hovhannes Babayan
committed
test files now end with .spec.js
1 parent 33af3b2 commit 2395786

10 files changed

Lines changed: 176 additions & 1 deletion

File tree

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ gulp.task('serve', function() {
9898

9999
var runTests = function() {
100100
var mocha = require('gulp-mocha');
101-
return gulp.src('test/**/*Spec.js', {read: false})
101+
return gulp.src('test/**/*.spec.js', {read: false})
102102
.pipe(mocha({}));
103103
};
104104

File renamed without changes.

test/plugins/request.spec.js

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
require('./../common');
2+
var nock = require('nock');
3+
4+
var Api = require('./../../').Api;
5+
6+
7+
describe('Api.request() method', function() {
8+
9+
it('should resolve returned promise with data if everything went ok', function(done) {
10+
var url = 'http://foobar:8080',
11+
path = '/test',
12+
params = {
13+
'foo': 1,
14+
'bar': 'baz'
15+
},
16+
fields = [
17+
'*', 'owner:*'
18+
],
19+
method = 'GET';
20+
21+
nock(url)
22+
.get('/attask/api' + path + '?foo=1&bar=baz&fields=*%2Cowner%3A*')
23+
.reply(200, {
24+
data: {
25+
'got': 'ok'
26+
}
27+
});
28+
29+
var api = new Api({url: url});
30+
var promise = api.request(path, params, fields, method);
31+
expect(promise).to.eventually.deep.equal({'got': 'ok'}).and.notify(done);
32+
});
33+
34+
35+
it('should resolve returned promise with data if everything went ok when using POST', function(done) {
36+
var url = 'http://foobar:8080',
37+
path = '/test',
38+
params = {
39+
'foo': 1,
40+
'bar': 'baz'
41+
},
42+
fields = [
43+
'*', 'owner:*'
44+
],
45+
method = 'POST';
46+
47+
nock(url)
48+
.post('/attask/api' + path, 'foo=1&bar=baz&fields=*%2Cowner%3A*')
49+
.reply(200, {
50+
data: {
51+
'got': 'ok'
52+
}
53+
});
54+
55+
var api = new Api({url: url});
56+
var promise = api.request(path, params, fields, method);
57+
expect(promise).to.eventually.deep.equal({'got': 'ok'}).and.notify(done);
58+
});
59+
60+
61+
it('should resolve returned promise with data if everything went ok (empty fields)', function(done) {
62+
var url = 'http://foobar:8080',
63+
path = '/test',
64+
params = {
65+
'foo': 1,
66+
'bar': 'baz'
67+
},
68+
fields = [],
69+
method = 'GET';
70+
71+
nock(url)
72+
.get('/attask/api' + path + '?foo=1&bar=baz')
73+
.reply(200, {
74+
data: {
75+
'got': 'ok'
76+
}
77+
});
78+
79+
var api = new Api({url: url});
80+
var promise = api.request(path, params, fields, method);
81+
expect(promise).to.eventually.deep.equal({'got': 'ok'}).and.notify(done);
82+
});
83+
84+
85+
it('should resolve returned promise with data if everything went ok (without fields)', function(done) {
86+
var url = 'http://foobar:8080',
87+
path = '/test',
88+
params = {
89+
'foo': 1,
90+
'bar': 'baz'
91+
},
92+
method = 'GET';
93+
94+
nock(url)
95+
.get('/attask/api' + path + '?foo=1&bar=baz')
96+
.reply(200, {
97+
data: {
98+
'got': 'ok'
99+
}
100+
});
101+
102+
var api = new Api({url: url});
103+
var promise = api.request(path, params, null, method);
104+
expect(promise).to.eventually.deep.equal({'got': 'ok'}).and.notify(done);
105+
});
106+
107+
108+
it('should resolve returned promise with data if everything went ok (without fields and params)', function(done) {
109+
var url = 'http://foobar:8080',
110+
path = '/test',
111+
method = 'GET';
112+
113+
nock(url)
114+
.get('/attask/api' + path)
115+
.reply(200, {
116+
data: {
117+
'got': 'ok'
118+
}
119+
});
120+
121+
var api = new Api({url: url});
122+
var promise = api.request(path, null, null, method);
123+
expect(promise).to.eventually.deep.equal({'got': 'ok'}).and.notify(done);
124+
});
125+
126+
127+
it('should resolve returned promise with data if everything went ok (path without leading /)', function(done) {
128+
var url = 'http://foobar:8080',
129+
path = 'test',
130+
params = {
131+
'foo': 1,
132+
'bar': 'baz'
133+
},
134+
fields = [],
135+
method = 'GET';
136+
137+
nock(url)
138+
.get('/attask/api/' + path + '?foo=1&bar=baz')
139+
.reply(200, {
140+
data: {
141+
'got': 'ok'
142+
}
143+
});
144+
145+
var api = new Api({url: url});
146+
var promise = api.request(path, params, fields, method);
147+
expect(promise).to.eventually.deep.equal({'got': 'ok'}).and.notify(done);
148+
});
149+
150+
151+
it('should reject returned promise with error data on error', function(done) {
152+
var url = 'http://foobar:8080',
153+
path = '/test',
154+
params = {
155+
'foo': 1,
156+
'bar': 'baz'
157+
},
158+
fields = [
159+
'*', 'owner:*'
160+
],
161+
method = 'GET';
162+
163+
nock(url)
164+
.get('/attask/api' + path + '?foo=1&bar=baz&fields=*%2Cowner%3A*')
165+
.reply(500, {
166+
error: {
167+
'message': 'fail'
168+
}
169+
});
170+
171+
var api = new Api({url: url});
172+
var promise = api.request(path, params, fields, method);
173+
expect(promise).to.be.rejectedWith({'message': 'fail'}).and.notify(done);
174+
});
175+
});

0 commit comments

Comments
 (0)