|
120 | 120 | 'GET api/some-method?params=123 HTTP/1.1\r\nHost: localhost:9876\r\n\r\n\r\n--boundary123--');
|
121 | 121 | });
|
122 | 122 |
|
| 123 | + it('should build the correct request that includes custom headers and a unique request name', function () { |
| 124 | + var rawRequest = { |
| 125 | + url: 'api/some-method?params=123', |
| 126 | + method: 'GET' |
| 127 | + }, |
| 128 | + config = { |
| 129 | + batchEndpointUrl: 'batchEndpointUrl', |
| 130 | + batchRequestHeaders: { |
| 131 | + 'Content-disposition': 'form-data' |
| 132 | + }, |
| 133 | + batchPartRequestHeaders: { |
| 134 | + 'Content-disposition': 'form-data' |
| 135 | + }, |
| 136 | + uniqueRequestName: "veryUniqueRequestName" |
| 137 | + }; |
| 138 | + |
| 139 | + var result = httpAdapter.buildRequest([rawRequest], config); |
| 140 | + |
| 141 | + expect(result.method).to.equal('POST'); |
| 142 | + expect(result.url).to.equal(config.batchEndpointUrl); |
| 143 | + expect(result.cache).to.equal(false); |
| 144 | + expect(result.headers['Content-Type']).to.equal('multipart/mixed; boundary=boundary123'); |
| 145 | + expect(result.headers['Content-disposition']).to.equal('form-data'); |
| 146 | + expect(result.data).to.equal('--boundary123\r\nContent-disposition: form-data; name=veryUniqueRequestName0\r\nContent-Type: application/http; msgtype=request\r\n\r\n' + |
| 147 | + 'GET api/some-method?params=123 HTTP/1.1\r\nHost: localhost:9876\r\n\r\n\r\n--boundary123--'); |
| 148 | + }); |
| 149 | + |
| 150 | + it('should ignore unique request name if content disposition is not sent', function () { |
| 151 | + var rawRequest = { |
| 152 | + url: 'api/some-method?params=123', |
| 153 | + method: 'GET' |
| 154 | + }, |
| 155 | + config = { |
| 156 | + batchEndpointUrl: 'batchEndpointUrl', |
| 157 | + batchRequestHeaders: { |
| 158 | + 'Custom-Header': 'sweet' |
| 159 | + }, |
| 160 | + batchPartRequestHeaders: { |
| 161 | + 'Custom-Header': 'sweet' |
| 162 | + }, |
| 163 | + uniqueRequestName: "veryUniqueRequestName" |
| 164 | + }; |
| 165 | + |
| 166 | + var result = httpAdapter.buildRequest([rawRequest], config); |
| 167 | + |
| 168 | + expect(result.method).to.equal('POST'); |
| 169 | + expect(result.url).to.equal(config.batchEndpointUrl); |
| 170 | + expect(result.cache).to.equal(false); |
| 171 | + expect(result.headers['Content-Type']).to.equal('multipart/mixed; boundary=boundary123'); |
| 172 | + expect(result.headers['Custom-Header']).to.equal('sweet'); |
| 173 | + expect(result.data).to.equal('--boundary123\r\nCustom-Header: sweet\r\nContent-Type: application/http; msgtype=request\r\n\r\n' + |
| 174 | + 'GET api/some-method?params=123 HTTP/1.1\r\nHost: localhost:9876\r\n\r\n\r\n--boundary123--'); |
| 175 | + }); |
| 176 | + |
123 | 177 | it('should build the correct request that includes uri ecoding the urls', function () {
|
124 | 178 | var rawRequest = {
|
125 | 179 | url: 'api/some method?params=123',
|
|
181 | 235 | expect(results[0].data[1].Id).to.equal(2);
|
182 | 236 | expect(results[0].data[2].Id).to.equal(3);
|
183 | 237 | });
|
| 238 | + |
| 239 | + it('should parse a single response with extra data on the Content-Type header', function () { |
| 240 | + var rawRequest = { |
| 241 | + url: 'api/some-method?params=123', |
| 242 | + method: 'GET' |
| 243 | + }, |
| 244 | + config = { |
| 245 | + batchEndpointUrl: 'batchEndpointUrl' |
| 246 | + }, |
| 247 | + responseData = '--boundary123\r\nContent-Type: application/http; msgtype=response\r\n\r\n' + |
| 248 | + 'HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=utf-8\r\n\r\n' + |
| 249 | + '[{"Name":"Product 1","Id":1,"StockQuantity":100},{"Name":"Product 2","Id":2,"StockQuantity":2},{"Name":"Product 3","Id":3,"StockQuantity":32432}]' + |
| 250 | + '\r\n--boundary123--\r\n', |
| 251 | + response = { |
| 252 | + data: responseData, |
| 253 | + headers: function () { |
| 254 | + return { |
| 255 | + 'content-type': 'multipart/mixed; boundary="boundary123"; charset=UTF-8' |
| 256 | + }; |
| 257 | + } |
| 258 | + }; |
| 259 | + |
| 260 | + var results = httpAdapter.parseResponse([rawRequest], response, config); |
| 261 | + |
| 262 | + expect(results.length).to.equal(1); |
| 263 | + expect(results[0].request).to.deep.equal(rawRequest); |
| 264 | + expect(results[0].statusCode).to.equal(200); |
| 265 | + expect(results[0].statusText).to.equal('OK'); |
| 266 | + expect(results[0].headers['Content-Type']).to.equal('json; charset=utf-8'); |
| 267 | + expect(results[0].data.length).to.equal(3); |
| 268 | + expect(results[0].data[0].Id).to.equal(1); |
| 269 | + expect(results[0].data[1].Id).to.equal(2); |
| 270 | + expect(results[0].data[2].Id).to.equal(3); |
| 271 | + }); |
184 | 272 | });
|
185 | 273 |
|
186 | 274 | describe('canBatchRequest', function () {
|
|
0 commit comments