Skip to content

Commit

Permalink
fix(config): bring up test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 19, 2019
1 parent 7a835a4 commit 61e0134
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/NamedMapHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
*/
const NamedMapHandler = (keyname = 'name') => ({
get: (target, prop) => {
if (prop === 'length') {
return Object.keys(target).length;
}
const index = Number.parseInt(prop, 10);
if (!Number.isNaN(index) && index >= 0) {
const [key, value] = Object.entries(target)[index];
const obj = value;
obj[keyname] = key;
return obj;
}
return target[prop];
return prop === 'length' ? Object.keys(target).length : target[prop];
},
});
exports.NamedMapHandler = NamedMapHandler;
5 changes: 1 addition & 4 deletions src/NamedPairHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
const NamedPairHandler = (keyname, valuename) => ({
get: (target, prop) => {
if (prop === 'length') {
return Object.keys(target).length;
}
const index = Number.parseInt(prop, 10);
if (!Number.isNaN(index) && index >= 0) {
const [key, value] = Object.entries(target)[index];
Expand All @@ -22,7 +19,7 @@ const NamedPairHandler = (keyname, valuename) => ({
obj[valuename] = value;
return obj;
}
return target[prop];
return prop === 'length' ? Object.keys(target).length : target[prop];
},
});
exports.NamedPairHandler = NamedPairHandler;
4 changes: 0 additions & 4 deletions src/SchemaDerivedConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ class SchemaDerivedConfig extends BaseConfig {

return this._content;
}

toJSON() {
return this._cfg;
}
}

module.exports = SchemaDerivedConfig;
15 changes: 11 additions & 4 deletions src/schemas/fstab.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
"type": "object",
"title": "FSTab (Mount Points)",
"description": "Defines a mapping between mount points and source URLs. Mount points **must** start with a slash (`/`) but may not end with one.",
"patternProperties": {
"^/.*[^/]$": {
"$ref": "https://ns.adobe.com/helix/shared/mountpoint"
"properties": {
"mountpoints": {
"type": "object",
"patternProperties": {
"^/.*[^/]$": {
"$ref": "https://ns.adobe.com/helix/shared/mountpoint"
}
}
}
}
},
"additionalProperties": false,
"required": ["mountpoints"]
}
6 changes: 6 additions & 0 deletions test/mountpoints.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const MountConfig = require('../src/MountConfig');
const SPEC_ROOT = path.resolve(__dirname, 'specs/mountconfigs');

const tests = [
{
title: 'fails with a broken config',
config: 'broken.yaml',
result: null,
error: 'Error: data should NOT have additional properties, data should have required property \'mountpoints\'',
},
{
title: 'loads a theblog example',
config: 'fstab.yaml',
Expand Down
2 changes: 2 additions & 0 deletions test/specs/mountconfigs/broken.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mounts:
/: https://adobe.sharepoint.com/sites/TheBlog/Shared%20Documents/theblog?csf=1&e=8Znxth

0 comments on commit 61e0134

Please sign in to comment.