Commit 42953eed authored by Tristan Cavelier's avatar Tristan Cavelier

jslint indexstorage tests

parent f9dd58fc
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
}; };
// post without id // post without id
o.spy (o, "jobstatus", "done", "Post without id"); o.spy(o, "jobstatus", "done", "Post without id");
o.jio.post({}, function (err, response) { o.jio.post({}, function (err, response) {
o.id = (response || {}).id; o.id = (response || {}).id;
o.f(err, response); o.f(err, response);
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
// post non empty document // post non empty document
o.doc = {"_id": "some_id", "title": "My Title", o.doc = {"_id": "some_id", "title": "My Title",
"year": 2000, "hey": "def"}; "year": 2000, "hey": "def"};
o.spy (o, "value", {"ok": true, "id": "some_id"}, "Post document"); o.spy(o, "value", {"ok": true, "id": "some_id"}, "Post document");
o.jio.post(o.doc, o.f); o.jio.post(o.doc, o.f);
o.tick(o); o.tick(o);
...@@ -100,19 +100,25 @@ ...@@ -100,19 +100,25 @@
o.tick(o); o.tick(o);
// post with escapable characters // post with escapable characters
o.doc = {"_id": "other_id", "title": "myPost2", o.doc = {
"findMeA":"keyword_*§$%&/()=?", "findMeB":"keyword_|ð@ł¶đæðſæðæſ³" "_id": "other_id",
}; "title": "myPost2",
o.spy (o, "value", {"ok": true, "id": "other_id"}, "findMeA": "keyword_*§$%&/()=?",
"Post with escapable characters"); "findMeB": "keyword_|ð@ł¶đæðſæðæſ³"
};
o.spy(o, "value", {"ok": true, "id": "other_id"},
"Post with escapable characters");
o.jio.post(o.doc, o.f); o.jio.post(o.doc, o.f);
o.tick(o); o.tick(o);
// post and document already exists // post and document already exists
o.doc = {"_id": "some_id", "title": "myPost3", o.doc = {
"findMeA":"keyword_ghi", "findMeB":"keyword_jkl" "_id": "some_id",
} "title": "myPost3",
o.spy (o, "status", 409, "Post and document already exists"); "findMeA": "keyword_ghi",
"findMeB": "keyword_jkl"
};
o.spy(o, "status", 409, "Post and document already exists");
o.jio.post(o.doc, o.f); o.jio.post(o.doc, o.f);
o.tick(o); o.tick(o);
...@@ -149,13 +155,13 @@ ...@@ -149,13 +155,13 @@
// put without id // put without id
// error 20 -> document id required // error 20 -> document id required
o.spy (o, "status", 20, "Put without id"); o.spy(o, "status", 20, "Put without id");
o.jio.put({}, o.f); o.jio.put({}, o.f);
o.tick(o); o.tick(o);
// put non empty document // put non empty document
o.doc = {"_id": "put1", "title": "myPut1", "author": "John Doe"}; o.doc = {"_id": "put1", "title": "myPut1", "author": "John Doe"};
o.spy (o, "value", {"ok": true, "id": "put1"}, "Put-create document"); o.spy(o, "value", {"ok": true, "id": "put1"}, "Put-create document");
o.jio.put(o.doc, o.f); o.jio.put(o.doc, o.f);
o.tick(o); o.tick(o);
...@@ -190,7 +196,7 @@ ...@@ -190,7 +196,7 @@
// modify document - modify keyword on index! // modify document - modify keyword on index!
o.doc = {"_id": "put1", "title": "myPuttter1", "author": "Jane Doe"}; o.doc = {"_id": "put1", "title": "myPuttter1", "author": "Jane Doe"};
o.spy (o, "value", {"ok": true, "id": "put1"}, "Modify existing document"); o.spy(o, "value", {"ok": true, "id": "put1"}, "Modify existing document");
o.jio.put(o.doc, o.f); o.jio.put(o.doc, o.f);
o.tick(o); o.tick(o);
...@@ -205,7 +211,7 @@ ...@@ -205,7 +211,7 @@
// add new document with same keyword! // add new document with same keyword!
o.doc = {"_id": "new_doc", "title": "myPut2", "author": "Jane Doe"}; o.doc = {"_id": "new_doc", "title": "myPut2", "author": "Jane Doe"};
o.spy (o, "value", {"ok": true, "id": "new_doc"}, o.spy(o, "value", {"ok": true, "id": "new_doc"},
"Add new document with same keyword"); "Add new document with same keyword");
o.jio.put(o.doc, o.f); o.jio.put(o.doc, o.f);
o.tick(o); o.tick(o);
...@@ -222,8 +228,8 @@ ...@@ -222,8 +228,8 @@
// add second keyword to index file // add second keyword to index file
o.doc = {"_id": "put1", "title": "myPut2", "author": "Jane Doe", o.doc = {"_id": "put1", "title": "myPut2", "author": "Jane Doe",
"year":"1912"}; "year": "1912"};
o.spy (o, "value", {"ok": true, "id": "put1"}, o.spy(o, "value", {"ok": true, "id": "put1"},
"add second keyword to index file"); "add second keyword to index file");
o.jio.put(o.doc, o.f); o.jio.put(o.doc, o.f);
o.tick(o); o.tick(o);
...@@ -247,7 +253,7 @@ ...@@ -247,7 +253,7 @@
// remove a keyword from an existing document // remove a keyword from an existing document
o.doc = {"_id": "new_doc", "title": "myPut2"}; o.doc = {"_id": "new_doc", "title": "myPut2"};
o.spy (o, "value", {"ok": true, "id": "new_doc"}, o.spy(o, "value", {"ok": true, "id": "new_doc"},
"Remove keyword from existing document"); "Remove keyword from existing document");
o.jio.put(o.doc, o.f); o.jio.put(o.doc, o.f);
o.tick(o); o.tick(o);
...@@ -372,15 +378,15 @@ ...@@ -372,15 +378,15 @@
o.fakeIndexB.database.unshift({"_id": "blah", "year": "y"}); o.fakeIndexB.database.unshift({"_id": "blah", "year": "y"});
o.spy(o, "status", 40, "Check Document"); o.spy(o, "status", 40, "Check Document");
o.jio.check({"_id": "blah"}, o.f) o.jio.check({"_id": "blah"}, o.f);
o.tick(o); o.tick(o);
o.spy(o, "value", {"id": "blah", "ok": true}, "Repair Document"); o.spy(o, "value", {"id": "blah", "ok": true}, "Repair Document");
o.jio.repair({"_id": "blah"}, o.f) o.jio.repair({"_id": "blah"}, o.f);
o.tick(o); o.tick(o);
o.spy(o, "value", {"id": "blah", "ok": true}, "Check Document again"); o.spy(o, "value", {"id": "blah", "ok": true}, "Check Document again");
o.jio.repair({"_id": "blah"}, o.f) o.jio.repair({"_id": "blah"}, o.f);
o.tick(o); o.tick(o);
// check index file // check index file
...@@ -440,41 +446,39 @@ ...@@ -440,41 +446,39 @@
o.tick(o); o.tick(o);
// putAttachment with document // putAttachment with document
o.doc = {"_id": "putattmt1","title": "myPutAttmt1"}; o.doc = {"_id": "putattmt1", "title": "myPutAttmt1"};
o.spy (o, "value", {"ok": true, "id": "putattmt1"}, o.spy(o, "value", {"ok": true, "id": "putattmt1"},
"Put underlying document"); "Put underlying document");
o.jio.put(o.doc, o.f); o.jio.put(o.doc, o.f);
o.tick(o); o.tick(o);
o.spy(o, "value", o.spy(o, "value", {
{"ok": true, "id": "putattmt1", "attachment": "putattmt2"}, "ok": true,
"PutAttachment with document, without data"); "id": "putattmt1",
"attachment": "putattmt2"
}, "PutAttachment with document, without data");
o.jio.putAttachment({"_id": "putattmt1", "_attachment": "putattmt2"}, o.f); o.jio.putAttachment({"_id": "putattmt1", "_attachment": "putattmt2"}, o.f);
o.tick(o); o.tick(o);
// check document // check document
deepEqual( deepEqual(util.jsonlocalstorage.getItem(
util.jsonlocalstorage.getItem("jio/localstorage/iputatt/iputatt/putattmt1"), "jio/localstorage/iputatt/iputatt/putattmt1"
{ ), {
"_id": "putattmt1", "_id": "putattmt1",
"title": "myPutAttmt1", "title": "myPutAttmt1",
"_attachments": { "_attachments": {
"putattmt2": { "putattmt2": {
"length": 0, "length": 0,
// md5("") // md5("")
"digest": "md5-d41d8cd98f00b204e9800998ecf8427e" "digest": "md5-d41d8cd98f00b204e9800998ecf8427e"
}
} }
}, }
"Check document" }, "Check document");
);
// check attachment // check attachment
deepEqual( deepEqual(util.jsonlocalstorage.getItem(
util.jsonlocalstorage.getItem( "jio/localstorage/iputatt/iputatt/putattmt1/putattmt2"
"jio/localstorage/iputatt/iputatt/putattmt1/putattmt2"), ), "", "Check attachment");
"", "Check attachment"
);
// update attachment // update attachment
o.spy(o, "value", o.spy(o, "value",
...@@ -488,28 +492,24 @@ ...@@ -488,28 +492,24 @@
o.tick(o); o.tick(o);
// check document // check document
deepEqual( deepEqual(util.jsonlocalstorage.getItem(
util.jsonlocalstorage.getItem("jio/localstorage/iputatt/iputatt/putattmt1"), "jio/localstorage/iputatt/iputatt/putattmt1"
{ ), {
"_id": "putattmt1", "_id": "putattmt1",
"title": "myPutAttmt1", "title": "myPutAttmt1",
"_attachments": { "_attachments": {
"putattmt2": { "putattmt2": {
"length": 3, "length": 3,
// md5("abc") // md5("abc")
"digest": "md5-900150983cd24fb0d6963f7d28e17f72" "digest": "md5-900150983cd24fb0d6963f7d28e17f72"
}
} }
}, }
"Check document" }, "Check document");
);
// check attachment // check attachment
deepEqual( deepEqual(util.jsonlocalstorage.getItem(
util.jsonlocalstorage.getItem( "jio/localstorage/iputatt/iputatt/putattmt1/putattmt2"
"jio/localstorage/iputatt/iputatt/putattmt1/putattmt2"), ), "abc", "Check attachment");
"abc", "Check attachment"
);
util.closeAndcleanUpJio(o.jio); util.closeAndcleanUpJio(o.jio);
}); });
...@@ -549,7 +549,10 @@ ...@@ -549,7 +549,10 @@
"_id": "get1", "_id": "get1",
"title": "myGet1" "title": "myGet1"
}; };
util.jsonlocalstorage.setItem("jio/localstorage/iget/iget/get1", o.doc_get1); util.jsonlocalstorage.setItem(
"jio/localstorage/iget/iget/get1",
o.doc_get1
);
// get document // get document
o.spy(o, "value", o.doc_get1, "Get document"); o.spy(o, "value", o.doc_get1, "Get document");
...@@ -562,14 +565,17 @@ ...@@ -562,14 +565,17 @@
o.tick(o); o.tick(o);
// adding an attachment // adding an attachment
o.doc_get1["_attachments"] = { o.doc_get1._attachments = {
"get2": { "get2": {
"length": 2, "length": 2,
// md5("de") // md5("de")
"digest": "md5-5f02f0889301fd7be1ac972c11bf3e7d" "digest": "md5-5f02f0889301fd7be1ac972c11bf3e7d"
} }
}; };
util.jsonlocalstorage.setItem("jio/localstorage/iget/iget/get1", o.doc_get1); util.jsonlocalstorage.setItem(
"jio/localstorage/iget/iget/get1",
o.doc_get1
);
util.jsonlocalstorage.setItem("jio/localstorage/iget/iget/get1/get2", "de"); util.jsonlocalstorage.setItem("jio/localstorage/iget/iget/get1/get2", "de");
// get attachment // get attachment
...@@ -687,7 +693,8 @@ ...@@ -687,7 +693,8 @@
"_id": "remove3", "_id": "remove3",
"_attachment": "removeAtt", "_attachment": "removeAtt",
"_mimetype": "text/plain", "_mimetype": "text/plain",
"_data": "hello"}); "_data": "hello"
});
o.tick(o); o.tick(o);
// add another attachment // add another attachment
...@@ -695,14 +702,17 @@ ...@@ -695,14 +702,17 @@
"_id": "remove3", "_id": "remove3",
"_attachment": "removeAtt2", "_attachment": "removeAtt2",
"_mimetype": "text/plain", "_mimetype": "text/plain",
"_data": "hello2"}); "_data": "hello2"
});
o.tick(o); o.tick(o);
// remove attachment // remove attachment
o.spy(o, "value", {"ok": true, "id": "remove3", "attachment": "removeAtt2"}, o.spy(o, "value", {"ok": true, "id": "remove3", "attachment": "removeAtt2"},
"Remove one of multiple attachment"); "Remove one of multiple attachment");
o.jio.removeAttachment({"_id": "remove3", "_attachment": "removeAtt2"}, o.jio.removeAttachment({
o.f); "_id": "remove3",
"_attachment": "removeAtt2"
}, o.f);
o.tick(o); o.tick(o);
// check index // check index
...@@ -798,25 +808,34 @@ ...@@ -798,25 +808,34 @@
o.all1 = { "_id": "dragon.doc", o.all1 = { "_id": "dragon.doc",
"title": "some title", "author": "Dr. No", "year": "1968" "title": "some title", "author": "Dr. No", "year": "1968"
}; };
o.spy (o, "value", {"ok": true, "id": "dragon.doc"}, "Put 1"); o.spy(o, "value", {"ok": true, "id": "dragon.doc"}, "Put 1");
o.jio.put(o.all1, o.f); o.jio.put(o.all1, o.f);
o.tick(o); o.tick(o);
o.all2 = {"_id": "timemachine", o.all2 = {
"title": "hello world", "author": "Dr. Who", "year": "1968" "_id": "timemachine",
} "title": "hello world",
o.spy (o, "value", {"ok": true, "id": "timemachine"}, "Put 2"); "author": "Dr. Who",
"year": "1968"
};
o.spy(o, "value", {"ok": true, "id": "timemachine"}, "Put 2");
o.jio.put(o.all2, o.f); o.jio.put(o.all2, o.f);
o.tick(o); o.tick(o);
o.all3 = {"_id": "rocket.ppt", o.all3 = {
"title": "sunshine.", "author": "Dr. Snuggles", "year": "1985" "_id": "rocket.ppt",
} "title": "sunshine.",
o.spy (o, "value", {"ok": true, "id": "rocket.ppt"}, "Put 3"); "author": "Dr. Snuggles",
"year": "1985"
};
o.spy(o, "value", {"ok": true, "id": "rocket.ppt"}, "Put 3");
o.jio.put(o.all3, o.f); o.jio.put(o.all3, o.f);
o.tick(o); o.tick(o);
o.all4 = {"_id": "stick.jpg", o.all4 = {
"title": "clouds", "author": "Dr. House", "year": "2005" "_id": "stick.jpg",
} "title": "clouds",
o.spy (o, "value", {"ok": true, "id": "stick.jpg"}, "Put 4"); "author": "Dr. House",
"year": "2005"
};
o.spy(o, "value", {"ok": true, "id": "stick.jpg"}, "Put 4");
o.jio.put(o.all4, o.f); o.jio.put(o.all4, o.f);
o.tick(o); o.tick(o);
...@@ -852,7 +871,7 @@ ...@@ -852,7 +871,7 @@
{"id": "stick.jpg", "key": "stick.jpg", "value": {} } {"id": "stick.jpg", "key": "stick.jpg", "value": {} }
], ],
"total_rows": 4 "total_rows": 4
} };
o.spy(o, "value", o.thisShouldBeTheAnswer, "allDocs (served by index)"); o.spy(o, "value", o.thisShouldBeTheAnswer, "allDocs (served by index)");
o.jio.allDocs(o.f); o.jio.allDocs(o.f);
o.tick(o); o.tick(o);
...@@ -867,8 +886,8 @@ ...@@ -867,8 +886,8 @@
o.jio = jIO.newJio({ o.jio = jIO.newJio({
"type": "indexed", "type": "indexed",
"indices": [ "indices": [
{"id":"A", "index": ["director"]}, {"id": "A", "index": ["director"]},
{"id":"B", "index": ["title", "year"]} {"id": "B", "index": ["title", "year"]}
], ],
"sub_storage": { "sub_storage": {
"type": "local", "type": "local",
...@@ -890,21 +909,56 @@ ...@@ -890,21 +909,56 @@
}; };
// sample data // sample data
o.titles = ["Shawshank Redemption", "Godfather", "Godfather 2", o.titles = [
"Pulp Fiction", "The Good, The Bad and The Ugly", "12 Angry Men", "Shawshank Redemption",
"The Dark Knight", "Schindlers List", "Godfather",
"Lord of the Rings - Return of the King", "Fight Club", "Godfather 2",
"Star Wars Episode V", "Lord Of the Rings - Fellowship of the Ring", "Pulp Fiction",
"One flew over the Cuckoo's Nest", "Inception", "Godfellas" "The Good, The Bad and The Ugly",
]; "12 Angry Men",
o.years = [1994,1972,1974,1994,1966,1957,2008,1993,2003,1999,1980,2001, "The Dark Knight",
1975,2010,1990]; "Schindlers List",
o.director = ["Frank Darabont", "Francis Ford Coppola", "Lord of the Rings - Return of the King",
"Francis Ford Coppola", "Quentin Tarantino", "Sergio Leone", "Fight Club",
"Sidney Lumet", "Christopher Nolan", "Steven Spielberg", "Star Wars Episode V",
"Peter Jackson", "David Fincher", "Irvin Kershner", "Peter Jackson", "Lord Of the Rings - Fellowship of the Ring",
"Milos Forman", "Christopher Nolan", " Martin Scorsese" "One flew over the Cuckoo's Nest",
]; "Inception", "Godfellas"
];
o.years = [
1994,
1972,
1974,
1994,
1966,
1957,
2008,
1993,
2003,
1999,
1980,
2001,
1975,
2010,
1990
];
o.director = [
"Frank Darabont",
"Francis Ford Coppola",
"Francis Ford Coppola",
"Quentin Tarantino",
"Sergio Leone",
"Sidney Lumet",
"Christopher Nolan",
"Steven Spielberg",
"Peter Jackson",
"David Fincher",
"Irvin Kershner",
"Peter Jackson",
"Milos Forman",
"Christopher Nolan",
" Martin Scorsese"
];
o.fakeIndexA = { o.fakeIndexA = {
"indexing": ["director"], "indexing": ["director"],
...@@ -922,23 +976,26 @@ ...@@ -922,23 +976,26 @@
for (i = 0; i < m; i += 1) { for (i = 0; i < m; i += 1) {
o.jio.put({ o.jio.put({
"_id": "" + i, "_id": i.toString(),
"director": o.director[i], "director": o.director[i],
"year": o.years[i], "year": o.years[i],
"title": o.titles[i] "title": o.titles[i]
}); });
o.tmp = o.fakeIndexA.free.pop() || o.fakeIndexA.database.length; o.tmp = o.fakeIndexA.free.pop() || o.fakeIndexA.database.length;
o.fakeIndexA.database[o.tmp] = {"_id": "" + i, "director": o.director[i]}; o.fakeIndexA.database[o.tmp] = {
o.fakeIndexA.location["" + i] = o.tmp; "_id": i.toString(),
"director": o.director[i]
};
o.fakeIndexA.location[i] = o.tmp;
o.tmp = o.fakeIndexB.free.pop() || o.fakeIndexB.database.length; o.tmp = o.fakeIndexB.free.pop() || o.fakeIndexB.database.length;
o.fakeIndexB.database[o.tmp] = { o.fakeIndexB.database[o.tmp] = {
"_id": "" + i, "_id": i.toString(),
"year": o.years[i], "year": o.years[i],
"title": o.titles[i] "title": o.titles[i]
}; };
o.fakeIndexB.location["" + i] = o.tmp; o.fakeIndexB.location[i] = o.tmp;
o.clock.tick(1000); o.clock.tick(1000);
} }
...@@ -965,11 +1022,11 @@ ...@@ -965,11 +1022,11 @@
o.allDocsResponse.total_rows = m; o.allDocsResponse.total_rows = m;
for (i = 0; i < m; i += 1) { for (i = 0; i < m; i += 1) {
o.allDocsResponse.rows.push({ o.allDocsResponse.rows.push({
"id": ""+i, "id": i.toString(),
"key": ""+i, "key": i.toString(),
"value": {}, "value": {},
"doc": { "doc": {
"_id": ""+i, "_id": i.toString(),
"title": o.titles[i], "title": o.titles[i],
"year": o.years[i], "year": o.years[i],
"director": o.director[i] "director": o.director[i]
...@@ -997,14 +1054,14 @@ ...@@ -997,14 +1054,14 @@
o.response.rows[i].value = { o.response.rows[i].value = {
"year": o.response.rows[i].doc.year, "year": o.response.rows[i].doc.year,
"title": o.response.rows[i].doc.title "title": o.response.rows[i].doc.title
} };
delete o.response.rows[i].doc; delete o.response.rows[i].doc;
i += 1; i += 1;
} }
} }
o.response.rows.sort(function (a, b) { o.response.rows.sort(function (a, b) {
return a.value.year > b.value.year ? -1 : return (a.value.year > b.value.year ? -1 :
a.value.year < b.value.year ? 1 : 0; a.value.year < b.value.year ? 1 : 0);
}); });
o.response.rows.length = 5; o.response.rows.length = 5;
o.response.total_rows = 5; o.response.total_rows = 5;
...@@ -1026,7 +1083,7 @@ ...@@ -1026,7 +1083,7 @@
// "query":'(year: >= "1980" AND year: < "2000")', // "query":'(year: >= "1980" AND year: < "2000")',
"query": '(year: >= "1980")', "query": '(year: >= "1980")',
"limit": [0, 5], "limit": [0, 5],
"sort_on": [['year','descending']], "sort_on": [['year', 'descending']],
"select_list": ['director', 'year'] "select_list": ['director', 'year']
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -1041,14 +1098,14 @@ ...@@ -1041,14 +1098,14 @@
i += 1; i += 1;
} }
o.response.rows.sort(function (a, b) { o.response.rows.sort(function (a, b) {
return a.value.title > b.value.title ? -1 : return (a.value.title > b.value.title ? -1 :
a.value.title < b.value.title ? 1 : 0; a.value.title < b.value.title ? 1 : 0);
}); });
o.spy(o, "value", o.response, o.spy(o, "value", o.response,
"allDocs (empty query in complex query)"); "allDocs (empty query in complex query)");
o.jio.allDocs({ o.jio.allDocs({
"sort_on":[['title','descending']], "sort_on": [['title', 'descending']],
"select_list":['title'] "select_list": ['title']
}, o.f); }, o.f);
o.tick(o); o.tick(o);
......
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