Commit b84a7fab authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: fix post and add tests

parent f380d001
......@@ -260,11 +260,16 @@
};
MappingStorage.prototype.post = function (doc) {
if (!this._id_is_mapped) {
return this._sub_storage.post(mapToSubstorageDocument(
var sub_doc = mapToSubstorageDocument(
this,
doc
));
),
id = doc[this._property_for_sub_id];
if (this._property_for_sub_id && id !== undefined) {
return this._sub_storage.put(id, sub_doc);
}
if (!this._id_mapped || doc[this._id_mapped] !== undefined) {
return this._sub_storage.post(sub_doc);
}
throw new jIO.util.jIOError(
"post is not supported with id mapped",
......
......@@ -580,7 +580,7 @@
});
/////////////////////////////////////////////////////////////////
// mappingStorage.remove
// mappingStorage.post
/////////////////////////////////////////////////////////////////
module("mappingStorage.post");
......@@ -615,7 +615,7 @@
});
});
test("post with id mapped", function () {
test("post with id mapped, no id in doc", function () {
stop();
expect(2);
......@@ -640,6 +640,65 @@
start();
});
});
test("post with id mapped and in doc", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
map_id: ["equalSubProperty", "otherId"],
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.post = function (doc) {
deepEqual(doc, {"title": "foo", "otherId": "bar"}, "post 2713 called");
return "42";
};
jio.post({"title": "foo", "otherId": "bar"})
.push(function (result) {
equal(result, "42");
})
.push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("post with sub_id mapped and in doc", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
mapping_dict: {"otherId": ["equalSubId"]},
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.put = function (id, doc) {
deepEqual(doc, {"title": "foo"}, "put 2713 called");
equal(id, "bar", "put 2713 called");
return "bar";
};
jio.post({"title": "foo", "otherId": "bar"})
.push(function (result) {
equal(result, "bar");
})
.push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.putAttachment
/////////////////////////////////////////////////////////////////
......@@ -1150,7 +1209,7 @@
"doc": {}
}
],
"total_rows": 1
"total_rows": 2
}
}, "allDocs check");
})
......
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