-
Notifications
You must be signed in to change notification settings - Fork 38
/
curation.js
112 lines (97 loc) · 4.42 KB
/
curation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const { expect } = require('chai')
const fs = require('fs')
const path = require('path')
const yaml = require('js-yaml')
const Curation = require('../../lib/curation')
function getFixture(file) {
return fs.readFileSync(path.join(__dirname, '../fixtures', file), { encoding: 'utf8' })
}
describe('Curations', () => {
it('should identify invalid yaml files', () => {
const content = '@#$%%'
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].message).to.equal('Invalid yaml')
})
it('should identify invalid date', () => {
const content = getFixture('curation-invalid.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('Release date must be formatted as a YYYY-MM-DD')
})
it('should identify invalid facet array', () => {
const content = getFixture('curation-invalid.1.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('Coordinates object require type, provider, namespace, and name')
expect(curation.errors[1].error.message).to.equal('Glob list must be an array')
})
it('should identify invalid facet field: unknown', () => {
const content = getFixture('curation-invalid.2.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal(
'Facets object can only contain data, dev, doc, examples, and tests'
)
})
it('should identify invalid field: facets not in licensed', () => {
const content = getFixture('curation-invalid.3.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('Licensed object can only contain declared')
})
it('should identify invalid coordinate provider (test enum)', () => {
const content = getFixture('curation-invalid.4.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('Provider type must be supported by ClearlyDefined')
})
it('should identify invalid revision (no revision)', () => {
const content = getFixture('curation-invalid.5.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('Revisions must be an object')
})
it('should identify invalid source location (no revision)', () => {
const content = getFixture('curation-invalid.6.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('Revision must be a string')
})
it('should identify invalid source location (url not URI format)', () => {
const content = getFixture('curation-invalid.7.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('URL must be formatted as a URI')
})
it('should identify invalid file (missing required path)', () => {
const content = getFixture('curation-invalid.8.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('Files elements object requires path')
})
it('should identify invalid declared license (incorrect key)', () => {
const content = getFixture('curation-invalid.9.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.false
expect(curation.errors[0].error.message).to.equal('Licensed object can only contain declared')
})
it('should identify valid curations', () => {
const content = getFixture('curation-valid.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.true
expect(curation.errors.length).to.not.be.ok
})
it('should identify valid curations (all fields)', () => {
const content = getFixture('curation-valid.1.yaml')
const curation = new Curation(content)
expect(curation.isValid).to.be.true
expect(curation.errors.length).to.not.be.ok
})
it('should also accept yaml data objects', () => {
const data = yaml.safeLoad('foo: bar')
const curation = new Curation(data)
expect(curation.isValid).to.be.false
expect(curation.errors[0].message).to.equal('Invalid curation')
})
})