Commit f71fb6cb authored by Bryan Kaperick's avatar Bryan Kaperick

Implemented attachment methods so that scenario_officejs.js runs with...

Implemented attachment methods so that scenario_officejs.js runs with historystorage as the local sub storage.
parent fede0168
...@@ -135,6 +135,7 @@ ...@@ -135,6 +135,7 @@
}, },
count: {} count: {}
}; };
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "replicate", type: "replicate",
query: { query: {
...@@ -153,7 +154,7 @@ ...@@ -153,7 +154,7 @@
parallel_operation_amount: 10, parallel_operation_amount: 10,
parallel_operation_attachment_amount: 10, parallel_operation_attachment_amount: 10,
local_sub_storage: { local_sub_storage: {
type: "query", type: "history",
sub_storage: { sub_storage: {
type: "uuid", type: "uuid",
sub_storage: { sub_storage: {
...@@ -213,7 +214,6 @@ ...@@ -213,7 +214,6 @@
doc_id = 'foo_module/1', doc_id = 'foo_module/1',
doc = {title: doc_id, portal_type: "Foo", modification_date: 'a'}, doc = {title: doc_id, portal_type: "Foo", modification_date: 'a'},
blob = new Blob(['a']); blob = new Blob(['a']);
putFullDoc(this.jio.__storage._remote_sub_storage, doc_id, doc, blob) putFullDoc(this.jio.__storage._remote_sub_storage, doc_id, doc, blob)
.then(function () { .then(function () {
return test.jio.repair(); return test.jio.repair();
...@@ -279,7 +279,6 @@ ...@@ -279,7 +279,6 @@
test("remote document modification: copy", function () { test("remote document modification: copy", function () {
expect(2); expect(2);
stop(); stop();
var test = this, var test = this,
doc_id = 'foo_module/1', doc_id = 'foo_module/1',
doc = {title: doc_id, portal_type: "Foo", modification_date: 'a'}, doc = {title: doc_id, portal_type: "Foo", modification_date: 'a'},
...@@ -367,7 +366,6 @@ ...@@ -367,7 +366,6 @@
doc_id = 'abc', doc_id = 'abc',
doc = {title: doc_id, portal_type: "Foo", modification_date: 'a'}, doc = {title: doc_id, portal_type: "Foo", modification_date: 'a'},
blob = new Blob(['a']); blob = new Blob(['a']);
putFullDoc(this.jio, doc_id, doc, blob) putFullDoc(this.jio, doc_id, doc, blob)
.then(function () { .then(function () {
resetCount(test.remote_mock_options.count); resetCount(test.remote_mock_options.count);
......
This diff is collapsed.
...@@ -11,6 +11,16 @@ ...@@ -11,6 +11,16 @@
equal = QUnit.equal, equal = QUnit.equal,
module = QUnit.module; module = QUnit.module;
function putFullDoc(storage, id, doc, attachment_name, attachment) {
return storage.put(id, doc)
.push(function () {
return storage.putAttachment(
id,
attachment_name,
attachment
);
});
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// _revision parameter updating with RSVP all // _revision parameter updating with RSVP all
...@@ -279,6 +289,148 @@ ...@@ -279,6 +289,148 @@
.always(function () {start(); }); .always(function () {start(); });
}); });
**/ **/
/////////////////////////////////////////////////////////////////
// Attachments
/////////////////////////////////////////////////////////////////
module("HistoryStorage.attachments");
test("Testing proper adding/removing attachments",
function () {
stop();
expect(9);
// create storage of type "history" with memory as substorage
var jio = jIO.createJIO({
type: "history",
sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
//type: "indexeddb",
//database: dbname
}
}
}),
not_history = jIO.createJIO({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
//type: "indexeddb",
//database: dbname
}
}
}),
blob1 = new Blob(['a']),
blob2 = new Blob(['b']),
other_blob = new Blob(['1']);
jio.put("doc", {title: "foo0"})
.push(function () {
return jio.putAttachment("doc", "attached", blob1);
})
.push(function () {
return jio.putAttachment("doc", "attached", blob2);
})
.push(function () {
return jio.putAttachment("doc", "other_attached", other_blob);
})
.push(function () {
return jio.get("doc");
})
.push(function (result) {
deepEqual(result, {
title: "foo0"
}, "Get does not return any attachment information");
return jio.getAttachment("doc", "attached");
})
.push(function (result) {
deepEqual(result,
blob2,
"Return the attachment information with getAttachment"
);
return jio.getAttachment("doc", "attached_-0");
})
.push(function (result) {
deepEqual(result,
blob2,
"Return the attachment information with getAttachment"
);
return jio.getAttachment("doc", "attached_-1");
})
.push(function (result) {
deepEqual(result,
blob1,
"Return the attachment information with getAttachment"
);
return jio.getAttachment("doc", "attached_-2");
})
.push(function () {
ok(false, "This query should have thrown a 404 error");
},
function (error) {
deepEqual(error.status_code,
404,
"Error if you try to go back more revisions than what exists");
return jio.allAttachments("doc");
})
.push(function (results) {
deepEqual(results, {
"attached": {},
"other_attached": {}
}, "allAttachments works as expected.");
return jio.removeAttachment("doc", "attached");
})
.push(function () {
return jio.get("doc");
})
.push(function (result) {
deepEqual(result, {
title: "foo0"
}, "Get does not return any attachment information");
return jio.getAttachment("doc", "attached");
})
.push(function () {
ok(false, "This query should have thrown a 404 error");
},
function (error) {
deepEqual(error.status_code,
404,
"Removed attachments cannot be queried");
return jio.allAttachments("doc");
})
.push(function (results) {
deepEqual(results, {
"other_attached": {}
}, "allAttachments works as expected with a removed attachment");
})
.push(function () {
return jio.allDocs();
})
.push(function (results) {
equal(results.data.rows.length, 1, "Only one document in storage");
return jio.get(results.data.rows[0].id);
})
.push(function (result) {
deepEqual(result, {
"title": "foo0"
});
return not_history.allDocs();
})
.push(function (results) {
return RSVP.all(results.data.rows.map(function (d) {
return not_history.get(d.id);
}));
})
.fail(function (error) {
//console.log(error);
ok(false, error);
})
.always(function () {start(); });
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Accessing older revisions // Accessing older revisions
...@@ -483,7 +635,7 @@ ...@@ -483,7 +635,7 @@
test("Testing retrieval of older revisions via allDocs calls", test("Testing retrieval of older revisions via allDocs calls",
function () { function () {
stop(); stop();
expect(37); expect(42);
// create storage of type "history" with memory as substorage // create storage of type "history" with memory as substorage
var jio = jIO.createJIO({ var jio = jIO.createJIO({
...@@ -527,7 +679,7 @@ ...@@ -527,7 +679,7 @@
.push(function (result) { .push(function (result) {
deepEqual(result, { deepEqual(result, {
"k": "v3" "k": "v3"
}); }, "One correct result.");
}) })
.push(function () { .push(function () {
return jio.allDocs({ return jio.allDocs({
...@@ -540,7 +692,7 @@ ...@@ -540,7 +692,7 @@
"Only one query returned with options.revision_limit == [1,1]"); "Only one query returned with options.revision_limit == [1,1]");
deepEqual(results.data.rows[0].doc, { deepEqual(results.data.rows[0].doc, {
"k": "v2" "k": "v2"
}); }, "One correct result.");
return jio.allDocs({ return jio.allDocs({
query: "_REVISION : =2" query: "_REVISION : =2"
}); });
...@@ -576,13 +728,14 @@ ...@@ -576,13 +728,14 @@
}); });
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, 2); equal(results.data.rows.length, 2,
"Only retrieve two most recent revions");
deepEqual(results.data.rows[0].doc, { deepEqual(results.data.rows[0].doc, {
"k": "v3" "k": "v3"
}, "Only retrieve two most recent revions"); }, "First retrieved revision is correct");
deepEqual(results.data.rows[1].doc, { deepEqual(results.data.rows[1].doc, {
"k": "v2" "k": "v2"
}); }, "Second retrieved revision is correct");
}) })
.push(function () { .push(function () {
return jio.remove("doc"); return jio.remove("doc");
...@@ -660,10 +813,10 @@ ...@@ -660,10 +813,10 @@
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, 1, equal(results.data.rows.length, 1,
"There is only one non-removed doc"); "There is only one non-removed doc.");
deepEqual(results.data.rows[0].doc, { deepEqual(results.data.rows[0].doc, {
"k2": "w1" "k2": "w1"
}); }, "Returned the one correct document.");
}) })
.push(function () { .push(function () {
return jio.remove("doc2"); return jio.remove("doc2");
...@@ -714,6 +867,91 @@ ...@@ -714,6 +867,91 @@
deepEqual(results.data.rows[3].doc, { deepEqual(results.data.rows[3].doc, {
"k": "v1" "k": "v1"
}, "Correct results with options.limit set"); }, "Correct results with options.limit set");
return jio.allDocs({
query: "_REVISION: = 1",
select_list: ["k"]
});
})
.push(function (results) {
equal(results.data.rows.length, 2);
deepEqual(results.data.rows[0].doc, {
"k2": "w1"
});
deepEqual(results.data.rows[0].value, {});
deepEqual(results.data.rows[1].doc, {
"k": "v3"
});
deepEqual(results.data.rows[1].value, {
"k": "v3"
});
})
.fail(function (error) {
//console.log(error);
ok(false, error);
})
.always(function () {start(); });
});
/////////////////////////////////////////////////////////////////
// Complex Queries
/////////////////////////////////////////////////////////////////
module("HistoryStorage.complex_queries");
test("Testing retrieval of older revisions via allDocs calls",
function () {
stop();
expect(3);
// create storage of type "history" with memory as substorage
var jio = jIO.createJIO({
type: "history",
sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
}
}),
doc = {
"modification_date": "a",
"portal_type": "Foo",
"title": "foo_module/1"
},
blob = new Blob(['a']);
putFullDoc(jio, "foo_module/1", doc, "data", blob)
.push(function () {
return jio.get("foo_module/1");
})
.push(function (result) {
deepEqual(result, {
"modification_date": "a",
"portal_type": "Foo",
"title": "foo_module/1"
}, "Can retrieve a document after attachment placed."
);
})
.push(function () {
return jio.allDocs({
query: "portal_type: Foo",
select_list: ["modification_date", "__id", "__id"],
sort_on: [["modification_date", "descending"],
["timestamp", "descending"],
["timestamp", "descending"]
]
});
})
.push(function (results) {
equal(results.data.rows.length, 1);
deepEqual(results.data.rows[0], {
doc: {
"modification_date": "a",
"portal_type": "Foo",
"title": "foo_module/1"
},
id: "foo_module/1",
value: {modification_date: "a"}
});
}) })
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(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