Commit 9aaf98f7 authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: add test and change way to add new mapping function

parent b84a7fab
......@@ -5,6 +5,116 @@
Query) {
"use strict";
function getSubIdEqualSubProperty(storage, value, key) {
var query;
query = new SimpleQuery({
key: key,
value: value,
type: "simple"
});
if (storage._query.query !== undefined) {
query = new ComplexQuery({
operator: "AND",
query_list: [query, storage._query.query],
type: "complex"
});
}
query = Query.objectToSearchText(query);
return storage._sub_storage.allDocs({
"query": query,
"sort_on": storage._query.sort_on,
"select_list": storage._query.select_list,
"limit": storage._query.limit
})
.push(function (data) {
if (data.data.rows.length === 0) {
throw new jIO.util.jIOError(
"Can not find id",
404
);
}
if (data.data.rows.length > 1) {
throw new TypeError("id must be unique field: " + key
+ ", result:" + data.data.rows.toString());
}
return data.data.rows[0].id;
});
}
/*jslint unparam: true*/
var mapping_function = {
"equalSubProperty": {
"mapToSubProperty": function (property, sub_doc, doc, args, id) {
sub_doc[args] = doc[property];
return args;
},
"mapToMainProperty": function (property, sub_doc, doc, args, sub_id) {
if (sub_doc.hasOwnProperty(args)) {
doc[property] = sub_doc[args];
}
return args;
},
"mapToSubId": function (storage, doc, id, args) {
if (doc !== undefined) {
if (storage._property_for_sub_id &&
doc.hasOwnProperty(storage._property_for_sub_id)) {
return doc[storage._property_for_sub_id];
}
if (doc.hasOwnProperty(args)) {
return doc[args];
}
}
return getSubIdEqualSubProperty(storage, id, storage._map_id[1]);
},
"mapToId": function (storage, sub_doc, sub_id, args) {
return sub_doc[args];
}
},
"equalValue": {
"mapToSubProperty": function (property, sub_doc, doc, args) {
sub_doc[property] = args;
return property;
},
"mapToMainProperty": function (property) {
return property;
}
},
"ignore": {
"mapToSubProperty": function () {
return false;
},
"mapToMainProperty": function (property) {
return property;
}
},
"equalSubId": {
"mapToSubProperty": function () {
return false;
},
"mapToMainProperty": function (property, sub_doc, doc, args, sub_id) {
doc[property] = sub_id;
return property;
},
"mapToSubId": function (storage, doc, id, args) {
return id;
},
"mapToId": function (storage, sub_doc, sub_id) {
return sub_id;
}
},
"keep": {
"mapToSubProperty": function (property, sub_doc, doc) {
sub_doc[property] = doc[property];
return property;
},
"mapToMainProperty": function (property, sub_doc, doc) {
doc[property] = sub_doc[property];
return property;
}
}
};
/*jslint unparam: false*/
function initializeQueryAndDefaultMapping(storage) {
var property, query_list = [];
for (property in storage._mapping_dict) {
......@@ -47,14 +157,14 @@
}
function MappingStorage(spec) {
this._mapping_dict = spec.mapping_dict || {};
this._mapping_dict = spec.property || {};
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._map_all_property = spec.map_all_property !== undefined ?
spec.map_all_property : true;
this._attachment_mapping_dict = spec.attachment_mapping_dict || {};
this._attachment_mapping_dict = spec.attachment || {};
this._query = spec.query || {};
this._map_id = spec.map_id;
this._id_mapped = (spec.map_id !== undefined) ? spec.map_id[1] : false;
this._map_id = spec.id || ["equalSubId"];
this._id_mapped = (spec.id !== undefined) ? spec.id[1] : false;
if (this._query.query !== undefined) {
this._query.query = QueryFactory.create(this._query.query);
......@@ -78,113 +188,42 @@
}
function getSubStorageId(storage, id, doc) {
var query;
return new RSVP.Queue()
.push(function () {
if (storage._property_for_sub_id !== undefined &&
doc !== undefined &&
doc[storage._property_for_sub_id] !== undefined) {
var map_info = storage._map_id || ["equalSubId"];
if (storage._property_for_sub_id && doc !== undefined &&
doc.hasOwnProperty(storage._property_for_sub_id)) {
return doc[storage._property_for_sub_id];
}
if (!storage._id_mapped) {
return id;
}
if (storage._map_id[0] === "equalSubProperty") {
query = new SimpleQuery({
key: storage._map_id[1],
value: id,
type: "simple"
});
if (storage._query.query !== undefined) {
query = new ComplexQuery({
operator: "AND",
query_list: [query, storage._query.query],
type: "complex"
});
}
query = Query.objectToSearchText(query);
return storage._sub_storage.allDocs({
"query": query,
"sort_on": storage._query.sort_on,
"select_list": storage._query.select_list,
"limit": storage._query.limit
})
.push(function (data) {
if (data.data.rows.length === 0) {
throw new jIO.util.jIOError(
"Can not find id",
404
);
}
if (data.data.rows.length > 1) {
throw new TypeError("id must be unique field: " + id
+ ", result:" + data.data.rows.toString());
}
return data.data.rows[0].id;
});
}
throw new jIO.util.jIOError(
"Unsuported option: " + storage._mapping_dict.id,
400
return mapping_function[map_info[0]].mapToSubId(
storage,
doc,
id,
map_info[1]
);
});
}
function mapToSubProperty(storage, property, sub_doc, doc) {
var mapping_function, parameter;
if (storage._mapping_dict[property] !== undefined) {
mapping_function = storage._mapping_dict[property][0];
parameter = storage._mapping_dict[property][1];
if (mapping_function === "equalSubProperty") {
sub_doc[parameter] = doc[property];
return parameter;
}
if (mapping_function === "equalValue") {
sub_doc[property] = parameter;
return property;
}
if (mapping_function === "ignore" || mapping_function === "equalSubId") {
return false;
}
}
if (!storage._map_all_property) {
return false;
}
if (storage._map_all_property) {
sub_doc[property] = doc[property];
return property;
}
throw new jIO.util.jIOError(
"Unsuported option(s): " + storage._mapping_dict[property],
400
function mapToSubProperty(storage, property, sub_doc, doc, id) {
var mapping_info = storage._mapping_dict[property] || ["keep"];
return mapping_function[mapping_info[0]].mapToSubProperty(
property,
sub_doc,
doc,
mapping_info[1],
id
);
}
function mapToMainProperty(storage, property, sub_doc, doc) {
var mapping_function, parameter;
if (storage._mapping_dict[property] !== undefined) {
mapping_function = storage._mapping_dict[property][0];
parameter = storage._mapping_dict[property][1];
if (mapping_function === "equalSubProperty") {
if (sub_doc.hasOwnProperty(parameter)) {
doc[property] = sub_doc[parameter];
}
return parameter;
}
if (mapping_function === "equalValue") {
return property;
}
if (mapping_function === "ignore") {
return property;
}
}
if (storage._map_all_property) {
if (sub_doc.hasOwnProperty(property)) {
doc[property] = sub_doc[property];
}
return property;
}
return false;
function mapToMainProperty(storage, property, sub_doc, doc, sub_id) {
var mapping_info = storage._mapping_dict[property] || ["keep"];
return mapping_function[mapping_info[0]].mapToMainProperty(
property,
sub_doc,
doc,
mapping_info[1],
sub_id
);
}
function mapToMainDocument(storage, sub_doc, sub_id) {
......@@ -193,7 +232,13 @@
property_list = [storage._id_mapped];
for (property in storage._mapping_dict) {
if (storage._mapping_dict.hasOwnProperty(property)) {
property_list.push(mapToMainProperty(storage, property, sub_doc, doc));
property_list.push(mapToMainProperty(
storage,
property,
sub_doc,
doc,
sub_id
));
}
}
if (storage._map_all_property) {
......@@ -205,9 +250,8 @@
}
}
}
if (storage._property_for_sub_id !== undefined &&
sub_id !== undefined) {
doc[storage._property_for_sub_id] = sub_id;
if (storage._map_for_sub_storage_id !== undefined) {
doc[storage._map_for_sub_storage_id] = sub_id;
}
return doc;
}
......@@ -217,7 +261,7 @@
for (property in doc) {
if (doc.hasOwnProperty(property)) {
mapToSubProperty(storage, property, sub_doc, doc);
mapToSubProperty(storage, property, sub_doc, doc, id);
}
}
for (property in storage._default_mapping) {
......@@ -225,36 +269,36 @@
sub_doc[property] = storage._default_mapping[property];
}
}
if (storage._id_mapped && id !== undefined) {
sub_doc[storage._id_mapped] = id;
if (storage._map_id[0] === "equalSubProperty" && id !== undefined) {
sub_doc[storage._map_id[1]] = id;
}
return sub_doc;
}
function handleAttachment(context, argument_list, method) {
return getSubStorageId(context, argument_list[0])
function handleAttachment(storage, argument_list, method) {
return getSubStorageId(storage, argument_list[0])
.push(function (sub_id) {
argument_list[0] = sub_id;
argument_list[1] = getAttachmentId(
context,
storage,
sub_id,
argument_list[1],
method
);
return context._sub_storage[method + "Attachment"].apply(
context._sub_storage,
return storage._sub_storage[method + "Attachment"].apply(
storage._sub_storage,
argument_list
);
});
}
MappingStorage.prototype.get = function (id) {
var context = this;
var storage = this;
return getSubStorageId(this, id)
.push(function (sub_id) {
return context._sub_storage.get(sub_id)
return storage._sub_storage.get(sub_id)
.push(function (sub_doc) {
return mapToMainDocument(context, sub_doc, sub_id);
return mapToMainDocument(storage, sub_doc, sub_id);
});
});
};
......@@ -278,15 +322,15 @@
};
MappingStorage.prototype.put = function (id, doc) {
var context = this,
var storage = this,
sub_doc = mapToSubstorageDocument(this, doc, id);
return getSubStorageId(this, id, doc)
.push(function (sub_id) {
return context._sub_storage.put(sub_id, sub_doc);
return storage._sub_storage.put(sub_id, sub_doc);
})
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError && error.status_code === 404) {
return context._sub_storage.post(sub_doc);
return storage._sub_storage.post(sub_doc);
}
throw error;
})
......@@ -296,10 +340,10 @@
};
MappingStorage.prototype.remove = function (id) {
var context = this;
var storage = this;
return getSubStorageId(this, id)
.push(function (sub_id) {
return context._sub_storage.remove(sub_id);
return storage._sub_storage.remove(sub_id);
})
.push(function () {
return id;
......@@ -325,19 +369,19 @@
};
MappingStorage.prototype.allAttachments = function (id) {
var context = this, sub_id;
return getSubStorageId(context, id)
var storage = this, sub_id;
return getSubStorageId(storage, id)
.push(function (sub_id_result) {
sub_id = sub_id_result;
return context._sub_storage.allAttachments(sub_id);
return storage._sub_storage.allAttachments(sub_id);
})
.push(function (result) {
var attachment_id,
attachments = {},
mapping_dict = {};
for (attachment_id in context._attachment_mapping_dict) {
if (context._attachment_mapping_dict.hasOwnProperty(attachment_id)) {
mapping_dict[getAttachmentId(context, sub_id, attachment_id, "get")]
for (attachment_id in storage._attachment_mapping_dict) {
if (storage._attachment_mapping_dict.hasOwnProperty(attachment_id)) {
mapping_dict[getAttachmentId(storage, sub_id, attachment_id, "get")]
= attachment_id;
}
}
......@@ -363,10 +407,10 @@
};
MappingStorage.prototype.bulk = function (id_list) {
var context = this;
var storage = this;
function mapId(parameter) {
return getSubStorageId(context, parameter.parameter_list[0])
return getSubStorageId(storage, parameter.parameter_list[0])
.push(function (id) {
return {"method": parameter.method, "parameter_list": [id]};
});
......@@ -378,13 +422,13 @@
return RSVP.all(promise_list);
})
.push(function (id_list_mapped) {
return context._sub_storage.bulk(id_list_mapped);
return storage._sub_storage.bulk(id_list_mapped);
})
.push(function (result) {
var mapped_result = [], i;
for (i = 0; i < result.length; i += 1) {
mapped_result.push(mapToMainDocument(
context,
storage,
result[i]
));
}
......@@ -393,7 +437,7 @@
};
MappingStorage.prototype.buildQuery = function (option) {
var context = this,
var storage = this,
i,
query,
property,
......@@ -412,7 +456,7 @@
one_query.query_list = query_list;
return one_query;
}
key = mapToMainProperty(context, one_query.key, {}, {});
key = mapToMainProperty(storage, one_query.key, {}, {});
if (key) {
one_query.key = key;
return one_query;
......@@ -483,17 +527,21 @@
}
)
.push(function (result) {
var doc;
var sub_doc, map_info = storage._map_id || ["equalSubId"];
for (i = 0; i < result.data.total_rows; i += 1) {
doc = result.data.rows[i].value;
sub_doc = result.data.rows[i].value;
result.data.rows[i].id =
mapping_function[map_info[0]].mapToId(
storage,
sub_doc,
result.data.rows[i].id,
map_info[1]
);
result.data.rows[i].value =
mapToMainDocument(
context,
doc
storage,
sub_doc
);
if (context._id_mapped) {
result.data.rows[i].id = doc[context._id_mapped];
}
}
return result.data.rows;
});
......
......@@ -46,9 +46,9 @@
type: "mapping",
map_all_property: false,
query: {"query": 'foo: "bar"'},
attachment_mapping_dict: {"foo": {"get": "bar"}},
mapping_dict: { "bar": ["equalSubProperty", "foo"]},
map_id: ["equalSubProperty", "otherId"],
attachment: {"foo": {"get": "bar"}},
property: { "bar": ["equalSubProperty", "foo"]},
id: ["equalSubProperty", "otherId"],
sub_storage: {
type: "mappingstorage2713"
}
......@@ -71,13 +71,13 @@
// mappingStorage.get
/////////////////////////////////////////////////////////////////
module("mappingStorage.get");
test("get called substorage get", function () {
test("called substorage get", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {"title": ["equalSubProperty", "title"]},
property: {"title": ["equalSubProperty", "title"]},
sub_storage: {
type: "mappingstorage2713"
}
......@@ -102,46 +102,14 @@
});
});
test("get with id mapped", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {"title": ["equalSubId"]},
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.get = function (id) {
equal(id, "bar", "get 2713 called");
return {};
};
jio.get("bar")
.push(function (result) {
deepEqual(result, {
"title": "bar"
});
}).push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("get with id and props mapped", function () {
test("with query and id equalSubProperty", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
"title": ["equalSubProperty", "otherTitle"]
},
id: ["equalSubProperty", 'otherId'],
query: {"query": 'otherTitle: "foo"'},
sub_storage: {
type: "mappingstorage2713"
}
......@@ -152,13 +120,17 @@
};
Storage2713.prototype.buildQuery = function (options) {
equal(options.query, 'otherId: "42"', "allDoc 2713 called");
equal(
options.query,
'( otherId: "42" AND otherTitle: "foo" )',
"allDoc 2713 called"
);
return [{id: "2713"}];
};
Storage2713.prototype.get = function (id) {
equal(id, "2713", "get 2713 called");
return {"otherTitle": "foo"};
return {"title": "foo"};
};
jio.get("42")
......@@ -174,17 +146,13 @@
});
});
test("get with id mapped and query", function () {
test("with id equalSubProperty", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
query: {"query": 'otherTitle: "foo"'},
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
"title": ["equalSubProperty", "otherTitle"]
},
id: ["equalSubProperty", "otherId"],
sub_storage: {
type: "mappingstorage2713"
}
......@@ -195,17 +163,13 @@
};
Storage2713.prototype.buildQuery = function (options) {
equal(
options.query,
'( otherId: "42" AND otherTitle: "foo" )',
"allDoc 2713 called"
);
equal(options.query, 'otherId: "42"', "allDoc 2713 called");
return [{id: "2713"}];
};
Storage2713.prototype.get = function (id) {
equal(id, "2713", "get 2713 called");
return {"otherTitle": "foo"};
return {"title": "foo"};
};
jio.get("42")
......@@ -221,15 +185,13 @@
});
});
test("get with not map_all_property", function () {
test("with prop equalSubProperty", function () {
stop();
expect(3);
expect(2);
var jio = jIO.createJIO({
type: "mapping",
map_all_property: false,
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
property: {
"title": ["equalSubProperty", "otherTitle"]
},
sub_storage: {
......@@ -237,25 +199,12 @@
}
});
Storage2713.prototype.hasCapacity = function () {
return true;
};
Storage2713.prototype.buildQuery = function (options) {
equal(
options.query,
'otherId: "42"',
"allDoc 2713 called"
);
return [{id: "2713"}];
};
Storage2713.prototype.get = function (id) {
equal(id, "2713", "get 2713 called");
return {"otherTitle": "foo", "foo": "bar"};
equal(id, "bar", "get 2713 called");
return {otherTitle: "foo"};
};
jio.get("42")
jio.get("bar")
.push(function (result) {
deepEqual(result, {
"title": "foo"
......@@ -268,15 +217,13 @@
});
});
test("get with props equal", function () {
test("with prop equalSubId", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {
"title": ["equalSubProperty", "otherTitle"]
},
property: {"title": ["equalSubId"]},
sub_storage: {
type: "mappingstorage2713"
}
......@@ -284,13 +231,13 @@
Storage2713.prototype.get = function (id) {
equal(id, "bar", "get 2713 called");
return {otherTitle: "foo"};
return {};
};
jio.get("bar")
.push(function (result) {
deepEqual(result, {
"title": "foo"
"title": "bar"
});
}).push(undefined, function (error) {
ok(false, error);
......@@ -300,13 +247,14 @@
});
});
test("get with ignore", function () {
test("with prop ignore", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {
property: {
"title": ["ignore"]
},
sub_storage: {
......@@ -337,13 +285,13 @@
/////////////////////////////////////////////////////////////////
module("mappingStorage.put");
test("put with substorage put", function () {
test("substorage put called", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {
property: {
"title": ["equalSubProperty", "title"]
},
sub_storage: {
......@@ -369,27 +317,36 @@
});
});
test("put with default values", function () {
test("with id equalSubProperty", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {"title": ["equalValue", "foobar"]},
id: ["equalSubProperty", "otherId"],
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.put = function (id, param) {
equal(id, "bar", "put 2713 called");
deepEqual(param, {"title": "foobar"}, "put 2713 called");
return id;
Storage2713.prototype.post = function (doc) {
deepEqual(doc,
{"otherId": "42", "title": "foo"}, "post 2713 called");
return "bar";
};
jio.put("bar", {})
Storage2713.prototype.buildQuery = function (option) {
equal(option.query, 'otherId: "42"', "allDocs 2713 called");
return [];
};
Storage2713.prototype.hasCapacity = function () {
return true;
};
jio.put("42", {"title": "foo"})
.push(function (result) {
equal(result, "bar");
equal(result, "42");
})
.push(undefined, function (error) {
ok(false, error);
......@@ -399,39 +356,61 @@
});
});
test("put with id and prop mapped", function () {
test("with id equalSubProperty and prop equalSubId", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
"title": ["equalSubProperty", "otherTitle"]
id: ["equalSubProperty", "otherId"],
property: {
"title": ["equalSubId"]
},
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.post = function (doc) {
Storage2713.prototype.put = function (id, doc) {
deepEqual(doc,
{"otherId": "42", "otherTitle": "foo"}, "post 2713 called");
{"otherId": "42"}, "post 2713 called");
equal(id, "bar");
return "bar";
};
Storage2713.prototype.buildQuery = function (option) {
equal(option.query, 'otherId: "42"', "allDocs 2713 called");
return [];
};
jio.put("42", {"title": "bar"})
.push(function (result) {
equal(result, "42");
})
.push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
Storage2713.prototype.hasCapacity = function () {
return true;
test("with prop equalSubId", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
property: {"title": ["equalSubId"]},
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.put = function (id, param) {
equal(id, "2713", "put 2713 called");
deepEqual(param, {"foo": "bar"}, "put 2713 called");
return id;
};
jio.put("42", {"title": "foo"})
jio.put("bar", {"title": "2713", "foo": "bar"})
.push(function (result) {
equal(result, "42");
equal(result, "bar");
})
.push(undefined, function (error) {
ok(false, error);
......@@ -441,31 +420,27 @@
});
});
test("put with id mapped", function () {
test("with prop equalSubProperty", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
"title": ["equalSubId"]
},
property: {"title": ["equalSubProperty", "subTitle"]},
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.put = function (id, doc) {
deepEqual(doc,
{"otherId": "42"}, "post 2713 called");
equal(id, "bar");
return "bar";
Storage2713.prototype.put = function (id, param) {
equal(id, "bar", "put 2713 called");
deepEqual(param, {"subTitle": "foo"}, "put 2713 called");
return id;
};
jio.put("42", {"title": "bar"})
jio.put("bar", {"title": "foo"})
.push(function (result) {
equal(result, "42");
equal(result, "bar");
})
.push(undefined, function (error) {
ok(false, error);
......@@ -475,31 +450,27 @@
});
});
test("put with no map_all_property", function () {
test("with prop equalValues", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
map_all_property: false,
mapping_dict: {
"title": ["equalSubProperty", "title"]
},
property: {"title": ["equalValue", "foobar"]},
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.put = function (id, doc) {
deepEqual(doc,
{"title": "foo"}, "post 2713 called");
equal(id, "42", "put 2713 called");
Storage2713.prototype.put = function (id, param) {
equal(id, "bar", "put 2713 called");
deepEqual(param, {"title": "foobar"}, "put 2713 called");
return id;
};
jio.put("42", {"title": "foo", "smth": "bar", "smth2": "bar2"})
jio.put("bar", {})
.push(function (result) {
equal(result, "42");
equal(result, "bar");
})
.push(undefined, function (error) {
ok(false, error);
......@@ -514,7 +485,7 @@
/////////////////////////////////////////////////////////////////
module("mappingStorage.remove");
test("remove with substorage remove", function () {
test("with substorage remove", function () {
stop();
expect(2);
......@@ -542,13 +513,13 @@
});
});
test("remove with id mapped", function () {
test("with id mapped", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
id: ["equalSubProperty", "otherId"],
sub_storage: {
type: "mappingstorage2713"
}
......@@ -584,44 +555,13 @@
/////////////////////////////////////////////////////////////////
module("mappingStorage.post");
test("post with mapped property", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {
"title": ["equalSubProperty", "otherTitle"]
},
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.post = function (doc) {
deepEqual(doc, {"otherTitle": "foo"}, "remove 2713 called");
return "42";
};
jio.post({"title": "foo"})
.push(function (result) {
equal(result, "42");
})
.push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("post with id mapped, no id in doc", function () {
test("with id equalSubProperty, no id in doc", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
id: ["equalSubProperty", "otherId"],
sub_storage: {
type: "mappingstorage2713"
}
......@@ -641,13 +581,13 @@
});
});
test("post with id mapped and in doc", function () {
test("with id equalSubProperty and id in doc", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
id: ["equalSubProperty", "otherId"],
sub_storage: {
type: "mappingstorage2713"
}
......@@ -670,13 +610,13 @@
});
});
test("post with sub_id mapped and in doc", function () {
test("with equalSubId mapped and id in doc", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {"otherId": ["equalSubId"]},
property: {"otherId": ["equalSubId"]},
sub_storage: {
type: "mappingstorage2713"
}
......@@ -704,7 +644,7 @@
/////////////////////////////////////////////////////////////////
module("mappingStorage.putAttachment");
test("putAttachment use sub_storage one's", function () {
test("sub_storage putAttachment called", function () {
stop();
expect(4);
var jio = jIO.createJIO({
......@@ -734,13 +674,13 @@
});
});
test("putAttachment with UriTemplate", function () {
test("with UriTemplate", function () {
stop();
expect(4);
var jio = jIO.createJIO({
type: "mapping",
attachment_mapping_dict: {
attachment: {
"2713": {"put": {"uri_template": "www.2713.foo/{id}"}}
},
sub_storage: {
......@@ -768,13 +708,13 @@
});
});
test("putAttachment with UriTemplate and id mapped", function () {
test("with UriTemplate and id equalSubProperty", function () {
stop();
expect(5);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
attachment_mapping_dict: {
id: ["equalSubProperty", "otherId"],
attachment: {
"2713": {"put": {"uri_template": "www.2713.foo/{id}"}}
},
sub_storage: {
......@@ -815,7 +755,7 @@
// mappingStorage.getAttachment
/////////////////////////////////////////////////////////////////
module("mappingStorage.getAttachment");
test("getAttachment use sub_storage one's", function () {
test("sub_storage getAttachment called", function () {
stop();
expect(3);
var jio = jIO.createJIO({
......@@ -843,13 +783,13 @@
});
});
test("getAttachment using UriTemplate", function () {
test("with UriTemplate", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
attachment_mapping_dict: {
attachment: {
"2713": {"get": {"uri_template": "www.2713/{id}/ok.com"}}
},
sub_storage: {
......@@ -875,14 +815,14 @@
});
});
test("getAttachment with UriTemplate and id mapped", function () {
test("with UriTemplate and id mapped", function () {
stop();
expect(4);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
attachment_mapping_dict: {
id: ["equalSubProperty", "otherId"],
attachment: {
"2713": {"get": {"uri_template": "www.2713.foo/{id}"}}
},
sub_storage: {
......@@ -922,7 +862,7 @@
// mappingStorage.removeAttachment
/////////////////////////////////////////////////////////////////
module("mappingStorage.removeAttachment");
test("removeAttachment use sub_storage one's", function () {
test("sub_storage removeAttachment called", function () {
stop();
expect(3);
......@@ -951,13 +891,13 @@
});
});
test("removeAttachment use UriTemplate", function () {
test("with use UriTemplate", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
attachment_mapping_dict: {
attachment: {
"2713": {"remove": {"uri_template": "www.2713/{id}.bar"}}
},
sub_storage: {
......@@ -983,14 +923,14 @@
});
});
test("removeAttachment with UriTemplate and id mapped", function () {
test("with UriTemplate and id equalSubProperty", function () {
stop();
expect(4);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
attachment_mapping_dict: {
id: ["equalSubProperty", "otherId"],
attachment: {
"2713": {"remove": {"uri_template": "www.2713.foo/{id}"}}
},
sub_storage: {
......@@ -1030,7 +970,7 @@
// mappingStorage.allAttachments
/////////////////////////////////////////////////////////////////
module("mappingStorage.allAttachments");
test("allAttachments use sub_storage one's", function () {
test("sub_storage allAttachments called", function () {
stop();
expect(2);
......@@ -1058,13 +998,13 @@
});
});
test("allAttachments use UriTemplate", function () {
test("with UriTemplate", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
attachment_mapping_dict: {
attachment: {
"2713": {"get": {"uri_template": "www.2713.bar"}}
},
sub_storage: {
......@@ -1093,7 +1033,7 @@
// mappingStorage.allDocs
/////////////////////////////////////////////////////////////////
module("mappingStorage.buildQuery");
test("allDocs with complex query, with map_all_property", function () {
test("with complex query", function () {
stop();
expect(1);
......@@ -1144,14 +1084,14 @@
});
});
test("allDocs with complex query, id and prop mapped", function () {
test("with complex query, id and prop equalSubProperty", function () {
stop();
expect(1);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
id: ["equalSubProperty", "otherId"],
property: {
"title": ["equalSubProperty", "otherTitle"],
"smth": ["equalSubProperty", "otherSmth"]
},
......@@ -1221,14 +1161,14 @@
});
});
test("allDocs without option, id and prop mapped", function () {
test("without option, id and prop equalSubProperty", function () {
stop();
expect(1);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
id: ["equalSubProperty", "otherId"],
property: {
"title": ["equalSubProperty", "otherTitle"]
},
sub_storage: {
......@@ -1273,14 +1213,14 @@
});
});
test("allDocs id and prop mapped and map_all_property", function () {
test("with id and prop equalSubProperty", function () {
stop();
expect(1);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
id: ["equalSubProperty", "otherId"],
property: {
"title": ["equalSubProperty", "otherTitle"]
},
sub_storage: {
......@@ -1328,15 +1268,15 @@
});
});
test("allDocs id and prop mapped and query", function () {
test("with id and prop equalSubProperty and query", function () {
stop();
expect(1);
var jio = jIO.createJIO({
type: "mapping",
query: {"query": 'otherId: "42"'},
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
id: ["equalSubProperty", "otherId"],
property: {
"title": ["equalSubProperty", "otherTitle"]
},
sub_storage: {
......@@ -1388,14 +1328,14 @@
// mappingStorage.bulk
/////////////////////////////////////////////////////////////////
module("mappingstorage.bulk");
test("bulk with map_all_property", function () {
test("with id and prop equalSubProperty", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
mapping_dict: {
id: ["equalSubProperty", "otherId"],
property: {
"title": ["equalSubProperty", "otherTitle"]
},
sub_storage: {
......@@ -1475,7 +1415,7 @@
/////////////////////////////////////////////////////////////////
module("mappingStorage.repair");
test("repair called substorage repair", function () {
test("substorage repair called", function () {
stop();
expect(2);
......@@ -1484,7 +1424,7 @@
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {
property: {
"title": ["equalSubProperty", "title"]
}
});
......
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