Commit f9cfbc47 authored by Romain Courteaud's avatar Romain Courteaud

[test] Update test code to make them compatible with node

Do not spy XMLHttpRequest, as it is node 100% compatible between node and browser.
Spy ajax calls instead.

Do not rely on storage not available in node (like localstorage).
parent 20f2d3e9
......@@ -44,17 +44,28 @@
originalAjax = jIO.util.ajax;
jIO.util.ajax = function ajax(param) {
if (param.data instanceof Blob) {
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param = Object.assign({}, param);
// Blob is not supported by xhr2, so convert to ArrayBuffer instead
return jIO.util.readBlobAsArrayBuffer(param.data).then(function (data) {
param.data = data.target.result;
return originalAjax(param);
});
return jIO.util.readBlobAsArrayBuffer(param.data)
.then(function (data) {
param.data = data.target.result;
return originalAjax(param);
});
}
if (param.data instanceof FormData) {
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param = Object.assign({}, param);
// Implement minimal FormData for erp5storage
if (!param.hasOwnProperty('headers')) {
param.headers = {};
} else {
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param.headers = Object.assign({}, param.headers);
}
param.headers["Content-Type"] = "multipart\/form-data; boundary=" +
param.data.boundary;
......
......@@ -709,6 +709,8 @@
this.server.autoRespond = true;
this.server.autoRespondAfter = 5;
this.spy_ajax = sinon.spy(jIO.util, "ajax");
this.jio = jIO.createJIO({
type: "dropbox",
access_token: token
......@@ -717,6 +719,8 @@
teardown: function () {
this.server.restore();
delete this.server;
this.spy_ajax.restore();
delete this.spy_ajax;
}
});
......@@ -789,14 +793,15 @@
test("putAttachment document", function () {
var blob = new Blob(["foo"], {"type": "xapplication/foo"}),
url_put_att = "https://content.dropboxapi.com/2/files/upload",
server = this.server;
server = this.server,
context = this;
this.server.respondWith("POST", url_put_att, [204, {
"Content-Type": "text/xml"
}, ""]);
stop();
expect(7);
expect(11);
this.jio.putAttachment(
"/putAttachment1/",
......@@ -804,20 +809,26 @@
blob
)
.then(function () {
ok(context.spy_ajax.calledOnce, "ajax count " +
context.spy_ajax.callCount);
equal(context.spy_ajax.firstCall.args[0].type, "POST");
equal(context.spy_ajax.firstCall.args[0].url, url_put_att);
deepEqual(context.spy_ajax.firstCall.args[0].xhrFields, undefined);
deepEqual(context.spy_ajax.firstCall.args[0].headers, {
"Authorization": "Bearer sample_token",
"Content-Type": "application/octet-stream",
"Dropbox-API-Arg": '{"path":"/putAttachment1/attachment1",' +
'"mode":"overwrite",' +
'"autorename":false,"mute":false}'
});
equal(context.spy_ajax.firstCall.args[0].data, blob);
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
equal(server.requests[0].url, url_put_att);
equal(server.requests[0].status, 204);
equal(server.requests[0].responseText, "");
deepEqual(server.requests[0].requestHeaders, {
"Authorization": "Bearer sample_token",
"Content-Type": "application/octet-stream;charset=utf-8",
"Dropbox-API-Arg": '{"path":"/putAttachment1/attachment1",' +
'"mode":"overwrite",' +
'"autorename":false,"mute":false}'
});
equal(server.requests[0].requestBody, blob);
})
.fail(function (error) {
ok(false, error);
......
......@@ -606,12 +606,15 @@
});
this.spy = sinon.spy(FormData.prototype, "append");
this.spy_ajax = sinon.spy(jIO.util, "ajax");
},
teardown: function () {
this.server.restore();
delete this.server;
this.spy.restore();
delete this.spy;
this.spy_ajax.restore();
delete this.spy_ajax;
}
});
......@@ -654,7 +657,7 @@
}, ""]);
stop();
expect(13);
expect(18);
this.jio = jIO.createJIO({
type: "erp5",
......@@ -668,12 +671,24 @@
new Blob([JSON.stringify(form_json)])
)
.then(function () {
ok(context.spy_ajax.calledOnce, "ajax count " +
context.spy_ajax.callCount);
equal(context.spy_ajax.firstCall.args[0].type, "POST");
equal(context.spy_ajax.firstCall.args[0].url, submit_url);
equal(context.spy_ajax.firstCall.args[0].dataType, "blob");
deepEqual(context.spy_ajax.firstCall.args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.firstCall.args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
ok(context.spy_ajax.firstCall.args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.firstCall.args[0].data);
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
equal(server.requests[0].url, submit_url);
equal(server.requests[0].status, 204);
equal(server.requests[0].responseType, "blob");
ok(server.requests[0].requestBody instanceof FormData);
ok(context.spy.calledTwice, "FormData.append count " +
context.spy.callCount);
......@@ -684,9 +699,7 @@
equal(context.spy.secondCall.args[1], "barè", "Second append call");
equal(server.requests[0].withCredentials, false);
deepEqual(server.requests[0].requestHeaders,
{'X-ACCESS-TOKEN': 'footoken',
'Content-Type': 'text/plain;charset=utf-8'});
equal(server.requests[0].requestHeaders['X-ACCESS-TOKEN'], 'footoken');
})
.fail(function (error) {
ok(false, error);
......@@ -712,7 +725,7 @@
}, ""]);
stop();
expect(13);
expect(17);
this.jio.putAttachment(
id,
......@@ -720,12 +733,22 @@
new Blob([JSON.stringify(form_json)])
)
.then(function () {
ok(context.spy_ajax.calledOnce, "ajax count " +
context.spy_ajax.callCount);
equal(context.spy_ajax.firstCall.args[0].type, "POST");
equal(context.spy_ajax.firstCall.args[0].url, submit_url);
equal(context.spy_ajax.firstCall.args[0].dataType, "blob");
deepEqual(context.spy_ajax.firstCall.args[0].xhrFields, {
withCredentials: true
});
ok(context.spy_ajax.firstCall.args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.firstCall.args[0].data);
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
equal(server.requests[0].url, submit_url);
equal(server.requests[0].status, 204);
equal(server.requests[0].responseType, "blob");
ok(server.requests[0].requestBody instanceof FormData);
ok(context.spy.calledTwice, "FormData.append count " +
context.spy.callCount);
......@@ -736,8 +759,6 @@
equal(context.spy.secondCall.args[1], "barè", "Second append call");
equal(server.requests[0].withCredentials, true);
deepEqual(server.requests[0].requestHeaders,
{'Content-Type': 'text/plain;charset=utf-8'});
})
.fail(function (error) {
ok(false, error);
......@@ -761,7 +782,7 @@
}, ""]);
stop();
expect(12);
expect(16);
this.jio.putAttachment(
id,
......@@ -769,12 +790,21 @@
new Blob([JSON.stringify(form_json)])
)
.then(function () {
ok(context.spy_ajax.calledOnce, "ajax count " +
context.spy_ajax.callCount);
equal(context.spy_ajax.firstCall.args[0].type, "POST");
equal(context.spy_ajax.firstCall.args[0].url, submit_url);
equal(context.spy_ajax.firstCall.args[0].dataType, "blob");
deepEqual(context.spy_ajax.firstCall.args[0].xhrFields, {
withCredentials: true
});
ok(context.spy_ajax.firstCall.args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.firstCall.args[0].data);
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
equal(server.requests[0].url, submit_url);
equal(server.requests[0].status, 204);
equal(server.requests[0].responseType, "blob");
ok(server.requests[0].requestBody instanceof FormData);
ok(context.spy.calledTwice, "FormData.append count " +
context.spy.callCount);
......@@ -812,7 +842,7 @@
}, ""]);
stop();
expect(13);
expect(17);
this.jio.putAttachment(
id,
......@@ -820,12 +850,21 @@
new Blob([JSON.stringify(form_json)])
)
.then(function () {
ok(context.spy_ajax.calledOnce, "ajax count " +
context.spy_ajax.callCount);
equal(context.spy_ajax.firstCall.args[0].type, "POST");
equal(context.spy_ajax.firstCall.args[0].url, submit_url);
equal(context.spy_ajax.firstCall.args[0].dataType, "blob");
deepEqual(context.spy_ajax.firstCall.args[0].xhrFields, {
withCredentials: true
});
ok(context.spy_ajax.firstCall.args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.firstCall.args[0].data);
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
equal(server.requests[0].url, submit_url);
equal(server.requests[0].status, 204);
equal(server.requests[0].responseType, "blob");
ok(server.requests[0].requestBody instanceof FormData);
ok(context.spy.calledOnce, "FormData.append count " +
context.spy.callCount);
......@@ -2049,6 +2088,7 @@
this.server.autoRespondAfter = 5;
this.spy = sinon.spy(FormData.prototype, "append");
this.spy_ajax = sinon.spy(jIO.util, "ajax");
this.jio = jIO.createJIO({
type: "erp5",
......@@ -2061,6 +2101,8 @@
delete this.server;
this.spy.restore();
delete this.spy;
this.spy_ajax.restore();
delete this.spy_ajax;
}
});
......@@ -2178,7 +2220,7 @@
}, ""]);
stop();
expect(26);
expect(44);
this.jio = jIO.createJIO({
type: "erp5",
......@@ -2190,26 +2232,66 @@
this.jio.put(id, {title: "barè", id: "foo", reference: "bar2"})
.then(function (result) {
equal(result, id);
equal(context.spy_ajax.callCount, 3, "ajax count");
equal(context.spy_ajax.getCall(0).args[0].type, "GET");
equal(context.spy_ajax.getCall(0).args[0].url, domain);
equal(context.spy_ajax.getCall(0).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(0).args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.getCall(0).args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
equal(context.spy_ajax.getCall(0).args[0].data, undefined);
equal(context.spy_ajax.getCall(1).args[0].type, "GET");
equal(context.spy_ajax.getCall(1).args[0].url, traverse_url);
equal(context.spy_ajax.getCall(1).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(1).args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.getCall(1).args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
equal(context.spy_ajax.getCall(1).args[0].data, undefined);
equal(context.spy_ajax.getCall(2).args[0].type, "POST");
equal(context.spy_ajax.getCall(2).args[0].url, put_url);
equal(context.spy_ajax.getCall(2).args[0].dataType, "blob");
deepEqual(context.spy_ajax.getCall(2).args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.getCall(2).args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
ok(context.spy_ajax.getCall(2).args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.getCall(2).args[0].data);
equal(server.requests.length, 3);
equal(server.requests[0].method, "GET");
equal(server.requests[0].url, domain);
equal(server.requests[0].requestBody, undefined);
equal(server.requests[0].withCredentials, false);
deepEqual(server.requests[0].requestHeaders,
{'X-ACCESS-TOKEN': 'footoken'});
equal(
server.requests[0].requestHeaders['X-ACCESS-TOKEN'],
'footoken'
);
equal(server.requests[1].method, "GET");
equal(server.requests[1].url, traverse_url);
equal(server.requests[1].requestBody, undefined);
equal(server.requests[1].withCredentials, false);
deepEqual(server.requests[1].requestHeaders,
{'X-ACCESS-TOKEN': 'footoken'});
equal(
server.requests[1].requestHeaders['X-ACCESS-TOKEN'],
'footoken'
);
equal(server.requests[2].method, "POST");
equal(server.requests[2].url, put_url);
ok(server.requests[2].requestBody instanceof FormData);
equal(server.requests[2].withCredentials, false);
deepEqual(server.requests[2].requestHeaders,
{'X-ACCESS-TOKEN': 'footoken',
'Content-Type': 'text/plain;charset=utf-8'});
equal(
server.requests[2].requestHeaders['X-ACCESS-TOKEN'],
'footoken'
);
equal(context.spy.callCount, 4, "FormData.append count");
equal(context.spy.firstCall.args[0], "form_id", "First append call");
......@@ -2317,11 +2399,41 @@
}, ""]);
stop();
expect(26);
expect(43);
this.jio.put(id, {title: "barè", id: "foo", reference: "bar2"})
.then(function (result) {
equal(result, id);
equal(context.spy_ajax.callCount, 3, "ajax count");
equal(context.spy_ajax.getCall(0).args[0].type, "GET");
equal(context.spy_ajax.getCall(0).args[0].url, domain);
equal(context.spy_ajax.getCall(0).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(0).args[0].xhrFields, {
withCredentials: true
});
deepEqual(context.spy_ajax.getCall(0).args[0].headers, undefined);
equal(context.spy_ajax.getCall(0).args[0].data, undefined);
equal(context.spy_ajax.getCall(1).args[0].type, "GET");
equal(context.spy_ajax.getCall(1).args[0].url, traverse_url);
equal(context.spy_ajax.getCall(1).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(1).args[0].xhrFields, {
withCredentials: true
});
deepEqual(context.spy_ajax.getCall(1).args[0].headers, undefined);
equal(context.spy_ajax.getCall(1).args[0].data, undefined);
equal(context.spy_ajax.getCall(2).args[0].type, "POST");
equal(context.spy_ajax.getCall(2).args[0].url, put_url);
equal(context.spy_ajax.getCall(2).args[0].dataType, "blob");
deepEqual(context.spy_ajax.getCall(2).args[0].xhrFields, {
withCredentials: true
});
deepEqual(context.spy_ajax.getCall(2).args[0].headers, undefined);
ok(context.spy_ajax.getCall(2).args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.getCall(2).args[0].data);
equal(server.requests.length, 3);
equal(server.requests[0].method, "GET");
equal(server.requests[0].url, domain);
......@@ -2335,10 +2447,7 @@
deepEqual(server.requests[1].requestHeaders, {});
equal(server.requests[2].method, "POST");
equal(server.requests[2].url, put_url);
ok(server.requests[2].requestBody instanceof FormData);
equal(server.requests[2].withCredentials, true);
deepEqual(server.requests[2].requestHeaders,
{'Content-Type': 'text/plain;charset=utf-8'});
equal(context.spy.callCount, 4, "FormData.append count");
equal(context.spy.firstCall.args[0], "form_id", "First append call");
......@@ -2540,6 +2649,7 @@
this.server.autoRespondAfter = 5;
this.spy = sinon.spy(FormData.prototype, "append");
this.spy_ajax = sinon.spy(jIO.util, "ajax");
this.jio = jIO.createJIO({
type: "erp5",
......@@ -2552,6 +2662,8 @@
delete this.server;
this.spy.restore();
delete this.spy;
this.spy_ajax.restore();
delete this.spy_ajax;
}
});
......@@ -2638,7 +2750,7 @@
}, ""]);
stop();
expect(40);
expect(67);
this.jio = jIO.createJIO({
type: "erp5",
......@@ -2656,6 +2768,65 @@
})
.then(function (result) {
equal(result, id);
equal(context.spy_ajax.callCount, 5, "ajax count");
equal(context.spy_ajax.getCall(0).args[0].type, "GET");
equal(context.spy_ajax.getCall(0).args[0].url, domain);
equal(context.spy_ajax.getCall(0).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(0).args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.getCall(0).args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
equal(context.spy_ajax.getCall(0).args[0].data, undefined);
equal(context.spy_ajax.getCall(1).args[0].type, "POST");
equal(context.spy_ajax.getCall(1).args[0].url, add_url);
equal(context.spy_ajax.getCall(1).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(1).args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.getCall(1).args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
ok(context.spy_ajax.getCall(1).args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.getCall(1).args[0].data);
equal(context.spy_ajax.getCall(2).args[0].type, "GET");
equal(context.spy_ajax.getCall(2).args[0].url, domain);
equal(context.spy_ajax.getCall(2).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(2).args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.getCall(2).args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
equal(context.spy_ajax.getCall(2).args[0].data, undefined);
equal(context.spy_ajax.getCall(3).args[0].type, "GET");
equal(context.spy_ajax.getCall(3).args[0].url, traverse_url);
equal(context.spy_ajax.getCall(3).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(3).args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.getCall(3).args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
equal(context.spy_ajax.getCall(3).args[0].data, undefined);
equal(context.spy_ajax.getCall(4).args[0].type, "POST");
equal(context.spy_ajax.getCall(4).args[0].url, put_url);
equal(context.spy_ajax.getCall(4).args[0].dataType, "blob");
deepEqual(context.spy_ajax.getCall(4).args[0].xhrFields, {
withCredentials: false
});
deepEqual(context.spy_ajax.getCall(4).args[0].headers, {
'X-ACCESS-TOKEN': 'footoken'
});
ok(context.spy_ajax.getCall(4).args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.getCall(4).args[0].data);
equal(server.requests.length, 5);
equal(server.requests[0].method, "GET");
......@@ -2667,11 +2838,7 @@
equal(server.requests[1].method, "POST");
equal(server.requests[1].url, add_url);
ok(server.requests[1].requestBody instanceof FormData);
equal(server.requests[1].withCredentials, false);
deepEqual(server.requests[1].requestHeaders,
{'X-ACCESS-TOKEN': 'footoken',
'Content-Type': 'text/plain;charset=utf-8'});
equal(server.requests[2].method, "GET");
equal(server.requests[2].url, domain);
......@@ -2689,11 +2856,7 @@
equal(server.requests[4].method, "POST");
equal(server.requests[4].url, put_url);
ok(server.requests[4].requestBody instanceof FormData);
equal(server.requests[4].withCredentials, false);
deepEqual(server.requests[4].requestHeaders,
{'X-ACCESS-TOKEN': 'footoken',
'Content-Type': 'text/plain;charset=utf-8'});
equal(context.spy.callCount, 6, "FormData.append count");
......@@ -2808,7 +2971,7 @@
}, ""]);
stop();
expect(40);
expect(67);
this.jio.post({
title: "barè",
......@@ -2819,6 +2982,56 @@
})
.then(function (result) {
equal(result, id);
equal(context.spy_ajax.callCount, 5, "ajax count");
equal(context.spy_ajax.getCall(0).args[0].type, "GET");
equal(context.spy_ajax.getCall(0).args[0].url, domain);
equal(context.spy_ajax.getCall(0).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(0).args[0].xhrFields, {
withCredentials: true
});
deepEqual(context.spy_ajax.getCall(0).args[0].headers, undefined);
equal(context.spy_ajax.getCall(0).args[0].data, undefined);
equal(context.spy_ajax.getCall(1).args[0].type, "POST");
equal(context.spy_ajax.getCall(1).args[0].url, add_url);
equal(context.spy_ajax.getCall(1).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(1).args[0].xhrFields, {
withCredentials: true
});
deepEqual(context.spy_ajax.getCall(1).args[0].headers, undefined);
ok(context.spy_ajax.getCall(1).args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.getCall(1).args[0].data);
equal(context.spy_ajax.getCall(2).args[0].type, "GET");
equal(context.spy_ajax.getCall(2).args[0].url, domain);
equal(context.spy_ajax.getCall(2).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(2).args[0].xhrFields, {
withCredentials: true
});
deepEqual(context.spy_ajax.getCall(2).args[0].headers, undefined);
equal(context.spy_ajax.getCall(2).args[0].data, undefined);
equal(context.spy_ajax.getCall(3).args[0].type, "GET");
equal(context.spy_ajax.getCall(3).args[0].url, traverse_url);
equal(context.spy_ajax.getCall(3).args[0].dataType, undefined);
deepEqual(context.spy_ajax.getCall(3).args[0].xhrFields, {
withCredentials: true
});
deepEqual(context.spy_ajax.getCall(3).args[0].headers, undefined);
equal(context.spy_ajax.getCall(3).args[0].data, undefined);
equal(context.spy_ajax.getCall(4).args[0].type, "POST");
equal(context.spy_ajax.getCall(4).args[0].url, put_url);
equal(context.spy_ajax.getCall(4).args[0].dataType, "blob");
deepEqual(context.spy_ajax.getCall(4).args[0].xhrFields, {
withCredentials: true
});
deepEqual(context.spy_ajax.getCall(4).args[0].headers, undefined);
ok(context.spy_ajax.getCall(4).args[0].data instanceof FormData,
'FormData expected: ' + context.spy_ajax.getCall(4).args[0].data);
equal(server.requests.length, 5);
equal(server.requests[0].method, "GET");
......@@ -2829,10 +3042,7 @@
equal(server.requests[1].method, "POST");
equal(server.requests[1].url, add_url);
ok(server.requests[1].requestBody instanceof FormData);
equal(server.requests[1].withCredentials, true);
deepEqual(server.requests[1].requestHeaders,
{'Content-Type': 'text/plain;charset=utf-8'});
equal(server.requests[2].method, "GET");
equal(server.requests[2].url, domain);
......@@ -2848,10 +3058,7 @@
equal(server.requests[4].method, "POST");
equal(server.requests[4].url, put_url);
ok(server.requests[4].requestBody instanceof FormData);
equal(server.requests[4].withCredentials, true);
deepEqual(server.requests[4].requestHeaders,
{'Content-Type': 'text/plain;charset=utf-8'});
equal(context.spy.callCount, 6, "FormData.append count");
......
......@@ -427,6 +427,8 @@
this.server.autoRespond = true;
this.server.autoRespondAfter = 5;
this.spy_ajax = sinon.spy(jIO.util, "ajax");
this.jio = jIO.createJIO({
type: "gdrive",
access_token: token
......@@ -435,6 +437,8 @@
teardown: function () {
this.server.restore();
delete this.server;
this.spy_ajax.restore();
delete this.spy_ajax;
}
});
......@@ -464,13 +468,14 @@
var blob = new Blob(["foo"]),
url_put_att = domain + "/upload/drive/v2/files/sampleId?" +
"uploadType=media&access_token=" + token,
server = this.server;
server = this.server,
context = this;
this.server.respondWith("PUT", url_put_att, [204, {
"Content-Type": "text/xml"
}, '{"mimeType": "text/xml"}']);
stop();
expect(7);
expect(11);
this.jio.putAttachment(
"sampleId",
......@@ -478,16 +483,20 @@
blob
)
.then(function () {
ok(context.spy_ajax.calledOnce, "ajax count " +
context.spy_ajax.callCount);
equal(context.spy_ajax.firstCall.args[0].type, "PUT");
equal(context.spy_ajax.firstCall.args[0].url, url_put_att);
deepEqual(context.spy_ajax.firstCall.args[0].xhrFields, undefined);
deepEqual(context.spy_ajax.firstCall.args[0].headers, undefined);
equal(context.spy_ajax.firstCall.args[0].data, blob);
equal(server.requests.length, 1);
equal(server.requests[0].method, "PUT");
equal(server.requests[0].url, url_put_att);
equal(server.requests[0].status, 204);
equal(server.requests[0].responseText, "{\"mimeType\": \"text/xml\"}");
deepEqual(server.requests[0].requestHeaders, {
"Content-Type": "text/plain;charset=utf-8"
});
equal(server.requests[0].requestBody, blob);
})
.fail(function (error) {
ok(false, error);
......
......@@ -3825,7 +3825,7 @@
test("signature document is not synced", function () {
stop();
expect(6);
expect(7);
var context = this;
......@@ -3836,41 +3836,50 @@
report_level: 1000,
signature_hash_key: 'foo_etag',
local_sub_storage: {
type: "uuid",
type: "storagealldocsdynamicselect",
sub_storage: {
type: "storagealldocsdynamicselect",
type: "query",
sub_storage: {
type: "query",
sub_storage: {
type: "document",
document_id: "/",
sub_storage: {
type: "local",
sessiononly: true
}
}
type: "memory"
}
}
},
remote_sub_storage: {
type: "uuid",
type: "storagealldocsdynamicselect",
sub_storage: {
type: "storagealldocsdynamicselect",
type: "query",
sub_storage: {
type: "query",
sub_storage: {
type: "memory"
}
type: "memory"
}
}
}
});
context.jio.post({title: "foo", foo_etag: "foo etag"})
// Hack to ensure that the signature is stored in the
// same local storage, even if memory is used
context.jio.__storage._signature_sub_storage
.__storage._sub_storage
.__storage._sub_storage
.__storage._sub_storage
.__storage._sub_storage
.__storage._database =
context.jio.__storage._local_sub_storage
.__storage._sub_storage
.__storage._sub_storage
.__storage._database;
context.jio.put('barfoo', {title: "foo", foo_etag: "foo etag"})
.then(function () {
return context.jio.repair();
})
.then(function () {
// Check that signature is a local document
// Otherwise, the test is meaningless
return context.jio.__storage._local_sub_storage.get(
context.jio.__storage._signature_hash
);
})
.then(function (result) {
deepEqual(result, {});
return context.jio.__storage._remote_sub_storage.get(
context.jio.__storage._signature_hash
);
......@@ -3878,7 +3887,7 @@
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " +
"_replicate_bc03c70b5346672bb87b14c4e17ed1e407676a41");
"_replicate_e9fa6706a8a6a961db3f9de41d44bdf11f25fb30");
equal(error.status_code, 404);
})
.then(function () {
......@@ -3892,7 +3901,7 @@
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " +
"_replicate_bc03c70b5346672bb87b14c4e17ed1e407676a41");
"_replicate_e9fa6706a8a6a961db3f9de41d44bdf11f25fb30");
equal(error.status_code, 404);
})
.fail(function (error) {
......
......@@ -3298,7 +3298,7 @@
test("signature document is not synced", function () {
stop();
expect(6);
expect(7);
var context = this;
......@@ -3307,26 +3307,34 @@
this.jio = jIO.createJIO({
type: "replicate",
local_sub_storage: {
type: "uuid",
sub_storage: {
type: "document",
document_id: "/",
sub_storage: {
type: "local",
sessiononly: true
}
}
type: "memory"
},
remote_sub_storage: {
type: "memory"
}
});
// Hack to ensure that the signature is stored in the
// same local storage, even if memory is used
context.jio.__storage._signature_sub_storage
.__storage._sub_storage
.__storage._sub_storage
.__storage._database =
context.jio.__storage._local_sub_storage
.__storage._database;
context.jio.post({"title": "foo"})
context.jio.put('barfoo', {"title": "foo"})
.then(function () {
return context.jio.repair();
})
.then(function () {
// Check that signature is a local document
// Otherwise, the test is meaningless
return context.jio.__storage._local_sub_storage.get(
context.jio.__storage._signature_hash
);
})
.then(function (result) {
deepEqual(result, {});
return context.jio.__storage._remote_sub_storage.get(
context.jio.__storage._signature_hash
);
......@@ -3334,7 +3342,7 @@
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " +
"_replicate_8662994dcefb3a2ceec61e86953efda8ec6520d6");
"_replicate_a0538a9def720b35ac7fd813d2ca008a5183375a");
equal(error.status_code, 404);
})
.then(function () {
......@@ -3348,7 +3356,7 @@
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " +
"_replicate_8662994dcefb3a2ceec61e86953efda8ec6520d6");
"_replicate_a0538a9def720b35ac7fd813d2ca008a5183375a");
equal(error.status_code, 404);
})
.fail(function (error) {
......
......@@ -3713,7 +3713,7 @@
test("use 4 parallel operation", function () {
stop();
expect(40);
expect(24);
var context = this,
order_number = 0,
......@@ -3728,20 +3728,9 @@
'stop put 1',
'start getAttachment 00',
'stop getAttachment 00',
'start putAttachment 00',
'start getAttachment 01',
'stop getAttachment 01',
'start putAttachment 01',
'start getAttachment 02',
'stop getAttachment 02',
'start putAttachment 02',
'start getAttachment 03',
'stop getAttachment 03',
'start putAttachment 03',
'stop putAttachment 00',
'stop putAttachment 01',
......@@ -3749,20 +3738,9 @@
'stop putAttachment 03',
'start getAttachment 10',
'stop getAttachment 10',
'start putAttachment 10',
'start getAttachment 11',
'stop getAttachment 11',
'start putAttachment 11',
'start getAttachment 12',
'stop getAttachment 12',
'start putAttachment 12',
'start getAttachment 13',
'stop getAttachment 13',
'start putAttachment 13',
'stop putAttachment 10',
'stop putAttachment 11',
......@@ -3808,14 +3786,14 @@
var storage = this;
return storage._sub_storage.getAttachment(id, name)
.push(undefined, function (error) {
assertExecutionOrder('stop getAttachment ' + name);
// assertExecutionOrder('stop getAttachment ' + name);
throw error;
});
};
StorageFourParallelOperation.prototype.putAttachment = function (id, name,
blob) {
assertExecutionOrder('start putAttachment ' + name);
// assertExecutionOrder('start putAttachment ' + name);
var storage = this;
return storage._sub_storage.putAttachment(id, name, blob)
.push(function (result) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment