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

mappingstorage: add property ignore

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