Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions lib/ContentModule.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AbstractApiModule } from 'adapt-authoring-api'
import { getDescendants } from './utils.js'
import { Hook, stringifyValues } from 'adapt-authoring-core'
import apidefs from './apidefs.js'
/**
* Module which handles course content
* @memberof content
Expand All @@ -10,19 +9,8 @@ import apidefs from './apidefs.js'
class ContentModule extends AbstractApiModule {
/** @override */
async setValues () {
/** @ignore */ this.root = this.collectionName = this.schemaName = 'content'
this.useDefaultRouteConfig()
this.routes.push({
route: '/insertrecursive',
handlers: { post: this.handleInsertRecursive.bind(this) },
permissions: { post: ['write:content'] },
meta: apidefs.insertrecursive
}, {
route: '/clone',
handlers: { post: this.handleClone.bind(this) },
permissions: { post: ['write:content'] },
meta: apidefs.clone
})
/** @ignore */ this.collectionName = this.schemaName = 'content'
// root and route definitions are configured declaratively via routes.json
}

/** @override */
Expand Down
15 changes: 15 additions & 0 deletions routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"root": "content",
"routes": [
{
"route": "/insertrecursive",
"handlers": { "post": "handleInsertRecursive" },
"permissions": { "post": ["write:${scope}"] }
},
{
"route": "/clone",
"handlers": { "post": "handleClone" },
"permissions": { "post": ["write:${scope}"] }
}
]
}
37 changes: 1 addition & 36 deletions tests/ContentModule.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,48 +97,13 @@ describe('ContentModule', () => {
// setValues
// -----------------------------------------------------------------------
describe('setValues', () => {
it('should set root, collectionName and schemaName to "content"', async () => {
it('should set collectionName and schemaName to "content"', async () => {
const inst = createInstance()
await ContentModule.prototype.setValues.call(inst)

assert.equal(inst.root, 'content')
assert.equal(inst.collectionName, 'content')
assert.equal(inst.schemaName, 'content')
})

it('should call useDefaultRouteConfig', async () => {
const inst = createInstance()
await ContentModule.prototype.setValues.call(inst)

assert.equal(inst.useDefaultRouteConfig.mock.callCount(), 1)
})

it('should push insertrecursive and clone routes', async () => {
const inst = createInstance()
await ContentModule.prototype.setValues.call(inst)

assert.equal(inst.routes.length, 2)
assert.equal(inst.routes[0].route, '/insertrecursive')
assert.equal(inst.routes[1].route, '/clone')
})

it('should assign correct HTTP methods for insertrecursive route', async () => {
const inst = createInstance()
await ContentModule.prototype.setValues.call(inst)

const route = inst.routes[0]
assert.ok(route.handlers.post)
assert.deepEqual(route.permissions, { post: ['write:content'] })
})

it('should assign correct HTTP methods for clone route', async () => {
const inst = createInstance()
await ContentModule.prototype.setValues.call(inst)

const route = inst.routes[1]
assert.ok(route.handlers.post)
assert.deepEqual(route.permissions, { post: ['write:content'] })
})
})

// -----------------------------------------------------------------------
Expand Down
Loading