Skip to content

Commit

Permalink
nudge: more bulkDocs tests and add allDocs overloads to fulfil the bu…
Browse files Browse the repository at this point in the history
…lkDocs tests
  • Loading branch information
AGBrown committed May 2, 2015
1 parent 86bff17 commit aba66fd
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 90 deletions.
129 changes: 95 additions & 34 deletions pouchdb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,41 @@ declare module pouchdb {
_deleted?: boolean;
}

/** Options for `changes()` and `allDocs()` output */
interface BasePaginationOptions {
/**
* Include the associated document in each row in the `doc` field
* @see conflicts
* @see attachments
* @default `false`
*/
include_docs?: boolean;
/**
* Include conflict information in the `_conflicts` field (see {@linkcode #include_docs})
* @see include_docs
* @see attachments
* @default `false`
*/
conflicts?: boolean;
/**
* Include attachment data as base64-encoded string. (see {@linkcode #include_docs})
* @see include_docs
* @see conflicts
* @default `false`
*/
attachments?: boolean;
/**
* Reverse the order of the output documents
* @default `false`
*/
descending?: boolean;
/**
* Maximum number of documents to return.
* @default undefined
*/
limit?: number;
}

//////////////////////////// Methods ///////////////////////////////
// Please keep these modules in alphabetical order

Expand All @@ -212,7 +247,10 @@ declare module pouchdb {
/** The document key */
key: string;
/** @todo not sure what this is */
value: { rev: string; }
value: {
rev: string;
deleted?: boolean;
}
}
/** Response object for `allDocs()` */
interface Response {
Expand All @@ -225,15 +263,68 @@ declare module pouchdb {
*/
rows: DocContainer<StoredDoc>[];
}

/** Options for `allDocs()` output */
interface RangeOptions extends BasePaginationOptions {
/**
* Get documents with IDs in a certain range from this to {@linkcode #endkey}
* (inclusive/see {@linkcode #inclusive_end}).
*/
startkey?: string;
/**
* Get documents with IDs in a certain range from {@linkcode #startkey} to this
* (inclusive/see {@linkcode #inclusive_end}).
*/
endkey?: string;
/**
* Include documents having an ID equal to the given {@linkcode #endkey}
* @default false
*/
inclusive_end?: boolean;

/**
* Number of docs to skip before returning (warning: poor performance on IndexedDB/LevelDB!).
*/
skip?: number
}

/** Options for `allDocs()` output */
interface PaginationOptions extends BasePaginationOptions {
/**
* Number of docs to skip before returning (warning: poor performance on IndexedDB/LevelDB!).
*/
skip?: number
}

/** Options for `allDocs()` output */
interface FilterOptions extends BasePaginationOptions {
/** Only return documents with IDs matching this string key. */
key?: string;
/** Array of string keys to fetch in a single shot. */
keys?: string;
}

/** Callback pattern for allDocs() */
interface Callback {
/** Fetch multiple documents, indexed and sorted by the `_id`. */
allDocs(callback: async.Callback<Response>): void;
allDocs(callback?: async.Callback<Response>): void;
/** Fetch multiple documents, indexed and sorted by the `_id`. */
allDocs(options: RangeOptions, callback?: async.Callback<Response>): void;
/** Fetch multiple documents, indexed and sorted by the `_id`. */
allDocs(options: PaginationOptions, callback?: async.Callback<Response>): void;
/** Fetch multiple documents, indexed and sorted by the `_id`. */
allDocs(options: FilterOptions, callback?: async.Callback<Response>): void;
}
/** Promise pattern for allDocs() */
interface Promise {
/** Fetch multiple documents, indexed and sorted by the `_id`. */
allDocs(): async.Thenable<Response>;
/** Fetch multiple documents, indexed and sorted by the `_id`. */
allDocs(options: RangeOptions): async.Thenable<Response>;
/** Fetch multiple documents, indexed and sorted by the `_id`. */
allDocs(options: PaginationOptions): async.Thenable<Response>;
/** Fetch multiple documents, indexed and sorted by the `_id`. */
allDocs(options: FilterOptions): async.Thenable<Response>;
}
}

Expand Down Expand Up @@ -402,50 +493,20 @@ declare module pouchdb {

/** Contains the method and call/return types for changes() */
module changes {

/** Options for `changes()` output */
interface BaseOptions {
interface BaseOptions extends BasePaginationOptions {
/**
* Does "live" changes, using CouchDB’s `_longpoll_` feed if remote.
* @default `false`
*/
live?: boolean;
/**
* Include the associated document with each change
* @see conflicts
* @see attachments
* @default `false`
*/
include_docs?: boolean;
/**
* Include conflicts (see {@linkcode #include_docs})
* @see include_docs
* @see attachments
* @default `false`
*/
conflicts?: boolean;
/**
* Include attachments (see {@linkcode #include_docs})
* @see include_docs
* @see conflicts
* @default `false`
*/
attachments?: boolean;
/**
* Reverse the order of output documents
* @default `false`
*/
descending?: boolean;
/**
* Start the results from the change immediately after the given sequence number.
* You can also pass `'now'` if you want only new changes (when `live` is `true`).
* @default undefined
*/
since?: any; // string | number
/**
* Limit the number of results to this number.
* @default undefined
*/
limit?: number;
/**
* Request timeout (in milliseconds).
* @default undefined
Expand Down
113 changes: 57 additions & 56 deletions tests/integration/test.bulk_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,67 +514,68 @@ adapters.forEach(function (adapter) {
});
});

//it('Testing successive new_edits to two doc', function () {
it('Testing successive new_edits to two doc', () => {

// var db = new PouchDB(dbs.name);
// var doc1 = {
// '_id': 'foo',
// '_rev': '1-x',
// '_revisions': {
// 'start': 1,
// 'ids': ['x']
// }
// };
// var doc2 = {
// '_id': 'bar',
// '_rev': '1-x',
// '_revisions': {
// 'start': 1,
// 'ids': ['x']
// }
// };
var db = new PouchDB(dbs.name);
var doc1 = {
'_id': 'foo',
'_rev': '1-x',
'_revisions': {
'start': 1,
'ids': ['x']
}
};
var doc2 = {
'_id': 'bar',
'_rev': '1-x',
'_revisions': {
'start': 1,
'ids': ['x']
}
};

// return db.put(doc1, { new_edits: false }).then(function () {
// return db.put(doc2, { new_edits: false });
// }).then(function () {
// return db.put(doc1, { new_edits: false });
// }).then(function () {
// return db.get('foo');
// }).then(function () {
// return db.get('bar');
// });
//});
return db.put(doc1, { new_edits: false }).then(() => {
return db.put(doc2, { new_edits: false });
}).then(() => {
return db.put(doc1, { new_edits: false });
}).then(() => {
return db.get('foo');
}).then(() => {
return db.get('bar');
});
});

//it('Deletion with new_edits=false', function () {
// todo: not sure how to handle allDocs with just keys specified
it('Deletion with new_edits=false', () => {

// var db = new PouchDB(dbs.name);
// var doc1 = {
// '_id': 'foo',
// '_rev': '1-x',
// '_revisions': {
// 'start': 1,
// 'ids': ['x']
// }
// };
// var doc2 = {
// '_deleted': true,
// '_id': 'foo',
// '_rev': '2-y',
// '_revisions': {
// 'start': 2,
// 'ids': ['y', 'x']
// }
// };
var db = new PouchDB(dbs.name);
var doc1 = {
'_id': 'foo',
'_rev': '1-x',
'_revisions': {
'start': 1,
'ids': ['x']
}
};
var doc2 = {
'_deleted': true,
'_id': 'foo',
'_rev': '2-y',
'_revisions': {
'start': 2,
'ids': ['y', 'x']
}
};

// return db.put(doc1, { new_edits: false }).then(function () {
// return db.put(doc2, { new_edits: false });
// }).then(function () {
// return db.allDocs({ keys: ['foo'] });
// }).then(function (res) {
// res.rows[0].value.rev.should.equal('2-y');
// res.rows[0].value.deleted.should.equal(true);
// });
//});
return db.put(doc1, { new_edits: false }).then(() => {
return db.put(doc2, { new_edits: false });
}).then(() => {
return db.allDocs({ keys: ['foo'] });
}).then((res) => {
expect(res.rows[0].value.rev).to.equal('2-y');
expect(res.rows[0].value.deleted).to.equal(true);
});
});

//it('Deletion with new_edits=false, no history', function () {

Expand Down

0 comments on commit aba66fd

Please sign in to comment.