-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #27
- Loading branch information
Showing
8 changed files
with
3,341 additions
and
55 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
{ | ||
"extends": "../.jshintrc", | ||
"predef": [ "before", "beforeEach", "describe", "it" ] | ||
"predef": [ | ||
"after", | ||
"afterEach", | ||
"before", | ||
"beforeEach", | ||
"describe", | ||
"it" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const memdown = require('memdown'); | ||
const memPouch = require('pouchdb').defaults({ db:memdown }); | ||
const express = require('express'); | ||
const expressPouch = require('express-pouchdb'); | ||
|
||
const PORT = 5988; | ||
|
||
const opts = { | ||
inMemoryConfig: true, | ||
logPath: 'build/test/express-pouchdb.log', | ||
mode: 'fullCouchDB', | ||
}; | ||
const app = express(); | ||
app.use('/', stripAuth, expressPouch(memPouch, opts)); | ||
|
||
let server; | ||
|
||
module.exports = { | ||
couchUrl: `http://admin:pass@localhost:${PORT}/medic`, | ||
db: new memPouch('medic'), | ||
start: () => { | ||
if(server) throw new Error('Server already started.'); | ||
server = app.listen(PORT); | ||
}, | ||
stop: () => { | ||
server.close(); | ||
server = null; | ||
}, | ||
}; | ||
|
||
/** | ||
* Strip basic auth header because right now | ||
* 1. we don't need to test it; and | ||
* 2. I don't know how to configure it in pouchdb-server/pouchdb-express | ||
*/ | ||
function stripAuth(req, res, next) { | ||
delete req.headers.authorization; | ||
next(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"_id": "one" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"_id": "three" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"_id": "two" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const api = require('../api-stub'); | ||
const assert = require('chai').assert; | ||
const ncp = require('ncp'); | ||
const uploadDocs = require('../../src/fn/upload-docs'); | ||
|
||
describe('upload-docs', function() { | ||
beforeEach(api.start); | ||
afterEach(api.stop); | ||
|
||
it('should upload docs to pouch', function(done) { | ||
|
||
// given | ||
const srcDir = `test/data/upload-docs`; | ||
const testDir = `build/test/upload-docs`; | ||
|
||
ncp(srcDir, testDir, err => { | ||
if(err) done(err); | ||
|
||
// and | ||
// TODO there are no docs in the db | ||
|
||
// when | ||
uploadDocs(testDir, api.couchUrl) | ||
|
||
.then(() => { | ||
|
||
api.db.allDocs() | ||
.then(res => { | ||
|
||
// then | ||
assert.deepEqual(res.rows.map(doc => doc.id), [ | ||
'one', 'three', 'two' | ||
]); | ||
|
||
done(); | ||
|
||
}) | ||
.catch(done); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |