adapt-authoring-content 3.2.1 → 3.2.2

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.
@@ -571,6 +571,8 @@ class ContentModule extends AbstractApiModule {
571
571
  if (originalDoc._courseId?.toString() !== payloads[0]._courseId?.toString()) {
572
572
  await this.updateEnabledPlugins(payloads[0])
573
573
  }
574
+ // place the clone at its requested _sortOrder and renumber siblings (no-op for course/config)
575
+ await this.updateSortOrder(payloads[0], payloads[0])
574
576
 
575
577
  return payloads[0]
576
578
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-content",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
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",
@@ -384,6 +384,7 @@ describe('ContentModule', () => {
384
384
  }),
385
385
  getSchema: mock.fn(async () => ({})),
386
386
  updateEnabledPlugins: mock.fn(async () => {}),
387
+ updateSortOrder: mock.fn(async () => {}),
387
388
  preCloneHook: { invoke: mock.fn(async () => {}) },
388
389
  preInsertHook: { invoke: mock.fn(async () => {}) },
389
390
  postInsertHook: { invoke: mock.fn(async () => {}) },
@@ -460,6 +461,25 @@ describe('ContentModule', () => {
460
461
  assert.equal(result._type, 'course')
461
462
  })
462
463
 
464
+ it('should renumber siblings for the cloned root so it lands at its _sortOrder', async () => {
465
+ const { inst } = createCloneInstance()
466
+
467
+ const items = [
468
+ { _id: COURSE_OID, _type: 'course', _courseId: COURSE_OID },
469
+ { _id: PAGE_OID, _type: 'page', _parentId: COURSE_OID, _courseId: COURSE_OID }
470
+ ]
471
+ const tree = new ContentTree(items)
472
+ const parent = { _id: COURSE_OID, _type: 'course', _courseId: COURSE_OID }
473
+ const result = await ContentModule.prototype.clone.call(inst, USER_OID, PAGE_OID, COURSE_OID, { _sortOrder: 1 }, { tree, parent })
474
+
475
+ assert.equal(inst.updateSortOrder.mock.callCount(), 1)
476
+ const [item, updateData] = inst.updateSortOrder.mock.calls[0].arguments
477
+ // called with the root payload (truthy updateData triggers the splice/renumber path)
478
+ assert.equal(item, result)
479
+ assert.ok(updateData)
480
+ assert.equal(item._sortOrder, 1)
481
+ })
482
+
463
483
  it('should remap parent IDs correctly', async () => {
464
484
  const { inst, mongodb } = createCloneInstance()
465
485