Skip to content

Commit

Permalink
Merge pull request #159 from hckrnews/feature/fix-sub-object-validation
Browse files Browse the repository at this point in the history
Feature/fix sub object validation
  • Loading branch information
w3nl authored Dec 7, 2021
2 parents 0490235 + 360ca7b commit 1eb23d1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: npm install, lint, and test
run: |
npm ci
npm run lint
npm run lint:report
npm test
env:
CI: true
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Create valid JavaScript objects

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Scrutinizer Code Quality][scrutinizer-image]][scrutinizer-url]
[![NPM version][npm-image]][npm-url] [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=coverage)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects) [![Scrutinizer Code Quality][scrutinizer-image]][scrutinizer-url] [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=bugs)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects) [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=hckrnews_objects&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=hckrnews_objects)

Create objects and validate the values, so you know all values are ok.
You don't have to create code to validate all fields of an object, just write a schema.
Expand Down Expand Up @@ -482,9 +484,5 @@ true

[npm-url]: https://www.npmjs.com/package/@hckrnews/objects
[npm-image]: https://img.shields.io/npm/v/@hckrnews/objects.svg
[travis-url]: https://travis-ci.org/hckrnews/objects
[travis-image]: https://img.shields.io/travis/hckrnews/objects/master.svg
[coveralls-url]: https://coveralls.io/r/hckrnews/objects
[coveralls-image]: https://img.shields.io/coveralls/hckrnews/objects/master.svg
[scrutinizer-url]: https://scrutinizer-ci.com/g/hckrnews/objects/?branch=master
[scrutinizer-image]: https://scrutinizer-ci.com/g/hckrnews/objects/badges/quality-score.png?b=master
4 changes: 2 additions & 2 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@hckrnews/objects",
"description": "Create valid JavaScript objects",
"version": "3.3.10",
"version": "3.3.11",
"author": {
"name": "Pieter Wigboldus",
"url": "https://hckr.news/"
},
"license": "LGPL-3.0",
"scripts": {
"lint": "eslint src/*.js --config .eslintrc -f json -o report.json",
"lint": "eslint src/*.js --config .eslintrc",
"lint:report": "eslint src/*.js --config .eslintrc -f json -o report.json",
"lint:fix": "eslint src/*.js --config .eslintrc --fix",
"test": "jest",
"test:watch": "jest src --watch",
Expand Down
26 changes: 13 additions & 13 deletions src/__tests__/validate-sub-objects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ describe('Object test', () => {

const personSchema = {
name: String,
address: addressSchema
address: addressSchema,
};

it('It should throw an exception for level 1', () => {
// deepcode ignore ExpectsArray: False error, it should allow an object
const Country = Obj({ schema: CountrySchema })
const Country = Obj({ schema: CountrySchema });
expect(() => {
Country.create({
name: 'Germany',
code: 'DE',
active: 'true',
})
}).toThrowError('The field active should be a Boolean')
name: 'Germany',
code: 'DE',
active: 'true',
});
}).toThrowError('The field active should be a Boolean');
});

it('It should throw an exception for level 2', () => {
// deepcode ignore ExpectsArray: False error, it should allow an object
const Address = Obj({ schema: addressSchema })
const Address = Obj({ schema: addressSchema });
expect(() => {
Address.create({
street: 'Abc',
Expand All @@ -47,13 +47,13 @@ describe('Object test', () => {
code: 'DE',
active: 'true',
},
})
}).toThrowError('The field country.active should be a Boolean')
});
}).toThrowError('The field country.active should be a Boolean');
});

it('It should throw an exception for level 3', () => {
// deepcode ignore ExpectsArray: False error, it should allow an object
const Person = Obj({ schema: personSchema })
const Person = Obj({ schema: personSchema });
expect(() => {
Person.create({
name: 'John',
Expand All @@ -68,7 +68,7 @@ describe('Object test', () => {
active: 'true',
},
},
})
}).toThrowError('The field address.country.active should be a Boolean')
});
}).toThrowError('The field address.country.active should be a Boolean');
});
});

0 comments on commit 1eb23d1

Please sign in to comment.