adapt-authoring-api 3.1.2 → 3.1.4
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/AbstractApiModule.js
CHANGED
|
@@ -123,7 +123,7 @@ class AbstractApiModule extends AbstractModule {
|
|
|
123
123
|
|
|
124
124
|
const config = await loadRouteConfig(this.rootDir, this, {
|
|
125
125
|
schema: 'apiroutes',
|
|
126
|
-
defaults:
|
|
126
|
+
defaults: `${import.meta.dirname}/../default-routes.json`
|
|
127
127
|
})
|
|
128
128
|
if (config) this.applyRouteConfig(config)
|
|
129
129
|
}
|
|
@@ -381,7 +381,7 @@ class AbstractApiModule extends AbstractModule {
|
|
|
381
381
|
}
|
|
382
382
|
if (Array.isArray(data) && req.params._id) { // special case for when _id param is present
|
|
383
383
|
if (!data.length) {
|
|
384
|
-
return next(this.app.errors.NOT_FOUND.setData({ id: req.params.
|
|
384
|
+
return next(this.app.errors.NOT_FOUND.setData({ id: req.params._id, type: req.apiData.schemaName }))
|
|
385
385
|
}
|
|
386
386
|
data = data[0]
|
|
387
387
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-api",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "Abstract module for creating APIs",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-api",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"adapt-authoring-core": "^2.0.0",
|
|
15
|
+
"adapt-authoring-server": "^2.1.0",
|
|
15
16
|
"lodash": "^4.17.21"
|
|
16
17
|
},
|
|
17
18
|
"peerDependencies": {
|
|
18
19
|
"adapt-authoring-auth": "^2.0.0",
|
|
19
20
|
"adapt-authoring-jsonschema": "^1.2.0",
|
|
20
|
-
"adapt-authoring-mongodb": "^3.0.0"
|
|
21
|
-
"adapt-authoring-server": "^2.1.0"
|
|
21
|
+
"adapt-authoring-mongodb": "^3.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@semantic-release/git": "^10.0.1",
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { describe, it } from 'node:test'
|
|
1
|
+
import { before, describe, it } from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
|
+
import { readJson } from 'adapt-authoring-core'
|
|
3
4
|
import AbstractApiModule from '../lib/AbstractApiModule.js'
|
|
4
5
|
|
|
6
|
+
let defaultRoutes
|
|
7
|
+
before(async () => {
|
|
8
|
+
defaultRoutes = await readJson(`${import.meta.dirname}/../default-routes.json`)
|
|
9
|
+
})
|
|
10
|
+
|
|
5
11
|
function createInstance (overrides = {}) {
|
|
6
12
|
const instance = Object.create(AbstractApiModule.prototype)
|
|
7
13
|
instance.root = 'test'
|
|
@@ -136,44 +142,40 @@ describe('AbstractApiModule', () => {
|
|
|
136
142
|
})
|
|
137
143
|
})
|
|
138
144
|
|
|
139
|
-
describe('
|
|
140
|
-
it('should
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
assert.ok(Array.isArray(routes))
|
|
144
|
-
assert.ok(routes.length > 0)
|
|
145
|
+
describe('default-routes.json', () => {
|
|
146
|
+
it('should define an array of route objects', () => {
|
|
147
|
+
assert.ok(Array.isArray(defaultRoutes.routes))
|
|
148
|
+
assert.ok(defaultRoutes.routes.length > 0)
|
|
145
149
|
})
|
|
146
150
|
|
|
147
|
-
it('should include routes for /, /schema, /:_id, and /query',
|
|
148
|
-
const
|
|
149
|
-
const routes = await instance.DEFAULT_ROUTES
|
|
150
|
-
const routePaths = routes.map(r => r.route)
|
|
151
|
+
it('should include routes for /, /schema, /:_id, and /query', () => {
|
|
152
|
+
const routePaths = defaultRoutes.routes.map(r => r.route)
|
|
151
153
|
assert.ok(routePaths.includes('/'))
|
|
152
154
|
assert.ok(routePaths.includes('/schema'))
|
|
153
155
|
assert.ok(routePaths.includes('/:_id'))
|
|
154
156
|
assert.ok(routePaths.includes('/query'))
|
|
155
157
|
})
|
|
156
158
|
|
|
157
|
-
it('should use permissionsScope when set',
|
|
159
|
+
it('should use permissionsScope when set', () => {
|
|
158
160
|
const instance = createInstance({ root: 'content', permissionsScope: 'custom' })
|
|
159
|
-
|
|
160
|
-
const rootRoute = routes.find(r => r.route === '/')
|
|
161
|
+
instance.applyRouteConfig({ root: 'content', permissionsScope: 'custom', routes: defaultRoutes.routes })
|
|
162
|
+
const rootRoute = instance.routes.find(r => r.route === '/')
|
|
161
163
|
assert.ok(rootRoute.permissions.post.includes('write:custom'))
|
|
162
164
|
assert.ok(rootRoute.permissions.get.includes('read:custom'))
|
|
163
165
|
})
|
|
164
166
|
|
|
165
|
-
it('should fall back to root for permissions when permissionsScope is not set',
|
|
167
|
+
it('should fall back to root for permissions when permissionsScope is not set', () => {
|
|
166
168
|
const instance = createInstance({ root: 'content', permissionsScope: undefined })
|
|
167
|
-
|
|
168
|
-
const rootRoute = routes.find(r => r.route === '/')
|
|
169
|
+
instance.applyRouteConfig({ root: 'content', routes: defaultRoutes.routes })
|
|
170
|
+
const rootRoute = instance.routes.find(r => r.route === '/')
|
|
169
171
|
assert.ok(rootRoute.permissions.post.includes('write:content'))
|
|
170
172
|
assert.ok(rootRoute.permissions.get.includes('read:content'))
|
|
171
173
|
})
|
|
172
174
|
|
|
173
|
-
it('should set validate: false and modifying: false on /query route',
|
|
175
|
+
it('should set validate: false and modifying: false on /query route', () => {
|
|
174
176
|
const instance = createInstance()
|
|
175
|
-
|
|
176
|
-
const queryRoute = routes.find(r => r.route === '/query')
|
|
177
|
+
instance.applyRouteConfig({ root: 'test', routes: defaultRoutes.routes })
|
|
178
|
+
const queryRoute = instance.routes.find(r => r.route === '/query')
|
|
177
179
|
assert.equal(queryRoute.validate, false)
|
|
178
180
|
assert.equal(queryRoute.modifying, false)
|
|
179
181
|
})
|
|
File without changes
|