Skip to content

Commit

Permalink
Stage docs from medic.json or compiled.json (#58)
Browse files Browse the repository at this point in the history
The name of the "main" cht-core attachment was changed from compiled.json to medic.json in 3.9.0. 
Ddocs are now staged from either one of these attachments.

#57
  • Loading branch information
dianabarsan authored Jul 13, 2020
1 parent e9bb942 commit 9a3031a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "horticulturalist",
"version": "0.13.0",
"version": "0.13.1",
"description": "A fancy gardener",
"repository": "https://github.com/medic/horticulturalist",
"license": "Apache-2.0",
Expand Down
9 changes: 6 additions & 3 deletions src/install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ const downloadBuild = deployDoc => {
};

const extractDdocs = ddoc => {
if (!ddoc._attachments || !ddoc._attachments['ddocs/compiled.json']) {
const compiledDdocs = ddoc._attachments &&
(ddoc._attachments['ddocs/compiled.json'] ||
ddoc._attachments['ddocs/medic.json']);

if (!compiledDdocs) {
debug('No extra ddocs to extract');
return;
}

const compiledDocs =
JSON.parse(ddoc._attachments['ddocs/compiled.json'].data).docs;
const compiledDocs = JSON.parse(compiledDdocs.data).docs;

compiledDocs.forEach(utils.stageDdoc);

Expand Down
4 changes: 2 additions & 2 deletions tests/int/tests/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Bootstrapping', () => {
.then(() => hortiUtils.start([
'--install=test:test-app-1:1.0.0',
'--no-daemon',
'--test'], { waitUntil: true }))
'--test'], { waitUntil: true, log: true }))
.then(() => dbUtils.appDb().get('_design/test-app-1'))
.then(ddoc => {
assert.equal(ddoc.deploy_info.user, 'horticulturalist cli');
Expand All @@ -29,7 +29,7 @@ describe('Bootstrapping', () => {
.then(() => hortiUtils.start([
'--install=@test:test-app-1:release',
'--no-daemon',
'--test'], { waitUntil: true }))
'--test'], { waitUntil: true, log: true }))
.then(() => dbUtils.appDb().get('_design/test-app-1'))
.then(ddoc => {
assert.equal(ddoc.deploy_info.user, 'horticulturalist cli');
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ describe('Installation flow', () => {
});
});
});

it('should work read ddocs from medic.json attachment', () => {
const newStagedMainDdoc = {
_id: '_design/:staged:medic',
_attachments: {
'ddocs/medic.json': {
data: Buffer.from(JSON.stringify(compiled))
}
}
};

DB.app.bulkDocs.resolves([]);

return install._extractDdocs(newStagedMainDdoc).then(() => {
DB.app.bulkDocs.callCount.should.equal(1);
DB.app.bulkDocs.args[0][0].should.deep.equal([{
_id: '_design/:staged:medic-test'
}, newStagedMainDdoc]);
});
});
});

describe('Warming views', () => {
Expand Down

0 comments on commit 9a3031a

Please sign in to comment.