adapt-authoring-content 3.0.5 → 3.0.6

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.
@@ -460,19 +460,6 @@ class ContentModule extends AbstractApiModule {
460
460
  friendlyIds.set(_type, { ids: await this.generateFriendlyIds(_type, newCourseId, count), next: 0 })
461
461
  }))
462
462
 
463
- // Pre-allocate sequential _trackingId for cloned blocks. Bulk insertMany
464
- // defeats SpoorTrackingModule's preInsertHook (which reads the current max
465
- // from the DB per-block), so without this every cloned block would get the
466
- // same id.
467
- const blockCount = typeCounts.get('block') ?? 0
468
- let nextTrackingId
469
- if (blockCount > 0) {
470
- const [{ _trackingId: maxTrackingId = 0 } = {}] = await this.find(
471
- { _courseId: newCourseId }, {}, { limit: 1, sort: [['_trackingId', -1]] }
472
- )
473
- nextTrackingId = maxTrackingId + 1
474
- }
475
-
476
463
  // Build all insert payloads with pre-mapped IDs and parent references
477
464
  const rootId = _id.toString()
478
465
  const payloads = allItems.map(item => {
@@ -497,7 +484,6 @@ class ContentModule extends AbstractApiModule {
497
484
  return stringifyValues({
498
485
  ...item,
499
486
  _id: newId,
500
- _trackingId: item._type === 'block' ? nextTrackingId++ : undefined,
501
487
  _friendlyId: friendlyId,
502
488
  _courseId: isCourse ? newId.toString() : newCourseId,
503
489
  _parentId: newParentId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-content",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
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",
@@ -517,15 +517,14 @@ describe('ContentModule', () => {
517
517
  assert.ok(inst.postInsertHook.invoke.mock.callCount() > 0)
518
518
  })
519
519
 
520
- it('should assign distinct sequential _trackingId values to cloned blocks', async () => {
521
- // Regression: bulk insertMany defeats SpoorTrackingModule's preInsertHook
522
- // which assumes each new block is persisted before the next hook runs.
523
- // The clone path must pre-allocate _trackingId so cloned blocks don't collide.
520
+ it('should delegate _trackingId assignment to preInsertHook (clone no longer allocates them)', async () => {
521
+ // Tracking IDs are owned by the spoortracking module, which taps preInsertHook. clone must
522
+ // fire that hook once per payload (so each cloned block can be assigned an id) and must not
523
+ // assign _trackingId itself. With no observer attached here, payloads pass through untouched.
524
524
  const BLOCK2_OID = '507f1f77bcf86cd79943a001'
525
525
  const BLOCK3_OID = '507f1f77bcf86cd79943a002'
526
526
 
527
527
  const { inst, mongodb } = createCloneInstance()
528
- inst.find = mock.fn(async () => [{ _trackingId: 7 }]) // existing max in course
529
528
 
530
529
  const items = [
531
530
  { _id: COURSE_OID, _type: 'course', _courseId: COURSE_OID },
@@ -539,18 +538,16 @@ describe('ContentModule', () => {
539
538
  const parent = { _id: COURSE_OID, _type: 'course', _courseId: COURSE_OID }
540
539
  await ContentModule.prototype.clone.call(inst, USER_OID, PAGE_OID, COURSE_OID, {}, { tree, parent })
541
540
 
541
+ // preInsertHook fired once per cloned payload — the seam the spoortracking observer uses.
542
+ // Cloning the page clones page + article + 3 blocks (5 items); the course is the source.
543
+ assert.equal(inst.preInsertHook.invoke.mock.callCount(), 5)
544
+ // every payload passed to the hook is a block/page/etc, and a block payload is present
545
+ const hookedTypes = inst.preInsertHook.invoke.mock.calls.map(c => c.arguments[0]._type)
546
+ assert.ok(hookedTypes.includes('block'))
547
+ // clone itself assigned nothing — block payloads still carry the (now irrelevant) source ids
542
548
  const inserted = mongodb.collection.insertMany.mock.calls[0].arguments[0]
543
549
  const blockTrackingIds = inserted.filter(d => d._type === 'block').map(d => d._trackingId)
544
- assert.equal(blockTrackingIds.length, 3)
545
- for (const id of blockTrackingIds) {
546
- assert.equal(typeof id, 'number', `block cloned without numeric _trackingId (got ${id})`)
547
- }
548
- // all distinct
549
- assert.equal(new Set(blockTrackingIds).size, blockTrackingIds.length, 'duplicate _trackingId among cloned blocks')
550
- // and continuing past the existing max
551
- for (const id of blockTrackingIds) {
552
- assert.ok(id > 7, `expected _trackingId > existing max (7), got ${id}`)
553
- }
550
+ assert.deepEqual(blockTrackingIds.sort(), [5, 6, 7])
554
551
  })
555
552
  })
556
553