Commit 7324f225 authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: modify attachment uritemplate and test

parent 09cc6aec
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
.push(function () { .push(function () {
if (mapping_dict !== undefined if (mapping_dict !== undefined
&& mapping_dict[attachment_id] !== undefined && mapping_dict[attachment_id] !== undefined
&& mapping_dict[attachment_id].uri_template !== undefined) { && mapping_dict[attachment_id][method].uri_template !== undefined) {
return UriTemplate.parse( return UriTemplate.parse(
mapping_dict[attachment_id][method].uri_template mapping_dict[attachment_id][method].uri_template
).expand({id: sub_id}); ).expand({id: sub_id});
...@@ -253,6 +253,9 @@ ...@@ -253,6 +253,9 @@
argument_list[1] = sub_attachment_id; argument_list[1] = sub_attachment_id;
return context._sub_storage.putAttachment.apply(context._sub_storage, return context._sub_storage.putAttachment.apply(context._sub_storage,
argument_list); argument_list);
})
.push(function () {
return attachment_id;
}); });
}; };
...@@ -281,6 +284,9 @@ ...@@ -281,6 +284,9 @@
argument_list[1] = sub_attachment_id; argument_list[1] = sub_attachment_id;
return context._sub_storage.removeAttachment.apply(context._sub_storage, return context._sub_storage.removeAttachment.apply(context._sub_storage,
argument_list); argument_list);
})
.push(function () {
return attachment_id;
}); });
}; };
......
...@@ -492,7 +492,7 @@ ...@@ -492,7 +492,7 @@
}; };
jio.putAttachment("42", "2713", blob) jio.putAttachment("42", "2713", blob)
.then(function (result) { .then(function (result) {
equal(result, "42"); equal(result, "2713");
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
...@@ -523,7 +523,50 @@ ...@@ -523,7 +523,50 @@
}; };
jio.putAttachment("42", "2713", blob) jio.putAttachment("42", "2713", blob)
.then(function (result) { .then(function (result) {
equal(result, "42"); equal(result, "2713");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("putAttachment with UriTemplate and id mapped", function () {
stop();
expect(5);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {"id": {"equal": "otherId"}},
mapping_dict_attachment: {"2713": {"put":
{"uri_template": "www.2713.foo/{id}"}}}
}),
blob = new Blob([""]);
Storage2713.prototype.putAttachment = function (id,
attachment_id, attachment) {
equal(id, "13", "putAttachment 2713 called");
equal(attachment_id, "www.2713.foo/13", "putAttachment 2713 called");
deepEqual(attachment, blob, "putAttachment 2713 called");
return id;
};
Storage2713.prototype.hasCapacity = function () {
return true;
};
Storage2713.prototype.buildQuery = function (option) {
equal(option.query, 'otherId: "42"');
return [{"id": "13"}];
};
jio.putAttachment("42", "2713", blob)
.then(function (result) {
equal(result, "2713");
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
...@@ -595,6 +638,48 @@ ...@@ -595,6 +638,48 @@
}); });
}); });
test("getAttachment with UriTemplate and id mapped", function () {
stop();
expect(4);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {"id": {"equal": "otherId"}},
mapping_dict_attachment: {"2713": {"get":
{"uri_template": "www.2713.foo/{id}"}}}
}),
blob = new Blob([""]);
Storage2713.prototype.getAttachment = function (id,
attachment_id) {
equal(id, "13", "getAttachment 2713 called");
equal(attachment_id, "www.2713.foo/13", "getAttachment 2713 called");
return blob;
};
Storage2713.prototype.hasCapacity = function () {
return true;
};
Storage2713.prototype.buildQuery = function (option) {
equal(option.query, 'otherId: "42"');
return [{"id": "13"}];
};
jio.getAttachment("42", "2713")
.then(function (result) {
deepEqual(result, blob);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// mappingStorage.removeAttachment // mappingStorage.removeAttachment
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -610,13 +695,13 @@ ...@@ -610,13 +695,13 @@
} }
}); });
Storage2713.prototype.removeAttachment = function (doc_id, attachment) { Storage2713.prototype.removeAttachment = function (doc_id, attachment) {
equal(doc_id, "42", "putAttachment 2713 called"); equal(doc_id, "42", "removeAttachment 2713 called");
equal(attachment, "2713", "getAttachment 2713 called"); equal(attachment, "2713", "getAttachment 2713 called");
return doc_id; return doc_id;
}; };
jio.removeAttachment("42", "2713") jio.removeAttachment("42", "2713")
.then(function (result) { .then(function (result) {
deepEqual(result, "42"); deepEqual(result, "2713");
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
...@@ -638,13 +723,54 @@ ...@@ -638,13 +723,54 @@
{"remove": {"uri_template": "www.2713/{id}.bar"}}} {"remove": {"uri_template": "www.2713/{id}.bar"}}}
}); });
Storage2713.prototype.removeAttachment = function (doc_id, attachment) { Storage2713.prototype.removeAttachment = function (doc_id, attachment) {
equal(doc_id, "42", "putAttachment 2713 called"); equal(doc_id, "42", "removeAttachment 2713 called");
equal(attachment, "www.2713/42.bar", "getAttachment 2713 called"); equal(attachment, "www.2713/42.bar", "removeAttachment 2713 called");
return doc_id; return doc_id;
}; };
jio.removeAttachment("42", "2713") jio.removeAttachment("42", "2713")
.then(function (result) { .then(function (result) {
deepEqual(result, "42"); deepEqual(result, "2713");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("removeAttachment with UriTemplate and id mapped", function () {
stop();
expect(4);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {"id": {"equal": "otherId"}},
mapping_dict_attachment: {"2713": {"remove":
{"uri_template": "www.2713.foo/{id}"}}}
});
Storage2713.prototype.removeAttachment = function (id,
attachment_id) {
equal(id, "13", "removeAttachment 2713 called");
equal(attachment_id, "www.2713.foo/13", "removeAttachment 2713 called");
return id;
};
Storage2713.prototype.hasCapacity = function () {
return true;
};
Storage2713.prototype.buildQuery = function (option) {
equal(option.query, 'otherId: "42"');
return [{"id": "13"}];
};
jio.removeAttachment("42", "2713")
.then(function (result) {
equal(result, "2713");
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
......
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