Commit 4c7d58a7 authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: add property ignore

parent f7e1c959
......@@ -78,10 +78,6 @@
if (sub_doc.id !== undefined) {
return sub_doc.id;
}
throw new jIO.util.jIOError(
"Cannot find id field related",
400
);
}
query = new SimpleQuery({
key: storage._mapping_dict.id.equal,
......@@ -134,6 +130,10 @@
return property;
}
}
if (!storage._map_all_property ||
storage._mapping_dict[property] === "ignore") {
return false;
}
if (storage._map_all_property) {
sub_doc[property] = doc[property];
return property;
......@@ -156,6 +156,10 @@
return property;
}
}
if (!storage._map_all_property ||
storage._mapping_dict[property] === "ignore") {
return property;
}
if (storage._map_all_property) {
if (sub_doc.hasOwnProperty(property)) {
doc[property] = sub_doc[property];
......
......@@ -97,36 +97,6 @@
});
});
test("get with props mapped", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {"title": {"equal": "otherTitle"}}
});
Storage2713.prototype.get = function (id) {
equal(id, "bar", "get 2713 called");
return {otherTitle: "foo"};
};
jio.get("bar")
.push(function (result) {
deepEqual(result, {
"title": "foo"
});
}).push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("get with id mapped", function () {
stop();
expect(2);
......@@ -246,17 +216,19 @@
});
});
test("get with map_all_property", function () {
test("get with not map_all_property", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
map_all_property: false,
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {
"id": {"equal": "otherId"}
"id": {"equal": "otherId"},
"title": {"equal": "otherTitle"}
}
});
......@@ -275,7 +247,7 @@
Storage2713.prototype.get = function (id) {
equal(id, "2713", "get 2713 called");
return {"title": "foo"};
return {"otherTitle": "foo", "foo": "bar"};
};
jio.get("42")
......@@ -291,6 +263,66 @@
});
});
test("get with props equal", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {"title": {"equal": "otherTitle"}}
});
Storage2713.prototype.get = function (id) {
equal(id, "bar", "get 2713 called");
return {otherTitle: "foo"};
};
jio.get("bar")
.push(function (result) {
deepEqual(result, {
"title": "foo"
});
}).push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("get with ignore", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {"title": "ignore"}
});
Storage2713.prototype.get = function (id) {
equal(id, "bar", "get 2713 called");
return {"title": "foo", "foo": "bar"};
};
jio.get("bar")
.push(function (result) {
deepEqual(result, {
"foo": "bar"
});
}).push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.put
/////////////////////////////////////////////////////////////////
......@@ -432,7 +464,7 @@
});
});
test("put with map_all_property", function () {
test("put with no map_all_property", function () {
stop();
expect(3);
......@@ -442,14 +474,15 @@
type: "mappingstorage2713"
},
mapping_dict: {
"id": {"equal": "id"}
"id": {"equal": "id"},
"title": {"equal": "title"}
},
map_all_property: true
map_all_property: false
});
Storage2713.prototype.put = function (id, doc) {
deepEqual(doc,
{"title": "foo", "smth": "bar", "smth2": "bar2"}, "post 2713 called");
{"title": "foo"}, "post 2713 called");
equal(id, "42", "put 2713 called");
return id;
};
......@@ -1339,11 +1372,9 @@
deepEqual(
result,
[{
"id": "foo",
"title": "bar",
"bar": "foo"
}, {
"id": "bar",
"title": "foo",
"foo": "bar"
}],
......
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