Commit 12bb5c55 authored by Romain Courteaud's avatar Romain Courteaud

Stop mixing API parameters and user data.

Modify jIO API to keep user data not modified.
    jIO.get({"_id": "foo"} -> jIO.get("foo")
    jIO.remove({"_id": "foo"} -> jIO.remove("foo")
    jIO.post({"title": "bar"}) -> jIO.post({"title": "bar"})
    jIO.put({"_id": "foo", "title": "bar"}) -> jIO.put("foo", {"title": "bar"})
    jIO.getAttachment({"_id": "foo", "_attachment": "enclosure"} -> jIO.get("foo", "enclosure")
    jIO.removeAttachment({"_id": "foo", "_attachment": "enclosure"} -> jIO.remove("foo", "enclosure")
    jIO.putAttachment({"_id": "foo", "_attachment": "enclosure", "_blob": blob} -> jIO.remove("foo", "enclosure", blob)

jIO.get does not return an _id attribute anymore.
parent f4a45ae1
......@@ -174,8 +174,8 @@
util.readBlobAsDataURL = readBlobAsDataURL;
// tools
function checkId(param, storage, method_name) {
if (typeof param._id !== 'string' || param._id === '') {
function checkId(argument_list, storage, method_name) {
if (typeof argument_list[0] !== 'string' || argument_list[0] === '') {
throw new jIO.util.jIOError(
"Document id must be a non empty string on '" + storage.__type +
"." + method_name + "'.",
......@@ -184,8 +184,8 @@
}
}
function checkAttachmentId(param, storage, method_name) {
if (typeof param._attachment !== 'string' || param._attachment === '') {
function checkAttachmentId(argument_list, storage, method_name) {
if (typeof argument_list[1] !== 'string' || argument_list[1] === '') {
throw new jIO.util.jIOError(
"Attachment id must be a non empty string on '" + storage.__type +
"." + method_name + "'.",
......@@ -204,7 +204,7 @@
if (precondition_function !== undefined) {
return precondition_function.apply(
context.__storage,
[argument_list[0], context, name]
[argument_list, context, name]
);
}
})
......@@ -252,24 +252,18 @@
}
declareMethod(JioProxyStorage, "put", checkId, function (argument_list) {
return argument_list[0]._id;
});
declareMethod(JioProxyStorage, "get", checkId,
function (argument_list, result) {
// XXX Drop all _ properties
// Put _id properties to the result
result._id = argument_list[0]._id;
return result;
return argument_list[0];
});
declareMethod(JioProxyStorage, "get", checkId);
declareMethod(JioProxyStorage, "remove", checkId, function (argument_list) {
return argument_list[0]._id;
return argument_list[0];
});
JioProxyStorage.prototype.post = function (param) {
var context = this;
JioProxyStorage.prototype.post = function () {
var context = this,
argument_list = arguments;
return new RSVP.Queue()
.push(function () {
if (param._id === undefined) {
var storage_method = context.__storage.post;
if (storage_method === undefined) {
throw new jIO.util.jIOError(
......@@ -277,53 +271,40 @@
501
);
}
return context.__storage.post(param);
}
return context.put(param);
return context.__storage.post.apply(context.__storage, argument_list);
});
};
declareMethod(JioProxyStorage, 'putAttachment', function (param, storage,
declareMethod(JioProxyStorage, 'putAttachment', function (argument_list,
storage,
method_name) {
checkId(param, storage, method_name);
checkAttachmentId(param, storage, method_name);
checkId(argument_list, storage, method_name);
checkAttachmentId(argument_list, storage, method_name);
var options = argument_list[3] || {};
if (!(param._blob instanceof Blob) &&
typeof param._data === 'string') {
param._blob = new Blob([param._data], {
"type": param._content_type || param._mimetype ||
if (typeof argument_list[2] === 'string') {
argument_list[2] = new Blob([argument_list[2]], {
"type": options._content_type || options._mimetype ||
"text/plain;charset=utf-8"
});
delete param._data;
delete param._mimetype;
delete param._content_type;
} else if (param._blob instanceof Blob) {
delete param._data;
delete param._mimetype;
delete param._content_type;
} else if (param._data instanceof Blob) {
param._blob = param._data;
delete param._data;
delete param._mimetype;
delete param._content_type;
} else {
} else if (!(argument_list[2] instanceof Blob)) {
throw new jIO.util.jIOError(
'Attachment information must be like {"_id": document id, ' +
'"_attachment": attachment name, "_data": string, ["_mimetype": ' +
'content type]} or {"_id": document id, "_attachment": ' +
'attachment name, "_blob": Blob}',
'Attachment content is not a blob',
400
);
}
});
declareMethod(JioProxyStorage, 'removeAttachment', function (param, storage,
declareMethod(JioProxyStorage, 'removeAttachment', function (argument_list,
storage,
method_name) {
checkId(param, storage, method_name);
checkAttachmentId(param, storage, method_name);
checkId(argument_list, storage, method_name);
checkAttachmentId(argument_list, storage, method_name);
});
declareMethod(JioProxyStorage, 'getAttachment', function (param, storage,
declareMethod(JioProxyStorage, 'getAttachment', function (argument_list,
storage,
method_name) {
// if (param.storage_spec.type !== "indexeddb" &&
// param.storage_spec.type !== "dav" &&
......@@ -336,8 +317,8 @@
// ]);
// return false;
// }
checkId(param, storage, method_name);
checkAttachmentId(param, storage, method_name);
checkId(argument_list, storage, method_name);
checkAttachmentId(argument_list, storage, method_name);
}, function (argument_list, result) {
if (!(result instanceof Blob)) {
throw new jIO.util.jIOError(
......
......@@ -81,8 +81,8 @@
}
DavStorage.prototype.put = function (param) {
var id = restrictDocumentId(param._id);
DavStorage.prototype.put = function (id, param) {
id = restrictDocumentId(id);
delete param._id;
if (Object.getOwnPropertyNames(param).length > 0) {
// Reject if param has other properties than _id
......@@ -95,18 +95,18 @@
});
};
DavStorage.prototype.remove = function (param) {
var id = restrictDocumentId(param._id);
DavStorage.prototype.remove = function (id) {
id = restrictDocumentId(id);
return ajax(this, {
type: "DELETE",
url: this._url + id
});
};
DavStorage.prototype.get = function (param) {
DavStorage.prototype.get = function (id) {
var id = restrictDocumentId(param._id),
context = this;
var context = this;
id = restrictDocumentId(id);
return new RSVP.Queue()
.push(function () {
......@@ -162,26 +162,26 @@
};
DavStorage.prototype.putAttachment = function (param) {
var id = restrictDocumentId(param._id);
restrictAttachmentId(param._attachment);
DavStorage.prototype.putAttachment = function (id, name, blob) {
id = restrictDocumentId(id);
restrictAttachmentId(name);
return ajax(this, {
type: "PUT",
url: this._url + id + param._attachment,
data: param._blob
url: this._url + id + name,
data: blob
});
};
DavStorage.prototype.getAttachment = function (param) {
var id = restrictDocumentId(param._id),
context = this;
restrictAttachmentId(param._attachment);
DavStorage.prototype.getAttachment = function (id, name) {
var context = this;
id = restrictDocumentId(id);
restrictAttachmentId(name);
return new RSVP.Queue()
.push(function () {
return ajax(context, {
type: "GET",
url: context._url + id + param._attachment,
url: context._url + id + name,
dataType: "blob"
});
})
......@@ -195,7 +195,7 @@
if ((error.target !== undefined) &&
(error.target.status === 404)) {
throw new jIO.util.jIOError("Cannot find attachment: "
+ param._id + " , " + param._attachment,
+ id + " , " + name,
404);
}
throw error;
......@@ -203,23 +203,23 @@
};
DavStorage.prototype.removeAttachment = function (param) {
var id = restrictDocumentId(param._id),
context = this;
restrictAttachmentId(param._attachment);
DavStorage.prototype.removeAttachment = function (id, name) {
var context = this;
id = restrictDocumentId(id);
restrictAttachmentId(name);
return new RSVP.Queue()
.push(function () {
return ajax(context, {
type: "DELETE",
url: context._url + id + param._attachment
url: context._url + id + name
});
})
.push(undefined, function (error) {
if ((error.target !== undefined) &&
(error.target.status === 404)) {
throw new jIO.util.jIOError("Cannot find attachment: "
+ param._id + " , " + param._attachment,
+ id + " , " + name,
404);
}
throw error;
......
......@@ -19,21 +19,21 @@
DOCUMENT_EXTENSION + "$"),
ATTACHMENT_REGEXP = new RegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");
function getSubAttachmentIdFromParam(param) {
if (param._attachment === undefined) {
return 'jio_document/' + btoa(param._id) + DOCUMENT_EXTENSION;
function getSubAttachmentIdFromParam(id, name) {
if (name === undefined) {
return 'jio_document/' + btoa(id) + DOCUMENT_EXTENSION;
}
return 'jio_attachment/' + btoa(param._id) + "/" + btoa(param._attachment);
return 'jio_attachment/' + btoa(id) + "/" + btoa(name);
}
DocumentStorage.prototype.get = function (param) {
DocumentStorage.prototype.get = function (id) {
var result,
context = this;
return this._sub_storage.getAttachment({
"_id": this._document_id,
"_attachment": getSubAttachmentIdFromParam(param)
})
return this._sub_storage.getAttachment(
this._document_id,
getSubAttachmentIdFromParam(id)
)
.push(function (blob) {
return jIO.util.readBlobAsText(blob);
})
......@@ -42,9 +42,7 @@
})
.push(function (json) {
result = json;
return context._sub_storage.get({
"_id": context._document_id
});
return context._sub_storage.get(context._document_id);
})
.push(function (document) {
var attachments = {},
......@@ -55,7 +53,7 @@
if (ATTACHMENT_REGEXP.test(key)) {
exec = ATTACHMENT_REGEXP.exec(key);
try {
if (atob(exec[1]) === param._id) {
if (atob(exec[1]) === id) {
attachments[atob(exec[2])] = {};
}
} catch (error) {
......@@ -74,27 +72,25 @@
});
};
DocumentStorage.prototype.put = function (param) {
var doc_id = param._id;
return this._sub_storage.putAttachment({
"_id": this._document_id,
"_attachment": getSubAttachmentIdFromParam(param),
"_blob": new Blob([JSON.stringify(param)], {type: "application/json"})
})
DocumentStorage.prototype.put = function (doc_id, param) {
return this._sub_storage.putAttachment(
this._document_id,
getSubAttachmentIdFromParam(doc_id),
new Blob([JSON.stringify(param)], {type: "application/json"})
)
.push(function () {
return doc_id;
});
};
DocumentStorage.prototype.remove = function (param) {
return this._sub_storage.removeAttachment({
"_id": this._document_id,
"_attachment": getSubAttachmentIdFromParam(param)
})
DocumentStorage.prototype.remove = function (id) {
return this._sub_storage.removeAttachment(
this._document_id,
getSubAttachmentIdFromParam(id)
)
.push(function () {
return param._id;
return id;
});
};
......@@ -103,9 +99,7 @@
};
DocumentStorage.prototype.buildQuery = function () {
return this._sub_storage.get({
"_id": this._document_id
})
return this._sub_storage.get(this._document_id)
.push(function (document) {
var result = [],
key;
......@@ -130,26 +124,26 @@
});
};
DocumentStorage.prototype.getAttachment = function (param) {
return this._sub_storage.getAttachment({
"_id": this._document_id,
"_attachment": getSubAttachmentIdFromParam(param)
});
DocumentStorage.prototype.getAttachment = function (id, name) {
return this._sub_storage.getAttachment(
this._document_id,
getSubAttachmentIdFromParam(id, name)
);
};
DocumentStorage.prototype.putAttachment = function (param) {
return this._sub_storage.putAttachment({
"_id": this._document_id,
"_attachment": getSubAttachmentIdFromParam(param),
"_blob": param._blob
});
DocumentStorage.prototype.putAttachment = function (id, name, blob) {
return this._sub_storage.putAttachment(
this._document_id,
getSubAttachmentIdFromParam(id, name),
blob
);
};
DocumentStorage.prototype.removeAttachment = function (param) {
return this._sub_storage.removeAttachment({
"_id": this._document_id,
"_attachment": getSubAttachmentIdFromParam(param)
});
DocumentStorage.prototype.removeAttachment = function (id, name) {
return this._sub_storage.removeAttachment(
this._document_id,
getSubAttachmentIdFromParam(id, name)
);
};
jIO.addStorage('document', DocumentStorage);
......
......@@ -18,7 +18,7 @@
DOCUMENT_KEY = "/.jio_documents/",
ROOT = "/";
FileSystemBridgeStorage.prototype.get = function (param) {
FileSystemBridgeStorage.prototype.get = function (id) {
var context = this,
json_document,
explicit_document = false;
......@@ -28,10 +28,10 @@
.push(function () {
// First get the document itself if it exists
return context._sub_storage.getAttachment({
"_id": DOCUMENT_KEY,
"_attachment": param._id + DOCUMENT_EXTENSION
});
return context._sub_storage.getAttachment(
DOCUMENT_KEY,
id + DOCUMENT_EXTENSION
);
})
.push(function (blob) {
return new RSVP.Queue()
......@@ -55,20 +55,18 @@
.push(function (result) {
json_document = result;
return context._sub_storage.get({
"_id": ROOT
});
return context._sub_storage.get(ROOT);
})
.push(function (directory_document) {
if ((directory_document.hasOwnProperty("_attachments")) &&
(directory_document._attachments.hasOwnProperty(param._id))) {
(directory_document._attachments.hasOwnProperty(id))) {
json_document._attachments = {
enclosure: {}
};
} else {
if (!explicit_document) {
throw new jIO.util.jIOError("Cannot find document " + param._id,
throw new jIO.util.jIOError("Cannot find document " + id,
404);
}
}
......@@ -77,29 +75,26 @@
};
FileSystemBridgeStorage.prototype.put = function (param) {
var context = this,
doc_id = param._id;
FileSystemBridgeStorage.prototype.put = function (doc_id, param) {
var context = this;
// XXX Handle conflict!
return context._sub_storage.putAttachment({
"_id": DOCUMENT_KEY,
"_attachment": doc_id + DOCUMENT_EXTENSION,
"_blob": new Blob([JSON.stringify(param)], {type: "application/json"})
})
return context._sub_storage.putAttachment(
DOCUMENT_KEY,
doc_id + DOCUMENT_EXTENSION,
new Blob([JSON.stringify(param)], {type: "application/json"})
)
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
return context._sub_storage.put({
"_id": DOCUMENT_KEY
})
return context._sub_storage.put(DOCUMENT_KEY, {})
.push(function () {
return context._sub_storage.putAttachment({
"_id": DOCUMENT_KEY,
"_attachment": doc_id + DOCUMENT_EXTENSION,
"_blob": new Blob([JSON.stringify(param)],
return context._sub_storage.putAttachment(
DOCUMENT_KEY,
doc_id + DOCUMENT_EXTENSION,
new Blob([JSON.stringify(param)],
{type: "application/json"})
});
);
});
}
throw error;
......@@ -110,18 +105,17 @@
};
FileSystemBridgeStorage.prototype.remove = function (param) {
FileSystemBridgeStorage.prototype.remove = function (doc_id) {
var context = this,
got_error = false,
doc_id = param._id;
got_error = false;
return new RSVP.Queue()
// First, try to remove enclosure
.push(function () {
return context._sub_storage.removeAttachment({
"_id": ROOT,
"_attachment": doc_id
});
return context._sub_storage.removeAttachment(
ROOT,
doc_id
);
})
.push(undefined, function (error) {
......@@ -135,10 +129,10 @@
// Second, try to remove explicit doc
.push(function () {
return context._sub_storage.removeAttachment({
"_id": DOCUMENT_KEY,
"_attachment": doc_id + DOCUMENT_EXTENSION
});
return context._sub_storage.removeAttachment(
DOCUMENT_KEY,
doc_id + DOCUMENT_EXTENSION
);
})
.push(undefined, function (error) {
......@@ -163,9 +157,7 @@
// First, get list of explicit documents
.push(function () {
return context._sub_storage.get({
"_id": DOCUMENT_KEY
});
return context._sub_storage.get(DOCUMENT_KEY);
})
.push(function (result) {
var key;
......@@ -187,9 +179,7 @@
// Second, get list of enclosure
.push(function () {
return context._sub_storage.get({
"_id": ROOT
});
return context._sub_storage.get(ROOT);
})
.push(function (result) {
var key;
......@@ -218,41 +208,35 @@
};
FileSystemBridgeStorage.prototype.getAttachment = function (param) {
if (param._attachment !== "enclosure") {
FileSystemBridgeStorage.prototype.getAttachment = function (id, name) {
if (name !== "enclosure") {
throw new jIO.util.jIOError("Only support 'enclosure' attachment",
400);
}
return this._sub_storage.getAttachment({
"_id": ROOT,
"_attachment": param._id
});
return this._sub_storage.getAttachment(ROOT, id);
};
FileSystemBridgeStorage.prototype.putAttachment = function (param) {
if (param._attachment !== "enclosure") {
FileSystemBridgeStorage.prototype.putAttachment = function (id, name, blob) {
if (name !== "enclosure") {
throw new jIO.util.jIOError("Only support 'enclosure' attachment",
400);
}
return this._sub_storage.putAttachment({
"_id": ROOT,
"_attachment": param._id,
"_blob": param._blob
});
return this._sub_storage.putAttachment(
ROOT,
id,
blob
);
};
FileSystemBridgeStorage.prototype.removeAttachment = function (param) {
if (param._attachment !== "enclosure") {
FileSystemBridgeStorage.prototype.removeAttachment = function (id, name) {
if (name !== "enclosure") {
throw new jIO.util.jIOError("Only support 'enclosure' attachment",
400);
}
return this._sub_storage.removeAttachment({
"_id": ROOT,
"_attachment": param._id
});
return this._sub_storage.removeAttachment(ROOT, id);
};
jIO.addStorage('drivetojiomapping', FileSystemBridgeStorage);
......
......@@ -9,7 +9,7 @@
// url: {string}
// }
/*jslint nomen: true */
/*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob) {
......@@ -31,7 +31,7 @@
});
}
function getDocumentAndHateoas(storage, param, options) {
function getDocumentAndHateoas(storage, id, options) {
if (options === undefined) {
options = {};
}
......@@ -42,7 +42,7 @@
"type": "GET",
"url": UriTemplate.parse(site_hal._links.traverse.href)
.expand({
relative_url: param._id,
relative_url: id,
view: options._view
}),
"xhrFields": {
......@@ -62,8 +62,8 @@
this._default_view_reference = spec.default_view_reference;
}
ERP5Storage.prototype.get = function (param) {
return getDocumentAndHateoas(this, param)
ERP5Storage.prototype.get = function (id) {
return getDocumentAndHateoas(this, id)
.push(function (response) {
var result = JSON.parse(response.target.responseText),
attachments = {
......@@ -72,7 +72,6 @@
},
key;
// action_type;
result._id = param._id;
result.portal_type = result._links.type.name;
// Remove all ERP5 hateoas links / convert them into jIO ID
......@@ -90,15 +89,14 @@
});
};
ERP5Storage.prototype.getAttachment = function (param) {
var action = param._attachment;
ERP5Storage.prototype.getAttachment = function (id, action) {
if (action === "view") {
return getDocumentAndHateoas(this, param,
return getDocumentAndHateoas(this, id,
{"_view": this._default_view_reference})
.push(function (response) {
var result = JSON.parse(response.target.responseText);
result._id = param._id;
result._id = id;
result.portal_type = result._links.type.name;
// Remove all ERP5 hateoas links / convert them into jIO ID
......@@ -113,7 +111,7 @@
});
}
if (action === "links") {
return getDocumentAndHateoas(this, param)
return getDocumentAndHateoas(this, id)
.push(function (response) {
return new Blob(
[JSON.stringify(JSON.parse(response.target.responseText))],
......@@ -134,7 +132,7 @@
})
.push(function (evt) {
var result = JSON.parse(evt.target.responseText);
result._id = param._id;
result._id = id;
return new Blob(
[JSON.stringify(result)],
{"type": evt.target.getResponseHeader("Content-Type")}
......@@ -145,16 +143,16 @@
400);
};
ERP5Storage.prototype.putAttachment = function (metadata) {
ERP5Storage.prototype.putAttachment = function (id, name, blob) {
// Assert we use a callable on a document from the ERP5 site
if (metadata._attachment.indexOf(this._url) !== 0) {
if (name.indexOf(this._url) !== 0) {
throw new jIO.util.jIOError("Can not store outside ERP5: " +
metadata._attachment, 400);
name, 400);
}
return new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsText(metadata._blob);
return jIO.util.readBlobAsText(blob);
})
.push(function (evt) {
var form_data = JSON.parse(evt.target.result),
......@@ -167,7 +165,7 @@
}
return jIO.util.ajax({
"type": "POST",
"url": metadata._attachment,
"url": name,
"data": data,
"xhrFields": {
withCredentials: true
......
......@@ -205,7 +205,7 @@
return new RSVP.Promise(resolver);
}
IndexedDBStorage.prototype.get = function (param) {
IndexedDBStorage.prototype.get = function (id) {
var attachment_dict = {};
function addEntry(cursor) {
......@@ -217,13 +217,13 @@
var transaction = openTransaction(db, ["metadata", "attachment"],
"readonly");
return RSVP.all([
handleGet(transaction.objectStore("metadata").get(param._id)),
handleGet(transaction.objectStore("metadata").get(id)),
handleCursor(transaction.objectStore("attachment").index("_id")
.openCursor(IDBKeyRange.only(param._id)), addEntry)
.openCursor(IDBKeyRange.only(id)), addEntry)
]);
})
.push(function (result_list) {
var result = result_list[0];
var result = result_list[0].doc;
if (Object.getOwnPropertyNames(attachment_dict).length > 0) {
result._attachments = attachment_dict;
}
......@@ -241,11 +241,14 @@
return new RSVP.Promise(resolver);
}
IndexedDBStorage.prototype.put = function (metadata) {
IndexedDBStorage.prototype.put = function (id, metadata) {
return openIndexedDB(this)
.push(function (db) {
var transaction = openTransaction(db, ["metadata"], "readwrite");
return handleRequest(transaction.objectStore("metadata").put(metadata));
return handleRequest(transaction.objectStore("metadata").put({
"_id": id,
"doc": metadata
}));
});
};
......@@ -253,33 +256,36 @@
cursor["delete"]();
}
IndexedDBStorage.prototype.remove = function (param) {
IndexedDBStorage.prototype.remove = function (id) {
return openIndexedDB(this)
.push(function (db) {
var transaction = openTransaction(db, ["metadata", "attachment",
"blob"], "readwrite");
return RSVP.all([
handleRequest(transaction
.objectStore("metadata")["delete"](param._id)),
.objectStore("metadata")["delete"](id)),
// XXX Why not possible to delete with KeyCursor?
handleCursor(transaction.objectStore("attachment").index("_id")
.openCursor(IDBKeyRange.only(param._id)), deleteEntry),
.openCursor(IDBKeyRange.only(id)), deleteEntry),
handleCursor(transaction.objectStore("blob").index("_id")
.openCursor(IDBKeyRange.only(param._id)), deleteEntry)
.openCursor(IDBKeyRange.only(id)), deleteEntry)
]);
});
};
IndexedDBStorage.prototype.getAttachment = function (param) {
IndexedDBStorage.prototype.getAttachment = function (id, name, options) {
var transaction,
start,
end;
if (options === undefined) {
options = {};
}
return openIndexedDB(this)
.push(function (db) {
transaction = openTransaction(db, ["attachment", "blob"], "readonly");
// XXX Should raise if key is not good
return handleGet(transaction.objectStore("attachment")
.get(buildKeyPath([param._id, param._attachment])));
.get(buildKeyPath([id, name])));
})
.push(function (attachment) {
var total_length = attachment.info.length,
......@@ -289,8 +295,8 @@
start_index,
end_index;
start = param._start || 0;
end = param._end || total_length;
start = options.start || 0;
end = options.end || total_length;
if (end > total_length) {
end = total_length;
}
......@@ -312,8 +318,8 @@
for (i = start_index; i <= end_index; i += 1) {
promise_list.push(
handleGet(store.get(buildKeyPath([param._id,
param._attachment, i])))
handleGet(store.get(buildKeyPath([id,
name, i])))
);
}
return RSVP.all(promise_list);
......@@ -331,22 +337,22 @@
});
};
function removeAttachment(transaction, param) {
function removeAttachment(transaction, id, name) {
return RSVP.all([
// XXX How to get the right attachment
handleRequest(transaction.objectStore("attachment")["delete"](
buildKeyPath([param._id, param._attachment])
buildKeyPath([id, name])
)),
handleCursor(transaction.objectStore("blob").index("_id_attachment")
.openCursor(IDBKeyRange.only(
[param._id, param._attachment]
[id, name]
)),
deleteEntry
)
]);
}
IndexedDBStorage.prototype.putAttachment = function (metadata) {
IndexedDBStorage.prototype.putAttachment = function (id, name, blob) {
var blob_part = [],
transaction,
db;
......@@ -356,11 +362,11 @@
db = database;
// Split the blob first
return jIO.util.readBlobAsArrayBuffer(metadata._blob);
return jIO.util.readBlobAsArrayBuffer(blob);
})
.push(function (event) {
var array_buffer = event.target.result,
total_size = metadata._blob.size,
total_size = blob.size,
handled_size = 0;
while (handled_size < total_size) {
......@@ -371,18 +377,18 @@
// Remove previous attachment
transaction = openTransaction(db, ["attachment", "blob"], "readwrite");
return removeAttachment(transaction, metadata);
return removeAttachment(transaction, id, name);
})
.push(function () {
var promise_list = [
handleRequest(transaction.objectStore("attachment").put({
"_key_path": buildKeyPath([metadata._id, metadata._attachment]),
"_id": metadata._id,
"_attachment": metadata._attachment,
"_key_path": buildKeyPath([id, name]),
"_id": id,
"_attachment": name,
"info": {
"content_type": metadata._blob.type,
"length": metadata._blob.size
"content_type": blob.type,
"length": blob.size
}
}))
],
......@@ -392,10 +398,10 @@
for (i = 0; i < len; i += 1) {
promise_list.push(
handleRequest(blob_store.put({
"_key_path": buildKeyPath([metadata._id, metadata._attachment,
"_key_path": buildKeyPath([id, name,
i]),
"_id" : metadata._id,
"_attachment" : metadata._attachment,
"_id" : id,
"_attachment" : name,
"_part" : i,
"blob": blob_part[i]
}))
......@@ -406,12 +412,12 @@
});
};
IndexedDBStorage.prototype.removeAttachment = function (param) {
IndexedDBStorage.prototype.removeAttachment = function (id, name) {
return openIndexedDB(this)
.push(function (db) {
var transaction = openTransaction(db, ["attachment", "blob"],
"readwrite");
return removeAttachment(transaction, param);
return removeAttachment(transaction, id, name);
});
};
......
......@@ -41,8 +41,8 @@
}
}
LocalStorage.prototype.get = function (param) {
restrictDocumentId(param._id);
LocalStorage.prototype.get = function (id) {
restrictDocumentId(id);
var doc = {},
attachments = {},
......@@ -78,38 +78,38 @@
return new Blob([arrayBuffer], {type: mimeString});
}
LocalStorage.prototype.getAttachment = function (param) {
restrictDocumentId(param._id);
LocalStorage.prototype.getAttachment = function (id, name) {
restrictDocumentId(id);
var textstring = this._storage.getItem(param._attachment);
var textstring = this._storage.getItem(name);
if (textstring === null) {
throw new jIO.util.jIOError(
"Cannot find attachment " + param._attachment,
"Cannot find attachment " + name,
404
);
}
return dataURItoBlob(textstring);
};
LocalStorage.prototype.putAttachment = function (param) {
LocalStorage.prototype.putAttachment = function (id, name, blob) {
var context = this;
restrictDocumentId(param._id);
restrictDocumentId(id);
// the document already exists
// download data
return new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsDataURL(param._blob);
return jIO.util.readBlobAsDataURL(blob);
})
.push(function (e) {
context._storage.setItem(param._attachment, e.target.result);
context._storage.setItem(name, e.target.result);
});
};
LocalStorage.prototype.removeAttachment = function (param) {
restrictDocumentId(param._id);
return this._storage.removeItem(param._attachment);
LocalStorage.prototype.removeAttachment = function (id, name) {
restrictDocumentId(id);
return this._storage.removeItem(name);
};
......
......@@ -33,28 +33,28 @@
this._database = {};
}
MemoryStorage.prototype.put = function (metadata) {
if (!this._database.hasOwnProperty(metadata._id)) {
this._database[metadata._id] = {
MemoryStorage.prototype.put = function (id, metadata) {
if (!this._database.hasOwnProperty(id)) {
this._database[id] = {
attachments: {}
};
}
this._database[metadata._id].doc = JSON.stringify(metadata);
return metadata._id;
this._database[id].doc = JSON.stringify(metadata);
return id;
};
MemoryStorage.prototype.get = function (param) {
MemoryStorage.prototype.get = function (id) {
var doc,
key,
found = false,
attachments = {};
try {
doc = JSON.parse(this._database[param._id].doc);
doc = JSON.parse(this._database[id].doc);
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
"Cannot find document: " + param._id,
"Cannot find document: " + id,
404
);
}
......@@ -62,8 +62,8 @@
}
// XXX NotImplemented: list all attachments
for (key in this._database[param._id].attachments) {
if (this._database[param._id].attachments.hasOwnProperty(key)) {
for (key in this._database[id].attachments) {
if (this._database[id].attachments.hasOwnProperty(key)) {
found = true;
attachments[key] = {};
}
......@@ -74,17 +74,17 @@
return doc;
};
MemoryStorage.prototype.remove = function (param) {
delete this._database[param._id];
return param._id;
MemoryStorage.prototype.remove = function (id) {
delete this._database[id];
return id;
};
MemoryStorage.prototype.getAttachment = function (param) {
MemoryStorage.prototype.getAttachment = function (id, name) {
try {
var result = this._database[param._id].attachments[param._attachment];
var result = this._database[id].attachments[name];
if (result === undefined) {
throw new jIO.util.jIOError(
"Cannot find attachment: " + param._id + " , " + param._attachment,
"Cannot find attachment: " + id + " , " + name,
404
);
}
......@@ -92,7 +92,7 @@
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
"Cannot find attachment: " + param._id + " , " + param._attachment,
"Cannot find attachment: " + id + " , " + name,
404
);
}
......@@ -100,26 +100,26 @@
}
};
MemoryStorage.prototype.putAttachment = function (param) {
MemoryStorage.prototype.putAttachment = function (id, name, blob) {
var attachment_dict;
try {
attachment_dict = this._database[param._id].attachments;
attachment_dict = this._database[id].attachments;
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError("Cannot find document: " + param._id, 404);
throw new jIO.util.jIOError("Cannot find document: " + id, 404);
}
throw error;
}
attachment_dict[param._attachment] = param._blob;
attachment_dict[name] = blob;
};
MemoryStorage.prototype.removeAttachment = function (param) {
MemoryStorage.prototype.removeAttachment = function (id, name) {
try {
delete this._database[param._id].attachments[param._attachment];
delete this._database[id].attachments[name];
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
"Cannot find document: " + param._id,
"Cannot find document: " + id,
404
);
}
......
......@@ -101,8 +101,13 @@
i;
function safeGet(j) {
return substorage.get({"_id": result[j].id})
.push(undefined, function (error) {
var id = result[j].id;
return substorage.get(id)
.push(function (doc) {
// XXX Can delete user data!
doc._id = id;
return doc;
}, function (error) {
// Document may have been dropped after listing
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
......
......@@ -101,7 +101,7 @@
UnionStorage.prototype.put = function () {
var arg = arguments,
context = this;
return this._getWithStorageIndex({"_id": arg[0]._id})
return this._getWithStorageIndex(arg[0])
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
......@@ -124,7 +124,7 @@
UnionStorage.prototype.remove = function () {
var arg = arguments,
context = this;
return this._getWithStorageIndex({"_id": arg[0]._id})
return this._getWithStorageIndex(arg[0])
.push(function (result) {
// Storage found, remove from it directly
var sub_storage = context._storage_list[result[0]];
......
......@@ -23,13 +23,13 @@
).toString(16)).slice(-4);
}
param._id = S4() + S4() + "-" +
var id = S4() + S4() + "-" +
S4() + "-" +
S4() + "-" +
S4() + "-" +
S4() + S4() + S4();
return this.put(param);
return this.put(id, param);
};
UUIDStorage.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage, arguments);
......
......@@ -73,7 +73,7 @@
stop();
expect(7);
this.jio.put({"_id": "/put1/"})
this.jio.put("/put1/", {})
.then(function () {
equal(server.requests.length, 1);
equal(server.requests[0].method, "MKCOL");
......@@ -98,7 +98,7 @@
stop();
expect(3);
this.jio.put({"_id": "put1/"})
this.jio.put("put1/", {})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id put1/ is forbidden (no begin /)");
......@@ -116,7 +116,7 @@
stop();
expect(3);
this.jio.put({"_id": "/put1"})
this.jio.put("/put1", {})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id /put1 is forbidden (no end /)");
......@@ -134,7 +134,7 @@
stop();
expect(3);
this.jio.put({"_id": "/put1/", title: "foo"})
this.jio.put("/put1/", {title: "foo"})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Can not store properties: title");
......@@ -180,7 +180,7 @@
stop();
expect(7);
this.jio.remove({"_id": "/remove1/"})
this.jio.remove("/remove1/")
.then(function () {
equal(server.requests.length, 1);
equal(server.requests[0].method, "DELETE");
......@@ -205,7 +205,7 @@
stop();
expect(3);
this.jio.remove({"_id": "remove1/"})
this.jio.remove("remove1/")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id remove1/ is forbidden (no begin /)");
......@@ -223,7 +223,7 @@
stop();
expect(3);
this.jio.remove({"_id": "/remove1"})
this.jio.remove("/remove1")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id /remove1 is forbidden (no end /)");
......@@ -263,7 +263,7 @@
stop();
expect(3);
this.jio.get({"_id": "get1/"})
this.jio.get("get1/")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id get1/ is forbidden (no begin /)");
......@@ -281,7 +281,7 @@
stop();
expect(3);
this.jio.get({"_id": "/get1"})
this.jio.get("/get1")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id /get1 is forbidden (no end /)");
......@@ -304,7 +304,7 @@
stop();
expect(3);
this.jio.get({"_id": "/inexistent/"})
this.jio.get("/inexistent/")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document");
......@@ -355,10 +355,9 @@
stop();
expect(1);
this.jio.get({"_id": id})
this.jio.get(id)
.then(function (result) {
deepEqual(result, {
"_id": id
}, "Check document");
})
.fail(function (error) {
......@@ -460,10 +459,9 @@
stop();
expect(1);
this.jio.get({"_id": id})
this.jio.get(id)
.then(function (result) {
deepEqual(result, {
"_id": id,
"_attachments": {
attachment1: {},
attachment2: {}
......@@ -504,11 +502,11 @@
stop();
expect(3);
this.jio.putAttachment({
"_id": "putAttachment1/",
"_attachment": "attachment1",
"_blob": new Blob([""])
})
this.jio.putAttachment(
"putAttachment1/",
"attachment1",
new Blob([""])
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id putAttachment1/ is forbidden (no begin /)");
......@@ -526,11 +524,11 @@
stop();
expect(3);
this.jio.putAttachment({
"_id": "/putAttachment1",
"_attachment": "attachment1",
"_blob": new Blob([""])
})
this.jio.putAttachment(
"/putAttachment1",
"attachment1",
new Blob([""])
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id /putAttachment1 is forbidden (no end /)");
......@@ -548,11 +546,11 @@
stop();
expect(3);
this.jio.putAttachment({
"_id": "/putAttachment1/",
"_attachment": "attach/ment1",
"_blob": new Blob([""])
})
this.jio.putAttachment(
"/putAttachment1/",
"attach/ment1",
new Blob([""])
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "attachment attach/ment1 is forbidden");
......@@ -577,11 +575,11 @@
stop();
expect(7);
this.jio.putAttachment({
"_id": "/putAttachment1/",
"_attachment": "attachment1",
"_blob": blob
})
this.jio.putAttachment(
"/putAttachment1/",
"attachment1",
blob
)
.then(function () {
equal(server.requests.length, 1);
equal(server.requests[0].method, "PUT");
......@@ -628,10 +626,10 @@
stop();
expect(3);
this.jio.removeAttachment({
"_id": "removeAttachment1/",
"_attachment": "attachment1"
})
this.jio.removeAttachment(
"removeAttachment1/",
"attachment1"
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id removeAttachment1/ is forbidden (no begin /)");
......@@ -649,10 +647,10 @@
stop();
expect(3);
this.jio.removeAttachment({
"_id": "/removeAttachment1",
"_attachment": "attachment1"
})
this.jio.removeAttachment(
"/removeAttachment1",
"attachment1"
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id /removeAttachment1 is forbidden (no end /)");
......@@ -670,10 +668,10 @@
stop();
expect(3);
this.jio.removeAttachment({
"_id": "/removeAttachment1/",
"_attachment": "attach/ment1"
})
this.jio.removeAttachment(
"/removeAttachment1/",
"attach/ment1"
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "attachment attach/ment1 is forbidden");
......@@ -697,10 +695,10 @@
stop();
expect(7);
this.jio.removeAttachment({
"_id": "/removeAttachment1/",
"_attachment": "attachment1"
})
this.jio.removeAttachment(
"/removeAttachment1/",
"attachment1"
)
.then(function () {
equal(server.requests.length, 1);
equal(server.requests[0].method, "DELETE");
......@@ -730,10 +728,10 @@
stop();
expect(3);
this.jio.removeAttachment({
"_id": "/removeAttachment1/",
"_attachment": "attachment1"
})
this.jio.removeAttachment(
"/removeAttachment1/",
"attachment1"
)
.then(function () {
ok(false);
})
......@@ -774,10 +772,10 @@
stop();
expect(3);
this.jio.getAttachment({
"_id": "getAttachment1/",
"_attachment": "attachment1"
})
this.jio.getAttachment(
"getAttachment1/",
"attachment1"
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id getAttachment1/ is forbidden (no begin /)");
......@@ -795,10 +793,10 @@
stop();
expect(3);
this.jio.getAttachment({
"_id": "/getAttachment1",
"_attachment": "attachment1"
})
this.jio.getAttachment(
"/getAttachment1",
"attachment1"
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id /getAttachment1 is forbidden (no end /)");
......@@ -816,10 +814,10 @@
stop();
expect(3);
this.jio.getAttachment({
"_id": "/getAttachment1/",
"_attachment": "attach/ment1"
})
this.jio.getAttachment(
"/getAttachment1/",
"attach/ment1"
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "attachment attach/ment1 is forbidden");
......@@ -843,10 +841,10 @@
stop();
expect(10);
this.jio.getAttachment({
"_id": "/getAttachment1/",
"_attachment": "attachment1"
})
this.jio.getAttachment(
"/getAttachment1/",
"attachment1"
)
.then(function (result) {
equal(server.requests.length, 1);
equal(server.requests[0].method, "GET");
......@@ -883,10 +881,10 @@
stop();
expect(3);
this.jio.getAttachment({
"_id": "/getAttachment1/",
"_attachment": "attachment1"
})
this.jio.getAttachment(
"/getAttachment1/",
"attachment1"
)
.then(function () {
ok(false);
})
......
......@@ -44,26 +44,25 @@
test("document without attachment", function () {
stop();
expect(3);
expect(4);
function StorageGetNoAttachment() {
return this;
}
StorageGetNoAttachment.prototype.getAttachment = function (options) {
deepEqual(options, {"_id": "foo",
"_attachment": "jio_document/YmFy.json"},
"getAttachment bar");
StorageGetNoAttachment.prototype.getAttachment = function (id, name) {
equal(id, "foo", "getAttachment bar");
equal(name, "jio_document/YmFy.json", "getAttachment bar");
return new Blob([JSON.stringify({
title: options._attachment,
id: "ID " + options._attachment,
title: name,
id: "ID " + name,
"another": "property"
})]);
};
StorageGetNoAttachment.prototype.get = function (options) {
deepEqual(options, {"_id": "foo"}, "Get foo");
StorageGetNoAttachment.prototype.get = function (id) {
equal(id, "foo", "Get foo");
return {
title: options._id,
id: "ID " + options._id,
title: id,
id: "ID " + id,
"another": "property"
};
};
......@@ -78,10 +77,9 @@
}
});
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
title: "jio_document/YmFy.json",
id: "ID jio_document/YmFy.json",
"another": "property"
......@@ -97,26 +95,25 @@
test("document with attachment", function () {
stop();
expect(3);
expect(4);
function StorageGetWithAttachment() {
return this;
}
StorageGetWithAttachment.prototype.getAttachment = function (options) {
deepEqual(options, {"_id": "foo",
"_attachment": "jio_document/YmFy.json"},
"getAttachment bar");
StorageGetWithAttachment.prototype.getAttachment = function (id, name) {
equal(id, "foo", "getAttachment bar");
equal(name, "jio_document/YmFy.json", "getAttachment bar");
return new Blob([JSON.stringify({
title: options._attachment,
id: "ID " + options._attachment,
title: name,
id: "ID " + name,
"another": "property"
})]);
};
StorageGetWithAttachment.prototype.get = function (options) {
deepEqual(options, {"_id": "foo"}, "Get foo");
StorageGetWithAttachment.prototype.get = function (id) {
equal(id, "foo", "Get foo");
var result = {
title: options._id,
id: "ID " + options._id,
title: id,
id: "ID " + id,
"another": "property",
"_attachments": {
"foo1": {}
......@@ -147,10 +144,9 @@
}
});
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
title: "jio_document/YmFy.json",
id: "ID jio_document/YmFy.json",
"another": "property",
......@@ -173,7 +169,7 @@
module("documentStorage.put");
test("put called substorage put", function () {
stop();
expect(4);
expect(5);
var jio = jIO.createJIO({
type: "document",
......@@ -182,26 +178,22 @@
type: "documentstorage200"
}
});
Storage200.prototype.putAttachment = function (param) {
var blob = param._blob;
delete param._blob;
Storage200.prototype.putAttachment = function (id, name, blob) {
equal(blob.type, "application/json", "Blob type is OK");
deepEqual(param, {
"_id": "foo",
"_attachment": "jio_document/YmFy.json"
}, "putAttachment 200 called");
equal(id, "foo", "putAttachment 200 called");
equal(name, "jio_document/YmFy.json", "putAttachment 200 called");
return jIO.util.readBlobAsText(blob)
.then(function (result) {
deepEqual(JSON.parse(result.target.result),
{"_id": "bar", "title": "bartitle"},
{"title": "bartitle"},
"JSON is in blob");
return param._id;
return id;
});
};
jio.put({"_id": "bar", "title": "bartitle"})
jio.put("bar", {"title": "bartitle"})
.then(function (result) {
equal(result, "bar");
})
......@@ -219,7 +211,7 @@
module("documentStorage.remove");
test("remove called substorage removeAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "document",
......@@ -228,14 +220,13 @@
type: "documentstorage200"
}
});
Storage200.prototype.removeAttachment = function (param) {
deepEqual(param, {"_id": "foo",
"_attachment": "jio_document/YmFy.json"},
"removeAttachment 200 called");
return param._id;
Storage200.prototype.removeAttachment = function (id, name) {
equal(id, "foo", "removeAttachment 200 called");
equal(name, "jio_document/YmFy.json", "removeAttachment 200 called");
return id;
};
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function (result) {
equal(result, "bar");
})
......@@ -254,7 +245,7 @@
module("documentStorage.getAttachment");
test("getAttachment called substorage getAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "document",
......@@ -265,14 +256,13 @@
}),
blob = new Blob([""]);
Storage200.prototype.getAttachment = function (param) {
deepEqual(param, {"_id": "foo",
"_attachment": "jio_attachment/YmFy/YmFyMg=="},
"getAttachment 200 called");
Storage200.prototype.getAttachment = function (id, name) {
equal(id, "foo", "getAttachment 200 called");
equal(name, "jio_attachment/YmFy/YmFyMg==", "getAttachment 200 called");
return blob;
};
jio.getAttachment({"_id": "bar", "_attachment": "bar2"})
jio.getAttachment("bar", "bar2")
.then(function (result) {
equal(result, blob);
})
......@@ -290,7 +280,7 @@
module("documentStorage.putAttachment");
test("putAttachment called substorage putAttachment", function () {
stop();
expect(2);
expect(4);
var jio = jIO.createJIO({
type: "document",
......@@ -301,15 +291,14 @@
}),
blob = new Blob([""]);
Storage200.prototype.putAttachment = function (param) {
deepEqual(param, {"_id": "foo",
"_attachment": "jio_attachment/YmFy/YmFyMg==",
"_blob": blob},
"putAttachment 200 called");
Storage200.prototype.putAttachment = function (id, name, blob2) {
equal(id, "foo", "putAttachment 200 called");
equal(name, "jio_attachment/YmFy/YmFyMg==", "putAttachment 200 called");
deepEqual(blob2, blob, "putAttachment 200 called");
return "OK";
};
jio.putAttachment({"_id": "bar", "_attachment": "bar2", "_blob": blob})
jio.putAttachment("bar", "bar2", blob)
.then(function (result) {
equal(result, "OK");
})
......@@ -327,7 +316,7 @@
module("documentStorage.removeAttachment");
test("removeAttachment called substorage removeAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "document",
......@@ -337,14 +326,14 @@
}
});
Storage200.prototype.removeAttachment = function (param) {
deepEqual(param, {"_id": "foo",
"_attachment": "jio_attachment/YmFy/YmFyMg=="},
Storage200.prototype.removeAttachment = function (id, name) {
equal(id, "foo", "removeAttachment 200 called");
equal(name, "jio_attachment/YmFy/YmFyMg==",
"removeAttachment 200 called");
return "Removed";
};
jio.removeAttachment({"_id": "bar", "_attachment": "bar2"})
jio.removeAttachment("bar", "bar2")
.then(function (result) {
equal(result, "Removed");
})
......@@ -383,9 +372,9 @@
function StorageAllDocsNoAttachment() {
return this;
}
StorageAllDocsNoAttachment.prototype.get = function (options) {
equal(options._id, "foo", "Get foo");
return {title: options._id, id: "ID " + options._id,
StorageAllDocsNoAttachment.prototype.get = function (id) {
equal(id, "foo", "Get foo");
return {title: id, id: "ID " + id,
"another": "property"};
};
......@@ -424,11 +413,11 @@
function StorageAllDocsWithAttachment() {
return this;
}
StorageAllDocsWithAttachment.prototype.get = function (options) {
equal(options._id, "foo", "Get foo");
StorageAllDocsWithAttachment.prototype.get = function (id) {
equal(id, "foo", "Get foo");
var result = {
title: options._id,
id: "ID " + options._id,
title: id,
id: "ID " + id,
"another": "property",
"_attachments": {
"foo1": {}
......
......@@ -43,22 +43,19 @@
test("get non existent document", function () {
stop();
expect(5);
expect(6);
function StorageGetNoDocument() {
return this;
}
StorageGetNoDocument.prototype.getAttachment = function (options) {
deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"},
"getAttachment");
StorageGetNoDocument.prototype.getAttachment = function (id, name) {
equal(id, "/.jio_documents/", "getAttachment");
equal(name, "bar.json", "getAttachment");
throw new jIO.util.jIOError("Cannot find subattachment", 404);
};
StorageGetNoDocument.prototype.get = function (options) {
deepEqual(options, {"_id": "/"}, "Get document");
return {
"_id": "/"
};
StorageGetNoDocument.prototype.get = function (id) {
equal(id, "/", "Get document");
return {};
};
jIO.addStorage('drivetojiomappinggetnodocument', StorageGetNoDocument);
......@@ -70,7 +67,7 @@
}
});
jio.get({"_id": "bar"})
jio.get("bar")
.then(function () {
ok(false);
})
......@@ -86,21 +83,19 @@
test("get document with only one attachment", function () {
stop();
expect(3);
expect(4);
function StorageGetOnlyAttachment() {
return this;
}
StorageGetOnlyAttachment.prototype.getAttachment = function (options) {
deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"},
"getAttachment");
StorageGetOnlyAttachment.prototype.getAttachment = function (id, name) {
equal(id, "/.jio_documents/", "getAttachment");
equal(name, "bar.json", "getAttachment");
throw new jIO.util.jIOError("Cannot find subattachment", 404);
};
StorageGetOnlyAttachment.prototype.get = function (options) {
deepEqual(options, {"_id": "/"}, "Get document");
StorageGetOnlyAttachment.prototype.get = function (id) {
equal(id, "/", "Get document");
return {
"_id": "/",
"_attachments": {
"bar": {}
}
......@@ -117,10 +112,9 @@
}
});
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
"_attachments": {
enclosure: {}
}
......@@ -136,22 +130,19 @@
test("get document with only one document", function () {
stop();
expect(3);
expect(4);
function StorageGetOnlyDocument() {
return this;
}
StorageGetOnlyDocument.prototype.getAttachment = function (options) {
deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"},
"getAttachment");
StorageGetOnlyDocument.prototype.getAttachment = function (id, name) {
equal(id, "/.jio_documents/", "getAttachment");
equal(name, "bar.json", "getAttachment");
return new Blob([JSON.stringify({title: "foo"})]);
};
StorageGetOnlyDocument.prototype.get = function (options) {
deepEqual(options, {"_id": "/"}, "Get document");
return {
"_id": "/"
};
StorageGetOnlyDocument.prototype.get = function (id) {
deepEqual(id, "/", "Get document");
return {};
};
jIO.addStorage('drivetojiomappinggetonlydocument', StorageGetOnlyDocument);
......@@ -163,10 +154,9 @@
}
});
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
"title": "foo"
});
})
......@@ -180,21 +170,19 @@
test("get document with one document and one attachment", function () {
stop();
expect(3);
expect(4);
function StorageGetBoth() {
return this;
}
StorageGetBoth.prototype.getAttachment = function (options) {
deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"},
"getAttachment");
StorageGetBoth.prototype.getAttachment = function (id, name) {
equal(id, "/.jio_documents/", "getAttachment");
equal(name, "bar.json", "getAttachment");
return new Blob([JSON.stringify({title: "foo"})]);
};
StorageGetBoth.prototype.get = function (options) {
deepEqual(options, {"_id": "/"}, "Get document");
StorageGetBoth.prototype.get = function (id) {
equal(id, "/", "Get document");
return {
"_id": "/",
"_attachments": {
"bar": {}
}
......@@ -210,10 +198,9 @@
}
});
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
"title": "foo",
"_attachments": {
enclosure: {}
......@@ -234,7 +221,7 @@
module("driveToJioMapping.put");
test("put called substorage put", function () {
stop();
expect(4);
expect(5);
var jio = jIO.createJIO({
type: "drivetojiomapping",
......@@ -242,26 +229,22 @@
type: "drivetojiomapping200"
}
});
Storage200.prototype.putAttachment = function (param) {
var blob = param._blob;
delete param._blob;
Storage200.prototype.putAttachment = function (id, name, blob) {
equal(blob.type, "application/json", "Blob type is OK");
deepEqual(param, {
"_id": "/.jio_documents/",
"_attachment": "bar.json"
}, "putAttachment 200 called");
equal(id, "/.jio_documents/", "putAttachment 200 called");
equal(name, "bar.json", "putAttachment 200 called");
return jIO.util.readBlobAsText(blob)
.then(function (result) {
deepEqual(JSON.parse(result.target.result),
{"_id": "bar", "title": "bartitle"},
{"title": "bartitle"},
"JSON is in blob");
return param._id;
return id;
});
};
jio.put({"_id": "bar", "title": "bartitle"})
jio.put("bar", {"title": "bartitle"})
.then(function (result) {
equal(result, "bar");
})
......@@ -275,7 +258,7 @@
test("automatically create subdocuments", function () {
stop();
expect(8);
expect(11);
var call_count = 0,
jio;
......@@ -283,20 +266,17 @@
function StorageCreateSubDocument() {
return this;
}
StorageCreateSubDocument.prototype.putAttachment = function (param) {
StorageCreateSubDocument.prototype.putAttachment = function (id, name,
blob) {
call_count += 1;
var blob = param._blob;
delete param._blob;
equal(blob.type, "application/json", "Blob type is OK");
deepEqual(param, {
"_id": "/.jio_documents/",
"_attachment": "bar.json"
}, "putAttachment 200 called");
equal(id, "/.jio_documents/", "putAttachment 200 called");
equal(name, "bar.json", "putAttachment 200 called");
return jIO.util.readBlobAsText(blob)
.then(function (result) {
deepEqual(JSON.parse(result.target.result),
{"_id": "bar", "title": "bartitle"},
{"title": "bartitle"},
"JSON is in blob");
if (call_count === 1) {
throw new jIO.util.jIOError("Cannot access subdocument", 404);
......@@ -305,10 +285,9 @@
});
};
StorageCreateSubDocument.prototype.put = function (param) {
deepEqual(param, {
"_id": "/.jio_documents/"
}, "put 200 called");
StorageCreateSubDocument.prototype.put = function (id, param) {
equal(id, "/.jio_documents/", "PutSubDocument OK");
deepEqual(param, {}, "put 200 called");
return "PutSubDocument OK";
};
......@@ -322,7 +301,7 @@
}
});
jio.put({"_id": "bar", "title": "bartitle"})
jio.put("bar", {"title": "bartitle"})
.then(function (result) {
equal(result, "bar");
})
......@@ -343,22 +322,20 @@
var call_count = 0,
jio;
stop();
expect(6);
expect(8);
function StorageRemoveNoDocument() {
return this;
}
StorageRemoveNoDocument.prototype.removeAttachment = function (options) {
StorageRemoveNoDocument.prototype.removeAttachment = function (id, name) {
call_count += 1;
if (call_count === 1) {
deepEqual(options, {"_id": "/",
"_attachment": "bar"},
"removeAttachment");
equal(id, "/", "removeAttachment");
equal(name, "bar", "removeAttachment");
throw new jIO.util.jIOError("Cannot find subattachment", 404);
}
deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"},
"removeAttachment");
equal(id, "/.jio_documents/", "removeAttachment");
equal(name, "bar.json", "removeAttachment");
throw new jIO.util.jIOError("Cannot find subdocument", 404);
};
......@@ -372,7 +349,7 @@
}
});
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function () {
ok(false);
})
......@@ -393,23 +370,21 @@
var call_count = 0,
jio;
stop();
expect(4);
expect(6);
function StorageRemoveOnlyAttachment() {
return this;
}
StorageRemoveOnlyAttachment.prototype.removeAttachment =
function (options) {
function (id, name) {
call_count += 1;
if (call_count === 1) {
deepEqual(options, {"_id": "/",
"_attachment": "bar"},
"removeAttachment");
equal(id, "/", "removeAttachment");
equal(name, "bar", "removeAttachment");
return "Removed";
}
deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"},
"removeAttachment");
equal(id, "/.jio_documents/", "removeAttachment");
equal(name, "bar.json", "removeAttachment");
throw new jIO.util.jIOError("Cannot find subdocument", 404);
};
......@@ -423,7 +398,7 @@
}
});
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function (result) {
equal(result, "bar");
equal(call_count, 2);
......@@ -440,22 +415,21 @@
var call_count = 0,
jio;
stop();
expect(4);
expect(6);
function StorageRemoveOnlyDocument() {
return this;
}
StorageRemoveOnlyDocument.prototype.removeAttachment = function (options) {
StorageRemoveOnlyDocument.prototype.removeAttachment = function (id,
name) {
call_count += 1;
if (call_count === 1) {
deepEqual(options, {"_id": "/",
"_attachment": "bar"},
"removeAttachment");
equal(id, "/", "removeAttachment");
equal(name, "bar", "removeAttachment");
throw new jIO.util.jIOError("Cannot find subattachment", 404);
}
deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"},
"removeAttachment");
equal(id, "/.jio_documents/", "removeAttachment");
equal(name, "bar.json", "removeAttachment");
return "Removed";
};
......@@ -469,7 +443,7 @@
}
});
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function (result) {
equal(result, "bar");
equal(call_count, 2);
......@@ -486,22 +460,20 @@
var call_count = 0,
jio;
stop();
expect(4);
expect(6);
function StorageRemoveBoth() {
return this;
}
StorageRemoveBoth.prototype.removeAttachment = function (options) {
StorageRemoveBoth.prototype.removeAttachment = function (id, name) {
call_count += 1;
if (call_count === 1) {
deepEqual(options, {"_id": "/",
"_attachment": "bar"},
"removeAttachment");
deepEqual(id, "/", "removeAttachment");
deepEqual(name, "bar", "removeAttachment");
return "Removed attachment";
}
deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"},
"removeAttachment");
deepEqual(id, "/.jio_documents/", "removeAttachment");
deepEqual(name, "bar.json", "removeAttachment");
return "Removed document";
};
......@@ -514,7 +486,7 @@
}
});
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function (result) {
equal(result, "bar");
equal(call_count, 2);
......@@ -542,7 +514,7 @@
}
});
jio.getAttachment({"_id": "bar", "_attachment": "foo"})
jio.getAttachment("bar", "foo")
.then(function () {
ok(false);
})
......@@ -561,7 +533,7 @@
test("getAttachment called substorage getAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "drivetojiomapping",
......@@ -571,14 +543,13 @@
}),
blob = new Blob(["foo"]);
Storage200.prototype.getAttachment = function (param) {
deepEqual(param, {"_id": "/",
"_attachment": "bar"},
"getAttachment 200 called");
Storage200.prototype.getAttachment = function (id, name) {
equal(id, "/", "getAttachment 200 called");
equal(name, "bar", "getAttachment 200 called");
return blob;
};
jio.getAttachment({"_id": "bar", "_attachment": "enclosure"})
jio.getAttachment("bar", "enclosure")
.then(function (result) {
equal(result, blob);
})
......@@ -605,8 +576,7 @@
}
});
jio.putAttachment({"_id": "bar", "_attachment": "foo",
"_blob": new Blob(["foo"])})
jio.putAttachment("bar", "foo", new Blob(["foo"]))
.then(function () {
ok(false);
})
......@@ -625,7 +595,7 @@
test("putAttachment called substorage putAttachment", function () {
stop();
expect(2);
expect(4);
var jio = jIO.createJIO({
type: "drivetojiomapping",
......@@ -635,15 +605,14 @@
}),
blob = new Blob(["foo"]);
Storage200.prototype.putAttachment = function (param) {
deepEqual(param, {"_id": "/",
"_blob": blob,
"_attachment": "bar"},
"putAttachment 200 called");
Storage200.prototype.putAttachment = function (id, name, blob2) {
equal(id, "/", "putAttachment 200 called");
equal(name, "bar", "putAttachment 200 called");
deepEqual(blob2, blob, "putAttachment 200 called");
return "Put";
};
jio.putAttachment({"_id": "bar", "_attachment": "enclosure", "_blob": blob})
jio.putAttachment("bar", "enclosure", blob)
.then(function (result) {
equal(result, "Put");
})
......@@ -670,7 +639,7 @@
}
});
jio.removeAttachment({"_id": "bar", "_attachment": "foo"})
jio.removeAttachment("bar", "foo")
.then(function () {
ok(false);
})
......@@ -689,7 +658,7 @@
test("removeAttachment called substorage removeAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "drivetojiomapping",
......@@ -698,14 +667,13 @@
}
});
Storage200.prototype.removeAttachment = function (param) {
deepEqual(param, {"_id": "/",
"_attachment": "bar"},
"removeAttachment 200 called");
Storage200.prototype.removeAttachment = function (id, name) {
equal(id, "/", "removeAttachment 200 called");
equal(name, "bar", "removeAttachment 200 called");
return "Removed";
};
jio.removeAttachment({"_id": "bar", "_attachment": "enclosure"})
jio.removeAttachment("bar", "enclosure")
.then(function (result) {
equal(result, "Removed");
})
......@@ -748,21 +716,15 @@
return this;
}
StorageAllDocsNoDirectory.prototype.get = function (param) {
StorageAllDocsNoDirectory.prototype.get = function (id) {
call_count += 1;
if (call_count === 1) {
deepEqual(param, {
"_id": "/.jio_documents/"
}, "get documents called");
equal(id, "/.jio_documents/", "get documents called");
throw new jIO.util.jIOError("Cannot access subdocument", 404);
}
deepEqual(param, {
"_id": "/"
}, "get attachments called");
return {
"_id": "/"
};
equal(id, "/", "get attachments called");
return {};
};
jIO.addStorage('drivetojiomappingalldocsnodirectory',
......@@ -803,23 +765,15 @@
return this;
}
StorageAllDocsEmpty.prototype.get = function (param) {
StorageAllDocsEmpty.prototype.get = function (id) {
call_count += 1;
if (call_count === 1) {
deepEqual(param, {
"_id": "/.jio_documents/"
}, "get documents called");
return {
"_id": "/.jio_documents/"
};
equal(id, "/.jio_documents/", "get documents called");
return {};
}
deepEqual(param, {
"_id": "/"
}, "get attachments called");
return {
"_id": "/"
};
equal(id, "/", "get attachments called");
return {};
};
jIO.addStorage('drivetojiomappingalldocsempty',
......@@ -861,20 +815,15 @@
return this;
}
StorageAllDocsAttachmentsOnly.prototype.get = function (param) {
StorageAllDocsAttachmentsOnly.prototype.get = function (id) {
call_count += 1;
if (call_count === 1) {
deepEqual(param, {
"_id": "/.jio_documents/"
}, "get documents called");
equal(id, "/.jio_documents/", "get documents called");
throw new jIO.util.jIOError("Cannot access subdocument", 404);
}
deepEqual(param, {
"_id": "/"
}, "get attachments called");
equal(id, "/", "get attachments called");
return {
"_id": "/",
"_attachments": {
foo: {},
bar: {}
......@@ -927,14 +876,11 @@
return this;
}
StorageAllDocsFilterDocument.prototype.get = function (param) {
StorageAllDocsFilterDocument.prototype.get = function (id) {
call_count += 1;
if (call_count === 1) {
deepEqual(param, {
"_id": "/.jio_documents/"
}, "get documents called");
equal(id, "/.jio_documents/", "get documents called");
return {
"_id": "/",
"_attachments": {
"foo.json": {},
"bar.json": {},
......@@ -943,12 +889,8 @@
};
}
deepEqual(param, {
"_id": "/"
}, "get attachments called");
return {
"_id": "/"
};
equal(id, "/", "get attachments called");
return {};
};
jIO.addStorage('drivetojiomappingalldocsfilterdocument',
......@@ -995,14 +937,11 @@
return this;
}
StorageAllDocsBoth.prototype.get = function (param) {
StorageAllDocsBoth.prototype.get = function (id) {
call_count += 1;
if (call_count === 1) {
deepEqual(param, {
"_id": "/.jio_documents/"
}, "get documents called");
equal(id, "/.jio_documents/", "get documents called");
return {
"_id": "/",
"_attachments": {
"foo.json": {},
"bar.json": {}
......@@ -1010,11 +949,8 @@
};
}
deepEqual(param, {
"_id": "/"
}, "get attachments called");
equal(id, "/", "get attachments called");
return {
"_id": "/",
"_attachments": {
"bar": {},
"foobar": {}
......
......@@ -91,12 +91,11 @@
stop();
expect(10);
this.jio.get({"_id": id})
this.jio.get(id)
.then(function (result) {
deepEqual(result, {
portal_type: "Person",
title: "foo",
"_id": id,
"_attachments": {
links: {},
view: {}
......@@ -149,11 +148,11 @@
stop();
expect(3);
this.jio.putAttachment({
"_id": "putAttachment1/",
"_attachment": "attachment1",
"_blob": new Blob(["foo"])
})
this.jio.putAttachment(
"putAttachment1/",
"attachment1",
new Blob(["foo"])
)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Can not store outside ERP5: attachment1");
......@@ -185,11 +184,11 @@
stop();
expect(11);
this.jio.putAttachment({
"_id": id,
"_attachment": submit_url,
"_blob": new Blob([JSON.stringify(form_json)])
})
this.jio.putAttachment(
id,
submit_url,
new Blob([JSON.stringify(form_json)])
)
.then(function () {
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
......@@ -241,10 +240,7 @@
stop();
expect(3);
this.jio.getAttachment({
"_id": "getAttachment1/",
"_attachment": "attachment1"
})
this.jio.getAttachment("getAttachment1/", "attachment1")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "ERP5: not support get attachment: attachment1");
......@@ -284,10 +280,7 @@
stop();
expect(12);
this.jio.getAttachment({
"_id": id,
"_attachment": "view"
})
this.jio.getAttachment(id, "view")
.then(function (result) {
equal(server.requests.length, 2);
equal(server.requests[0].method, "GET");
......@@ -344,10 +337,7 @@
stop();
expect(12);
this.jio.getAttachment({
"_id": id,
"_attachment": "links"
})
this.jio.getAttachment(id, "links")
.then(function (result) {
equal(server.requests.length, 2);
equal(server.requests[0].method, "GET");
......@@ -398,10 +388,7 @@
stop();
expect(8);
this.jio.getAttachment({
"_id": id,
"_attachment": callable_url
})
this.jio.getAttachment(id, callable_url)
.then(function (result) {
equal(server.requests.length, 1);
equal(server.requests[0].method, "GET");
......
......@@ -230,8 +230,8 @@
deleteIndexedDB(context.jio)
.then(function () {
return RSVP.all([
context.jio.put({"_id": "2", "title": "title2"}),
context.jio.put({"_id": "1", "title": "title1"})
context.jio.put("2", {"title": "title2"}),
context.jio.put("1", {"title": "title1"})
]);
})
.then(function () {
......@@ -278,7 +278,7 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
context.spy_open = sinon.spy(indexedDB, "open");
......@@ -294,7 +294,7 @@
context.spy_cursor = sinon.spy(IDBIndex.prototype, "openCursor");
context.spy_key_range = sinon.spy(IDBKeyRange, "only");
return context.jio.get({"_id": "foo"});
return context.jio.get("foo");
})
.then(function () {
......@@ -374,7 +374,7 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.get({"_id": "inexistent"});
return context.jio.get("inexistent");
})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
......@@ -397,14 +397,13 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": id, "title": "bar"});
return context.jio.put(id, {"title": "bar"});
})
.then(function () {
return context.jio.get({"_id": id});
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {
"_id": "/",
"title": "bar"
}, "Check document");
})
......@@ -425,18 +424,16 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": id, "title": "bar"});
return context.jio.put(id, {"title": "bar"});
})
.then(function () {
return context.jio.putAttachment({"_id": id, "_attachment": attachment,
"_data": "bar"});
return context.jio.putAttachment(id, attachment, "bar");
})
.then(function () {
return context.jio.get({"_id": id});
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {
"_id": id,
"title": "bar",
"_attachments": {
"foo": {}
......@@ -483,7 +480,7 @@
context.spy_cursor = sinon.spy(IDBIndex.prototype, "openCursor");
context.spy_key_range = sinon.spy(IDBKeyRange, "only");
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
......@@ -560,7 +557,7 @@
ok(context.spy_put.calledOnce, "put count " +
context.spy_put.callCount);
deepEqual(context.spy_put.firstCall.args[0],
{"_id": "foo", title: "bar"},
{"_id": "foo", doc: {title: "bar"}},
"put first argument");
ok(!context.spy_index.called, "index count " +
......@@ -608,7 +605,7 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "inexistent"});
return context.jio.put("inexistent", {});
})
.then(function (result) {
equal(result, "inexistent");
......@@ -640,7 +637,7 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
context.spy_open = sinon.spy(indexedDB, "open");
......@@ -657,7 +654,7 @@
context.spy_cursor_delete = sinon.spy(IDBCursor.prototype, "delete");
context.spy_key_range = sinon.spy(IDBKeyRange, "only");
return context.jio.remove({"_id": "foo"});
return context.jio.remove("foo");
})
.then(function () {
......@@ -749,16 +746,12 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
return RSVP.all([
context.jio.putAttachment({"_id": "foo",
"_attachment": "attachment1",
"_data": "bar"}),
context.jio.putAttachment({"_id": "foo",
"_attachment": "attachment2",
"_data": "bar2"})
context.jio.putAttachment("foo", "attachment1", "bar"),
context.jio.putAttachment("foo", "attachment2", "bar2")
]);
})
.then(function () {
......@@ -776,7 +769,7 @@
context.spy_cursor_delete = sinon.spy(IDBCursor.prototype, "delete");
context.spy_key_range = sinon.spy(IDBKeyRange, "only");
return context.jio.remove({"_id": "foo"});
return context.jio.remove("foo");
})
.then(function () {
......@@ -882,12 +875,10 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
return context.jio.putAttachment({"_id": "foo",
"_attachment": attachment,
"_data": big_string});
return context.jio.putAttachment("foo", attachment, big_string);
})
.then(function () {
context.spy_open = sinon.spy(indexedDB, "open");
......@@ -901,8 +892,7 @@
context.spy_create_index = sinon.spy(IDBObjectStore.prototype,
"createIndex");
return context.jio.getAttachment({"_id": "foo",
"_attachment": attachment});
return context.jio.getAttachment("foo", attachment);
})
.then(function () {
......@@ -974,16 +964,13 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
return context.jio.putAttachment({"_id": "foo",
"_attachment": attachment,
"_data": big_string});
return context.jio.putAttachment("foo", attachment, big_string);
})
.then(function () {
return context.jio.getAttachment({"_id": "foo",
"_attachment": attachment});
return context.jio.getAttachment("foo", attachment);
})
.then(function (result) {
ok(result instanceof Blob, "Data is Blob");
......@@ -1009,17 +996,14 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
return context.jio.putAttachment({"_id": "foo",
"_attachment": attachment,
"_data": big_string});
return context.jio.putAttachment("foo", attachment, big_string);
})
.then(function () {
return context.jio.getAttachment({"_id": "foo",
"_attachment": attachment,
"_start": 1999995, "_end": 2000005});
return context.jio.getAttachment("foo", attachment,
{"start": 1999995, "end": 2000005});
})
.then(function (result) {
ok(result instanceof Blob, "Data is Blob");
......@@ -1057,12 +1041,10 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
return context.jio.putAttachment({"_id": "foo",
"_attachment": attachment,
"_data": big_string});
return context.jio.putAttachment("foo", attachment, big_string);
})
.then(function () {
context.spy_open = sinon.spy(indexedDB, "open");
......@@ -1080,8 +1062,7 @@
context.spy_cursor_delete = sinon.spy(IDBCursor.prototype, "delete");
context.spy_key_range = sinon.spy(IDBKeyRange, "only");
return context.jio.removeAttachment({"_id": "foo",
"_attachment": attachment});
return context.jio.removeAttachment("foo", attachment);
})
.then(function () {
......@@ -1179,7 +1160,7 @@
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put({"_id": "foo", "title": "bar"});
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
context.spy_open = sinon.spy(indexedDB, "open");
......@@ -1197,9 +1178,7 @@
context.spy_cursor_delete = sinon.spy(IDBCursor.prototype, "delete");
context.spy_key_range = sinon.spy(IDBKeyRange, "only");
return context.jio.putAttachment({"_id": "foo",
"_attachment": attachment,
"_data": big_string});
return context.jio.putAttachment("foo", attachment, big_string);
})
.then(function () {
......
......@@ -52,7 +52,7 @@
stop();
expect(3);
this.jio.get({"_id": "inexistent"})
this.jio.get("inexistent")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id inexistent is forbidden (!== /)");
......@@ -71,11 +71,9 @@
stop();
expect(1);
this.jio.get({"_id": id})
this.jio.get(id)
.then(function (result) {
deepEqual(result, {
"_id": "/"
}, "Check document");
deepEqual(result, {}, "Check document");
})
.fail(function (error) {
ok(false, error);
......@@ -93,10 +91,9 @@
localStorage.setItem(attachment, "bar");
this.jio.get({"_id": id})
this.jio.get(id)
.then(function (result) {
deepEqual(result, {
"_id": id,
"_attachments": {
"foo": {}
}
......@@ -126,10 +123,7 @@
stop();
expect(3);
this.jio.getAttachment({
"_id": "inexistent",
"_attachment": "a"
})
this.jio.getAttachment("inexistent", "a")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id inexistent is forbidden (!== /)");
......@@ -148,10 +142,7 @@
stop();
expect(3);
this.jio.getAttachment({
"_id": id,
"_attachment": "inexistent"
})
this.jio.getAttachment(id, "inexistent")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find attachment inexistent");
......@@ -175,10 +166,7 @@
localStorage.setItem(attachment, "data:text/plain;charset=utf-8;base64," +
btoa(unescape(encodeURIComponent(value))));
this.jio.getAttachment({
"_id": id,
"_attachment": attachment
})
this.jio.getAttachment(id, attachment)
.then(function (result) {
ok(result instanceof Blob, "Data is Blob");
deepEqual(result.type, "text/plain;charset=utf-8",
......@@ -217,10 +205,7 @@
data_url = imgCanvas.toDataURL("image/png");
localStorage.setItem(attachment, data_url);
return context.jio.getAttachment({
"_id": id,
"_attachment": attachment
})
return context.jio.getAttachment(id, attachment)
.then(function (result) {
ok(result instanceof Blob, "Data is Blob");
return jIO.util.readBlobAsDataURL(result);
......@@ -252,11 +237,7 @@
stop();
expect(3);
this.jio.putAttachment({
"_id": "inexistent",
"_attachment": "putattmt2",
"_data": ""
})
this.jio.putAttachment("inexistent", "putattmt2", "")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "id inexistent is forbidden (!== /)");
......@@ -278,11 +259,7 @@
expect(1);
this.jio.putAttachment({
"_id": id,
"_attachment": attachment,
"_data": value
})
this.jio.putAttachment(id, attachment, value)
.then(function () {
equal(
localStorage.getItem(attachment),
......@@ -336,11 +313,7 @@
}
imgCanvas.toBlob(function (blob) {
return context.jio.putAttachment({
"_id": id,
"_attachment": attachment,
"_blob": blob
})
return context.jio.putAttachment(id, attachment, blob)
.then(function () {
equal(localStorage.getItem(attachment), data_url);
})
......@@ -368,10 +341,7 @@
stop();
expect(3);
this.jio.removeAttachment({
"_id": "inexistent",
"_attachment": "removeattmt2"
})
this.jio.removeAttachment("inexistent", "removeattmt2")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError, error);
equal(error.message, "id inexistent is forbidden (!== /)");
......@@ -394,10 +364,7 @@
stop();
expect(1);
this.jio.removeAttachment({
"_id": id,
"_attachment": attachment
})
this.jio.removeAttachment(id, attachment)
.then(function () {
ok(!localStorage.hasOwnProperty(attachment));
})
......
......@@ -53,13 +53,12 @@
var test = this;
this.jio.put({"_id": "put1", "title": "myPut1"})
this.jio.put("put1", {"title": "myPut1"})
.then(function (uuid) {
equal(uuid, "put1");
deepEqual(test.jio.__storage._database.put1, {
attachments: {},
doc: JSON.stringify({
"_id": "put1",
"title": "myPut1"
})
});
......@@ -83,14 +82,13 @@
expect(2);
stop();
this.jio.put({"_id": id, "title": "myPut2"})
this.jio.put(id, {"title": "myPut2"})
.then(function (uuid) {
equal(uuid, "put1");
deepEqual(test.jio.__storage._database.put1, {
"foo": "bar",
"attachments": {"foo": "bar"},
doc: JSON.stringify({
"_id": "put1",
"title": "myPut2"
})
});
......@@ -118,7 +116,7 @@
stop();
expect(3);
this.jio.get({"_id": "inexistent"})
this.jio.get("inexistent")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError, error);
equal(error.message, "Cannot find document: inexistent");
......@@ -140,10 +138,9 @@
stop();
expect(1);
this.jio.get({"_id": id})
this.jio.get(id)
.then(function (result) {
deepEqual(result, {
"_id": id,
"title": "myPost1"
}, "Check document");
})
......@@ -168,10 +165,9 @@
stop();
expect(1);
this.jio.get({"_id": id})
this.jio.get(id)
.then(function (result) {
deepEqual(result, {
"_id": id,
"_attachments": {putattmt2: {}}
}, "Check document");
})
......@@ -204,7 +200,7 @@
stop();
expect(1);
this.jio.remove({"_id": "foo"})
this.jio.remove("foo")
.then(function (result) {
equal(result, "foo");
})
......@@ -230,10 +226,7 @@
stop();
expect(3);
this.jio.getAttachment({
"_id": "inexistent",
"_attachment": "a"
})
this.jio.getAttachment("inexistent", "a")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find attachment: inexistent , a");
......@@ -256,10 +249,7 @@
"doc": JSON.stringify({})
};
this.jio.getAttachment({
"_id": id,
"_attachment": "inexistent"
})
this.jio.getAttachment(id, "inexistent")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find attachment: b , inexistent");
......@@ -284,10 +274,7 @@
attachments: {"foo": "bar"}
};
this.jio.getAttachment({
"_id": id,
"_attachment": "inexistent"
})
this.jio.getAttachment(id, "inexistent")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find attachment: b , inexistent");
......@@ -315,10 +302,7 @@
}
};
this.jio.getAttachment({
"_id": id,
"_attachment": attachment
})
this.jio.getAttachment(id, attachment)
.then(function (result) {
ok(result instanceof Blob, "Data is Blob");
equal(result, blob);
......@@ -346,11 +330,7 @@
stop();
expect(3);
this.jio.putAttachment({
"_id": "inexistent",
"_attachment": "putattmt2",
"_data": ""
})
this.jio.putAttachment("inexistent", "putattmt2", "")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError, error);
equal(error.message, "Cannot find document: inexistent");
......@@ -377,11 +357,7 @@
stop();
expect(1);
jio.putAttachment({
"_id": id,
"_attachment": "putattmt2",
"_blob": blob
})
jio.putAttachment(id, "putattmt2", blob)
.then(function () {
equal(jio.__storage._database[id].attachments.putattmt2, blob);
})
......@@ -408,10 +384,7 @@
stop();
expect(3);
this.jio.removeAttachment({
"_id": "inexistent",
"_attachment": "removeattmt2"
})
this.jio.removeAttachment("inexistent", "removeattmt2")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError, error);
equal(error.message, "Cannot find document: inexistent");
......@@ -437,10 +410,7 @@
stop();
expect(1);
jio.removeAttachment({
"_id": id,
"_attachment": "removeattmt2"
})
jio.removeAttachment(id, "removeattmt2")
.then(function () {
deepEqual(jio.__storage._database[id].attachments, {});
})
......
......@@ -52,15 +52,14 @@
}
});
Storage200.prototype.get = function (param) {
equal(param._id, "bar", "get 200 called");
Storage200.prototype.get = function (id) {
equal(id, "bar", "get 200 called");
return {title: "foo"};
};
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
"title": "foo"
}, "Check document");
})
......@@ -110,7 +109,7 @@
module("queryStorage.put");
test("put called substorage put", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "query",
......@@ -118,12 +117,13 @@
type: "querystorage200"
}
});
Storage200.prototype.put = function (param) {
deepEqual(param, {"_id": "bar", "title": "foo"}, "put 200 called");
return param._id;
Storage200.prototype.put = function (id, param) {
equal(id, "bar", "put 200 called");
deepEqual(param, {"title": "foo"}, "put 200 called");
return id;
};
jio.put({"_id": "bar", "title": "foo"})
jio.put("bar", {"title": "foo"})
.then(function (result) {
equal(result, "bar");
})
......@@ -149,12 +149,12 @@
type: "querystorage200"
}
});
Storage200.prototype.remove = function (param) {
deepEqual(param, {"_id": "bar"}, "remove 200 called");
return param._id;
Storage200.prototype.remove = function (id) {
deepEqual(id, "bar", "remove 200 called");
return id;
};
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function (result) {
equal(result, "bar");
})
......@@ -172,7 +172,7 @@
module("queryStorage.getAttachment");
test("getAttachment called substorage getAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "query",
......@@ -182,13 +182,13 @@
}),
blob = new Blob([""]);
Storage200.prototype.getAttachment = function (param) {
deepEqual(param, {"_id": "bar", "_attachment": "foo"},
"getAttachment 200 called");
Storage200.prototype.getAttachment = function (id, name) {
equal(id, "bar", "getAttachment 200 called");
equal(name, "foo", "getAttachment 200 called");
return blob;
};
jio.getAttachment({"_id": "bar", "_attachment": "foo"})
jio.getAttachment("bar", "foo")
.then(function (result) {
equal(result, blob);
})
......@@ -206,7 +206,7 @@
module("queryStorage.putAttachment");
test("putAttachment called substorage putAttachment", function () {
stop();
expect(2);
expect(4);
var jio = jIO.createJIO({
type: "query",
......@@ -216,13 +216,15 @@
}),
blob = new Blob([""]);
Storage200.prototype.putAttachment = function (param) {
deepEqual(param, {"_id": "bar", "_attachment": "foo", "_blob": blob},
Storage200.prototype.putAttachment = function (id, name, blob2) {
equal(id, "bar", "putAttachment 200 called");
equal(name, "foo", "putAttachment 200 called");
deepEqual(blob2, blob,
"putAttachment 200 called");
return "OK";
};
jio.putAttachment({"_id": "bar", "_attachment": "foo", "_blob": blob})
jio.putAttachment("bar", "foo", blob)
.then(function (result) {
equal(result, "OK");
})
......@@ -240,7 +242,7 @@
module("queryStorage.removeAttachment");
test("removeAttachment called substorage removeAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "query",
......@@ -249,13 +251,13 @@
}
});
Storage200.prototype.removeAttachment = function (param) {
deepEqual(param, {"_id": "bar", "_attachment": "foo"},
"removeAttachment 200 called");
Storage200.prototype.removeAttachment = function (id, name) {
equal(id, "bar", "removeAttachment 200 called");
equal(name, "foo", "removeAttachment 200 called");
return "Removed";
};
jio.removeAttachment({"_id": "bar", "_attachment": "foo"})
jio.removeAttachment("bar", "foo")
.then(function (result) {
equal(result, "Removed");
})
......@@ -408,13 +410,13 @@
function StorageNoSortCapacity() {
return this;
}
StorageNoSortCapacity.prototype.get = function (options) {
if (options._id === "foo") {
equal(options._id, "foo", "Get foo");
StorageNoSortCapacity.prototype.get = function (id) {
if (id === "foo") {
equal(id, "foo", "Get foo");
} else {
equal(options._id, "bar", "Get bar");
equal(id, "bar", "Get bar");
}
return {title: options._id, id: "ID " + options._id,
return {title: id, id: "ID " + id,
"another": "property"};
};
StorageNoSortCapacity.prototype.hasCapacity = function (capacity) {
......@@ -484,13 +486,13 @@
function StorageNoSelectCapacity() {
return this;
}
StorageNoSelectCapacity.prototype.get = function (options) {
if (options._id === "foo") {
equal(options._id, "foo", "Get foo");
StorageNoSelectCapacity.prototype.get = function (id) {
if (id === "foo") {
equal(id, "foo", "Get foo");
} else {
equal(options._id, "bar", "Get bar");
equal(id, "bar", "Get bar");
}
return {title: options._id, id: "ID " + options._id,
return {title: id, id: "ID " + id,
"another": "property"};
};
StorageNoSelectCapacity.prototype.hasCapacity = function (capacity) {
......@@ -560,13 +562,13 @@
function StorageNoLimitCapacity() {
return this;
}
StorageNoLimitCapacity.prototype.get = function (options) {
if (options._id === "foo") {
equal(options._id, "foo", "Get foo");
StorageNoLimitCapacity.prototype.get = function (id) {
if (id === "foo") {
equal(id, "foo", "Get foo");
} else {
equal(options._id, "bar", "Get bar");
equal(id, "bar", "Get bar");
}
return {title: options._id, id: "ID " + options._id,
return {title: id, id: "ID " + id,
"another": "property"};
};
StorageNoLimitCapacity.prototype.hasCapacity = function (capacity) {
......@@ -636,13 +638,13 @@
function StorageNoQueryCapacity() {
return this;
}
StorageNoQueryCapacity.prototype.get = function (options) {
if (options._id === "foo") {
equal(options._id, "foo", "Get foo");
StorageNoQueryCapacity.prototype.get = function (id) {
if (id === "foo") {
equal(id, "foo", "Get foo");
} else {
equal(options._id, "bar", "Get bar");
equal(id, "bar", "Get bar");
}
return {title: options._id, id: "ID " + options._id,
return {title: id, id: "ID " + id,
"another": "property"};
};
StorageNoQueryCapacity.prototype.hasCapacity = function (capacity) {
......
......@@ -17,8 +17,8 @@
function Storage404() {
return this;
}
function generate404Error(param) {
equal(param._id, "bar", "get 404 called");
function generate404Error(id) {
equal(id, "bar", "get 404 called");
throw new jIO.util.jIOError("Cannot find document", 404);
}
Storage404.prototype.get = generate404Error;
......@@ -27,17 +27,18 @@
function Storage200() {
return this;
}
Storage200.prototype.get = function (param) {
equal(param._id, "bar", "get 200 called");
Storage200.prototype.get = function (id) {
equal(id, "bar", "get 200 called");
return {title: "foo"};
};
Storage200.prototype.put = function (param) {
deepEqual(param, {"_id": "bar", "title": "foo"}, "put 200 called");
return param._id;
Storage200.prototype.put = function (id, param) {
equal(id, "bar", "put 200 called");
deepEqual(param, {"title": "foo"}, "put 200 called");
return id;
};
Storage200.prototype.remove = function (param) {
deepEqual(param, {"_id": "bar"}, "remove 200 called");
return param._id;
Storage200.prototype.remove = function (id) {
equal(id, "bar", "remove 200 called");
return id;
};
Storage200.prototype.post = function (param) {
deepEqual(param, {"title": "foo"}, "post 200 called");
......@@ -134,7 +135,7 @@
}]
});
jio.get({"_id": "bar"})
jio.get("bar")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document");
......@@ -161,10 +162,9 @@
}]
});
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
"title": "foo"
}, "Check document");
})
......@@ -189,10 +189,9 @@
}]
});
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
"title": "foo"
}, "Check document");
})
......@@ -217,7 +216,7 @@
}]
});
jio.get({"_id": "bar"})
jio.get("bar")
.fail(function (error) {
ok(error instanceof Error);
equal(error.message, "manually triggered error");
......@@ -244,7 +243,7 @@
}]
});
jio.get({"_id": "bar"})
jio.get("bar")
.fail(function (error) {
ok(error instanceof Error);
equal(error.message, "manually triggered error");
......@@ -275,7 +274,7 @@
}]
});
jio.post({"_id": "bar", "title": "foo"})
jio.post({"title": "foo"})
.fail(function (error) {
ok(error instanceof Error);
equal(error.message, "manually triggered error");
......@@ -331,7 +330,7 @@
}]
});
jio.put({"_id": "bar", "title": "foo"})
jio.put("bar", {"title": "foo"})
.fail(function (error) {
ok(error instanceof Error);
equal(error.message, "manually triggered error");
......@@ -347,7 +346,7 @@
test("put on first storage", function () {
stop();
expect(3);
expect(4);
var jio = jIO.createJIO({
type: "union",
......@@ -358,7 +357,7 @@
}]
});
jio.put({"_id": "bar", "title": "foo"})
jio.put("bar", {"title": "foo"})
.then(function (result) {
equal(result, "bar");
})
......@@ -372,7 +371,7 @@
test("put on second storage", function () {
stop();
expect(4);
expect(5);
var jio = jIO.createJIO({
type: "union",
......@@ -383,7 +382,7 @@
}]
});
jio.put({"_id": "bar", "title": "foo"})
jio.put("bar", {"title": "foo"})
.then(function (result) {
equal(result, "bar");
})
......@@ -397,19 +396,20 @@
test("put create on first storage", function () {
stop();
expect(4);
expect(5);
function StoragePut404() {
return this;
}
function generatePut404Error(param) {
equal(param._id, "bar", "get Put404 called");
function generatePut404Error(id) {
equal(id, "bar", "get Put404 called");
throw new jIO.util.jIOError("Cannot find document", 404);
}
StoragePut404.prototype.get = generatePut404Error;
StoragePut404.prototype.put = function (param) {
deepEqual(param, {"_id": "bar", "title": "foo"}, "put 404 called");
return param._id;
StoragePut404.prototype.put = function (id, param) {
equal(id, "bar", "put 404 called");
deepEqual(param, {"title": "foo"}, "put 404 called");
return id;
};
jIO.addStorage('unionstorageput404', StoragePut404);
......@@ -422,7 +422,7 @@
}]
});
jio.put({"_id": "bar", "title": "foo"})
jio.put("bar", {"title": "foo"})
.then(function (result) {
equal(result, "bar");
})
......@@ -451,7 +451,7 @@
}]
});
jio.remove({"_id": "bar"})
jio.remove("bar")
.fail(function (error) {
ok(error instanceof Error);
equal(error.message, "manually triggered error");
......@@ -478,7 +478,7 @@
}]
});
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function (result) {
equal(result, "bar");
})
......@@ -503,7 +503,7 @@
}]
});
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function (result) {
equal(result, "bar");
})
......
......@@ -53,14 +53,13 @@
});
Storage200.prototype.get = function (param) {
equal(param._id, "bar", "get 200 called");
equal(param, "bar", "get 200 called");
return {title: "foo"};
};
jio.get({"_id": "bar"})
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"_id": "bar",
"title": "foo"
}, "Check document");
})
......@@ -99,9 +98,9 @@
) === null ? false : true);
}
Storage200.prototype.put = function (param) {
uuid = param._id;
deepEqual(param, {"_id": uuid, "title": "foo"}, "post 200 called");
Storage200.prototype.put = function (id, param) {
uuid = id;
deepEqual(param, {"title": "foo"}, "post 200 called");
return "bar";
};
......@@ -124,7 +123,7 @@
module("uuidStorage.put");
test("put called substorage put", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "uuid",
......@@ -132,12 +131,13 @@
type: "uuidstorage200"
}
});
Storage200.prototype.put = function (param) {
deepEqual(param, {"_id": "bar", "title": "foo"}, "put 200 called");
return param._id;
Storage200.prototype.put = function (id, param) {
equal(id, "bar", "put 200 called");
deepEqual(param, {"title": "foo"}, "put 200 called");
return id;
};
jio.put({"_id": "bar", "title": "foo"})
jio.put("bar", {"title": "foo"})
.then(function (result) {
equal(result, "bar");
})
......@@ -164,11 +164,11 @@
}
});
Storage200.prototype.remove = function (param) {
deepEqual(param, {"_id": "bar"}, "remove 200 called");
equal(param, "bar", "remove 200 called");
return param._id;
};
jio.remove({"_id": "bar"})
jio.remove("bar")
.then(function (result) {
equal(result, "bar");
})
......@@ -186,7 +186,7 @@
module("uuidStorage.getAttachment");
test("getAttachment called substorage getAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "uuid",
......@@ -196,13 +196,13 @@
}),
blob = new Blob([""]);
Storage200.prototype.getAttachment = function (param) {
deepEqual(param, {"_id": "bar", "_attachment": "foo"},
"getAttachment 200 called");
Storage200.prototype.getAttachment = function (id, name) {
equal(id, "bar", "getAttachment 200 called");
equal(name, "foo", "getAttachment 200 called");
return blob;
};
jio.getAttachment({"_id": "bar", "_attachment": "foo"})
jio.getAttachment("bar", "foo")
.then(function (result) {
equal(result, blob);
})
......@@ -220,7 +220,7 @@
module("uuidStorage.putAttachment");
test("putAttachment called substorage putAttachment", function () {
stop();
expect(2);
expect(4);
var jio = jIO.createJIO({
type: "uuid",
......@@ -230,13 +230,14 @@
}),
blob = new Blob([""]);
Storage200.prototype.putAttachment = function (param) {
deepEqual(param, {"_id": "bar", "_attachment": "foo", "_blob": blob},
"putAttachment 200 called");
Storage200.prototype.putAttachment = function (id, name, blob2) {
equal(id, "bar", "putAttachment 200 called");
equal(name, "foo", "putAttachment 200 called");
deepEqual(blob2, blob, "putAttachment 200 called");
return "OK";
};
jio.putAttachment({"_id": "bar", "_attachment": "foo", "_blob": blob})
jio.putAttachment("bar", "foo", blob)
.then(function (result) {
equal(result, "OK");
})
......@@ -254,7 +255,7 @@
module("uuidStorage.removeAttachment");
test("removeAttachment called substorage removeAttachment", function () {
stop();
expect(2);
expect(3);
var jio = jIO.createJIO({
type: "uuid",
......@@ -263,13 +264,13 @@
}
});
Storage200.prototype.removeAttachment = function (param) {
deepEqual(param, {"_id": "bar", "_attachment": "foo"},
"removeAttachment 200 called");
Storage200.prototype.removeAttachment = function (id, name) {
equal(id, "bar", "removeAttachment 200 called");
equal(name, "foo", "removeAttachment 200 called");
return "Removed";
};
jio.removeAttachment({"_id": "bar", "_attachment": "foo"})
jio.removeAttachment("bar", "foo")
.then(function (result) {
equal(result, "Removed");
})
......
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