adapt-authoring-api 3.1.1 → 3.1.3

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.
@@ -1,4 +1,4 @@
1
- name: Standard.js formatting check
1
+ name: Lint
2
2
  on: push
3
3
  jobs:
4
4
  default:
@@ -10,3 +10,4 @@ jobs:
10
10
  node-version: 'lts/*'
11
11
  - run: npm install
12
12
  - run: npx standard
13
+
@@ -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: new URL('./default-routes.json', import.meta.url).pathname
126
+ defaults: `${import.meta.dirname}/../default-routes.json`
127
127
  })
128
128
  if (config) this.applyRouteConfig(config)
129
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-api",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
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",
@@ -17,10 +17,6 @@
17
17
  "type": "boolean",
18
18
  "description": "Whether to generate default CRUD routes",
19
19
  "default": true
20
- },
21
- "routes": {
22
- "type": "array",
23
- "items": { "$ref": "routeitem" }
24
20
  }
25
21
  }
26
22
  }
@@ -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('#DEFAULT_ROUTES', () => {
140
- it('should return an array of route objects', async () => {
141
- const instance = createInstance()
142
- const routes = await instance.DEFAULT_ROUTES
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', async () => {
148
- const instance = createInstance()
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', async () => {
159
+ it('should use permissionsScope when set', () => {
158
160
  const instance = createInstance({ root: 'content', permissionsScope: 'custom' })
159
- const routes = await instance.DEFAULT_ROUTES
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', async () => {
167
+ it('should fall back to root for permissions when permissionsScope is not set', () => {
166
168
  const instance = createInstance({ root: 'content', permissionsScope: undefined })
167
- const routes = await instance.DEFAULT_ROUTES
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', async () => {
175
+ it('should set validate: false and modifying: false on /query route', () => {
174
176
  const instance = createInstance()
175
- const routes = await instance.DEFAULT_ROUTES
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
  })