The purpose of this coding exercise is to create a Node.js application that can programmatically remove all duplicate fields and objects from the given mock application schema and output a new sanitized version.
Please check the original README file.
The following assumptions have been made:
schema.versions
is an array of objectsschema.versions[\*].objects
is an array of objectsschema.versions[\*].objects[\*].name
exists and is a scalarschema.versions[\*].objects[\*].fields
is an array of objectsschema.versions[\*].objects[\*].fields[\*].name
exists and is a scalarschema.versions[\*].scenes
is an array of objectsschema.versions[\*].scenes[\*].key
exists and is a scalarschema.versions[\*].scenes[\*].views
is an array of objectsschema.versions[\*].scenes[\*].views[\*].key
exists and is a scalar
The main app is src/index.js, by default it reads the schema from data/mock_application.json and writes a sanitized version to output/clean_application.json
.
The parsing logic is in src/lib/removeDuplicates.js, it exports a single function which accepts a javascript object (the application schema) and optionally a filter object that overrides the default fields to be sanitized (as specified in the original requirements).
Unit tests have been written for this main function, but not for the application's CLI parsing / file handling.
Possible next steps:
- Implement an ApplicationSchema class that allows to:
- Read / write from different sources (object, ile, db, cache, etc)
- Configure the fields to be checked
- Validate the input schema against a JSON schema
- Increase coverage of tests
Install dependencies
npm install
Run tests
npm test
Run application
npm start <file>
If file is not specified it will read the schema from {repo_root}/data/mock_application.json
.
The output schema will be written to {repo_root}/out/clean_application.json
The following external modules have been used:
- Linting: eslint with the Airbnb styleguide
- Testing: jest