Permalink
Browse files

Added basic tests for views

  • Loading branch information...
1 parent 8e3b2b9 commit 7ebda76b09a31d2c441790b4e2d88069bc42da74 @daleharvey daleharvey committed Apr 12, 2012
Showing with 74 additions and 0 deletions.
  1. +74 −0 tests/test.views.js
View
74 tests/test.views.js
@@ -0,0 +1,74 @@
+module('views', {
+ setup : function () {
+ this.name = 'test_suite_db';
+ }
+});
+
+asyncTest("Create a pouch", function() {
+
+ var values = [];
+
+ // special values sort before all other types
+ values.push(null);
+ values.push(false);
+ values.push(true);
+
+ // then numbers
+ values.push(1);
+ values.push(2);
+ values.push(3.0);
+ values.push(4);
+
+ // then text, case sensitive
+ values.push("a");
+ values.push("A");
+ values.push("aa");
+ values.push("b");
+ values.push("B");
+ values.push("ba");
+ values.push("bb");
+
+ // then arrays. compared element by element until different.
+ // Longer arrays sort after their prefixes
+ values.push(["a"]);
+ values.push(["b"]);
+ values.push(["b","c"]);
+ values.push(["b","c", "a"]);
+ values.push(["b","d"]);
+ values.push(["b","d", "e"]);
+
+ // then object, compares each key value in the list until different.
+ // larger objects sort after their subset objects.
+ values.push({a:1});
+ values.push({a:2});
+ values.push({b:1});
+ values.push({b:2});
+ values.push({b:2, a:1}); // Member order does matter for collation.
+ // CouchDB preserves member order
+ // but doesn't require that clients will.
+ // (this test might fail if used with a js engine
+ // that doesn't preserve order)
+ values.push({b:2, c:2});
+
+ initTestDB(this.name, function(err, db) {
+ var docs = values.map(function(x, i) {
+ return {_id: (i).toString(), foo: x};
+ });
+ db.bulkDocs({docs: docs}, {}, function() {
+ var queryFun = function(doc) { emit(doc.foo, null); };
+ db.query(queryFun, function(_, res) {
+ res.rows.forEach(function(x, i) {
+ ok(x === values[i], 'keys collate');
+ });
+ db.query(queryFun, null, {descending: true}, function(res) {
+ res.rows.forEach(function(x, i) {
+ ok(x === values[values.length - 1 - i], 'keys collate descending')
+ });
+ start();
+ });
+ });
+ });
+ });
+
+});
+

0 comments on commit 7ebda76

Please sign in to comment.