Skip to content

Commit

Permalink
pouchdb#6230 Fix tests for pouchdb-server
Browse files Browse the repository at this point in the history
Also, fix flakey test timeout failure
 (unrelated test, selenium:firefox)
  • Loading branch information
dharders committed Nov 10, 2017
1 parent 9f6ab4c commit d318711
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 65 deletions.
58 changes: 32 additions & 26 deletions tests/integration/test.all_docs.js
Expand Up @@ -766,35 +766,41 @@ adapters.forEach(function (adapter) {


it('#6230 Test allDocs opts update_seq: true', function () {
var db = new PouchDB(dbs.name);
return db.bulkDocs(origDocs).then(function () {
return db.allDocs({
update_seq: true
testUtils.isPouchDbServer(function (isPouchDbServer) {
if (isPouchDbServer) {
// pouchdb-server does not currently support opts.update_seq
return;
}
var db = new PouchDB(dbs.name);
return db.bulkDocs(origDocs).then(function () {
return db.allDocs({
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');
});
}).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;

function normalizeSeq(seq) {
try {
if (typeof seq === 'string' && seq.indexOf('-') > 0) {
return parseInt(seq.substring(0, seq.indexOf('-')));
}
return seq;
} catch (err) {
return seq;
}
});
var normSeq = normalizeSeq(result.update_seq);
normSeq.should.equal(4);
}
});

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 allDocs opts with update_seq missing', function () {
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test.attachments.js
Expand Up @@ -3582,7 +3582,7 @@ repl_adapters.forEach(function (adapters) {
var db = new PouchDB(dbs.name);
var remote = new PouchDB(dbs.remote);

for (var i = 0; i < 100; i++) {
for (var i = 0; i < 30; i++) {
doc._attachments[i + '.txt'] = {
data: testUtils.btoa(i.toString()),
content_type: 'text/plain'
Expand All @@ -3597,8 +3597,8 @@ repl_adapters.forEach(function (adapters) {
].map(function (pouch) {
return pouch.get('foo', {attachments: true}).then(function (doc) {
var atts = doc._attachments;
Object.keys(atts).length.should.equal(100);
for (var i = 0; i < 100; i++) {
Object.keys(atts).length.should.equal(30);
for (var i = 0; i < 30; i++) {
var att = atts[i + '.txt'];
should.not.exist(att.stub);
att.data.should.equal(testUtils.btoa(i.toString()));
Expand All @@ -3608,8 +3608,8 @@ repl_adapters.forEach(function (adapters) {
return pouch.get('foo');
}).then(function (doc) {
var atts = doc._attachments;
Object.keys(atts).length.should.equal(100);
for (var i = 0; i < 100; i++) {
Object.keys(atts).length.should.equal(30);
for (var i = 0; i < 30; i++) {
var att = atts[i + '.txt'];
att.stub.should.equal(true);
att.content_type.should.equal('text/plain');
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/utils.js
Expand Up @@ -198,6 +198,12 @@ testUtils.isCouchDB = function (cb) {
});
};

testUtils.isPouchDbServer = function (cb) {
testUtils.ajax({url: testUtils.couchHost() + '/' }, function (err, res) {
cb('express-pouchdb' in res);
});
};

testUtils.writeDocs = function (db, docs, callback, res) {
if (!res) {
res = [];
Expand Down
74 changes: 40 additions & 34 deletions tests/mapreduce/test.mapreduce.js
Expand Up @@ -3764,44 +3764,50 @@ function tests(suiteName, dbName, dbType, viewType) {


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;
}
testUtils.isPouchDbServer(function (isPouchDbServer) {
if (isPouchDbServer) {
// pouchdb-server does not currently support opts.update_seq
return;
}
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');
});
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('-')));

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

it('#6230 Test db.query() opts with update_seq missing', function () {
Expand Down

0 comments on commit d318711

Please sign in to comment.