adapt-authoring-content 3.2.4 → 3.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.
@@ -694,6 +694,7 @@ class ContentModule extends AbstractApiModule {
694
694
  '_theme',
695
695
  '_enabledPlugins',
696
696
  '_colorLabel',
697
+ '_language',
697
698
  'heroImage',
698
699
  'updatedAt'
699
700
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-content",
3
- "version": "3.2.4",
3
+ "version": "3.3.0",
4
4
  "description": "Module for managing Adapt content",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-content",
6
6
  "license": "GPL-3.0",
package/tests/_ht.js DELETED
@@ -1,116 +0,0 @@
1
- import { describe, it, mock } from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import ContentModule from '../lib/ContentModule.js'
5
-
6
- const COURSE_ID = '507f1f77bcf86cd799439011'
7
-
8
- function createMockCollection (overrides = {}) {
9
- return {
10
- findOne: mock.fn(async () => null),
11
- updateOne: mock.fn(async () => {}),
12
- findOneAndUpdate: mock.fn(async () => ({ seq: 1 })),
13
- find: mock.fn(() => ({ toArray: mock.fn(async () => []) })),
14
- deleteMany: mock.fn(async () => {}),
15
- ...overrides
16
- }
17
- }
18
-
19
- function createMockMongodb (collectionOverrides) {
20
- const col = createMockCollection(collectionOverrides)
21
- return { getCollection: mock.fn(() => col), collection: col }
22
- }
23
-
24
- function createInstance (overrides = {}) {
25
- return {
26
- schemaName: 'content',
27
- collectionName: 'content',
28
- counterCollectionName: 'contentcounters',
29
- idInterval: 5,
30
- contentplugin: { findOne: mock.fn(async () => null) },
31
- jsonschema: { extendSchema: mock.fn() },
32
- authored: { schemaName: 'authored' },
33
- tags: { schemaExtensionName: 'tags' },
34
- mongodb: createMockMongodb(),
35
- find: mock.fn(async () => []),
36
- findOne: mock.fn(async () => null),
37
- ...overrides
38
- }
39
- }
40
-
41
- describe('ContentModule', () => {
42
- describe('handleTree', () => {
43
- it('should return 304 when content has not been modified', async () => {
44
- const lastModified = new Date('2025-01-01T00:00:00Z')
45
- const inst = createInstance({
46
- findOne: mock.fn(async () => ({ updatedAt: lastModified }))
47
- })
48
- let statusCode
49
- let ended = false
50
- const req = {
51
- apiData: { query: { _courseId: COURSE_ID } },
52
- headers: { 'if-modified-since': new Date('2025-01-02T00:00:00Z').toUTCString() }
53
- }
54
- const res = {
55
- status: mock.fn(function (code) { statusCode = code; return this }),
56
- end: mock.fn(() => { ended = true })
57
- }
58
- const next = mock.fn()
59
- await ContentModule.prototype.handleTree.call(inst, req, res, next)
60
- assert.equal(statusCode, 304)
61
- assert.equal(ended, true)
62
- assert.equal(next.mock.callCount(), 0)
63
- })
64
-
65
- it('should return items with _children when content has been modified', async () => {
66
- const lastModified = new Date('2025-01-15T00:00:00Z')
67
- const items = [
68
- { _id: COURSE_ID, _type: 'course', _courseId: COURSE_ID },
69
- { _id: 'page1', _type: 'page', _parentId: COURSE_ID, _courseId: COURSE_ID },
70
- { _id: 'art1', _type: 'article', _parentId: 'page1', _courseId: COURSE_ID }
71
- ]
72
- const inst = createInstance({
73
- findOne: mock.fn(async () => ({ updatedAt: lastModified })),
74
- find: mock.fn(async () => items)
75
- })
76
- const req = {
77
- apiData: { query: { _courseId: COURSE_ID } },
78
- headers: {}
79
- }
80
- let responseData
81
- let lastModifiedHeader
82
- const res = {
83
- set: mock.fn((key, val) => { if (key === 'Last-Modified') lastModifiedHeader = val }),
84
- json: mock.fn((data) => { responseData = data })
85
- }
86
- const next = mock.fn()
87
- await ContentModule.prototype.handleTree.call(inst, req, res, next)
88
-
89
- assert.equal(next.mock.callCount(), 0)
90
- assert.equal(responseData.length, 3)
91
- // course should have page1 as child
92
- const course = responseData.find(i => i._id === COURSE_ID)
93
- assert.deepEqual(course._children, ['page1'])
94
- // page should have art1 as child
95
- const page = responseData.find(i => i._id === 'page1')
96
- assert.deepEqual(page._children, ['art1'])
97
- // article should have no children
98
- const art = responseData.find(i => i._id === 'art1')
99
- assert.deepEqual(art._children, [])
100
- // Last-Modified header should be set
101
- assert.equal(lastModifiedHeader, lastModified.toUTCString())
102
- })
103
-
104
- it('should call next on error', async () => {
105
- const inst = createInstance({
106
- findOne: mock.fn(async () => { throw new Error('db error') })
107
- })
108
- const req = { apiData: { query: { _courseId: COURSE_ID } }, headers: {} }
109
- const res = {}
110
- const next = mock.fn()
111
- await ContentModule.prototype.handleTree.call(inst, req, res, next)
112
- assert.equal(next.mock.callCount(), 1)
113
- assert.equal(next.mock.calls[0].arguments[0].message, 'db error')
114
- })
115
- })
116
- })