Skip to content

Commit

Permalink
no longer exporting validator. using jest for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antialias committed Apr 23, 2020
1 parent 791c85e commit 9ddfcea
Show file tree
Hide file tree
Showing 47 changed files with 8,575 additions and 2,151 deletions.
40 changes: 18 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,32 @@ Standard, Specification, Schema
* 2014-07-12 - `email` and `phone` were changed from objects into strings - [Discussion](https://github.com/jsonresume/resume-schema/issues/27) - [Commit](https://github.com/jsonresume/resume-schema/pull/98)
* 2014-07-12 - `firstName` and `lastName` were merged into `name` - [Discussion](https://github.com/jsonresume/resume-schema/issues/4) - [Commit](https://github.com/jsonresume/resume-schema/commit/717b2a525f4f42e9994c54bfa3cdbe0cea5776a6)

### Gitter
### Community Chat

Everyone working on the early stages of the project should join our gitter channel [gitter.im/jsonresume/public](https://gitter.im/jsonresume/public).
* [Gitter](https://gitter.im/jsonresume/public)

### Getting started
### Installation

Resume-schema is intended to be installed as a dependency of your project:

```sh
npm add resume-schema
```
npm install --save resume-schema
```

To use
### Usage
The main export of this package is an object that validates as a [JSON schema](https://json-schema.org/understanding-json-schema/). It should work with [any compliant implementation](https://json-schema.org/implementations.html#validator-javascript).

#### validation
To determine if an object is a valid JSON resume, you can do something like this:

```js
var resumeSchema = require('resume-schema');
resumeSchema.validate({ name: "Thomas" }, function (err, report) {
if (err) {
console.error('The resume was invalid:', err);
return;
}
console.log('Resume validated successfully:', report);
});
```
import schema from 'resume-schema';
import Ajv from 'ajv'; // validator. See https://ajv.js.org/

More likely
const validate = new Ajv().compile(schema);

```js
var fs = require('fs');
var resumeSchema = require('resume-schema');
var resumeObject = JSON.parse(fs.readFileSync('resume.json', 'utf8'));
resumeSchema.validate(resumeObject);
validate({basics: {name: "Thomas"}}); // true
validate({invalidProperty: "foo bar"}); // false
```

The JSON Resume schema is available from:
Expand All @@ -73,7 +69,7 @@ require('resume-schema').schema;

### Contribute

We encourage anyone who's interested in participating in the formation of this standard, to join us on Gitter, and/or to join the discussions [here on GitHub](https://github.com/jsonresume/resume-schema/issues). Also feel free to fork this project and submit new ideas to add to the JSON Resume Schema standard. To make sure all formatting is kept in check, please install the [EditorConfig plugin](http://editorconfig.org/) for your editor of choice.
We encourage anyone who's interested in participating in evolving this standard to join us on Gitter, and/or to join the discussions [here on GitHub](https://github.com/jsonresume/resume-schema/issues). Also feel free to fork this project and submit new ideas to add to the JSON Resume Schema standard. To make sure all formatting is kept in check, please install the [EditorConfig plugin](http://editorconfig.org/) for your editor of choice.

### Versioning

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"valid": {
"$schema": "foo-bar-baz"
"$schema": "http://example.com/"
},
"invalid": {
"$schema": {}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 50 additions & 0 deletions __tests__/awards.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import validate from '../utils/validate';
const fixtures = require('./__test__/awards.json');

test('awards - valid', () => {
expect(validate(fixtures.awardsValid)).toBeTruthy();
});

test('awards - invalid', () => {
expect(validate(fixtures.awardsInvalid)).toBeFalsy();
});

test('awards[].title - valid', () => {
expect(validate(fixtures.titleValid)).toBeTruthy();
});

test('awards[].title - invalid', () => {
expect(validate(fixtures.titleInvalid)).toBeFalsy();
});

test('awards[].date - valid [YYYY-MM-DD]', () => {
expect(validate(fixtures.dateValid)).toBeTruthy();
});

test('awards[].date - valid [YYYY-MM]', () => {
expect(validate(fixtures.dateValid2)).toBeTruthy();
});

test('awards[].date - valid [YYYY]', () => {
expect(validate(fixtures.dateValid3)).toBeTruthy();
});

test('awards[].date - invalid', () => {
expect(validate(fixtures.dateInvalid)).toBeFalsy();
});

test('awards[].awarder - valid', () => {
expect(validate(fixtures.awarderValid)).toBeTruthy();
});

test('awards[].awarder - invalid', () => {
expect(validate(fixtures.awarderInvalid)).toBeFalsy();
});

test('awards[].summary - valid', () => {
expect(validate(fixtures.summaryValid)).toBeTruthy();
});

test('awards[].summary - invalid', () => {
expect(validate(fixtures.summaryInvalid)).toBeFalsy();
});
146 changes: 146 additions & 0 deletions __tests__/basics.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import validate from '../utils/validate';
const fixtures = require('./__test__/basics.json');

test('basics - valid', () => {
expect(validate(fixtures.basicsValid)).toBeTruthy();
});

test('basics - invalid', () => {
expect(validate(fixtures.basicsInvalid)).toBeFalsy();
});

test('basics.name - valid', () => {
expect(validate(fixtures.nameValid)).toBeTruthy();
});

test('basics.name - invalid', () => {
expect(validate(fixtures.nameInvalid)).toBeFalsy();
});

test('basics.label - valid', () => {
expect(validate(fixtures.labelValid)).toBeTruthy();
});

test('basics.label - invalid', () => {
expect(validate(fixtures.labelInvalid)).toBeFalsy();
});

test('basics.image - valid', () => {
expect(validate(fixtures.imageValid)).toBeTruthy();
});

test('basics.image - invalid', () => {
expect(validate(fixtures.imageInvalid)).toBeFalsy();
});

test('basics.email - valid', () => {
expect(validate(fixtures.emailValid)).toBeTruthy();
});

test('basics.email - invalid', () => {
expect(validate(fixtures.emailInvalid)).toBeFalsy();
});

test('basics.phone - valid', () => {
expect(validate(fixtures.phoneValid)).toBeTruthy();
});

test('basics.phone - invalid', () => {
expect(validate(fixtures.phoneInvalid)).toBeFalsy();
});

test('basics.url - valid', () => {
expect(validate(fixtures.urlValid)).toBeTruthy();
});

test('basics.url - invalid', () => {
expect(validate(fixtures.urlInvalid)).toBeFalsy();
});

test('basics.summary - valid', () => {
expect(validate(fixtures.summaryValid)).toBeTruthy();
});

test('basics.summary - invalid', () => {
expect(validate(fixtures.summaryInvalid)).toBeFalsy();
});

test('basics.location - valid', () => {
expect(validate(fixtures.locationValid)).toBeTruthy();
});

test('basics.location - invalid', () => {
expect(validate(fixtures.locationInvalid)).toBeFalsy();
});

test('basics.location.address - valid', () => {
expect(validate(fixtures.locationAddressValid)).toBeTruthy();
});

test('basics.location.address - invalid', () => {
expect(validate(fixtures.locationAddressInvalid)).toBeFalsy();
});

test('basics.location.postal - valid', () => {
expect(validate(fixtures.locationPostalValid)).toBeTruthy();
});

test('basics.location.postal - invalid', () => {
expect(validate(fixtures.locationPostalInvalid)).toBeFalsy();
});

test('basics.location.city - valid', () => {
expect(validate(fixtures.locationCityValid)).toBeTruthy();
});

test('basics.location.city - invalid', () => {
expect(validate(fixtures.locationCityInvalid)).toBeFalsy();
});

test('basics.location.country - valid', () => {
expect(validate(fixtures.locationCountryValid)).toBeTruthy();
});

test('basics.location.country - invalid', () => {
expect(validate(fixtures.locationCountryInvalid)).toBeFalsy();
});

test('basics.location.region - valid', () => {
expect(validate(fixtures.locationRegionValid)).toBeTruthy();
});

test('basics.location.region - invalid', () => {
expect(validate(fixtures.locationRegionInvalid)).toBeFalsy();
});

test('basics.profiles - valid', () => {
expect(validate(fixtures.profilesValid)).toBeTruthy();
});

test('basics.profiles - invalid', () => {
expect(validate(fixtures.profilesInvalid)).toBeFalsy();
});

test('basics.profiles[].network - valid', () => {
expect(validate(fixtures.profilesNetworkValid)).toBeTruthy();
});

test('basics.profiles[].network - invalid', () => {
expect(validate(fixtures.profilesNetworkInvalid)).toBeFalsy();
});

test('basics.profiles[].username - valid', () => {
expect(validate(fixtures.profilesUsernameValid)).toBeTruthy();
});

test('basics.profiles[].username - invalid', () => {
expect(validate(fixtures.profilesUsernameInvalid)).toBeFalsy();
});

test('basics.profiles[].url - valid', () => {
expect(validate(fixtures.profilesUrlValid)).toBeTruthy();
});

test('basics.profiles[].url - invalid', () => {
expect(validate(fixtures.profilesUrlInvalid)).toBeFalsy();
});
26 changes: 26 additions & 0 deletions __tests__/dates.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const Ajv = require('ajv');
const fixtures = require('./__test__/dates.json');

const mockDateSchema = {
"type": "string",
"description": "Mock Date Format",
"pattern": "^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$"
};

const validate = new Ajv().compile(mockDateSchema)

test('dates - YYYY-MM-DD', () => {
expect(validate(fixtures.yearMonthDay)).toBeTruthy();
});

test('dates - YYYY-MM', () => {
expect(validate(fixtures.yearMonth)).toBeTruthy();
});

test('dates - YYYY', () => {
expect(validate(fixtures.yearMonthDay)).toBeTruthy();
});

test('dates - invalid', () => {
expect(validate(fixtures.invalid)).toBeFalsy();
});
90 changes: 90 additions & 0 deletions __tests__/education.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import validate from '../utils/validate';
const fixtures = require('./__test__/education.json');

test('eductaion - valid', () => {
expect(validate(fixtures.educationValid)).toBeTruthy();
});

test('education - invalid', () => {
expect(validate(fixtures.educationInvalid)).toBeFalsy();
});

test('education[].institution - valid', () => {
expect(validate(fixtures.institutionValid)).toBeTruthy();
});

test('education[].institution - invalid', () => {
expect(validate(fixtures.institutionInvalid)).toBeFalsy();
});

test('education[].area - valid', () => {
expect(validate(fixtures.areaValid)).toBeTruthy();
});

test('education[].area - invalid', () => {
expect(validate(fixtures.areaInvalid)).toBeFalsy();
});

test('education[].studyType - valid', () => {
expect(validate(fixtures.studyTypeValid)).toBeTruthy();
});

test('education[].studyType - invalid', () => {
expect(validate(fixtures.studyTypeInvalid)).toBeFalsy();
});

test('education[].startDate - valid [YYYY-MM-DD]', () => {
expect(validate(fixtures.startDateValid)).toBeTruthy();
});

test('education[].startDate - valid [YYYY-MM]', () => {
expect(validate(fixtures.startDateValid2, )).toBeTruthy();
});

test('education[].startDate - valid [YYYY]', () => {
expect(validate(fixtures.startDateValid3)).toBeTruthy();
});

test('education[].startDate - invalid', () => {
expect(validate(fixtures.startDateInvalid)).toBeFalsy();
});

test('education[].endDate - valid [YYYY-MM-DD]', () => {
expect(validate(fixtures.endDateValid)).toBeTruthy();
});

test('education[].endDate - valid [YYYY-MM]', () => {
expect(validate(fixtures.endDateValid2)).toBeTruthy();
});

test('education[].endDate - valid [YYYY]', () => {
expect(validate(fixtures.endDateValid3)).toBeTruthy();
});

test('education[].endDate - invalid', () => {
expect(validate(fixtures.endDateInvalid)).toBeFalsy();
});

test('education[].gpa - valid', () => {
expect(validate(fixtures.gpaValid)).toBeTruthy();
});

test('education[].gpa - invalid', () => {
expect(validate(fixtures.gpaInvalid)).toBeFalsy();
});

test('education[].courses - valid', () => {
expect(validate(fixtures.coursesValid)).toBeTruthy();
});

test('education[].courses - invalid', () => {
expect(validate(fixtures.coursesInvalid)).toBeFalsy();
});

test('education[].courses[item] - valid', () => {
expect(validate(fixtures.coursesItemValid)).toBeTruthy();
});

test('education[].courses[item] - invalid', () => {
expect(validate(fixtures.coursesItemInvalid)).toBeFalsy();
});
Loading

0 comments on commit 9ddfcea

Please sign in to comment.