Commit e3d3b88f authored by Tristan Cavelier's avatar Tristan Cavelier

complex queries tests added

parent 17dfeaa4
......@@ -272,135 +272,6 @@ isUuid = function (uuid) {
false: true;
};
//// QUnit Tests ////
module('Complex Queries');
test('Empty Query', function () {
var doc_list = [
{"identifier": "a"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create('').exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": ["b", "c"]}
], 'Nothing done on the list');
});
test('Simple Query', function () {
var doc_list = [
{"identifier": "a"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create('identifier: "a"').exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a"},
], 'Document with several identifier should be removed');
doc_list = [
{"identifier": "a"},
{"identifier": ["a", "b"]}
];
complex_queries.QueryFactory.create('identifier: "a"').exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": ["a", "b"]}
], 'Document with several identifier should be kept');
});
test('Complex Query', function () {
var doc_list = [
{"identifier": "a"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create(
'identifier: "b" AND identifier: "c"'
).exec(doc_list);
deepEqual(doc_list, [
{"identifier": ["b", "c"]}
], 'Document with only one identifier should be removed');
doc_list = [
{"identifier": "a"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create(
'identifier: "a" OR identifier: "c"'
).exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": ["b", "c"]}
], 'All document matches');
doc_list = [
{"identifier": "a", "title": "o"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create(
'(identifier: "a" OR identifier: "b") AND title: "o"'
).exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a", "title": "o"}
], 'Only first document should be kept');
});
test('Wildcard Character', function () {
var doc_list = [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
];
complex_queries.QueryFactory.create('identifier: "a%"').exec(doc_list, {
// "wildcard_character": "%" // default
});
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
], 'All documents should be kept');
doc_list = [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
];
complex_queries.QueryFactory.create('identifier: "a%"').exec(doc_list, {
"wildcard_character": null
});
deepEqual(doc_list, [
{"identifier": "a%"}
], 'Document "a%" should be kept');
doc_list = [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
];
complex_queries.QueryFactory.create('identifier: "b"').exec(doc_list, {
"wildcard_character": "b"
});
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
], 'All documents should be kept');
});
test("Additional Filters", function () {
var doc_list = [
{"identifier": "b", "title": "e"},
{"identifier": "a", "title": "f"},
{"identifier": "b", "title": "d"}
];
complex_queries.QueryFactory.create('').exec(doc_list, {
"select_list": ["title"],
"limit": [2, 1],
"sort_on": [["identifier", "ascending"], ["title", "descending"]]
});
deepEqual(doc_list, [
{"title": "d"}
], 'The first document should be kept');
});
module ( "Jio Dummy Storages" );
test ("All requests ok", function () {
......
......@@ -11,11 +11,13 @@
<script src="../lib/sinon/sinon.js"></script>
<script src="../lib/sinon/sinon-qunit.js"></script>
<script src="../complex_queries.js"></script>
<script src="./queries/tests.js"></script>
<script src="../lib/md5/md5.js"></script>
<script src="../jio.js"></script>
<script src="./jio/tests.js"></script>
<script src="../complex_queries.js"></script>
<script src="../src/jio.storage/localstorage.js"></script>
<script src="./jio.storage/localstorage.tests.js"></script>
</body>
......
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, complex_queries, window, test, ok, deepEqual, sinon */
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
module(complex_queries);
}(['complex_queries'], function (complex_queries) {
"use strict";
module('Complex Queries');
// XXX test documentation
test('Empty Query', function () {
var doc_list = [
{"identifier": "a"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create('').exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": ["b", "c"]}
], 'Nothing done on the list');
});
test('Simple Query', function () {
var doc_list = [
{"identifier": "a"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create('identifier: "a"').exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a"},
], 'Document with several identifier should be removed');
doc_list = [
{"identifier": "a"},
{"identifier": ["a", "b"]}
];
complex_queries.QueryFactory.create('identifier: "a"').exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": ["a", "b"]}
], 'Document with several identifier should be kept');
});
test('Complex Query', function () {
var doc_list = [
{"identifier": "a"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create(
'identifier: "b" AND identifier: "c"'
).exec(doc_list);
deepEqual(doc_list, [
{"identifier": ["b", "c"]}
], 'Document with only one identifier should be removed');
doc_list = [
{"identifier": "a"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create(
'identifier: "a" OR identifier: "c"'
).exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": ["b", "c"]}
], 'All document matches');
doc_list = [
{"identifier": "a", "title": "o"},
{"identifier": ["b", "c"]}
];
complex_queries.QueryFactory.create(
'(identifier: "a" OR identifier: "b") AND title: "o"'
).exec(doc_list);
deepEqual(doc_list, [
{"identifier": "a", "title": "o"}
], 'Only first document should be kept');
});
test('Wildcard Character', function () {
var doc_list = [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
];
complex_queries.QueryFactory.create('identifier: "a%"').exec(doc_list, {
// "wildcard_character": "%" // default
});
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
], 'All documents should be kept');
doc_list = [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
];
complex_queries.QueryFactory.create('identifier: "a%"').exec(doc_list, {
"wildcard_character": null
});
deepEqual(doc_list, [
{"identifier": "a%"}
], 'Document "a%" should be kept');
doc_list = [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
];
complex_queries.QueryFactory.create('identifier: "b"').exec(doc_list, {
"wildcard_character": "b"
});
deepEqual(doc_list, [
{"identifier": "a"},
{"identifier": "a%"},
{"identifier": ["ab", "b"]}
], 'All documents should be kept');
});
test("Additional Filters", function () {
var doc_list = [
{"identifier": "b", "title": "e"},
{"identifier": "a", "title": "f"},
{"identifier": "b", "title": "d"}
];
complex_queries.QueryFactory.create('').exec(doc_list, {
"select_list": ["title"],
"limit": [2, 1],
"sort_on": [["identifier", "ascending"], ["title", "descending"]]
});
deepEqual(doc_list, [
{"title": "d"}
], 'The first document should be kept');
});
}));
......@@ -8,6 +8,7 @@
"paths": {
"md5": "../lib/md5/md5",
"complex_queries": "../complex_queries",
"complex_queries_tests": "queries/tests",
"jio": "../jio",
"jio_tests": "jio/tests",
"localstorage": "../src/jio.storage/localstorage",
......@@ -19,7 +20,6 @@
},
"shim": {
"md5": {"exports": "hex_md5"},
"localstorage": ["jio", "complex_queries"],
"sinon": ["qunit"],
"sinon_qunit": ["sinon"]
......@@ -28,6 +28,7 @@
require([
"sinon_qunit",
"complex_queries_tests",
"jio_tests",
"localstorage_tests"
]);
......
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