Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema@ draft-7, no longer exporting validator, using jest for tests #371

Open
wants to merge 1 commit into
base: v1.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,32 @@

Standard, Specification, Schema

### 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 install resume-schema
```
npm install --save resume-schema
```

To use
evanplaice marked this conversation as resolved.
Show resolved Hide resolved
### 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 @@ -51,7 +47,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.
51 changes: 51 additions & 0 deletions __tests__/awards.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {describe, expect, it} from '@jest/globals'
import validate from '../utils/validate';
import fixtures from './__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();
});
147 changes: 147 additions & 0 deletions __tests__/basics.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import {describe, expect, it} from '@jest/globals'
import validate from '../utils/validate';
import fixtures from './__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();
});
27 changes: 27 additions & 0 deletions __tests__/dates.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {describe, expect, it} from '@jest/globals'
import Ajv from 'ajv';
import fixtures from './__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();
});
91 changes: 91 additions & 0 deletions __tests__/education.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {describe, expect, it} from '@jest/globals'
import validate from '../utils/validate';
import fixtures from './__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