@tillhub/schemas 6.465.0 → 6.465.1
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.
- package/lib/v0/tags/create.js +10 -1
- package/lib/v0/tags/update.js +10 -1
- package/package.json +1 -1
- package/test/tags/tags.v0.spec.js +42 -0
- package/test/tags/tags.v0.specs.js +0 -20
package/lib/v0/tags/create.js
CHANGED
package/lib/v0/tags/update.js
CHANGED
|
@@ -7,7 +7,16 @@ module.exports.request = {
|
|
|
7
7
|
additionalProperties: false,
|
|
8
8
|
type: 'object',
|
|
9
9
|
required: [],
|
|
10
|
-
properties:
|
|
10
|
+
properties: {
|
|
11
|
+
...base,
|
|
12
|
+
name: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
minLength: 1,
|
|
15
|
+
not: {
|
|
16
|
+
pattern: '^\\s|\\s$'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
module.exports.response = {
|
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const test = require('tape')
|
|
2
|
+
const Ajv = require('ajv')
|
|
3
|
+
const validate = require('../helpers/validate-schema')
|
|
4
|
+
const tags = require('../../lib/v0/tags')
|
|
5
|
+
|
|
6
|
+
test('Tags: create schema validation', function (t) {
|
|
7
|
+
t.plan(2)
|
|
8
|
+
const createRequest = require('../../lib/v0/tags').create.request
|
|
9
|
+
const { valid, error } = validate(createRequest)
|
|
10
|
+
t.ok(valid, 'create schema is valid')
|
|
11
|
+
t.error(error, 'should not get any error')
|
|
12
|
+
t.end()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('Tags: update schema validation', function (t) {
|
|
16
|
+
t.plan(2)
|
|
17
|
+
const updateRequest = require('../../lib/v0/tags').update.request
|
|
18
|
+
const { valid, error } = validate(updateRequest)
|
|
19
|
+
t.ok(valid, 'update schema is valid')
|
|
20
|
+
t.error(error, 'should not get any error')
|
|
21
|
+
t.end()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
for (const operation of ['create', 'update']) {
|
|
25
|
+
test(`Tags: ${operation} rejects empty names and surrounding whitespace`, function (t) {
|
|
26
|
+
const validateRequest = new Ajv().compile(tags[operation].request)
|
|
27
|
+
|
|
28
|
+
for (const name of [
|
|
29
|
+
'', ' ', '\t\n', null, 42,
|
|
30
|
+
' green', 'green ', ' green ',
|
|
31
|
+
'\tgreen', 'green\t', 'green\n', 'green\r\n',
|
|
32
|
+
'\u00a0green', 'green\u00a0', '\ufeffgreen', 'green\ufeff'
|
|
33
|
+
]) {
|
|
34
|
+
t.notOk(validateRequest({ name }), `rejects name ${JSON.stringify(name)}`)
|
|
35
|
+
}
|
|
36
|
+
for (const name of ['g', 'green', 'Grüner Tee', 'Grüner Tee', '🟢']) {
|
|
37
|
+
t.ok(validateRequest({ name }), `accepts name ${JSON.stringify(name)}`)
|
|
38
|
+
}
|
|
39
|
+
t.equal(validateRequest({ deleted: true }), operation === 'update', 'only updates may omit the name')
|
|
40
|
+
t.end()
|
|
41
|
+
})
|
|
42
|
+
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const test = require('tape')
|
|
2
|
-
const validate = require('../helpers/validate-schema')
|
|
3
|
-
|
|
4
|
-
test('Tags: create schema validation', function (t) {
|
|
5
|
-
t.plan(2)
|
|
6
|
-
const createRequest = require('../../lib/v0/tags').create.request
|
|
7
|
-
const { valid, error } = validate(createRequest)
|
|
8
|
-
t.ok(valid, 'create schema is valid')
|
|
9
|
-
t.error(error, 'should not get any error')
|
|
10
|
-
t.end()
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('Tags: update schema validation', function (t) {
|
|
14
|
-
t.plan(2)
|
|
15
|
-
const updateRequest = require('../../lib/v0/tags').update.request
|
|
16
|
-
const { valid, error } = validate(updateRequest)
|
|
17
|
-
t.ok(valid, 'update schema is valid')
|
|
18
|
-
t.error(error, 'should not get any error')
|
|
19
|
-
t.end()
|
|
20
|
-
})
|