Skip to content

Commit

Permalink
(#341) - Fix crash on admin setup at db initialization
Browse files Browse the repository at this point in the history
* test(express-pouchdb): replicates 
* fix(express-pouchdb): wait for the database when refreshing users

Fixes #341.
  • Loading branch information
QuentinRoy authored and marten-de-vries committed Aug 11, 2018
1 parent f126857 commit 3c6b805
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.

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

43 changes: 43 additions & 0 deletions tests/express-pouchdb/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,49 @@ describe('config', function () {
});
});
});
it('should support setting admins', function (done) {
var cleanUpTest = function () {
return fse.removeAsync(TEST_DATA + 'one-shot');
};
fse.mkdirsAsync(TEST_DATA + 'one-shot').then(function () {
// Creates a single usage app.
var oneShotExpressApp = buildApp(PouchDB.defaults({
prefix: TEST_DATA + 'one-shot/',
}), {
configPath: TEST_DATA + 'one-shot/config.json',
logPath: TEST_DATA + 'one-shot/log.txt'
});
// Set up an admin.
return new Promise(function (resolve, reject) {
oneShotExpressApp.couchConfig.set('admins', 'admin', 'pass', function (err) {
if (err) { reject(err); }
resolve();
});
});
}).then(function () {
// Read the config file.
return fse.readFile(TEST_DATA + 'one-shot/config.json');
}).then(function (data) {
var config = JSON.parse(data.toString());
if (!config.admins['admin']) {
// Make sure the admin has been created.
throw new Error("Admin does not exist");
} else if (config.admins['admin'] === 'pass') {
// Also make sure the password has been hashed.
throw new Error("Admin's password is not hashed");
}
}).then(
// Whatever happened, clean up.
function () {
return cleanUpTest().then(done);
},
function (err) {
return cleanUpTest().then(function () {
throw err;
});
}
);
});
it('should support setting a different config path', function (done) {
// make sure the file is written to disk.
expressApp2.couchConfig.set('demo', 'demo', true, function () {
Expand Down

0 comments on commit 3c6b805

Please sign in to comment.