From 4eddad479fd47fe68aea6f40e5d0a1119ea08d6b Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Fri, 24 Jan 2025 10:00:24 +0000 Subject: [PATCH 1/4] Added migration scripts --- migrations/v3.js | 36 ++++++++++++++++++++++++++++++++++++ migrations/v4.js | 42 ++++++++++++++++++++++++++++++++++++++++++ migrations/v6.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 migrations/v3.js create mode 100644 migrations/v4.js create mode 100644 migrations/v6.js diff --git a/migrations/v3.js b/migrations/v3.js new file mode 100644 index 0000000..3d0b6cf --- /dev/null +++ b/migrations/v3.js @@ -0,0 +1,36 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +const getGlobals = content => { + return getCourse(content)?._globals?._menu?._boxMenu; +}; + +describe('Box menu - v2.0.0 to v3.0.0', async () => { + let courseBoxMenuGlobals; + const durationLabel = 'Duration:'; + + whereFromPlugin('Box menu - from v2.0.0', { name: 'adapt-contrib-boxMenu', version: '<3.0.0' }); + + mutateContent('Box menu - add globals if missing', async (content) => { + courseBoxMenuGlobals = getGlobals(content); + if (courseBoxMenuGlobals) return true; + const course = getCourse(content); + course._globals._menu = course._globals._menu || {}; + courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + return true; + }); + mutateContent('Box menu - add new globals', async (content) => { + courseBoxMenuGlobals.durationLabel = durationLabel; + return true; + }); + + checkContent('Box menu - check new globals', async (content) => { + return getGlobals(content).durationLabel === durationLabel; + }); + + updatePlugin('Box menu - update to v3.0.0', { name: 'adapt-contrib-boxMenu', version: '3.0.0', framework: '">=2.1' }); +}); diff --git a/migrations/v4.js b/migrations/v4.js new file mode 100644 index 0000000..e29efe0 --- /dev/null +++ b/migrations/v4.js @@ -0,0 +1,42 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +const getGlobals = content => { + return getCourse(content)?._globals?._menu?._boxMenu; +}; + +describe('Box menu - v3.0.0 to v4.0.1', async () => { + let courseBoxMenuGlobals; + + whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.1' }); + + mutateContent('Box menu - add globals if missing', async (content) => { + courseBoxMenuGlobals = getGlobals(content); + if (courseBoxMenuGlobals) return true; + const course = getCourse(content); + course._globals._menu = course._globals._menu || {}; + courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + return true; + }); + mutateContent('Box menu - remove globals', async (content) => { + delete courseBoxMenuGlobals.ariaRegion; + delete courseBoxMenuGlobals.menuItem; + delete courseBoxMenuGlobals.menuEnd; + return true; + }); + + checkContent('Box menu - check globals', async (content) => { + const globals = getGlobals(content); + return ( + Object.hasOwn(globals, 'ariaRegion') === false && + Object.hasOwn(globals, 'menuItem') === false && + Object.hasOwn(globals, 'menuEnd') === false + ); + }); + + updatePlugin('Box menu - update to v4.0.1', { name: 'adapt-contrib-boxMenu', version: '4.0.1', framework: '">=4' }); +}); diff --git a/migrations/v6.js b/migrations/v6.js new file mode 100644 index 0000000..a907af5 --- /dev/null +++ b/migrations/v6.js @@ -0,0 +1,36 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +const getGlobals = content => { + return getCourse(content)?._globals?._menu?._boxMenu; +}; + +describe('Box menu - v5.5.0 to v6.7.0', async () => { + let courseBoxMenuGlobals; + const itemCount = 'Item {{_nthChild}} of {{_totalChild}}'; + + whereFromPlugin('Box menu - from v5.5.0', { name: 'adapt-contrib-boxMenu', version: '<6.7.0' }); + + mutateContent('Box menu - add globals if missing', async (content) => { + courseBoxMenuGlobals = getGlobals(content); + if (courseBoxMenuGlobals) return true; + const course = getCourse(content); + course._globals._menu = course._globals._menu || {}; + courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + return true; + }); + mutateContent('Box menu - add new globals', async (content) => { + courseBoxMenuGlobals.itemCount = itemCount; + return true; + }); + + checkContent('Box menu - check new globals', async (content) => { + return getGlobals(content).itemCount === itemCount; + }); + + updatePlugin('Box menu - update to v6.7.0', { name: 'adapt-contrib-boxMenu', version: '6.7.0', framework: '">=5.24.2' }); +}); From fa3b64320252ed64e97f4f9faaa18a91f3d901cd Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Tue, 28 Jan 2025 12:03:35 +0000 Subject: [PATCH 2/4] Migration corrections --- migrations/{v3.js => v2.js} | 9 ++- migrations/v4.js | 9 ++- migrations/v5.js | 82 +++++++++++++++++++++++++ migrations/v6.js | 116 +++++++++++++++++++++++++++++++++++- 4 files changed, 207 insertions(+), 9 deletions(-) rename migrations/{v3.js => v2.js} (74%) create mode 100644 migrations/v5.js diff --git a/migrations/v3.js b/migrations/v2.js similarity index 74% rename from migrations/v3.js rename to migrations/v2.js index 3d0b6cf..c8e4dd5 100644 --- a/migrations/v3.js +++ b/migrations/v2.js @@ -9,11 +9,14 @@ const getGlobals = content => { return getCourse(content)?._globals?._menu?._boxMenu; }; -describe('Box menu - v2.0.0 to v3.0.0', async () => { +describe('Box menu - v2.0.2 to v2.0.3', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v2.0.2..v2.0.3 + let courseBoxMenuGlobals; const durationLabel = 'Duration:'; - whereFromPlugin('Box menu - from v2.0.0', { name: 'adapt-contrib-boxMenu', version: '<3.0.0' }); + whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '<2.0.3' }); mutateContent('Box menu - add globals if missing', async (content) => { courseBoxMenuGlobals = getGlobals(content); @@ -32,5 +35,5 @@ describe('Box menu - v2.0.0 to v3.0.0', async () => { return getGlobals(content).durationLabel === durationLabel; }); - updatePlugin('Box menu - update to v3.0.0', { name: 'adapt-contrib-boxMenu', version: '3.0.0', framework: '">=2.1' }); + updatePlugin('Box menu - update to v2.0.3', { name: 'adapt-contrib-boxMenu', version: '2.0.3', framework: '">=2.0.0' }); }); diff --git a/migrations/v4.js b/migrations/v4.js index e29efe0..7d48642 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -9,10 +9,13 @@ const getGlobals = content => { return getCourse(content)?._globals?._menu?._boxMenu; }; -describe('Box menu - v3.0.0 to v4.0.1', async () => { +describe('Box menu - v3.0.0 to v4.0.0', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v3.0.0..v4.0.0 + let courseBoxMenuGlobals; - whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.1' }); + whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.0' }); mutateContent('Box menu - add globals if missing', async (content) => { courseBoxMenuGlobals = getGlobals(content); @@ -38,5 +41,5 @@ describe('Box menu - v3.0.0 to v4.0.1', async () => { ); }); - updatePlugin('Box menu - update to v4.0.1', { name: 'adapt-contrib-boxMenu', version: '4.0.1', framework: '">=4' }); + updatePlugin('Box menu - update to v4.0.0', { name: 'adapt-contrib-boxMenu', version: '4.0.0', framework: '">=4' }); }); diff --git a/migrations/v5.js b/migrations/v5.js new file mode 100644 index 0000000..2003e57 --- /dev/null +++ b/migrations/v5.js @@ -0,0 +1,82 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +const getGlobals = content => { + return getCourse(content)?._globals?._menu?._boxMenu; +}; + +describe('Box menu - v4.0.1 to v5.0.0', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v4.0.1..v5.0.0 + + const defaults = { + _backgroundImage: { + _large: '', + _medium: '', + _small: '' + }, + _backgroundStyles: { + _backgroundSize: '', + _backgroundRepeat: '', + _backgroundPosition: '' + }, + _menuHeader: { + _backgroundImage: { + _large: '', + _medium: '', + _small: '' + }, + _backgroundStyles: { + _backgroundSize: '', + _backgroundRepeat: '', + _backgroundPosition: '' + } + } + }; + + whereFromPlugin('Box menu - from v4.0.1', { name: 'adapt-contrib-boxMenu', version: '<5.5.0' }); + + mutateContent('Box menu - add config to course', async (content) => { + getCourse(content)._boxMenu = defaults; + return true; + }); + + checkContent('Box menu - check course config', async (content) => { + return getCourse(content)._boxMenu === defaults; + }); + + updatePlugin('Box menu - update to v5.0.0', { name: 'adapt-contrib-boxMenu', version: '5.0.0', framework: '">=5' }); +}); + +describe('Box menu - v5.0.0 to v5.1.0', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v5.0.0..v5.1.0 + + const defaults = { + _renderAsGroup: false + }; + + let contentObjects; + + whereFromPlugin('Box menu - from v5.0.0', { name: 'adapt-contrib-boxMenu', version: '<5.5.0' }); + + whereContent('Box menu - where content objects', async (content) => { + contentObjects = content.filter(({ _type }) => ['menu', 'page'].includes(_type)); + if (contentObjects.length > 0) return true; + }); + + mutateContent('Box menu - add config to content objects', async (content) => { + contentObjects.forEach(co => (co._boxMenu = defaults)); + return true; + }); + + checkContent('Box menu - check content objects config', async (content) => { + return contentObjects.every(co => co._boxMenu === defaults); + }); + + updatePlugin('Box menu - update to v5.1.0', { name: 'adapt-contrib-boxMenu', version: '5.1.0', framework: '">=5.7' }); +}); diff --git a/migrations/v6.js b/migrations/v6.js index a907af5..b810ca1 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -9,11 +9,120 @@ const getGlobals = content => { return getCourse(content)?._globals?._menu?._boxMenu; }; -describe('Box menu - v5.5.0 to v6.7.0', async () => { +describe('Box menu - v6.0.2 to v6.1.0', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.0.2..v6.1.0 + + let course; + const defaultTextAlignment = { + _title: '', + _body: '', + _instruction: '' + }; + + whereFromPlugin('Box menu - from v6.0.2', { name: 'adapt-contrib-boxMenu', version: '<6.1.0' }); + + whereContent('Box menu - where course has _menuHeader', async (content) => { + course = getCourse(content); + return course?._boxMenu?._menuHeader; + }); + + mutateContent('Box menu - add _textAlignment attribute', async (content) => { + course._boxMenu._menuHeader._textAlignment = defaultTextAlignment; + return true; + }); + + checkContent('Box menu - check _textAlignment attribute', async (content) => { + return course._boxMenu._menuHeader._textAlignment === defaultTextAlignment; + }); + + updatePlugin('Box menu - update to v6.1.0', { name: 'adapt-contrib-boxMenu', version: '6.1.0', framework: '">=5.22.6' }); +}); + +describe('Box menu - v6.2.0 to v6.2.1', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.2.0..v6.2.1 + + let course; + const defaultGraphic = { + _src: '', + alt: '' + }; + + whereFromPlugin('Box menu - from v6.2.0', { name: 'adapt-contrib-boxMenu', version: '<6.2.1' }); + + whereContent('Box menu - where course has _boxMenu', async (content) => { + course = getCourse(content); + return course?._boxMenu; + }); + + mutateContent('Box menu - add _graphic attribute', async (content) => { + course._boxMenu._graphic = defaultGraphic; + return true; + }); + + checkContent('Box menu - check _graphic attribute', async (content) => { + return course._boxMenu._graphic === defaultGraphic; + }); + + updatePlugin('Box menu - update to v6.2.1', { name: 'adapt-contrib-boxMenu', version: '6.2.1', framework: '">=5.24.2' }); +}); + +describe('Box menu - v6.3.8 to v6.3.9', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.3.8..v6.3.9 + + let course; + + whereFromPlugin('Box menu - from v6.3.8', { name: 'adapt-contrib-boxMenu', version: '<6.3.9' }); + + whereContent('Box menu - where course has _backgroundImage', async (content) => { + course = getCourse(content); + return ( + course?._boxMenu?._backgroundImage || + course?._boxMenu?._menuHeader?._backgroundImage + ); + }); + + mutateContent('Box menu - add _xlarge attribute', async (content) => { + if (course._boxMenu._backgroundImage) { + course._boxMenu._backgroundImage._xlarge = ''; + } + return true; + }); + + mutateContent('Box menu - add _xlarge attribute to _menuHeader', async (content) => { + if (course._boxMenu._menuHeader._backgroundImage) { + course._boxMenu._menuHeader._backgroundImage._xlarge = ''; + } + return true; + }); + + checkContent('Box menu - check _xlarge attribute', async (content) => { + return ( + !course._boxMenu._backgroundImage || + course._boxMenu._backgroundImage._xlarge === '' + ); + }); + + checkContent('Box menu - check _xlarge attribute for _menuHeader', async (content) => { + return ( + !course._boxMenu._menuHeader?._backgroundImage || + course._boxMenu._menuHeader._backgroundImage._xlarge === '' + ); + }); + + updatePlugin('Box menu - update to v6.3.9', { name: 'adapt-contrib-boxMenu', version: '6.3.9', framework: '">=5.24.2' }); +}); + +describe('Box menu - v6.3.9 to v6.3.10', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.3.9..v6.3.10 + let courseBoxMenuGlobals; const itemCount = 'Item {{_nthChild}} of {{_totalChild}}'; - whereFromPlugin('Box menu - from v5.5.0', { name: 'adapt-contrib-boxMenu', version: '<6.7.0' }); + whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: ' { courseBoxMenuGlobals = getGlobals(content); @@ -23,6 +132,7 @@ describe('Box menu - v5.5.0 to v6.7.0', async () => { courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; return true; }); + mutateContent('Box menu - add new globals', async (content) => { courseBoxMenuGlobals.itemCount = itemCount; return true; @@ -32,5 +142,5 @@ describe('Box menu - v5.5.0 to v6.7.0', async () => { return getGlobals(content).itemCount === itemCount; }); - updatePlugin('Box menu - update to v6.7.0', { name: 'adapt-contrib-boxMenu', version: '6.7.0', framework: '">=5.24.2' }); + updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: 'v6.3.10', framework: '">=5.24.2' }); }); From 915d06376d4cbd3cb72f1e5bf4b90bb204f78042 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Wed, 29 Jan 2025 10:31:13 +0000 Subject: [PATCH 3/4] Migration corrections --- migrations/v5.js | 82 ------------------------------------------------ 1 file changed, 82 deletions(-) delete mode 100644 migrations/v5.js diff --git a/migrations/v5.js b/migrations/v5.js deleted file mode 100644 index 2003e57..0000000 --- a/migrations/v5.js +++ /dev/null @@ -1,82 +0,0 @@ -import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; - -const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); - return course; -}; - -const getGlobals = content => { - return getCourse(content)?._globals?._menu?._boxMenu; -}; - -describe('Box menu - v4.0.1 to v5.0.0', async () => { - - // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v4.0.1..v5.0.0 - - const defaults = { - _backgroundImage: { - _large: '', - _medium: '', - _small: '' - }, - _backgroundStyles: { - _backgroundSize: '', - _backgroundRepeat: '', - _backgroundPosition: '' - }, - _menuHeader: { - _backgroundImage: { - _large: '', - _medium: '', - _small: '' - }, - _backgroundStyles: { - _backgroundSize: '', - _backgroundRepeat: '', - _backgroundPosition: '' - } - } - }; - - whereFromPlugin('Box menu - from v4.0.1', { name: 'adapt-contrib-boxMenu', version: '<5.5.0' }); - - mutateContent('Box menu - add config to course', async (content) => { - getCourse(content)._boxMenu = defaults; - return true; - }); - - checkContent('Box menu - check course config', async (content) => { - return getCourse(content)._boxMenu === defaults; - }); - - updatePlugin('Box menu - update to v5.0.0', { name: 'adapt-contrib-boxMenu', version: '5.0.0', framework: '">=5' }); -}); - -describe('Box menu - v5.0.0 to v5.1.0', async () => { - - // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v5.0.0..v5.1.0 - - const defaults = { - _renderAsGroup: false - }; - - let contentObjects; - - whereFromPlugin('Box menu - from v5.0.0', { name: 'adapt-contrib-boxMenu', version: '<5.5.0' }); - - whereContent('Box menu - where content objects', async (content) => { - contentObjects = content.filter(({ _type }) => ['menu', 'page'].includes(_type)); - if (contentObjects.length > 0) return true; - }); - - mutateContent('Box menu - add config to content objects', async (content) => { - contentObjects.forEach(co => (co._boxMenu = defaults)); - return true; - }); - - checkContent('Box menu - check content objects config', async (content) => { - return contentObjects.every(co => co._boxMenu === defaults); - }); - - updatePlugin('Box menu - update to v5.1.0', { name: 'adapt-contrib-boxMenu', version: '5.1.0', framework: '">=5.7' }); -}); From 61cafe9b431fa4590b702d7ae25f8385f69cf8d6 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Thu, 6 Feb 2025 14:14:59 +0000 Subject: [PATCH 4/4] Review amendments --- migrations/v2.js | 18 ++++++++++-------- migrations/v4.js | 20 +++++++++++--------- migrations/v6.js | 33 +++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/migrations/v2.js b/migrations/v2.js index c8e4dd5..e353146 100644 --- a/migrations/v2.js +++ b/migrations/v2.js @@ -1,7 +1,8 @@ import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import _ from 'lodash'; const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); + const course = content.find(({ _type }) => _type === 'course'); return course; }; @@ -13,26 +14,27 @@ describe('Box menu - v2.0.2 to v2.0.3', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v2.0.2..v2.0.3 - let courseBoxMenuGlobals; + let course, courseBoxMenuGlobals; const durationLabel = 'Duration:'; whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '<2.0.3' }); mutateContent('Box menu - add globals if missing', async (content) => { - courseBoxMenuGlobals = getGlobals(content); - if (courseBoxMenuGlobals) return true; - const course = getCourse(content); - course._globals._menu = course._globals._menu || {}; - courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + course = getCourse(content); + if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); + courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; }); + mutateContent('Box menu - add new globals', async (content) => { courseBoxMenuGlobals.durationLabel = durationLabel; return true; }); checkContent('Box menu - check new globals', async (content) => { - return getGlobals(content).durationLabel === durationLabel; + const isValid = getGlobals(content).durationLabel === durationLabel; + if (!isValid) throw new Error('Box menu - global attribute durationLabel'); + return true; }); updatePlugin('Box menu - update to v2.0.3', { name: 'adapt-contrib-boxMenu', version: '2.0.3', framework: '">=2.0.0' }); diff --git a/migrations/v4.js b/migrations/v4.js index 7d48642..206f87b 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -1,7 +1,8 @@ import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import _ from 'lodash'; const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); + const course = content.find(({ _type }) => _type === 'course'); return course; }; @@ -12,19 +13,18 @@ const getGlobals = content => { describe('Box menu - v3.0.0 to v4.0.0', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v3.0.0..v4.0.0 - - let courseBoxMenuGlobals; + + let course, courseBoxMenuGlobals; whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.0' }); mutateContent('Box menu - add globals if missing', async (content) => { - courseBoxMenuGlobals = getGlobals(content); - if (courseBoxMenuGlobals) return true; - const course = getCourse(content); - course._globals._menu = course._globals._menu || {}; - courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + course = getCourse(content); + if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); + courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; }); + mutateContent('Box menu - remove globals', async (content) => { delete courseBoxMenuGlobals.ariaRegion; delete courseBoxMenuGlobals.menuItem; @@ -34,11 +34,13 @@ describe('Box menu - v3.0.0 to v4.0.0', async () => { checkContent('Box menu - check globals', async (content) => { const globals = getGlobals(content); - return ( + const isValid = ( Object.hasOwn(globals, 'ariaRegion') === false && Object.hasOwn(globals, 'menuItem') === false && Object.hasOwn(globals, 'menuEnd') === false ); + if (!isValid) throw new Error('Box menu - global attributes ariaRegion menuItem menuEnd'); + return true; }); updatePlugin('Box menu - update to v4.0.0', { name: 'adapt-contrib-boxMenu', version: '4.0.0', framework: '">=4' }); diff --git a/migrations/v6.js b/migrations/v6.js index b810ca1..d7340c6 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -1,7 +1,8 @@ import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import _ from 'lodash'; const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); + const course = content.find(({ _type }) => _type === 'course'); return course; }; @@ -33,7 +34,9 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { }); checkContent('Box menu - check _textAlignment attribute', async (content) => { - return course._boxMenu._menuHeader._textAlignment === defaultTextAlignment; + const isValid = _.isEqual(course._boxMenu._menuHeader._textAlignment, defaultTextAlignment); + if (!isValid) throw new Error('Box menu - course attribute _textAlignment'); + return true; }); updatePlugin('Box menu - update to v6.1.0', { name: 'adapt-contrib-boxMenu', version: '6.1.0', framework: '">=5.22.6' }); @@ -62,7 +65,9 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { }); checkContent('Box menu - check _graphic attribute', async (content) => { - return course._boxMenu._graphic === defaultGraphic; + const isValid = _.isEqual(course._boxMenu._graphic, defaultGraphic); + if (!isValid) throw new Error('Box menu - course attribute _graphic'); + return true; }); updatePlugin('Box menu - update to v6.2.1', { name: 'adapt-contrib-boxMenu', version: '6.2.1', framework: '">=5.24.2' }); @@ -99,17 +104,21 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { }); checkContent('Box menu - check _xlarge attribute', async (content) => { - return ( + const isValid = ( !course._boxMenu._backgroundImage || course._boxMenu._backgroundImage._xlarge === '' ); + if (!isValid) throw new Error('Box menu - course attribute _xlarge'); + return true; }); checkContent('Box menu - check _xlarge attribute for _menuHeader', async (content) => { - return ( + const isValid = ( !course._boxMenu._menuHeader?._backgroundImage || course._boxMenu._menuHeader._backgroundImage._xlarge === '' ); + if (!isValid) throw new Error('Box menu - course attribute _xlarge'); + return true; }); updatePlugin('Box menu - update to v6.3.9', { name: 'adapt-contrib-boxMenu', version: '6.3.9', framework: '">=5.24.2' }); @@ -119,17 +128,15 @@ describe('Box menu - v6.3.9 to v6.3.10', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.3.9..v6.3.10 - let courseBoxMenuGlobals; + let course, courseBoxMenuGlobals; const itemCount = 'Item {{_nthChild}} of {{_totalChild}}'; whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: ' { - courseBoxMenuGlobals = getGlobals(content); - if (courseBoxMenuGlobals) return true; - const course = getCourse(content); - course._globals._menu = course._globals._menu || {}; - courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + course = getCourse(content); + if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); + courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; }); @@ -139,7 +146,9 @@ describe('Box menu - v6.3.9 to v6.3.10', async () => { }); checkContent('Box menu - check new globals', async (content) => { - return getGlobals(content).itemCount === itemCount; + const isValid = getGlobals(content).itemCount === itemCount; + if (!isValid) throw new Error('Box menu - global attribute itemCount'); + return true; }); updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: 'v6.3.10', framework: '">=5.24.2' });