This commit is contained in:
Kevin Anthoney 2016-08-13 12:19:31 +01:00
Родитель 347e78aaa3
Коммит 4b10f29531
2 изменённых файлов: 85 добавлений и 1 удалений

Просмотреть файл

@ -129,8 +129,8 @@ Batch.prototype.body = function()
}
msg += `Content-Type: multipart/mixed; boundary=${op.changeset}\r\n`;
msg += 'Content-Transfer-Encoding: binary\r\n\r\n';
msg += `--${op.changeset}\r\n`;
}
msg += `--${op.changeset}\r\n`;
} else {
if(last_changeset) {
msg += `--${last_changeset}--\r\n`;

84
spec/service-spec.js Normal file
Просмотреть файл

@ -0,0 +1,84 @@
'use strict';
const request = require('../request');
const Odata = require('../index');
describe('batch tests', function() {
var config;
var q;
beforeAll(function(done) {
request.getAsync('http://services.odata.org/V4/(S(readwrite))/OData/OData.svc/')
.then(function(response) {
var body = JSON.parse(response.body);
var r = /(.*)\$metadata/.exec(body['@odata.context']);
if(r) {
config = {
service: r[1],
format: 'json'
};
}
})
.finally(done);
});
beforeEach(function() {
q = Odata(config);
});
it('should retrieve price for item ID 6', function(done) {
q.resource('Products', 6).select('Price').get()
.then(function(response) {
var body = JSON.parse(response.body);
expect(body.Price).toEqual(18.8);
})
.catch(function(err) {
fail(err);
})
.finally(done);
});
it('should change price for item ID 6', function(done) {
q.resource('Products', 6).patch({'@odata.type': 'ODataDemo.Product', Price: 20.0}).
then(function(response) {
expect(response.statusCode).toEqual(204);
q = Odata(config);
return q.resource('Products', 6).get();
})
.then(function(response) {
var body = JSON.parse(response.body);
expect(body.Price).toEqual(20.0);
})
.catch(function(err) {
fail(err);
})
.finally(done);
});
it('should change price for items 4 and 5 using a batch', function(done) {
q.batch()
.resource('Products', 4).patch({'@odata.type': 'ODataDemo.Product', Price: 14.4}, {content_id: 1})
.resource('Products', 5).patch({'@odata.type': 'ODataDemo.Product', Price: 23.2}, {content_id: 2});
q.send()
.then(function(response) {
q = Odata(config);
return q.resource('Products', 4).select('Price').get()
})
.then(function(response) {
var body = JSON.parse(response.body);
expect(body.Price).toEqual(14.4);
q = Odata(config);
return q.resource('Products', 5).select('Price').get()
})
.then(function(response) {
var body = JSON.parse(response.body);
expect(body.Price).toEqual(23.2);
})
.catch(function(err) {
fail(err);
})
.finally(done);
});
});