adapt-authoring-tags 1.2.1 → 1.3.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.
- package/lib/TagsModule.js +1 -46
- package/package.json +2 -2
- package/routes.json +48 -0
- package/tests/TagsModule.spec.js +5 -44
package/lib/TagsModule.js
CHANGED
|
@@ -14,7 +14,7 @@ class TagsModule extends AbstractApiModule {
|
|
|
14
14
|
|
|
15
15
|
/** @override */
|
|
16
16
|
async setValues () {
|
|
17
|
-
|
|
17
|
+
await super.setValues()
|
|
18
18
|
/** @ignore */ this.schemaName = 'tag'
|
|
19
19
|
/** @ignore */ this.schemaExtensionName = 'tags'
|
|
20
20
|
/** @ignore */ this.collectionName = 'tags'
|
|
@@ -23,51 +23,6 @@ class TagsModule extends AbstractApiModule {
|
|
|
23
23
|
* @type {Array<AbstractApiModule>}
|
|
24
24
|
*/
|
|
25
25
|
this.modules = []
|
|
26
|
-
|
|
27
|
-
this.useDefaultRouteConfig()
|
|
28
|
-
|
|
29
|
-
this.routes = [{
|
|
30
|
-
route: '/autocomplete',
|
|
31
|
-
handlers: { get: this.autocompleteHandler.bind(this) },
|
|
32
|
-
permissions: { get: ['read:content'] },
|
|
33
|
-
meta: {
|
|
34
|
-
get: {
|
|
35
|
-
summary: 'Retrieve tags for UI autocomplete',
|
|
36
|
-
description: 'A streamlined query API to allow searching of tag data.',
|
|
37
|
-
parameters: [{ name: 'term', in: 'query', description: 'Search term', required: true }],
|
|
38
|
-
responses: {
|
|
39
|
-
200: {
|
|
40
|
-
content: {
|
|
41
|
-
'application/json': {
|
|
42
|
-
schema: {
|
|
43
|
-
type: 'array',
|
|
44
|
-
items: {
|
|
45
|
-
type: 'object',
|
|
46
|
-
properties: {
|
|
47
|
-
_id: { type: 'string' },
|
|
48
|
-
title: { type: 'string' },
|
|
49
|
-
value: { type: 'string' }
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}, {
|
|
60
|
-
route: '/transfer/:_id',
|
|
61
|
-
handlers: { post: this.transferHandler.bind(this) },
|
|
62
|
-
permissions: { post: ['write:content'] },
|
|
63
|
-
modifying: false,
|
|
64
|
-
meta: {
|
|
65
|
-
post: {
|
|
66
|
-
summary: 'Transfer tag',
|
|
67
|
-
description: 'Transfers all items using one tag for another.'
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}, ...this.routes]
|
|
71
26
|
// make title unique
|
|
72
27
|
const mongodb = await this.app.waitForModule('mongodb')
|
|
73
28
|
return mongodb.setIndex(this.collectionName, 'title', { unique: true })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-tags",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Module for managing tags",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-tags",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"adapt-authoring-api": "^
|
|
47
|
+
"adapt-authoring-api": "^3.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"adapt-authoring-core": "^2.0.0",
|
package/routes.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": "tags",
|
|
3
|
+
"routes": [
|
|
4
|
+
{
|
|
5
|
+
"route": "/autocomplete",
|
|
6
|
+
"handlers": { "get": "autocompleteHandler" },
|
|
7
|
+
"permissions": { "get": ["read:content"] },
|
|
8
|
+
"meta": {
|
|
9
|
+
"get": {
|
|
10
|
+
"summary": "Retrieve tags for UI autocomplete",
|
|
11
|
+
"description": "A streamlined query API to allow searching of tag data.",
|
|
12
|
+
"parameters": [{ "name": "term", "in": "query", "description": "Search term", "required": true }],
|
|
13
|
+
"responses": {
|
|
14
|
+
"200": {
|
|
15
|
+
"content": {
|
|
16
|
+
"application/json": {
|
|
17
|
+
"schema": {
|
|
18
|
+
"type": "array",
|
|
19
|
+
"items": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": {
|
|
22
|
+
"_id": { "type": "string" },
|
|
23
|
+
"title": { "type": "string" },
|
|
24
|
+
"value": { "type": "string" }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"route": "/transfer/:_id",
|
|
37
|
+
"modifying": false,
|
|
38
|
+
"handlers": { "post": "transferHandler" },
|
|
39
|
+
"permissions": { "post": ["write:content"] },
|
|
40
|
+
"meta": {
|
|
41
|
+
"post": {
|
|
42
|
+
"summary": "Transfer tag",
|
|
43
|
+
"description": "Transfers all items using one tag for another."
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
package/tests/TagsModule.spec.js
CHANGED
|
@@ -55,25 +55,10 @@ function createInstance (overrides = {}) {
|
|
|
55
55
|
|
|
56
56
|
describe('TagsModule', () => {
|
|
57
57
|
describe('#setValues()', () => {
|
|
58
|
-
it('should set root to "tags"', async () => {
|
|
59
|
-
const { instance } = createInstance()
|
|
60
|
-
instance.root = undefined
|
|
61
|
-
instance.schemaName = undefined
|
|
62
|
-
instance.schemaExtensionName = undefined
|
|
63
|
-
instance.collectionName = undefined
|
|
64
|
-
instance.modules = undefined
|
|
65
|
-
instance.routes = undefined
|
|
66
|
-
// useDefaultRouteConfig normally sets this.routes; mock must do the same
|
|
67
|
-
instance.useDefaultRouteConfig = mock.fn(function () { this.routes = [] })
|
|
68
|
-
await instance.setValues()
|
|
69
|
-
assert.equal(instance.root, 'tags')
|
|
70
|
-
})
|
|
71
|
-
|
|
72
58
|
it('should set schemaName to "tag"', async () => {
|
|
73
59
|
const { instance } = createInstance()
|
|
74
|
-
instance.root = undefined
|
|
75
60
|
instance.schemaName = undefined
|
|
76
|
-
|
|
61
|
+
Object.getPrototypeOf(TagsModule.prototype).setValues = mock.fn(async function () {})
|
|
77
62
|
await instance.setValues()
|
|
78
63
|
assert.equal(instance.schemaName, 'tag')
|
|
79
64
|
})
|
|
@@ -81,7 +66,7 @@ describe('TagsModule', () => {
|
|
|
81
66
|
it('should set schemaExtensionName to "tags"', async () => {
|
|
82
67
|
const { instance } = createInstance()
|
|
83
68
|
instance.schemaExtensionName = undefined
|
|
84
|
-
|
|
69
|
+
Object.getPrototypeOf(TagsModule.prototype).setValues = mock.fn(async function () {})
|
|
85
70
|
await instance.setValues()
|
|
86
71
|
assert.equal(instance.schemaExtensionName, 'tags')
|
|
87
72
|
})
|
|
@@ -89,7 +74,7 @@ describe('TagsModule', () => {
|
|
|
89
74
|
it('should set collectionName to "tags"', async () => {
|
|
90
75
|
const { instance } = createInstance()
|
|
91
76
|
instance.collectionName = undefined
|
|
92
|
-
|
|
77
|
+
Object.getPrototypeOf(TagsModule.prototype).setValues = mock.fn(async function () {})
|
|
93
78
|
await instance.setValues()
|
|
94
79
|
assert.equal(instance.collectionName, 'tags')
|
|
95
80
|
})
|
|
@@ -97,38 +82,14 @@ describe('TagsModule', () => {
|
|
|
97
82
|
it('should initialise modules as an empty array', async () => {
|
|
98
83
|
const { instance } = createInstance()
|
|
99
84
|
instance.modules = undefined
|
|
100
|
-
|
|
85
|
+
Object.getPrototypeOf(TagsModule.prototype).setValues = mock.fn(async function () {})
|
|
101
86
|
await instance.setValues()
|
|
102
87
|
assert.deepEqual(instance.modules, [])
|
|
103
88
|
})
|
|
104
89
|
|
|
105
|
-
it('should call useDefaultRouteConfig', async () => {
|
|
106
|
-
const { instance } = createInstance()
|
|
107
|
-
instance.useDefaultRouteConfig = mock.fn(function () { this.routes = [] })
|
|
108
|
-
await instance.setValues()
|
|
109
|
-
assert.equal(instance.useDefaultRouteConfig.mock.calls.length, 1)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('should add autocomplete and transfer routes', async () => {
|
|
113
|
-
const { instance } = createInstance()
|
|
114
|
-
instance.useDefaultRouteConfig = mock.fn(function () { this.routes = [] })
|
|
115
|
-
await instance.setValues()
|
|
116
|
-
|
|
117
|
-
const autocompleteRoute = instance.routes.find(r => r.route === '/autocomplete')
|
|
118
|
-
assert.ok(autocompleteRoute, 'autocomplete route should exist')
|
|
119
|
-
assert.ok(autocompleteRoute.handlers.get, 'autocomplete should have GET handler')
|
|
120
|
-
assert.deepEqual(autocompleteRoute.permissions.get, ['read:content'])
|
|
121
|
-
|
|
122
|
-
const transferRoute = instance.routes.find(r => r.route === '/transfer/:_id')
|
|
123
|
-
assert.ok(transferRoute, 'transfer route should exist')
|
|
124
|
-
assert.ok(transferRoute.handlers.post, 'transfer should have POST handler')
|
|
125
|
-
assert.deepEqual(transferRoute.permissions.post, ['write:content'])
|
|
126
|
-
assert.equal(transferRoute.modifying, false)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
90
|
it('should call mongodb.setIndex for unique title', async () => {
|
|
130
91
|
const { instance, mockMongodb } = createInstance()
|
|
131
|
-
|
|
92
|
+
Object.getPrototypeOf(TagsModule.prototype).setValues = mock.fn(async function () {})
|
|
132
93
|
await instance.setValues()
|
|
133
94
|
assert.equal(mockMongodb.setIndex.mock.calls.length, 1)
|
|
134
95
|
const call = mockMongodb.setIndex.mock.calls[0]
|