Commit a97df9e9 authored by Tristan Cavelier's avatar Tristan Cavelier

gidstorage.js get, alldocs method done + tests

parent 7f5f4e44
......@@ -350,14 +350,15 @@
"status": 409,
"statusText": "Conflict",
"error": "conflict",
"message": "Cannot post document",
"message": "Cannot get document",
"reason": "metadata should respect constraints"
});
}
complex_query = gidToComplexQuery(gid_object);
that.addJob('allDocs', priv.sub_storage, {}, {
"query": complex_query,
"wildcard_character": null
"wildcard_character": null,
"include_docs": true
}, function (response) {
if (response.total_rows === 0) {
return that.error({
......@@ -368,10 +369,44 @@
"reason": "missing"
});
}
// XXX
return that.success(response.rows[0].doc);
}, function (err) {
err.message = "Cannot post document";
that.error(err);
err.message = "Cannot get document";
return that.error(err);
});
});
};
that.allDocs = function (command) {
setTimeout(function () {
var options = command.cloneOption(), include_docs;
include_docs = options.include_docs;
options.include_docs = true;
that.addJob('allDocs', priv.sub_storage, {
}, options, function (response) {
var result = [], doc_gids = {}, i, row, gid;
console.log(JSON.parse(JSON.stringify(response)));
while ((row = response.rows.shift()) !== undefined) {
if ((gid = gidFormat(row.doc, priv.constraints)) !== undefined) {
if (!doc_gids[gid]) {
doc_gids[gid] = true;
row.id = gid;
delete row.key;
result[result.length] = row;
if (include_docs === true) {
row.doc._id = gid;
} else {
delete row.doc;
}
}
}
}
doc_gids = undefined; // free memory
row = undefined;
that.success({"total_rows": result.length, "rows": result});
}, function (err) {
err.message = "Cannot get all documents";
return that.error(err);
});
});
};
......
......@@ -8038,17 +8038,87 @@ test("Get", function () {
});
o.local_jio.put({"_id": "blue", "identifier": "a"});
o.local_jio.put({"_id": "green", "identifier": ["ac", "b"]});
o.local_jio.put({"_id": "red", "identifier": ["ac", "b"]});
o.clock.tick(2000);
o.local_jio.stop();
o.spy(o, 'status', 404, 'Get inexistent document');
o.jio.get({"_id": "{\"identifier\":[\"c\"]}"}, o.f);
o.tick(o);
o.spy(o, 'value', {"_id": "red", "identifier": ["ac", "b"]}, 'Get document');
o.jio.get({"_id": "{\"identifier\":[\"b\"]}"}, o.f);
o.tick(o);
o.spy(o, 'value', {"_id": "blue", "identifier": "a"}, 'Get document');
o.jio.get({"_id": "{\"identifier\":[\"a\"]}"}, o.f);
o.jio.stop();
});
test("AllDocs", function () {
var o = generateTools(this);
o.localstorage_spec = {
"type": "local",
"username": "one",
"application_name": "gid storage allDocs test"
};
o.local_jio = JIO.newJio(o.localstorage_spec);
o.jio = JIO.newJio({
"type": "gid",
"sub_storage": o.localstorage_spec,
"constraints": {
"default": {
"identifier": "list"
}
}
});
o.local_jio.put({"_id": "green", "identifier": ["a"]})
o.local_jio.put({"_id": "red", "identifier": ["a", "b"]})
o.local_jio.put({"_id": "yellow", "identifier": ["c", "d"]})
o.local_jio.put({"_id": "purple", "identifier": ["p", "d"]})
o.clock.tick(3000);
console.log(JSON.parse(JSON.stringify(localStorage)));
o.local_jio.stop();
o.spy(o, 'value', {
"rows": [{
"id": "{\"identifier\":[\"a\"]}",
"value": {}
}, {
"id": "{\"identifier\":[\"a\",\"b\"]}",
"value": {}
}, {
"id": "{\"identifier\":[\"c\",\"d\"]}",
"value": {}
}, {
"id": "{\"identifier\":[\"p\",\"d\"]}",
"value": {}
}],
"total_rows": 4
}, 'Get all docs');
o.jio.allDocs({
"sort_on": [["identifier", "ascending"]]
}, o.f);
o.tick(o);
o.spy(o, 'value', {
"rows": [{
"id": "{\"identifier\":[\"a\",\"b\"]}",
"value": {}
}],
"total_rows": 1
}, 'Get all docs');
o.jio.allDocs({
"query": 'identifier: "a"',
"select": ["identifier"],
"limit": [1, 1],
"sort_on": [["identifier", "ascending"]]
}, o.f);
o.tick(o);
o.jio.stop();
......
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