vets_json_schema 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.babelrc +3 -0
- data/.gitattributes +1 -0
- data/.gitignore +1 -0
- data/.nvmrc +1 -0
- data/.travis.yml +12 -0
- data/README.md +9 -0
- data/dist/edu-benefits-schema.json +0 -0
- data/lib/vets_json_schema.rb +5 -0
- data/package.json +28 -0
- data/src/common/constants.js +1597 -0
- data/src/edu-benefits/schema.js +462 -0
- data/src/generate-schemas.js +5 -0
- data/src/start.js +10 -0
- data/src/watch.js +16 -0
- data/test/edu-benefits/schema.spec.js +330 -0
- data/test/mocha.opts +1 -0
- data/vets_json_schema.gemspec +13 -0
- metadata +59 -0
data/src/start.js
ADDED
data/src/watch.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import watch from 'node-watch';
|
2
|
+
import { execSync } from 'child_process';
|
3
|
+
|
4
|
+
const build = () => {
|
5
|
+
try {
|
6
|
+
execSync('npm run build', { stdio:[0,1,2] });
|
7
|
+
} catch (e) {
|
8
|
+
console.log(e.message);
|
9
|
+
}
|
10
|
+
};
|
11
|
+
|
12
|
+
build();
|
13
|
+
|
14
|
+
console.log('watching for changes in src dir..');
|
15
|
+
|
16
|
+
watch('src', { recursive: true }, build);
|
@@ -0,0 +1,330 @@
|
|
1
|
+
import { expect } from 'chai';
|
2
|
+
import schema from '../../dist/edu-benefits-schema.json';
|
3
|
+
import Ajv from 'ajv';
|
4
|
+
import _ from 'lodash';
|
5
|
+
|
6
|
+
describe('education benefits json schema', () => {
|
7
|
+
let ajv = new Ajv();
|
8
|
+
let currentSchema;
|
9
|
+
const validateSchema = (data) => {
|
10
|
+
return ajv.validate(currentSchema, data);
|
11
|
+
};
|
12
|
+
const validators = {
|
13
|
+
valid: (data) => {
|
14
|
+
expect(validateSchema(data)).to.equal(true);
|
15
|
+
},
|
16
|
+
invalid: (data) => {
|
17
|
+
expect(validateSchema(data)).to.equal(false);
|
18
|
+
expect(ajv.errors[0].dataPath).to.contain(`.${Object.keys(data)[0]}`);
|
19
|
+
}
|
20
|
+
};
|
21
|
+
const objectBuilder = (keys, value) => {
|
22
|
+
let object = {};
|
23
|
+
|
24
|
+
keys.split('.').reverse().forEach((key, i) => {
|
25
|
+
if (i === 0) {
|
26
|
+
object = {
|
27
|
+
[key]: value
|
28
|
+
};
|
29
|
+
} else {
|
30
|
+
object = {
|
31
|
+
[key]: object
|
32
|
+
};
|
33
|
+
}
|
34
|
+
});
|
35
|
+
|
36
|
+
return object;
|
37
|
+
};
|
38
|
+
const testValidAndInvalid = (parentKey, fields) => {
|
39
|
+
['valid', 'invalid'].forEach((fieldType) => {
|
40
|
+
fields[fieldType].forEach((values) => {
|
41
|
+
it(`should${fieldType === 'valid' ? '' : 'nt'} allow ${parentKey} with ${JSON.stringify(values)}`, () => {
|
42
|
+
validators[fieldType](objectBuilder(parentKey, values));
|
43
|
+
});
|
44
|
+
});
|
45
|
+
});
|
46
|
+
};
|
47
|
+
const validDateRange = {
|
48
|
+
from: '2000-01-01',
|
49
|
+
to: '2000-01-02'
|
50
|
+
};
|
51
|
+
|
52
|
+
beforeEach(() => {
|
53
|
+
currentSchema = schema;
|
54
|
+
});
|
55
|
+
|
56
|
+
context('ssn validations', () => {
|
57
|
+
testValidAndInvalid('veteranSocialSecurityNumber', {
|
58
|
+
valid: ['123456789'],
|
59
|
+
invalid: ['123-45-6789', '12345678']
|
60
|
+
});
|
61
|
+
});
|
62
|
+
|
63
|
+
context('name validations', () => {
|
64
|
+
['veteranFullName'].forEach((parentKey) => {
|
65
|
+
testValidAndInvalid(parentKey, {
|
66
|
+
valid: [{
|
67
|
+
first: 'john',
|
68
|
+
last: 'doe'
|
69
|
+
}],
|
70
|
+
invalid: [{
|
71
|
+
first: 'john'
|
72
|
+
}]
|
73
|
+
});
|
74
|
+
});
|
75
|
+
});
|
76
|
+
|
77
|
+
context('gender validations', () => {
|
78
|
+
testValidAndInvalid('gender', {
|
79
|
+
valid: ['M', 'F'],
|
80
|
+
invalid: ['Z']
|
81
|
+
});
|
82
|
+
});
|
83
|
+
|
84
|
+
context('address validations', () => {
|
85
|
+
beforeEach(() => {
|
86
|
+
let modifiedSchema = _.cloneDeep(schema);
|
87
|
+
delete(modifiedSchema.properties.school.required);
|
88
|
+
currentSchema = modifiedSchema;
|
89
|
+
});
|
90
|
+
|
91
|
+
['veteranAddress', 'secondaryContact.address', 'school.address'].forEach((parentKey) => {
|
92
|
+
testValidAndInvalid(parentKey, {
|
93
|
+
valid: [{
|
94
|
+
street: '123 a rd',
|
95
|
+
city: 'abc',
|
96
|
+
country: 'USA'
|
97
|
+
}],
|
98
|
+
invalid: [{
|
99
|
+
city: 'foo',
|
100
|
+
country: 'USA'
|
101
|
+
}]
|
102
|
+
});
|
103
|
+
});
|
104
|
+
});
|
105
|
+
|
106
|
+
context('phone # validations', () => {
|
107
|
+
['homePhone', 'mobilePhone', 'secondaryContact.phone'].forEach((parentKey) => {
|
108
|
+
testValidAndInvalid(parentKey, {
|
109
|
+
valid: ['5555555555'],
|
110
|
+
invalid: ['1a']
|
111
|
+
});
|
112
|
+
});
|
113
|
+
});
|
114
|
+
|
115
|
+
context('bank account validations', () => {
|
116
|
+
testValidAndInvalid('bankAccount.accountType', {
|
117
|
+
valid: ['checking', 'savings'],
|
118
|
+
invalid: ['bitcoin']
|
119
|
+
});
|
120
|
+
|
121
|
+
testValidAndInvalid('bankAccount.routingNumber', {
|
122
|
+
valid: ['123456789'],
|
123
|
+
invalid: ['12345678']
|
124
|
+
});
|
125
|
+
});
|
126
|
+
|
127
|
+
context('serviceAcademyGraduationYear validations', () => {
|
128
|
+
testValidAndInvalid('serviceAcademyGraduationYear', {
|
129
|
+
valid: [2004],
|
130
|
+
invalid: [1899]
|
131
|
+
});
|
132
|
+
});
|
133
|
+
|
134
|
+
context('dateRange validations', () => {
|
135
|
+
testValidAndInvalid('activeDutyRepayingPeriod', {
|
136
|
+
valid: [
|
137
|
+
validDateRange,
|
138
|
+
{
|
139
|
+
from: '2000-01-01',
|
140
|
+
to: 'present'
|
141
|
+
}
|
142
|
+
],
|
143
|
+
invalid: [
|
144
|
+
{
|
145
|
+
from: 'foo',
|
146
|
+
to: 'bar'
|
147
|
+
},
|
148
|
+
{
|
149
|
+
from: '2000-01-01',
|
150
|
+
to: 'future'
|
151
|
+
},
|
152
|
+
{
|
153
|
+
from: '2000-01-01'
|
154
|
+
}
|
155
|
+
]
|
156
|
+
});
|
157
|
+
});
|
158
|
+
|
159
|
+
context('date validations', () => {
|
160
|
+
testValidAndInvalid('veteranDateOfBirth', {
|
161
|
+
valid: ['2000-01-02'],
|
162
|
+
invalid: ['4/6/1998', 'Fri Aug 19 2016 15:09:46 GMT-0400 (EDT)']
|
163
|
+
});
|
164
|
+
});
|
165
|
+
|
166
|
+
context('tours of duty validation', () => {
|
167
|
+
testValidAndInvalid('toursOfDuty', {
|
168
|
+
valid: [[{
|
169
|
+
dateRange: validDateRange,
|
170
|
+
serviceBranch: 'navy',
|
171
|
+
serviceStatus: 'active',
|
172
|
+
involuntarilyCalledToDuty: 'yes',
|
173
|
+
benefitsToApplyTo: 'chapter30'
|
174
|
+
}]],
|
175
|
+
invalid: [
|
176
|
+
[{
|
177
|
+
serviceBranch: 'navy',
|
178
|
+
serviceStatus: 'active',
|
179
|
+
involuntarilyCalledToDuty: 'yes'
|
180
|
+
}],
|
181
|
+
[{
|
182
|
+
dateRange: validDateRange,
|
183
|
+
serviceBranch: 1,
|
184
|
+
serviceStatus: 'active',
|
185
|
+
involuntarilyCalledToDuty: 'yes'
|
186
|
+
}],
|
187
|
+
[{
|
188
|
+
dateRange: validDateRange,
|
189
|
+
serviceBranch: 'navy',
|
190
|
+
serviceStatus: 'active',
|
191
|
+
involuntarilyCalledToDuty: 'yes',
|
192
|
+
benefitsToApplyTo: ['chapter85968568']
|
193
|
+
}]
|
194
|
+
],
|
195
|
+
});
|
196
|
+
});
|
197
|
+
|
198
|
+
context('post high school trainings validation', () => {
|
199
|
+
testValidAndInvalid('postHighSchoolTrainings', {
|
200
|
+
valid: [[{
|
201
|
+
name: 'college',
|
202
|
+
dateRange: validDateRange,
|
203
|
+
city: 'new york',
|
204
|
+
hoursType: 'semester',
|
205
|
+
state: 'NY'
|
206
|
+
}]],
|
207
|
+
invalid: [
|
208
|
+
[{
|
209
|
+
name: 'college'
|
210
|
+
}],
|
211
|
+
[{
|
212
|
+
name: 'college',
|
213
|
+
dateRange: validDateRange,
|
214
|
+
city: 'new york',
|
215
|
+
hoursType: 'semestar',
|
216
|
+
state: 'NY'
|
217
|
+
}],
|
218
|
+
[{
|
219
|
+
name: 'college',
|
220
|
+
dateRange: validDateRange,
|
221
|
+
city: 'new york',
|
222
|
+
hoursType: 'semester',
|
223
|
+
state: 'ABC'
|
224
|
+
}]
|
225
|
+
]
|
226
|
+
});
|
227
|
+
});
|
228
|
+
|
229
|
+
context('non military jobs validation', () => {
|
230
|
+
testValidAndInvalid('nonMilitaryJobs', {
|
231
|
+
valid: [[{
|
232
|
+
name: 'president',
|
233
|
+
months: 9999,
|
234
|
+
postMilitaryJob: true
|
235
|
+
}]],
|
236
|
+
invalid: [[{
|
237
|
+
postMilitaryJob: true,
|
238
|
+
months: 1
|
239
|
+
}]]
|
240
|
+
});
|
241
|
+
});
|
242
|
+
|
243
|
+
context('senior rotc validation', () => {
|
244
|
+
testValidAndInvalid('seniorRotc', {
|
245
|
+
valid: [{
|
246
|
+
commissionYear: 1981,
|
247
|
+
rotcScholarshipAmounts: [{
|
248
|
+
year: 1999,
|
249
|
+
amount: 99.99
|
250
|
+
}]
|
251
|
+
}],
|
252
|
+
invalid: [{
|
253
|
+
commissionYear: 1981,
|
254
|
+
}]
|
255
|
+
});
|
256
|
+
});
|
257
|
+
|
258
|
+
context('email validation', () => {
|
259
|
+
testValidAndInvalid('email', {
|
260
|
+
valid: [
|
261
|
+
'foo@foo.com',
|
262
|
+
'foo+1@foo.com'
|
263
|
+
],
|
264
|
+
invalid: ['foo']
|
265
|
+
});
|
266
|
+
});
|
267
|
+
|
268
|
+
context('preferredContactMethod validation', () => {
|
269
|
+
testValidAndInvalid('preferredContactMethod', {
|
270
|
+
valid: [
|
271
|
+
'mail',
|
272
|
+
'email'
|
273
|
+
],
|
274
|
+
invalid: ['foo']
|
275
|
+
});
|
276
|
+
});
|
277
|
+
|
278
|
+
context('benefitsRelinquished validation', () => {
|
279
|
+
testValidAndInvalid('benefitsRelinquished', {
|
280
|
+
valid: ['chapter30', 'unknown', 'chapter1607', 'chapter1606'],
|
281
|
+
invalid: ['chapter33']
|
282
|
+
});
|
283
|
+
});
|
284
|
+
|
285
|
+
context('serviceBefore1977 validation', () => {
|
286
|
+
testValidAndInvalid('serviceBefore1977', {
|
287
|
+
valid: [{
|
288
|
+
married: true,
|
289
|
+
haveDependents: true,
|
290
|
+
parentDependent: false
|
291
|
+
}],
|
292
|
+
invalid: [{
|
293
|
+
married: true
|
294
|
+
}]
|
295
|
+
});
|
296
|
+
});
|
297
|
+
|
298
|
+
context('school validation', () => {
|
299
|
+
testValidAndInvalid('school', {
|
300
|
+
valid: [{
|
301
|
+
name: 'harvard'
|
302
|
+
}],
|
303
|
+
invalid: [{
|
304
|
+
name: true
|
305
|
+
}]
|
306
|
+
});
|
307
|
+
});
|
308
|
+
|
309
|
+
context('previous va claims validation', () => {
|
310
|
+
testValidAndInvalid('previousVaClaims', {
|
311
|
+
valid: [
|
312
|
+
[{
|
313
|
+
claimType: 'vocationalRehab'
|
314
|
+
}],
|
315
|
+
[{
|
316
|
+
claimType: 'vocationalRehab',
|
317
|
+
fileNumber: 'blah',
|
318
|
+
sponsorVeteran: {
|
319
|
+
fileNumber: 'number'
|
320
|
+
}
|
321
|
+
}]
|
322
|
+
],
|
323
|
+
invalid: [
|
324
|
+
[{
|
325
|
+
fileNumber: 'blah',
|
326
|
+
}]
|
327
|
+
]
|
328
|
+
});
|
329
|
+
});
|
330
|
+
});
|
data/test/mocha.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--compilers js:babel-register
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'vets_json_schema'
|
5
|
+
|
6
|
+
gem.version = JSON.parse(File.read('package.json'))['version']
|
7
|
+
gem.summary = 'JSON Schemas for all Vets.gov projects'
|
8
|
+
gem.author = 'VA devs'
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
|
+
gem.require_paths = ['lib']
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vets_json_schema
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- VA devs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".babelrc"
|
20
|
+
- ".gitattributes"
|
21
|
+
- ".gitignore"
|
22
|
+
- ".nvmrc"
|
23
|
+
- ".travis.yml"
|
24
|
+
- README.md
|
25
|
+
- dist/edu-benefits-schema.json
|
26
|
+
- lib/vets_json_schema.rb
|
27
|
+
- package.json
|
28
|
+
- src/common/constants.js
|
29
|
+
- src/edu-benefits/schema.js
|
30
|
+
- src/generate-schemas.js
|
31
|
+
- src/start.js
|
32
|
+
- src/watch.js
|
33
|
+
- test/edu-benefits/schema.spec.js
|
34
|
+
- test/mocha.opts
|
35
|
+
- vets_json_schema.gemspec
|
36
|
+
homepage:
|
37
|
+
licenses: []
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.5.1
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: JSON Schemas for all Vets.gov projects
|
59
|
+
test_files: []
|