adapt-authoring-jsonschema 1.2.2 → 1.4.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.
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
on: push
|
|
3
|
+
jobs:
|
|
4
|
+
default:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
permissions:
|
|
7
|
+
contents: read
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v4
|
|
10
|
+
- uses: actions/setup-node@v4
|
|
11
|
+
with:
|
|
12
|
+
node-version: 'lts/*'
|
|
13
|
+
cache: 'npm'
|
|
14
|
+
- run: npm ci
|
|
15
|
+
- run: npm test
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-jsonschema",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Module to add support for the JSON schema specification",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-jsonschema",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"repository": "github:adapt-security/adapt-authoring-jsonschema",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"adapt-schemas": "
|
|
14
|
+
"adapt-schemas": "github:cgkineo/adapt-schemas#issue/12"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"adapt-authoring-config": "^1.1.4",
|
|
@@ -61,5 +61,8 @@
|
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
]
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"test": "node --test 'tests/**/*.spec.js'"
|
|
64
67
|
}
|
|
65
68
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { describe, it, mock } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import JsonSchemaModule from '../lib/JsonSchemaModule.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* JsonSchemaModule extends AbstractModule and requires App.instance + adapt-schemas.
|
|
7
|
+
* We test the thin wrapper methods and logSchemas logic.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
function createInstance () {
|
|
11
|
+
const mockSchemas = {
|
|
12
|
+
schemas: {},
|
|
13
|
+
schemaExtensions: {},
|
|
14
|
+
xssWhitelist: {},
|
|
15
|
+
validator: {},
|
|
16
|
+
options: { enableCache: true },
|
|
17
|
+
on: mock.fn(),
|
|
18
|
+
init: mock.fn(async () => {}),
|
|
19
|
+
addKeyword: mock.fn(),
|
|
20
|
+
addStringFormats: mock.fn(),
|
|
21
|
+
registerSchema: mock.fn(async () => ({ name: 'test' })),
|
|
22
|
+
deregisterSchema: mock.fn(),
|
|
23
|
+
extendSchema: mock.fn(),
|
|
24
|
+
getSchema: mock.fn(async () => ({ name: 'test' })),
|
|
25
|
+
resetSchemaRegistry: mock.fn(async () => {}),
|
|
26
|
+
createSchema: mock.fn(async () => ({ name: 'test' }))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const mockApp = {
|
|
30
|
+
waitForModule: mock.fn(async () => {}),
|
|
31
|
+
errors: {
|
|
32
|
+
MISSING_SCHEMA: { setData: mock.fn(function () { return this }) }
|
|
33
|
+
},
|
|
34
|
+
jsonschema: null,
|
|
35
|
+
dependencies: {},
|
|
36
|
+
dependencyloader: {
|
|
37
|
+
moduleLoadedHook: { tap: () => {}, untap: () => {} }
|
|
38
|
+
},
|
|
39
|
+
onReady: mock.fn(async () => {})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const originalInit = JsonSchemaModule.prototype.init
|
|
43
|
+
JsonSchemaModule.prototype.init = async function () {}
|
|
44
|
+
|
|
45
|
+
const instance = new JsonSchemaModule(mockApp, { name: 'adapt-authoring-jsonschema' })
|
|
46
|
+
|
|
47
|
+
JsonSchemaModule.prototype.init = originalInit
|
|
48
|
+
|
|
49
|
+
instance._library = mockSchemas
|
|
50
|
+
|
|
51
|
+
return { instance, mockApp, mockSchemas }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe('JsonSchemaModule', () => {
|
|
55
|
+
describe('#schemas', () => {
|
|
56
|
+
it('should return the library schemas', () => {
|
|
57
|
+
const { instance, mockSchemas } = createInstance()
|
|
58
|
+
mockSchemas.schemas = { test: { name: 'test' } }
|
|
59
|
+
assert.deepEqual(instance.schemas, { test: { name: 'test' } })
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe('#schemaExtensions', () => {
|
|
64
|
+
it('should return the library schemaExtensions', () => {
|
|
65
|
+
const { instance, mockSchemas } = createInstance()
|
|
66
|
+
mockSchemas.schemaExtensions = { ext: {} }
|
|
67
|
+
assert.deepEqual(instance.schemaExtensions, { ext: {} })
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('#xssWhitelist', () => {
|
|
72
|
+
it('should return the library xssWhitelist', () => {
|
|
73
|
+
const { instance, mockSchemas } = createInstance()
|
|
74
|
+
mockSchemas.xssWhitelist = { a: ['href'] }
|
|
75
|
+
assert.deepEqual(instance.xssWhitelist, { a: ['href'] })
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
describe('#validator', () => {
|
|
80
|
+
it('should return the library validator', () => {
|
|
81
|
+
const { instance, mockSchemas } = createInstance()
|
|
82
|
+
mockSchemas.validator = { validate: () => {} }
|
|
83
|
+
assert.equal(instance.validator, mockSchemas.validator)
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('#resetSchemaRegistry()', () => {
|
|
88
|
+
it('should call the library resetSchemaRegistry', async () => {
|
|
89
|
+
const { instance, mockSchemas } = createInstance()
|
|
90
|
+
await instance.resetSchemaRegistry()
|
|
91
|
+
assert.equal(mockSchemas.resetSchemaRegistry.mock.calls.length, 1)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
describe('#addStringFormats()', () => {
|
|
96
|
+
it('should call the library addStringFormats', () => {
|
|
97
|
+
const { instance, mockSchemas } = createInstance()
|
|
98
|
+
instance.addStringFormats({ email: /.*/ })
|
|
99
|
+
assert.equal(mockSchemas.addStringFormats.mock.calls.length, 1)
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
describe('#addKeyword()', () => {
|
|
104
|
+
it('should call the library addKeyword', () => {
|
|
105
|
+
const { instance, mockSchemas } = createInstance()
|
|
106
|
+
instance.addKeyword({ keyword: 'test' })
|
|
107
|
+
assert.equal(mockSchemas.addKeyword.mock.calls.length, 1)
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
describe('#deregisterSchema()', () => {
|
|
112
|
+
it('should call the library deregisterSchema', () => {
|
|
113
|
+
const { instance, mockSchemas } = createInstance()
|
|
114
|
+
instance.deregisterSchema('test')
|
|
115
|
+
assert.equal(mockSchemas.deregisterSchema.mock.calls.length, 1)
|
|
116
|
+
assert.equal(mockSchemas.deregisterSchema.mock.calls[0].arguments[0], 'test')
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
describe('#extendSchema()', () => {
|
|
121
|
+
it('should call the library extendSchema with correct args', () => {
|
|
122
|
+
const { instance, mockSchemas } = createInstance()
|
|
123
|
+
instance.extendSchema('base', 'ext')
|
|
124
|
+
assert.equal(mockSchemas.extendSchema.mock.calls.length, 1)
|
|
125
|
+
assert.equal(mockSchemas.extendSchema.mock.calls[0].arguments[0], 'base')
|
|
126
|
+
assert.equal(mockSchemas.extendSchema.mock.calls[0].arguments[1], 'ext')
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
describe('#logSchemas()', () => {
|
|
131
|
+
it('should call log with schema names', () => {
|
|
132
|
+
const { instance, mockSchemas } = createInstance()
|
|
133
|
+
mockSchemas.schemas = {
|
|
134
|
+
schema1: { extensions: ['ext1'] },
|
|
135
|
+
schema2: { extensions: [] }
|
|
136
|
+
}
|
|
137
|
+
instance.log = mock.fn()
|
|
138
|
+
instance.logSchemas()
|
|
139
|
+
assert.equal(instance.log.mock.calls.length, 2)
|
|
140
|
+
assert.equal(instance.log.mock.calls[0].arguments[0], 'debug')
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
})
|