Skip to content

Commit 8e9f289

Browse files
author
c1moore
committed
Fixed testing environment.
1 parent 8f150c5 commit 8e9f289

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"devDependencies": {
3636
"sinon": "~1.10.3",
3737
"angular-mocks": ">=1.2.23",
38-
"angular-resource": ">=1.2.23"
38+
"angular-resource": ">=1.2.23",
39+
"angular-route": ">=1.2.23"
3940
},
4041
"dependencies": {
4142
"angular": ">= 1.2.23"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"karma-phantomjs-launcher": "^0.1.4",
4646
"karma-sinon": "^1.0.3",
4747
"mocha": "^1.20.1",
48+
"phantomjs-polyfill": "0.*",
4849
"sinon": "^1.10.2"
4950
},
5051
"ignore": [

src/services/adapters/npmBatchRequestAdapter.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
function transformGETRequest(requestIndex, request, httpConfig) {
2424
var paramSerializer;
2525

26-
httpConfig.data = httpConfig.data || {};
27-
2826
httpConfig.data[requestIndex] = {
2927
method: request.method,
3028
uri: request.url,
@@ -41,8 +39,6 @@
4139
* @param httpConfig (Object) - the Angular $http config Object for the batched request
4240
*/
4341
function transformRequestWithBody(requestIndex, request, httpConfig) {
44-
httpConfig.data = httpConfig.data || {};
45-
4642
httpConfig.data[requestIndex] = {
4743
method: request.method,
4844
uri: request.url,
@@ -69,7 +65,8 @@
6965
var httpConfig = {
7066
method: 'POST',
7167
url: config.batchEndpointUrl,
72-
headers: config.batchRequestHeaders || {}
68+
headers: config.batchRequestHeaders || {},
69+
data: {}
7370
};
7471

7572
for(requestIndex = 0; requestIndex < requests.length; requestIndex++) {
@@ -84,6 +81,8 @@
8481

8582
transformRequest(requestIndex, requests[requestIndex], httpConfig);
8683
}
84+
85+
return httpConfig;
8786
};
8887

8988
/**
@@ -102,7 +101,7 @@
102101
var batchResponses = [];
103102
var response;
104103

105-
for(requestIndex = requests.length - 1; requestIndex >= 0; requestIndex--) {
104+
for(requestIndex = 0; requestIndex < requests.length; requestIndex++) {
106105
response = rawResponse.data[requestIndex];
107106

108107
batchResponses.push(new HttpBatchResponseData(

tests/karma.conf.shared.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ shared.files = [
7373
'src/angular-http-batch.js',
7474
'src/providers/httpBatchConfig.js',
7575
'src/services/httpBatcher.js',
76-
'src/services/adapters/httpBatchResponseData.js',
77-
'src/services/adapters/httpAdapter.js',
78-
'src/services/adapters/nodeJsMultiFetchAdapter.js',
79-
'src/config/httpBackendDecorator.js'
76+
'src/services/adapters/*.js',
77+
'src/config/httpBackendDecorator.js',
78+
'./node_modules/phantomjs-polyfill/bind-polyfill.js'
8079
];
8180

8281
module.exports = shared;

tests/services/adapters/npmBatchRequestAdapter.spec.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
'use strict';
33

44
describe('npmBatchRequestAdapter', function() {
5+
beforeEach(module(window.ahb.name));
6+
57
beforeEach(inject(function($injector) {
68
this.adapter = $injector.get('npmBatchRequestAdapter');
79
this.sandbox = sinon.sandbox.create();
@@ -39,13 +41,18 @@
3941
for(requestIndex = 0; requestIndex < requests.length; requestIndex++) {
4042
requestData = batchRequest.data[requestIndex];
4143

42-
expect(requestData).to.have.all.keys('method', 'uri', 'headers');
44+
expect(requestData).to.include.keys('method', 'uri');
4345
expect(requestData.method).to.equal(requests[requestIndex].method);
4446
expect(requestData.uri).to.equal(requests[requestIndex].url);
45-
expect(requestData.headers).to.deep.equal(requests[requestIndex].headers);
47+
48+
if(requestData.headers) {
49+
expect(requestData).to.include.keys('headers');
50+
51+
expect(requestData.headers).to.deep.equal(requests[requestIndex].headers);
52+
};
4653

4754
if(requestData.method !== 'GET') {
48-
expect(requestData).to.have.all.keys('body');
55+
expect(requestData).to.include.keys('body');
4956

5057
expect(requestData.body).to.deep.equal(requests[requestIndex].data);
5158
}
@@ -194,7 +201,7 @@
194201

195202
it('should parse multiple responses and multiplex them appropriately', function() {
196203
var requests;
197-
var responses;
204+
var response;
198205
var parsedResponses;
199206

200207
requests = [{
@@ -208,7 +215,7 @@
208215
}
209216
}];
210217

211-
responses = {
218+
response = {
212219
data: {
213220
0: {
214221
statusCode: 200,
@@ -231,12 +238,12 @@
231238
}
232239
};
233240

234-
parsedResponses = this.adapter.parseResponse([request], response);
241+
parsedResponses = this.adapter.parseResponse(requests, response);
235242

236243
expect(parsedResponses).to.be.an('array').with.lengthOf(2);
237244

238-
this.testResponse(request, response.data[0], parsedResponses[0]);
239-
this.testResponse(request, response.data[1], parsedResponses[1]);
245+
this.testResponse(requests[0], response.data[0], parsedResponses[0]);
246+
this.testResponse(requests[1], response.data[1], parsedResponses[1]);
240247
});
241248
});
242249
});

0 commit comments

Comments
 (0)