Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pouchdb-update #246

Merged
merged 23 commits into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0e7c999
Converted all the JS to node modules. (Re)added geopouch.
marten-de-vries Apr 28, 2014
858ffb0
Quite some stuff.
marten-de-vries May 7, 2014
ebd9c46
Updated node modules (PouchDB 2.2!). Made licensing (Apache v2.0) a b…
marten-de-vries May 7, 2014
e563fe2
Fixed test regression on Ubuntu 12.04; switched to bluebird on node (…
marten-de-vries May 8, 2014
dd29635
All JS are now Node modules of their own, that could even be publishe…
marten-de-vries May 8, 2014
d4caece
All dev tools are now accessable via setup.py. Reduced code size of t…
marten-de-vries May 20, 2014
a224938
JS coverage is back at 100%. Added viewCleanup() wrapper function. Re…
marten-de-vries May 28, 2014
29dd477
Update plug-in now included as public method. More consistent errors.…
marten-de-vries May 28, 2014
6355916
Python-PouchDB 0.4 - added a single mapping test & added some info on…
marten-de-vries May 30, 2014
9cd5fa3
Adds NodeJS tests. Some small fixes.
marten-de-vries May 31, 2014
fb5c4db
A start for a pouchdb-rewrite plug-in. Some small other changes along…
marten-de-vries Jun 2, 2014
667fb7e
Ported part of the rewrite test suite over from CouchDB, which found …
marten-de-vries Jun 3, 2014
80285d9
Python-PouchDB 0.4.1 - plug-in documentation + JS coverage back at 100%
marten-de-vries Jun 4, 2014
50b2d00
Gave node modules version numbers and published them on npm, small fi…
marten-de-vries Jun 5, 2014
0efe492
Some minor JS stuff mostly.
marten-de-vries Jun 6, 2014
98f484a
Improved docs + JS
marten-de-vries Jul 6, 2014
3d2fb91
New: PouchDB Seamless Auth; PouchDB Security. Lots of fixes. PouchDB …
marten-de-vries Aug 12, 2014
ce57b9d
Show/list/update fixes against couchdb-harness
marten-de-vries Jan 13, 2015
a4993bd
(pouchdb/express-pouchdb#232) - Modernize pouchdb-update
marten-de-vries Dec 21, 2015
9c7e499
pouchdb-update: post rebase fixes
gr2m Jul 3, 2017
d2deafa
pouchdb-update: adapt package.json
gr2m Jul 3, 2017
29ab32e
pouchdb-update: move dependencies into mono repo
gr2m Jul 3, 2017
ee02cea
pouchdb-update: adapt tests
gr2m Jul 3, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"cookie-parser": "^1.4.3",
"corser": "~2.0.0",
"couchdb-calculate-session-id": "^1.1.0",
"couchdb-eval": "^1.0.0",
"couchdb-harness": "*",
"couchdb-log-parse": "^0.0.4",
"couchdb-objects": "^1.0.0",
Expand Down Expand Up @@ -58,6 +59,7 @@
"pouchdb-promise": "^6.1.2",
"pouchdb-replication": "^6.1.0",
"pouchdb-req-http-query": "^1.0.3",
"couchdb-resp-completer": "^1.0.0",
"pouchdb-rewrite": "^1.0.7",
"pouchdb-show": "^1.0.8",
"pouchdb-size": "^1.2.2",
Expand Down
9 changes: 9 additions & 0 deletions packages/node_modules/pouchdb-update/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions packages/node_modules/pouchdb-update/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/node_modules/pouchdb-update/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions tests/pouchdb-update/features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const {setup, setupWithDoc, teardown, updateDocument, should, shouldThrowError} = require('./utils');

describe('Sync update tests', () => {
let db;

beforeEach(() => {
return setupWithDoc()

.then((result) => {
db = result.db;
return db.put(updateDocument);
});
});
afterEach(teardown);

it('args', () => {
return db.update('test/args/mytest', {query: {'a': 3}})

.then((response) => {
const [doc, req] = JSON.parse(response.body);
doc.test.should.be.ok;
req.id.should.equal('mytest');
req.raw_path.should.equal('/test/_design/test/_update/args/mytest?a=3');
});
});

it('args without doc', () => {
return db.update('test/args', {withValidation: true})

.then((response) => {
const [doc, req] = JSON.parse(response.body);
should.equal(doc, null);
req.should.not.have.property('withValidation');
});
});

it('missing function', () => {
shouldThrowError(() => {
return db.update('test/missing/mytest');
})

.then((error) => {
error.toString().should.be.ok;
error.name.should.equal('not_found');
error.message.should.equal('missing update function missing on design doc _design/test');
});
});

it('saving', () => {
db.update('test/save-adding-date', {body: JSON.stringify({
_id: 'test',
name: 'Today'
})})

.then((response) => {
response.body.should.equal('Hello World!');

return db.get('test');
})

.then((doc) => {
doc.updated.should.be.ok;
doc.name.should.equal('Today');
});
});
});

describe('Async update tests', () => {
let db;

beforeEach(() => {
db = setup();
return db.put(updateDocument);
});
afterEach(teardown);

it('exception', () => {
return db.update('test/exception')

.then(() => {
'db.update("test/exception") should not resolve'.should.equal('');
})

.catch((error) => {
error.status.should.equal(500);
error.name.should.equal('ReferenceError');
error.message.should.contain('abc');
});
});
});

describe('Async update with empty design doc', () => {
let db;

beforeEach(() => {
db = setup();
return db.put({_id: '_design/test'});
});
afterEach(teardown);

it('basic', () => {
return db.update('test/missing')

.then(() => {
'db.update("test/missing") should not resolve'.should.equal('');
})

.catch((error) => {
error.status.should.equal(404);
error.name.should.equal('not_found');
error.message.should.equal('missing update function missing on design doc _design/test');
});
});
});
21 changes: 21 additions & 0 deletions tests/pouchdb-update/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const {setupHTTP, teardown, updateDocument, should} = require('./utils');

let db;

describe('http tests', () => {
beforeEach(() => {
db = setupHTTP();
return db.put(updateDocument);
});
afterEach(teardown);

it('update', () => {
return db.update('test/args/my-id')

.then((result) => {
const [doc, req] = JSON.parse(result.body);
should.not.exist(doc);
req.id.should.equal('my-id');
});
});
});
15 changes: 15 additions & 0 deletions tests/pouchdb-update/signatures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {setup, teardown} = require('./utils');

describe('signature tests', () => {
let db;
beforeEach(() => {
db = setup();
});
afterEach(teardown);

it('update', () => {
const promise = db.update('test/test/test', () => {});
promise.then.should.be.ok;
promise.catch.should.be.ok;
});
});
23 changes: 23 additions & 0 deletions tests/pouchdb-update/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const stuff = require('pouchdb-plugin-helper/testutils');
const Update = require('../../packages/node_modules/pouchdb-update');

stuff.PouchDB.plugin(Update);

stuff.updateDocument = {
_id: "_design/test",
updates: {
args: `function (doc, req) {
return [null, toJSON([doc, req])];
}`,
exception: `function (doc, req) {
return abc;
}`,
'save-adding-date': `function (oldDoc, req) {
var doc = JSON.parse(req.body);
doc.updated = new Date();
return [doc, "Hello World!"];
}`
}
};

module.exports = stuff;