Commit b2948e5d authored by Bryan Kaperick's avatar Bryan Kaperick

Added additional testing of the revisions and removed extraneous tests.

parent 5762d991
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
sub_storage: spec.sub_storage sub_storage: spec.sub_storage
} }
}); });
} }
BryanStorage.prototype.get = function (id_in) { BryanStorage.prototype.get = function (id_in) {
...@@ -28,7 +27,7 @@ ...@@ -28,7 +27,7 @@
sort_on: [['_revision', 'descending']] sort_on: [['_revision', 'descending']]
//include_docs: true //include_docs: true
}; };
return this._sub_storage.allDocs(options) return this.allDocs(options)
// Return query results if there are any, else throw error // Return query results if there are any, else throw error
.push(function (query_results) { .push(function (query_results) {
var docs = query_results.data.rows; var docs = query_results.data.rows;
...@@ -71,6 +70,10 @@ ...@@ -71,6 +70,10 @@
); );
}; };
BryanStorage.prototype.allDocs = function () {
return this._sub_storage.allDocs.apply(this._sub_storage, arguments);
};
BryanStorage.prototype.allAttachments = function () { BryanStorage.prototype.allAttachments = function () {
return this._sub_storage.allAttachments.apply(this._sub_storage, arguments); return this._sub_storage.allAttachments.apply(this._sub_storage, arguments);
}; };
......
/*jslint nomen: true*/ /*jslint nomen: true*/
/*global Blob, jiodate*/ /*global Blob, jiodate*/
(function (jIO, QUnit, Blob) { (function (jIO, QUnit) {
"use strict"; "use strict";
var test = QUnit.test, var test = QUnit.test,
stop = QUnit.stop, stop = QUnit.stop,
...@@ -29,204 +29,10 @@ ...@@ -29,204 +29,10 @@
}); });
/////////////////////////////////////////////////////////////////
// bryanStorage.get
/////////////////////////////////////////////////////////////////
module("bryanStorage.get");
test("get called substorage get", function () {
stop();
expect(2);
// create storage of type "bryan" with memory as substorage
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
});
jio.put("bar", {"title": "foo"});
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"title": "foo",
"_revision": 0
}, "Check document");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
jio.get("bar")
.then(function (result) {
deepEqual(result, {
"title": "foo",
"_revision": 0
}, "Check document");
})
.fail(function (error) {
ok(false, error);
});
//.always(function () {
// start();
//});
});
/////////////////////////////////////////////////////////////////
// _revision parameter initialization
/////////////////////////////////////////////////////////////////
module("bryanStorage initialize _revision");
test("verifying _revision updates correctly", function () {
stop();
expect(2);
// create storage of type "bryan" with memory as substorage
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
});
jio.put("bar", {"title": "foo"})
.push(function (result) {
equal(result, "bar");
return jio.get("bar");
})
.push(function (result) {
deepEqual(result, {
"title": "foo",
"_revision": 0
}, "Check document");
})
.fail(function (error) {ok(false, error); })
.always(function () {start(); });
});
/////////////////////////////////////////////////////////////////
// _revision parameter updating with put
/////////////////////////////////////////////////////////////////
module("bryanStorage _revision with put");
test("verifying _revision updates correctly", function () {
stop();
expect(1);
// create storage of type "bryan" with memory as substorage
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {type: "memory"}
});
jio.put("bar", {"title": "foo"})
.push(function () {return jio.put("bar", {"title2": "foo2"}); })
.push(function () {return jio.put("bar", {"title3": "foo3"}); })
.push(function () {return jio.get("bar"); })
.push(function (result) {
deepEqual(result, {
"title3": "foo3",
"_revision": 2
}, "Check document after initialization");
})
.fail(function (error) {ok(false, error); })
.always(function () {start(); });
});
/////////////////////////////////////////////////////////////////
// _revision parameter updating with putAttachment
/////////////////////////////////////////////////////////////////
module("bryanStorage _revision with putAttachment");
test("verifying _revision updates correctly after putAttachment",
function () {
stop();
expect(1);
// Create storage of type "bryan" with memory as substorage
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {type: "memory"}
});
jio.put("bar", {"title": "foo"})
// Put two unique attachments in the document
.push(function () {
return jio.putAttachment(
"bar",
"blob",
new Blob(["text data"], {type: "text/plain"})
);
})
.push(function () {
return jio.putAttachment(
"bar",
"blob2",
new Blob(["more text data"], {type: "text/plain"})
);
})
// Get metadata for document
.push(function () {return jio.get("bar"); })
// Verify "_revision" is incremented twice
.push(function (result) {
deepEqual(result, {
"title": "foo",
"_revision": 2
}, "Check document after 2 revisions");
})
.fail(function (error) {ok(false, error); })
.always(function () {start(); });
}
);
/////////////////////////////////////////////////////////////////
// _revision parameter updating with removeAttachment
/////////////////////////////////////////////////////////////////
module("bryanStorage _revision with removeAttachment");
test("verifying _revision updates correctly after removeAttachment",
function () {
stop();
expect(1);
// create storage of type "bryan" with memory as substorage
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {type: "memory"}
});
jio.put("bar", {"title": "foo"})
.push(function () {
return jio.putAttachment(
"bar",
"blob",
new Blob(["text data"], {type: "text/plain"})
);
})
.push(function () {
return jio.putAttachment(
"bar",
"blob2",
new Blob(["more text data"], {type: "text/plain"})
);
})
.push(function () {return jio.removeAttachment("bar", "blob"); })
.push(function () {return jio.removeAttachment("bar", "blob2"); })
.push(function () {return jio.get("bar"); })
.push(function (result) {
deepEqual(result, {
"title": "foo",
"_revision": 4
}, "Check document after 4 revisions");
})
.fail(function (error) {ok(false, error); })
.always(function () {start(); });
}
);
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// _revision parameter updating with RSVP all // _revision parameter updating with RSVP all
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/**
module("bryanStorage _revision with RSVP all"); module("bryanStorage _revision with RSVP all");
test("verifying _revision updates correctly when puts are done in parallel", test("verifying _revision updates correctly when puts are done in parallel",
function () { function () {
...@@ -249,216 +55,21 @@ ...@@ -249,216 +55,21 @@
.fail(function (error) {ok(false, error); }) .fail(function (error) {ok(false, error); })
.always(function () {start(); }); .always(function () {start(); });
}); });
**/
/////////////////////////////////////////////////////////////////
// bryanStorage.allAttachments
/////////////////////////////////////////////////////////////////
module("bryanStorage.allAttachments");
test("allAttachments called substorage allAttachments", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
});
jio.allAttachments("bar")
.push(function (result) {
deepEqual(result, {
attachmentname: {}
}, "Check document");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.post
/////////////////////////////////////////////////////////////////
module("bryanStorage.post");
test("post called substorage post", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
});
jio.post({"title": "foo"})
.push(function (result) {
equal(result, "youhou");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.put
/////////////////////////////////////////////////////////////////
module("bryanStorage.put");
test("put called substorage put", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
});
// If .put does not give the appropriate return, fail assertion
jio.put("bar", {"title": "foo"})
.push(function (result) {
equal(result, "bar");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.remove
/////////////////////////////////////////////////////////////////
module("bryanStorage.remove");
test("remove called substorage remove", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
});
jio.remove("bar")
.push(function (result) {
equal(result, "bar");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.getAttachment
/////////////////////////////////////////////////////////////////
module("bryanStorage.getAttachment");
test("getAttachment called substorage getAttachment", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
}),
blob = new Blob([""]);
jio.getAttachment("bar", "foo")
.then(function (result) {
equal(result, blob);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.putAttachment
/////////////////////////////////////////////////////////////////
module("bryanStorage.putAttachment");
test("putAttachment called substorage putAttachment", function () {
stop();
expect(4);
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
}),
blob = new Blob([""]);
jio.putAttachment("bar", "foo", blob)
.then(function (result) {
equal(result, "OK");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.removeAttachment
/////////////////////////////////////////////////////////////////
module("bryanStorage.removeAttachment");
test("removeAttachment called substorage removeAttachment", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "memory"
}
});
jio.removeAttachment("bar", "foo")
.then(function (result) {
equal(result, "Removed");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// bryanStorage revision history // bryanStorage revision history
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
module("bryanStorage revision history"); module("bryanStorage.revision_history");
test("put and get the correct version", function () { test("put and get the correct version", function () {
stop(); stop();
expect(1); expect(1);
var jio = jIO.createJIO({ var jio = jIO.createJIO({
type: "bryan", type: "bryan",
sub_storage: { sub_storage: {
type: "indexeddb", type: "memory"
database: "newdb4" //database: "newdb4"
} }
}); });
jio.put("doc1", { jio.put("doc1", {
...@@ -482,15 +93,15 @@ ...@@ -482,15 +93,15 @@
}); });
}); });
module("bryanStorage revision history multiple edits"); module("bryanStorage.revision_history_multiple_edits");
test("modify first version but save both", function () { test("modify first version but save both", function () {
stop(); stop();
expect(2); expect(6);
var jio = jIO.createJIO({ var jio = jIO.createJIO({
type: "bryan", type: "bryan",
sub_storage: { sub_storage: {
type: "indexeddb", type: "memory"
database: "otherdb5" //database: "otherdb8"
} }
}); });
jio.put("other_doc", { jio.put("other_doc", {
...@@ -539,6 +150,39 @@ ...@@ -539,6 +150,39 @@
"_doc_id": "other_doc" "_doc_id": "other_doc"
}, "Retrieve other document correctly"); }, "Retrieve other document correctly");
}) })
.push(function () {
return jio.allDocs({
query: '(_doc_id: "main_doc") AND (_revision: 0)',
sort_on: [['_revision', 'descending']]
});
})
.push(function (result) {
equal(result.length, 1, "Correct number of results returned");
})
.push(function () {
return jio.allDocs({
query: '(_doc_id: "main_doc") AND (_revision: 1)'
});
})
.push(function (result) {
equal(result.length, 1, "Correct number of results returned");
})
.push(function () {
return jio.allDocs({
query: '(_doc_id: "other_doc") AND (_revision: 0)'
});
})
.push(function (result) {
equal(result.length, 1, "Correct number of results returned");
})
.push(function () {
return jio.allDocs({
query: ''
});
})
.push(function (result) {
equal(result.length, 5, "Correct number of results returned");
})
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
}) })
...@@ -547,6 +191,6 @@ ...@@ -547,6 +191,6 @@
}); });
}); });
}(jIO, QUnit, Blob)); }(jIO, QUnit));
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