diff --git a/schema.json b/schema.json index d6778f41..504d211d 100644 --- a/schema.json +++ b/schema.json @@ -3,6 +3,13 @@ "title": "Resume Schema", "type": "object", "additionalProperties": false, + "definitions": { + "iso8601": { + "type": "string", + "description": "e.g. 2014-06-29", + "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})$" + } + }, "properties": { "basics": { "type": "object", @@ -115,16 +122,8 @@ "description": "e.g. http://facebook.example.com", "format": "uri" }, - "startDate": { - "type": "string", - "description": "resume.json uses the ISO 8601 date standard e.g. 2014-06-29", - "format": "date" - }, - "endDate": { - "type": "string", - "description": "e.g. 2012-06-29", - "format": "date" - }, + "startDate": { "$ref": "#/definitions/iso8601" }, + "endDate": { "$ref": "#/definitions/iso8601" }, "summary": { "type": "string", "description": "Give an overview of your responsibilities at the company" @@ -161,16 +160,8 @@ "description": "e.g. http://facebook.example.com", "format": "uri" }, - "startDate": { - "type": "string", - "description": "resume.json uses the ISO 8601 date standard e.g. 2014-06-29", - "format": "date" - }, - "endDate": { - "type": "string", - "description": "e.g. 2012-06-29", - "format": "date" - }, + "startDate": { "$ref": "#/definitions/iso8601" }, + "endDate": { "$ref": "#/definitions/iso8601" }, "summary": { "type": "string", "description": "Give an overview of your responsibilities at the company" @@ -206,16 +197,8 @@ "type": "string", "description": "e.g. Bachelor" }, - "startDate": { - "type": "string", - "description": "e.g. 2014-06-29", - "format": "date" - }, - "endDate": { - "type": "string", - "description": "e.g. 2012-06-29", - "format": "date" - }, + "startDate": { "$ref": "#/definitions/iso8601" }, + "endDate": { "$ref": "#/definitions/iso8601" }, "gpa": { "type": "string", "description": "grade point average, e.g. 3.67/4.0" @@ -244,11 +227,7 @@ "type": "string", "description": "e.g. One of the 100 greatest minds of the century" }, - "date": { - "type": "string", - "description": "e.g. 1989-06-12", - "format": "date" - }, + "date": { "$ref": "#/definitions/iso8601" }, "awarder": { "type": "string", "description": "e.g. Time Magazine" @@ -276,10 +255,7 @@ "type": "string", "description": "e.g. IEEE, Computer Magazine" }, - "releaseDate": { - "type": "string", - "description": "e.g. 1990-08-01" - }, + "releaseDate": { "$ref": "#/definitions/iso8601" }, "url": { "type": "string", "description": "e.g. http://www.computer.org.example.com/csdl/mags/co/1996/10/rx069-abs.html", @@ -414,16 +390,8 @@ "description": "e.g. AngularJS" } }, - "startDate": { - "type": "string", - "description": "resume.json uses the ISO 8601 date standard e.g. 2014-06-29", - "format": "date" - }, - "endDate": { - "type": "string", - "description": "e.g. 2012-06-29", - "format": "date" - }, + "startDate": { "$ref": "#/definitions/iso8601" }, + "endDate": { "$ref": "#/definitions/iso8601" }, "url": { "type": "string", "format":"uri", diff --git a/test/__test__/awards.json b/test/__test__/awards.json index 261f72c9..fc0020c8 100644 --- a/test/__test__/awards.json +++ b/test/__test__/awards.json @@ -27,6 +27,20 @@ } ] }, + "dateValid2": { + "awards": [ + { + "date": "2014-11" + } + ] + }, + "dateValid3": { + "awards": [ + { + "date": "2014" + } + ] + }, "dateInvalid": { "awards": [ { diff --git a/test/__test__/dates.json b/test/__test__/dates.json new file mode 100644 index 00000000..a3446714 --- /dev/null +++ b/test/__test__/dates.json @@ -0,0 +1,6 @@ +{ + "yearMonthDay": "2013-12-02", + "yearMonth": "2013-12-01", + "year": "2013-12-01", + "invalid": "2013-12-021" +} diff --git a/test/__test__/education.json b/test/__test__/education.json index 5dbae348..172455da 100644 --- a/test/__test__/education.json +++ b/test/__test__/education.json @@ -54,6 +54,20 @@ } ] }, + "startDateValid2": { + "education": [ + { + "startDate": "2011-06" + } + ] + }, + "startDateValid3": { + "education": [ + { + "startDate": "2011" + } + ] + }, "startDateInvalid": { "education": [ { @@ -68,6 +82,20 @@ } ] }, + "endDateValid2": { + "education": [ + { + "endDate": "2014-01" + } + ] + }, + "endDateValid3": { + "education": [ + { + "endDate": "2014" + } + ] + }, "endDateInvalid": { "education": [ { diff --git a/test/__test__/projects.json b/test/__test__/projects.json index 6a217b00..022fec23 100644 --- a/test/__test__/projects.json +++ b/test/__test__/projects.json @@ -104,6 +104,20 @@ } ] }, + "startDateValid2": { + "projects": [ + { + "startDate": "2015-08" + } + ] + }, + "startDateValid3": { + "projects": [ + { + "startDate": "2015" + } + ] + }, "startDateInvalid": { "projects": [ { @@ -118,6 +132,20 @@ } ] }, + "endDateValid2": { + "projects": [ + { + "endDate": "2016-08" + } + ] + }, + "endDateValid3": { + "projects": [ + { + "endDate": "2016" + } + ] + }, "endDateInvalid": { "projects": [ { diff --git a/test/__test__/publications.json b/test/__test__/publications.json index 550f6553..08bdff8d 100644 --- a/test/__test__/publications.json +++ b/test/__test__/publications.json @@ -40,6 +40,20 @@ } ] }, + "releaseDateValid2": { + "publications": [ + { + "releaseDate": "2014-10" + } + ] + }, + "releaseDateValid3": { + "publications": [ + { + "releaseDate": "2014" + } + ] + }, "releaseDateInvalid": { "publications": [ { diff --git a/test/__test__/volunteer.json b/test/__test__/volunteer.json index 17ad1773..28a847a7 100644 --- a/test/__test__/volunteer.json +++ b/test/__test__/volunteer.json @@ -54,6 +54,20 @@ } ] }, + "startDateValid2": { + "volunteer": [ + { + "startDate": "2012-01" + } + ] + }, + "startDateValid3": { + "volunteer": [ + { + "startDate": "2012" + } + ] + }, "startDateInvalid": { "volunteer": [ { @@ -68,6 +82,20 @@ } ] }, + "endDateValid2": { + "volunteer": [ + { + "endDate": "2013-01" + } + ] + }, + "endDateValid3": { + "volunteer": [ + { + "endDate": "2013" + } + ] + }, "endDateInvalid": { "volunteer": [ { diff --git a/test/__test__/work.json b/test/__test__/work.json index b101b5b9..c31a568e 100644 --- a/test/__test__/work.json +++ b/test/__test__/work.json @@ -82,6 +82,20 @@ } ] }, + "startDateValid2": { + "work": [ + { + "startDate": "2013-12" + } + ] + }, + "startDateValid3": { + "work": [ + { + "startDate": "2013" + } + ] + }, "startDateInvalid": { "work": [ { @@ -96,6 +110,20 @@ } ] }, + "endDateValid2": { + "work": [ + { + "endDate": "2014-12" + } + ] + }, + "endDateValid3": { + "work": [ + { + "endDate": "2014" + } + ] + }, "endDateInvalid": { "work": [ { diff --git a/test/awards.spec.js b/test/awards.spec.js index 5c6e9ffb..95b4dd73 100644 --- a/test/awards.spec.js +++ b/test/awards.spec.js @@ -34,7 +34,7 @@ test('awards[].title - invalid', (t) => { t.end(); }); -test('awards[].date - valid', (t) => { +test('awards[].date - valid [YYYY-MM-DD]', (t) => { validate(fixtures.dateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -42,6 +42,22 @@ test('awards[].date - valid', (t) => { t.end(); }); +test('awards[].date - valid [YYYY-MM]', (t) => { + validate(fixtures.dateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('awards[].date - valid [YYYY]', (t) => { + validate(fixtures.dateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('awards[].date - invalid', (t) => { validate(fixtures.dateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error'); diff --git a/test/dates.spec.js b/test/dates.spec.js new file mode 100644 index 00000000..b1012c9d --- /dev/null +++ b/test/dates.spec.js @@ -0,0 +1,54 @@ +var test = require('tape'); +var ZSchema = require('z-schema'); +const fixtures = require('./__test__/dates.json'); +// var mockDateSchema = require('./__test__/mockDateSchema.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})$" +}; + +function dateValidate(resumeJson, callback) { + var callbackWrapper = function(err, valid) { + if(err) { + callback(err) + } else { + callback(null, {valid: valid}); + } + } + + new ZSchema().validate(resumeJson, mockDateSchema, callbackWrapper); +} + +test('dates - YYYY-MM-DD', (t) => { + dateValidate(fixtures.yearMonthDay, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('dates - YYYY-MM', (t) => { + dateValidate(fixtures.yearMonth, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('dates - YYYY', (t) => { + dateValidate(fixtures.yearMonthDay, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('dates - invalid', (t) => { + dateValidate(fixtures.invalid, (err, valid) => { + t.notEqual(err, null, 'err should contain an error'); + t.false(valid, 'valid is false'); + }); + t.end(); +}); diff --git a/test/education.spec.js b/test/education.spec.js index 8b73f3ba..4e09ba8d 100644 --- a/test/education.spec.js +++ b/test/education.spec.js @@ -66,7 +66,7 @@ test('education[].studyType - invalid', (t) => { t.end(); }); -test('education[].startDate - valid', (t) => { +test('education[].startDate - valid [YYYY-MM-DD]', (t) => { validate(fixtures.startDateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -74,6 +74,22 @@ test('education[].startDate - valid', (t) => { t.end(); }); +test('education[].startDate - valid [YYYY-MM]', (t) => { + validate(fixtures.startDateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('education[].startDate - valid [YYYY]', (t) => { + validate(fixtures.startDateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('education[].startDate - invalid', (t) => { validate(fixtures.startDateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error'); @@ -82,7 +98,7 @@ test('education[].startDate - invalid', (t) => { t.end(); }); -test('education[].endDate - valid', (t) => { +test('education[].endDate - valid [YYYY-MM-DD]', (t) => { validate(fixtures.endDateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -90,6 +106,22 @@ test('education[].endDate - valid', (t) => { t.end(); }); +test('education[].endDate - valid [YYYY-MM]', (t) => { + validate(fixtures.endDateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('education[].endDate - valid [YYYY]', (t) => { + validate(fixtures.endDateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('education[].endDate - invalid', (t) => { validate(fixtures.endDateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error'); diff --git a/test/projects.spec.js b/test/projects.spec.js index 553e7159..aaae1379 100644 --- a/test/projects.spec.js +++ b/test/projects.spec.js @@ -114,7 +114,7 @@ test('projects[].keywords[item] - invalid', (t) => { t.end(); }); -test('projects[].startDate - valid', (t) => { +test('projects[].startDate - valid [YYYY-MM-DD]', (t) => { validate(fixtures.startDateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -122,6 +122,22 @@ test('projects[].startDate - valid', (t) => { t.end(); }); +test('projects[].startDate - valid [YYYY-MM]', (t) => { + validate(fixtures.startDateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('projects[].startDate - valid [YYYY]', (t) => { + validate(fixtures.startDateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('projects[].startDate - invalid', (t) => { validate(fixtures.startDateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error'); @@ -130,7 +146,7 @@ test('projects[].startDate - invalid', (t) => { t.end(); }); -test('projects[].endDate - valid', (t) => { +test('projects[].endDate - valid [YYYY-MM-DD]', (t) => { validate(fixtures.endDateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -138,6 +154,22 @@ test('projects[].endDate - valid', (t) => { t.end(); }); +test('projects[].endDate - valid [YYYY-MM]', (t) => { + validate(fixtures.endDateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('projects[].endDate - valid [YYYY]', (t) => { + validate(fixtures.endDateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('projects[].endDate - invalid', (t) => { validate(fixtures.endDateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error'); diff --git a/test/publications.spec.js b/test/publications.spec.js index 24a3c431..86d24b2c 100644 --- a/test/publications.spec.js +++ b/test/publications.spec.js @@ -50,7 +50,7 @@ test('publications[].publisher - invalid', (t) => { t.end(); }); -test('publications[].releaseDate - valid', (t) => { +test('publications[].releaseDate - valid [YYYY-MM-DD]', (t) => { validate(fixtures.releaseDateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -58,6 +58,22 @@ test('publications[].releaseDate - valid', (t) => { t.end(); }); +test('publications[].releaseDate - valid [YYYY-MM]', (t) => { + validate(fixtures.releaseDateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('publications[].releaseDate - valid [YYYY]', (t) => { + validate(fixtures.releaseDateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('publications[].releaseDate - invalid', (t) => { validate(fixtures.releaseDateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error'); diff --git a/test/volunteer.spec.js b/test/volunteer.spec.js index 15a245bd..4ad41dd3 100644 --- a/test/volunteer.spec.js +++ b/test/volunteer.spec.js @@ -66,7 +66,7 @@ test('volunteer[].url - invalid', (t) => { t.end(); }); -test('volunteer[].startDate - valid', (t) => { +test('volunteer[].startDate - valid [YYYY-MM-DD]', (t) => { validate(fixtures.startDateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -74,6 +74,22 @@ test('volunteer[].startDate - valid', (t) => { t.end(); }); +test('volunteer[].startDate - valid [YYYY-MM]', (t) => { + validate(fixtures.startDateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('volunteer[].startDate - valid [YYYY]', (t) => { + validate(fixtures.startDateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('volunteer[].startDate - invalid', (t) => { validate(fixtures.startDateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error'); diff --git a/test/work.spec.js b/test/work.spec.js index 44f30f66..fdf7c585 100644 --- a/test/work.spec.js +++ b/test/work.spec.js @@ -98,7 +98,7 @@ test('work[].url - invalid', (t) => { t.end(); }); -test('work[].startDate - valid', (t) => { +test('work[].startDate - valid [YYYY-MM-DD]', (t) => { validate(fixtures.startDateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -106,6 +106,22 @@ test('work[].startDate - valid', (t) => { t.end(); }); +test('work[].startDate - valid [YYYY-MM]', (t) => { + validate(fixtures.startDateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('work[].startDate - valid [YYYY]', (t) => { + validate(fixtures.startDateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('work[].startDate - invalid', (t) => { validate(fixtures.startDateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error'); @@ -114,7 +130,7 @@ test('work[].startDate - invalid', (t) => { t.end(); }); -test('work[].endDate - valid', (t) => { +test('work[].endDate - valid [YYYY-MM-DD]', (t) => { validate(fixtures.endDateValid, (err, valid) => { t.equal(err, null, 'err should be null'); t.true(valid, 'valid is true'); @@ -122,6 +138,22 @@ test('work[].endDate - valid', (t) => { t.end(); }); +test('work[].endDate - valid [YYYY-MM]', (t) => { + validate(fixtures.endDateValid2, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + +test('work[].endDate - valid [YYYY]', (t) => { + validate(fixtures.endDateValid3, (err, valid) => { + t.equal(err, null, 'err should be null'); + t.true(valid, 'valid is true'); + }); + t.end(); +}); + test('work[].endDate - invalid', (t) => { validate(fixtures.endDateInvalid, (err, valid) => { t.notEqual(err, null, 'err should contain an error');