Skip to content

Commit

Permalink
pouchdb#6230 Add map/reduce tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dharders committed Nov 21, 2017
1 parent 0fef29a commit 40cbf3a
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/mapreduce/test.mapreduce.js
Expand Up @@ -3830,5 +3830,89 @@ function tests(suiteName, dbName, dbType, viewType) {
});
});
});

it('#6230 Test db.query() opts update_seq: false', function () {
var db = new PouchDB(dbName);
var docs = [];
for (var i = 0; i < 4; i++) {
docs.push({
_id: i.toString(),
name: 'foo',
});
}
return createView(db, {
map: "function(doc){emit(doc.name);};\n"
}).then(function (queryFun) {
return db.bulkDocs({ docs: docs }).then(function () {
return db.query(queryFun, { update_seq: false });
}).then(function (result) {
result.rows.should.have.length(4);
should.not.exist(result.update_seq);
});
});
});


it('#6230 Test db.query() opts update_seq: true', function () {
var db = new PouchDB(dbName);
var docs = [];
for (var i = 0; i < 4; i++) {
docs.push({
_id: i.toString(),
name: 'foo',
});
}
return createView(db, {
map: "function(doc){emit(doc.name);};\n"
}).then(function (queryFun) {
return db.bulkDocs({ docs: docs }).then(function () {
return db.query(queryFun, { update_seq: true });
}).then(function (result) {
result.rows.should.have.length(4);
should.exist(result.update_seq);
result.update_seq.should.satisfy(function (update_seq) {
if (typeof update_seq === 'number' || typeof update_seq === 'string') {
return true;
} else {
return false;
}
});
var normSeq = normalizeSeq(result.update_seq);
normSeq.should.be.a('number');
});
});

function normalizeSeq(seq) {
try {
if (typeof seq === 'string' && seq.indexOf('-') > 0) {
return parseInt(seq.substring(0, seq.indexOf('-')));
}
return seq;
} catch (err) {
return seq;
}
}
});

it('#6230 Test db.query() opts with update_seq missing', function () {
var db = new PouchDB(dbName);
var docs = [];
for (var i = 0; i < 4; i++) {
docs.push({
_id: i.toString(),
name: 'foo',
});
}
return createView(db, {
map: "function(doc){emit(doc.name);};\n"
}).then(function (queryFun) {
return db.bulkDocs({ docs: docs }).then(function () {
return db.query(queryFun);
}).then(function (result) {
result.rows.should.have.length(4);
should.not.exist(result.update_seq);
});
});
});
});
}

0 comments on commit 40cbf3a

Please sign in to comment.