-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathresponse.spec.js
150 lines (145 loc) · 5.04 KB
/
response.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Generated by CoffeeScript 1.12.3
(function() {
var AWS, EventEmitter, helpers;
helpers = require('./helpers');
EventEmitter = require('events').EventEmitter;
AWS = helpers.AWS;
describe('AWS.Response', function() {
var fill, makePageable, response, service;
service = null;
response = null;
beforeEach(function() {
service = new AWS.Service({
apiConfig: new AWS.Model.Api({
metadata: {
signingName: 'ocean-wave'
},
operations: {
op: {}
}
})
});
return response = new AWS.Response(service.makeRequest('op'));
});
makePageable = function() {
return service.api.paginators.op = new AWS.Model.Paginator('op', {
limit_key: 'Limit',
input_token: 'Marker',
output_token: 'Marker',
result_key: 'Result'
});
};
fill = function(err, data, pageable) {
if (pageable) {
makePageable();
}
response.error = err;
return response.data = data;
};
describe('hasNextPage', function() {
it('returns undefined if the request is not pageable', function() {
fill(null, {
Marker: 'next_page'
});
return expect(response.hasNextPage()).to.equal(void 0);
});
it('returns false if there is no marker in the response', function() {
fill(null, {}, true);
return expect(response.hasNextPage()).to.equal(false);
});
it('returns false if the response returned an error', function() {
fill(new Error, null, true);
return expect(response.hasNextPage()).to.equal(false);
});
return it('returns true if there is a marker in the response', function() {
fill(null, {
Marker: 'next_page'
}, true);
return expect(response.hasNextPage()).to.equal(true);
});
});
describe('cacheNextPageTokens', function() {
it('sets nextPageTokens to null if no token in data', function() {
fill(null, {
notMarker: 'someData'
}, true);
response.cacheNextPageTokens();
return expect(response.nextPageTokens).to.equal(null);
});
it('sets nextPageTokens for one token', function() {
fill(null, {
notMarker: 'someData',
Marker: 'token'
}, true);
response.cacheNextPageTokens();
return expect(response.nextPageTokens).to.eql(['token']);
});
it('sets nextPageTokens for multiple tokens', function() {
fill(null, {
MarkerI: 'token1',
MarkerII: 'token2',
MarkerIII: 'token3'
}, true);
service.api.paginators.op.outputToken = ['MarkerI', 'MarkerII', 'MarkerIV'];
response.cacheNextPageTokens();
return expect(response.nextPageTokens).to.eql(['token1', 'token2']);
});
return it('returns cached tokens if nextPageTokens exists', function() {
response.nextPageTokens = ['cachedToken'];
return expect(response.cacheNextPageTokens()).to.eql(['cachedToken']);
});
});
return describe('nextPage', function() {
it('throws an exception if the operation has no pagination information', function() {
service.api.pagination = {};
return expect(function() {
return response.nextPage();
}).to['throw']('No pagination configuration for op');
});
it('returns null if there are no more pages', function() {
fill(null, {}, true);
return expect(response.nextPage()).to.equal(null);
});
it('returns a request object with the next page marker filled in params', function() {
var req;
fill(null, {
Marker: 'next_page'
}, true);
req = response.nextPage();
expect(req.params.Marker).to.equal('next_page');
return expect(req.operation).to.equal(response.request.operation);
});
it('throws error if response returned an error and there is no callback', function() {
fill(new Error('error!'), null, true);
return expect(function() {
return response.nextPage();
}).to['throw']('error!');
});
it('sends the request if passed with a callback', function(done) {
helpers.mockHttpResponse(200, {}, ['']);
fill(null, {
Marker: 'next_page'
}, true);
return response.nextPage(function(err, data) {
expect(err).to.equal(null);
expect(data).to.eql({});
return done();
});
});
it('passes null to callback if there are no more pages', function() {
fill(null, {}, true);
return response.nextPage(function(err, data) {
expect(err).to.equal(null);
return expect(data).to.equal(null);
});
});
return it('passes error through if original response returned an error', function() {
fill('error!', null, true);
return response.nextPage(function(err, data) {
expect(err).to.equal('error!');
return expect(data).to.equal(null);
});
});
});
});
}).call(this);