Skip to content

Commit d41963a

Browse files
author
antialias
committed
no longer exporting validator. using jest for tests
1 parent ba9140f commit d41963a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+7729
-2332
lines changed

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,32 @@
77

88
Standard, Specification, Schema
99

10-
### Gitter
10+
### Community Chat
1111

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

14-
### Getting started
14+
### Installation
1515

16+
Resume-schema is intended to be installed as a dependency of your project:
17+
18+
```sh
19+
npm install resume-schema
1620
```
17-
npm install --save resume-schema
18-
```
1921

20-
To use
22+
### Usage
23+
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).
24+
25+
#### validation
26+
To determine if an object is a valid JSON resume, you can do something like this:
2127

2228
```js
23-
var resumeSchema = require('resume-schema');
24-
resumeSchema.validate({ name: "Thomas" }, function (err, report) {
25-
if (err) {
26-
console.error('The resume was invalid:', err);
27-
return;
28-
}
29-
console.log('Resume validated successfully:', report);
30-
});
31-
```
29+
import schema from 'resume-schema';
30+
import Ajv from 'ajv'; // validator. See https://ajv.js.org/
3231

33-
More likely
32+
const validate = new Ajv().compile(schema);
3433

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

4238
The JSON Resume schema is available from:
@@ -51,7 +47,7 @@ require('resume-schema').schema;
5147

5248
### Contribute
5349

54-
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.
50+
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.
5551

5652
### Versioning
5753

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.

test/__test__/schema.json renamed to __tests__/__test__/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{
33
"valid": {
4-
"$schema": "foo-bar-baz"
4+
"$schema": "http://example.com/"
55
},
66
"invalid": {
77
"$schema": {}
File renamed without changes.
File renamed without changes.
File renamed without changes.

__tests__/awards.spec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {describe, expect, it} from '@jest/globals'
2+
import validate from '../utils/validate';
3+
import fixtures from './__test__/awards.json';
4+
5+
test('awards - valid', () => {
6+
expect(validate(fixtures.awardsValid)).toBeTruthy();
7+
});
8+
9+
test('awards - invalid', () => {
10+
expect(validate(fixtures.awardsInvalid)).toBeFalsy();
11+
});
12+
13+
test('awards[].title - valid', () => {
14+
expect(validate(fixtures.titleValid)).toBeTruthy();
15+
});
16+
17+
test('awards[].title - invalid', () => {
18+
expect(validate(fixtures.titleInvalid)).toBeFalsy();
19+
});
20+
21+
test('awards[].date - valid [YYYY-MM-DD]', () => {
22+
expect(validate(fixtures.dateValid)).toBeTruthy();
23+
});
24+
25+
test('awards[].date - valid [YYYY-MM]', () => {
26+
expect(validate(fixtures.dateValid2)).toBeTruthy();
27+
});
28+
29+
test('awards[].date - valid [YYYY]', () => {
30+
expect(validate(fixtures.dateValid3)).toBeTruthy();
31+
});
32+
33+
test('awards[].date - invalid', () => {
34+
expect(validate(fixtures.dateInvalid)).toBeFalsy();
35+
});
36+
37+
test('awards[].awarder - valid', () => {
38+
expect(validate(fixtures.awarderValid)).toBeTruthy();
39+
});
40+
41+
test('awards[].awarder - invalid', () => {
42+
expect(validate(fixtures.awarderInvalid)).toBeFalsy();
43+
});
44+
45+
test('awards[].summary - valid', () => {
46+
expect(validate(fixtures.summaryValid)).toBeTruthy();
47+
});
48+
49+
test('awards[].summary - invalid', () => {
50+
expect(validate(fixtures.summaryInvalid)).toBeFalsy();
51+
});

__tests__/basics.spec.js

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import {describe, expect, it} from '@jest/globals'
2+
import validate from '../utils/validate';
3+
import fixtures from './__test__/basics.json';
4+
5+
test('basics - valid', () => {
6+
expect(validate(fixtures.basicsValid)).toBeTruthy();
7+
});
8+
9+
test('basics - invalid', () => {
10+
expect(validate(fixtures.basicsInvalid)).toBeFalsy();
11+
});
12+
13+
test('basics.name - valid', () => {
14+
expect(validate(fixtures.nameValid)).toBeTruthy();
15+
});
16+
17+
test('basics.name - invalid', () => {
18+
expect(validate(fixtures.nameInvalid)).toBeFalsy();
19+
});
20+
21+
test('basics.label - valid', () => {
22+
expect(validate(fixtures.labelValid)).toBeTruthy();
23+
});
24+
25+
test('basics.label - invalid', () => {
26+
expect(validate(fixtures.labelInvalid)).toBeFalsy();
27+
});
28+
29+
test('basics.image - valid', () => {
30+
expect(validate(fixtures.imageValid)).toBeTruthy();
31+
});
32+
33+
test('basics.image - invalid', () => {
34+
expect(validate(fixtures.imageInvalid)).toBeFalsy();
35+
});
36+
37+
test('basics.email - valid', () => {
38+
expect(validate(fixtures.emailValid)).toBeTruthy();
39+
});
40+
41+
test('basics.email - invalid', () => {
42+
expect(validate(fixtures.emailInvalid)).toBeFalsy();
43+
});
44+
45+
test('basics.phone - valid', () => {
46+
expect(validate(fixtures.phoneValid)).toBeTruthy();
47+
});
48+
49+
test('basics.phone - invalid', () => {
50+
expect(validate(fixtures.phoneInvalid)).toBeFalsy();
51+
});
52+
53+
test('basics.url - valid', () => {
54+
expect(validate(fixtures.urlValid)).toBeTruthy();
55+
});
56+
57+
test('basics.url - invalid', () => {
58+
expect(validate(fixtures.urlInvalid)).toBeFalsy();
59+
});
60+
61+
test('basics.summary - valid', () => {
62+
expect(validate(fixtures.summaryValid)).toBeTruthy();
63+
});
64+
65+
test('basics.summary - invalid', () => {
66+
expect(validate(fixtures.summaryInvalid)).toBeFalsy();
67+
});
68+
69+
test('basics.location - valid', () => {
70+
expect(validate(fixtures.locationValid)).toBeTruthy();
71+
});
72+
73+
test('basics.location - invalid', () => {
74+
expect(validate(fixtures.locationInvalid)).toBeFalsy();
75+
});
76+
77+
test('basics.location.address - valid', () => {
78+
expect(validate(fixtures.locationAddressValid)).toBeTruthy();
79+
});
80+
81+
test('basics.location.address - invalid', () => {
82+
expect(validate(fixtures.locationAddressInvalid)).toBeFalsy();
83+
});
84+
85+
test('basics.location.postal - valid', () => {
86+
expect(validate(fixtures.locationPostalValid)).toBeTruthy();
87+
});
88+
89+
test('basics.location.postal - invalid', () => {
90+
expect(validate(fixtures.locationPostalInvalid)).toBeFalsy();
91+
});
92+
93+
test('basics.location.city - valid', () => {
94+
expect(validate(fixtures.locationCityValid)).toBeTruthy();
95+
});
96+
97+
test('basics.location.city - invalid', () => {
98+
expect(validate(fixtures.locationCityInvalid)).toBeFalsy();
99+
});
100+
101+
test('basics.location.country - valid', () => {
102+
expect(validate(fixtures.locationCountryValid)).toBeTruthy();
103+
});
104+
105+
test('basics.location.country - invalid', () => {
106+
expect(validate(fixtures.locationCountryInvalid)).toBeFalsy();
107+
});
108+
109+
test('basics.location.region - valid', () => {
110+
expect(validate(fixtures.locationRegionValid)).toBeTruthy();
111+
});
112+
113+
test('basics.location.region - invalid', () => {
114+
expect(validate(fixtures.locationRegionInvalid)).toBeFalsy();
115+
});
116+
117+
test('basics.profiles - valid', () => {
118+
expect(validate(fixtures.profilesValid)).toBeTruthy();
119+
});
120+
121+
test('basics.profiles - invalid', () => {
122+
expect(validate(fixtures.profilesInvalid)).toBeFalsy();
123+
});
124+
125+
test('basics.profiles[].network - valid', () => {
126+
expect(validate(fixtures.profilesNetworkValid)).toBeTruthy();
127+
});
128+
129+
test('basics.profiles[].network - invalid', () => {
130+
expect(validate(fixtures.profilesNetworkInvalid)).toBeFalsy();
131+
});
132+
133+
test('basics.profiles[].username - valid', () => {
134+
expect(validate(fixtures.profilesUsernameValid)).toBeTruthy();
135+
});
136+
137+
test('basics.profiles[].username - invalid', () => {
138+
expect(validate(fixtures.profilesUsernameInvalid)).toBeFalsy();
139+
});
140+
141+
test('basics.profiles[].url - valid', () => {
142+
expect(validate(fixtures.profilesUrlValid)).toBeTruthy();
143+
});
144+
145+
test('basics.profiles[].url - invalid', () => {
146+
expect(validate(fixtures.profilesUrlInvalid)).toBeFalsy();
147+
});

__tests__/dates.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {describe, expect, it} from '@jest/globals'
2+
import Ajv from 'ajv';
3+
import fixtures from './__test__/dates.json';
4+
5+
const mockDateSchema = {
6+
"type": "string",
7+
"description": "Mock Date Format",
8+
"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})$"
9+
};
10+
11+
const validate = new Ajv().compile(mockDateSchema)
12+
13+
test('dates - YYYY-MM-DD', () => {
14+
expect(validate(fixtures.yearMonthDay)).toBeTruthy();
15+
});
16+
17+
test('dates - YYYY-MM', () => {
18+
expect(validate(fixtures.yearMonth)).toBeTruthy();
19+
});
20+
21+
test('dates - YYYY', () => {
22+
expect(validate(fixtures.yearMonthDay)).toBeTruthy();
23+
});
24+
25+
test('dates - invalid', () => {
26+
expect(validate(fixtures.invalid)).toBeFalsy();
27+
});

__tests__/education.spec.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import {describe, expect, it} from '@jest/globals'
2+
import validate from '../utils/validate';
3+
import fixtures from './__test__/education.json';
4+
5+
test('eductaion - valid', () => {
6+
expect(validate(fixtures.educationValid)).toBeTruthy();
7+
});
8+
9+
test('education - invalid', () => {
10+
expect(validate(fixtures.educationInvalid)).toBeFalsy();
11+
});
12+
13+
test('education[].institution - valid', () => {
14+
expect(validate(fixtures.institutionValid)).toBeTruthy();
15+
});
16+
17+
test('education[].institution - invalid', () => {
18+
expect(validate(fixtures.institutionInvalid)).toBeFalsy();
19+
});
20+
21+
test('education[].area - valid', () => {
22+
expect(validate(fixtures.areaValid)).toBeTruthy();
23+
});
24+
25+
test('education[].area - invalid', () => {
26+
expect(validate(fixtures.areaInvalid)).toBeFalsy();
27+
});
28+
29+
test('education[].studyType - valid', () => {
30+
expect(validate(fixtures.studyTypeValid)).toBeTruthy();
31+
});
32+
33+
test('education[].studyType - invalid', () => {
34+
expect(validate(fixtures.studyTypeInvalid)).toBeFalsy();
35+
});
36+
37+
test('education[].startDate - valid [YYYY-MM-DD]', () => {
38+
expect(validate(fixtures.startDateValid)).toBeTruthy();
39+
});
40+
41+
test('education[].startDate - valid [YYYY-MM]', () => {
42+
expect(validate(fixtures.startDateValid2, )).toBeTruthy();
43+
});
44+
45+
test('education[].startDate - valid [YYYY]', () => {
46+
expect(validate(fixtures.startDateValid3)).toBeTruthy();
47+
});
48+
49+
test('education[].startDate - invalid', () => {
50+
expect(validate(fixtures.startDateInvalid)).toBeFalsy();
51+
});
52+
53+
test('education[].endDate - valid [YYYY-MM-DD]', () => {
54+
expect(validate(fixtures.endDateValid)).toBeTruthy();
55+
});
56+
57+
test('education[].endDate - valid [YYYY-MM]', () => {
58+
expect(validate(fixtures.endDateValid2)).toBeTruthy();
59+
});
60+
61+
test('education[].endDate - valid [YYYY]', () => {
62+
expect(validate(fixtures.endDateValid3)).toBeTruthy();
63+
});
64+
65+
test('education[].endDate - invalid', () => {
66+
expect(validate(fixtures.endDateInvalid)).toBeFalsy();
67+
});
68+
69+
test('education[].gpa - valid', () => {
70+
expect(validate(fixtures.gpaValid)).toBeTruthy();
71+
});
72+
73+
test('education[].gpa - invalid', () => {
74+
expect(validate(fixtures.gpaInvalid)).toBeFalsy();
75+
});
76+
77+
test('education[].courses - valid', () => {
78+
expect(validate(fixtures.coursesValid)).toBeTruthy();
79+
});
80+
81+
test('education[].courses - invalid', () => {
82+
expect(validate(fixtures.coursesInvalid)).toBeFalsy();
83+
});
84+
85+
test('education[].courses[item] - valid', () => {
86+
expect(validate(fixtures.coursesItemValid)).toBeTruthy();
87+
});
88+
89+
test('education[].courses[item] - invalid', () => {
90+
expect(validate(fixtures.coursesItemInvalid)).toBeFalsy();
91+
});

0 commit comments

Comments
 (0)