adapt-authoring-adaptframework 2.6.0 → 3.0.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.
@@ -0,0 +1,101 @@
1
+ import { describe, it, mock } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import fs from 'node:fs'
4
+ import os from 'node:os'
5
+ import path from 'node:path'
6
+
7
+ const testCachePath = fs.mkdtempSync(path.join(os.tmpdir(), 'runContentMigration-test-'))
8
+
9
+ const mockLoad = mock.fn(async () => {})
10
+ const mockMigrate = mock.fn(async ({ journal }) => {
11
+ journal.data.content[0].title = 'migrated'
12
+ })
13
+
14
+ class FakeJournal {
15
+ constructor ({ data }) {
16
+ this.data = data
17
+ }
18
+ }
19
+
20
+ class FakeLogger {
21
+ info () {}
22
+ error () {}
23
+ warn () {}
24
+ debug () {}
25
+ log () {}
26
+ }
27
+
28
+ mock.module('adapt-migrations', {
29
+ namedExports: {
30
+ load: mockLoad,
31
+ migrate: mockMigrate,
32
+ Journal: FakeJournal,
33
+ Logger: { getInstance: () => new FakeLogger() }
34
+ }
35
+ })
36
+
37
+ const { runContentMigration } = await import('../lib/utils/runContentMigration.js')
38
+
39
+ describe('runContentMigration()', () => {
40
+ it('should call load with scripts and logger', async () => {
41
+ mockLoad.mock.resetCalls()
42
+ const scripts = ['/path/to/migration.js']
43
+ await runContentMigration({
44
+ content: [{ _id: 'c1', title: 'old' }],
45
+ fromPlugins: [{ name: 'core', version: '1.0.0' }],
46
+ toPlugins: [{ name: 'core', version: '2.0.0' }],
47
+ scripts,
48
+ cachePath: testCachePath
49
+ })
50
+ assert.equal(mockLoad.mock.calls.length, 1)
51
+ assert.deepEqual(mockLoad.mock.calls[0].arguments[0].scripts, scripts)
52
+ })
53
+
54
+ it('should create a Journal with correct data shape', async () => {
55
+ mockMigrate.mock.resetCalls()
56
+ await runContentMigration({
57
+ content: [{ _id: 'c1', title: 'old' }],
58
+ fromPlugins: [{ name: 'core', version: '1.0.0' }],
59
+ toPlugins: [{ name: 'core', version: '2.0.0' }],
60
+ scripts: [],
61
+ cachePath: testCachePath
62
+ })
63
+ assert.equal(mockMigrate.mock.calls.length, 1)
64
+ const journal = mockMigrate.mock.calls[0].arguments[0].journal
65
+ assert.ok(journal.data.content)
66
+ assert.ok(journal.data.fromPlugins)
67
+ assert.ok(journal.data.originalFromPlugins)
68
+ assert.ok(journal.data.toPlugins)
69
+ })
70
+
71
+ it('should return mutated content', async () => {
72
+ mockMigrate.mock.resetCalls()
73
+ mockMigrate.mock.mockImplementation(async ({ journal }) => {
74
+ journal.data.content[0].title = 'migrated'
75
+ })
76
+ const result = await runContentMigration({
77
+ content: [{ _id: 'c1', title: 'old' }],
78
+ fromPlugins: [{ name: 'core', version: '1.0.0' }],
79
+ toPlugins: [{ name: 'core', version: '2.0.0' }],
80
+ scripts: [],
81
+ cachePath: testCachePath
82
+ })
83
+ assert.equal(result[0].title, 'migrated')
84
+ })
85
+
86
+ it('should deep-clone fromPlugins into originalFromPlugins', async () => {
87
+ mockMigrate.mock.resetCalls()
88
+ mockMigrate.mock.mockImplementation(async () => {})
89
+ const fromPlugins = [{ name: 'core', version: '1.0.0' }]
90
+ await runContentMigration({
91
+ content: [{ _id: 'c1' }],
92
+ fromPlugins,
93
+ toPlugins: [{ name: 'core', version: '2.0.0' }],
94
+ scripts: [],
95
+ cachePath: testCachePath
96
+ })
97
+ const journal = mockMigrate.mock.calls[0].arguments[0].journal
98
+ assert.deepEqual(journal.data.originalFromPlugins, fromPlugins)
99
+ assert.notEqual(journal.data.originalFromPlugins, journal.data.fromPlugins)
100
+ })
101
+ })