Skip to content

Commit

Permalink
Merge pull request #181 from benTrust/feat-deep-nested-tree-structure…
Browse files Browse the repository at this point in the history
…-tests

Test on deep nested tree structure
  • Loading branch information
madarche committed Feb 26, 2017
2 parents 1b63e88 + c93d9d7 commit 45511a5
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ var config = convict({
});
```

Deep nested example:

```javascript
conf = convict({
db: {
name: {
format: String,
default: ''
},
synchro: {
active: {
format: 'Boolean',
default: false
},
remote_url: {
format: 'url',
default: 'http://localhost:8080/'
}
}

}
});
```

Note: Search for the word "nested" throughout this documentation to find out
more about nested configuration settings.

Expand Down
108 changes: 108 additions & 0 deletions test/deep_nested_tree_structure_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
'use strict'

describe('deep nested tree structure', function() {
const convict = require('../');
let conf;

it('must parse a deep nested config specification', function() {
conf = convict({
db: {
name: {
format: String,
default: ''
},
synchro: {
active: {
format: 'Boolean',
default: false
},
remote_url: {
format: 'url',
default: 'http://localhost:8080/'
}
}
}
});
});

it('instance must be valid', function() {
conf.load({
db: {
name: 'some_db',
synchro: {
active: true,
remote_url: 'http://localhost:3333/'
}
}
});
(function() {
conf.validate({
strict: true
});
}).must.not.throw();
});

describe('get nested fields value', function() {
it('must find a value', function() {
(function() {
conf.get('db');
}).must.not.throw();
});

it('must handle two levels of nesting', function() {
conf.get('db.name').must.be('some_db');
});

it('must handle three levels of nesting', function() {
conf.get('db.synchro.active').must.be(true);
});

it('must handle three levels of side by side nesting', function() {
conf.get('db.synchro.remote_url').must.be('http://localhost:3333/');
});
});

describe('alter nested fields value', function() {
let synchro;

it('must find a nested value', function() {
(function() {
synchro = conf.get('db.synchro');
}).must.not.throw();
});

it('modify a nested value and must be valid', function() {
synchro.active = false;
conf.set('db.synchro', synchro);
(function() {
conf.validate({
strict: true
});
}).must.not.throw();
conf.get('db.synchro.active').must.be(false);
});

});

describe('alter deep nested fields value', function() {
let db;

it('must find a deep nested value', function() {
(function() {
db = conf.get('db');
}).must.not.throw();
});

it('modify a deep nested value and must be valid', function() {
db.synchro.remote_url = 'http://local.test:9876';
conf.set('db', db);
(function() {
conf.validate({
strict: true
});
}).must.not.throw();
conf.get('db.synchro.remote_url').must.be('http://local.test:9876');
});

});
})

0 comments on commit 45511a5

Please sign in to comment.