From a9c5fc871318f80e979cd73e0b64405e9343aaa2 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Wed, 29 Jan 2025 14:36:23 +0000 Subject: [PATCH 1/3] Added migration scripts --- migrations/v2.js | 84 ++++++++++++++++++++++++++++ migrations/v3.js | 141 +++++++++++++++++++++++++++++++++++++++++++++++ migrations/v4.js | 30 ++++++++++ 3 files changed, 255 insertions(+) create mode 100644 migrations/v2.js create mode 100644 migrations/v3.js create mode 100644 migrations/v4.js diff --git a/migrations/v2.js b/migrations/v2.js new file mode 100644 index 0000000..54fc05b --- /dev/null +++ b/migrations/v2.js @@ -0,0 +1,84 @@ +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?._extensions?._glossary; +}; + +describe('Glossary - v2.0.3 to v2.1.0', async () => { + // https://github.com/adaptlearning/adapt-contrib-glossary/compare/v2.0.3..v2.1.0 + + let course; + + whereFromPlugin('Glossary - from v2.0.3', { name: 'adapt-contrib-glossary', version: '<2.1.0' }); + + whereContent('Glossary - where configured', async (content) => { + course = getCourse(content); + if (course._glossary) return true; + }); + + mutateContent('Glossary - add _drawerOrder attribute', async (content) => { + course._glossary._drawerOrder = 0; + return true; + }); + + checkContent('Glossary - check _drawerOrder attribute', async (content) => { + return course._glossary._drawerOrder === 0; + }); + + updatePlugin('Glossary - update to v2.1.0', { name: 'adapt-contrib-glossary', version: '2.1.0', framework: '">=2.2.0' }); +}); + +describe('Glossary - v2.1.0 to v2.1.1', async () => { + // https://github.com/adaptlearning/adapt-contrib-glossary/compare/v2.1.0..v2.1.1 + + let course, courseGlossaryGlobals; + + whereFromPlugin('Glossary - from v2.1.0', { name: 'adapt-contrib-glossary', version: '<2.1.1' }); + + mutateContent('Glossary - add globals if missing', async (content) => { + course = getCourse(content); + courseGlossaryGlobals = getGlobals(content); + if (courseGlossaryGlobals) return true; + course._globals._extensions = course._globals._extensions || {}; + courseGlossaryGlobals = course._globals._extensions._glossary = {}; + return true; + }); + + mutateContent('Glossary - add new globals', async (content) => { + courseGlossaryGlobals.glossary = 'Glossary'; + return true; + }); + + mutateContent('Glossary - add attribute clearSearch', async (content) => { + if (!course._glossary) return true; + course._glossary.clearSearch = ''; + return true; + }); + + mutateContent('Glossary - add attribute searchItemsAlert', async (content) => { + if (!course._glossary) return true; + course._glossary.searchItemsAlert = '{{filteredItems.length}} found.'; + return true; + }); + + checkContent('Glossary - check new globals', async (content) => { + return getGlobals(content).glossary === 'Glossary'; + }); + + checkContent('Glossary - check attribute clearSearch', async (content) => { + if (!course._glossary) return true; + return course._glossary.clearSearch === ''; + }); + + checkContent('Glossary - check attribute searchItemsAlert', async (content) => { + if (!course._glossary) return true; + return course._glossary.searchItemsAlert === ''; + }); + + updatePlugin('Glossary - update to v2.1.1', { name: 'adapt-contrib-glossary', version: '2.1.1', framework: '">=2.2.5' }); +}); diff --git a/migrations/v3.js b/migrations/v3.js new file mode 100644 index 0000000..bc022a8 --- /dev/null +++ b/migrations/v3.js @@ -0,0 +1,141 @@ +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?._extensions?._glossary; +}; + +describe('Glossary - v2.1.3 to v3.0.0', async () => { + // https://github.com/adaptlearning/adapt-contrib-glossary/compare/v2.1.3..v3.0.0 + + let course, courseGlossaryGlobals; + + whereFromPlugin('Glossary - from v2.1.3', { name: 'adapt-contrib-glossary', version: '<3.0.0' }); + + mutateContent('Glossary - add globals if missing', async (content) => { + course = getCourse(content); + courseGlossaryGlobals = getGlobals(content); + if (courseGlossaryGlobals) return true; + course._globals._extensions = course._globals._extensions || {}; + courseGlossaryGlobals = course._globals._extensions._glossary = {}; + return true; + }); + + mutateContent('Glossary - add new globals', async (content) => { + courseGlossaryGlobals.labelLink = 'Terms beginning with'; + courseGlossaryGlobals.labelNavigation = 'Glossary navigation'; + return true; + }); + + mutateContent('Glossary - change default title', async (content) => { + if (course._glossary?.title !== '') return true; + course._glossary.title = 'Glossary'; + return true; + }); + + mutateContent('Glossary - change default description', async (content) => { + if (course._glossary?.description !== '') return true; + course._glossary.description = 'Select here to view the glossary for this course'; + return true; + }); + + mutateContent('Glossary - change default clearSearch', async (content) => { + if (course._glossary?.clearSearch !== '') return true; + course._glossary.clearSearch = 'Clear search'; + return true; + }); + + mutateContent('Glossary - change default searchItemsAlert', async (content) => { + if (course._glossary?.searchItemsAlert !== '{{filteredItems.length}} found.') return true; + course._glossary.searchItemsAlert = '{{filteredItems.length}} found'; + return true; + }); + + mutateContent('Glossary - change default searchPlaceholder', async (content) => { + if (course._glossary?.searchPlaceholder !== '') return true; + course._glossary.searchPlaceholder = 'Search'; + return true; + }); + + mutateContent('Glossary - change default searchWithInDescriptionLabel', async (content) => { + if (course._glossary?.searchWithInDescriptionLabel !== '') return true; + course._glossary.searchWithInDescriptionLabel = 'Search within Description'; + return true; + }); + + mutateContent('Glossary - add attribute _isSearchEnabled', async (content) => { + if (!course._glossary) return true; + course._glossary._isSearchEnabled = true; + return true; + }); + + mutateContent('Glossary - add attribute _isIndexEnabled', async (content) => { + if (!course._glossary) return true; + course._glossary._isIndexEnabled = false; + return true; + }); + + mutateContent('Glossary - add attribute _isGroupHeadersEnabled', async (content) => { + if (!course._glossary) return true; + course._glossary._isGroupHeadersEnabled = false; + return true; + }); + + checkContent('Glossary - check new globals', async (content) => { + return ( + getGlobals(content).labelLink === 'Terms beginning with' && + getGlobals(content).labelNavigation === 'Glossary navigation' + ); + }); + + checkContent('Glossary - check default title', async (content) => { + return course._glossary?.title !== ''; + }); + + checkContent('Glossary - check default description', async (content) => { + return course._glossary?.description !== ''; + }); + + checkContent('Glossary - check default clearSearch', async (content) => { + return course._glossary?.clearSearch !== ''; + }); + + checkContent('Glossary - check default searchItemsAlert', async (content) => { + return course._glossary?.searchItemsAlert !== '{{filteredItems.length}} found.'; + }); + + checkContent('Glossary - check default searchPlaceholder', async (content) => { + return course._glossary?.searchPlaceholder !== ''; + }); + + checkContent('Glossary - check default searchWithInDescriptionLabel', async (content) => { + return course._glossary?.searchWithInDescriptionLabel !== ''; + }); + + checkContent('Glossary - check attribute _isSearchEnabled', async (content) => { + return ( + !course._glossary || + course._glossary._isSearchEnabled === true + ); + }); + + checkContent('Glossary - check attribute _isIndexEnabled', async (content) => { + return ( + !course._glossary || + course._glossary._isIndexEnabled === false + ); + }); + + checkContent('Glossary - check attribute _isGroupHeadersEnabled', async (content) => { + return ( + !course._glossary || + course._glossary._isGroupHeadersEnabled === false + ); + }); + + updatePlugin('Glossary - update to v3.0.0', { name: 'adapt-contrib-glossary', version: '3.0.0', framework: '">=5' }); +}); diff --git a/migrations/v4.js b/migrations/v4.js new file mode 100644 index 0000000..49067e2 --- /dev/null +++ b/migrations/v4.js @@ -0,0 +1,30 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +describe('Glossary - v4.3.1 to v4.4.0', async () => { + // https://github.com/adaptlearning/adapt-contrib-glossary/compare/v4.3.1..v4.4.0 + + let course; + + whereFromPlugin('Glossary - from v4.3.1', { name: 'adapt-contrib-glossary', version: '<4.4.0' }); + + whereContent('Glossary has items', async content => { + course = getCourse(content); + return course._glossary?._items?.length > 0; + }); + + mutateContent('Glossary - add attribute termAriaLabel', async (content) => { + course._glossary._items.forEach(item => (item.termAriaLabel = '')); + return true; + }); + + checkContent('Glossary - check attribute termAriaLabel', async (content) => { + return course._glossary._items.every(item => item.termAriaLabel === ''); + }); + + updatePlugin('Glossary - update to v4.4.0', { name: 'adapt-contrib-glossary', version: '4.4.0', framework: '">=5.19.1' }); +}); From 36d9021757ab6868340f188b85df2f1dc88b2489 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Mon, 3 Feb 2025 10:28:57 +0000 Subject: [PATCH 2/3] Migration script consistency --- migrations/v2.js | 10 +++++----- migrations/v3.js | 48 ++++++++++++++++++++---------------------------- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/migrations/v2.js b/migrations/v2.js index 54fc05b..7593f7a 100644 --- a/migrations/v2.js +++ b/migrations/v2.js @@ -40,8 +40,12 @@ describe('Glossary - v2.1.0 to v2.1.1', async () => { whereFromPlugin('Glossary - from v2.1.0', { name: 'adapt-contrib-glossary', version: '<2.1.1' }); - mutateContent('Glossary - add globals if missing', async (content) => { + whereContent('Glossary - where configured', async (content) => { course = getCourse(content); + if (course._glossary) return true; + }); + + mutateContent('Glossary - add globals if missing', async (content) => { courseGlossaryGlobals = getGlobals(content); if (courseGlossaryGlobals) return true; course._globals._extensions = course._globals._extensions || {}; @@ -55,13 +59,11 @@ describe('Glossary - v2.1.0 to v2.1.1', async () => { }); mutateContent('Glossary - add attribute clearSearch', async (content) => { - if (!course._glossary) return true; course._glossary.clearSearch = ''; return true; }); mutateContent('Glossary - add attribute searchItemsAlert', async (content) => { - if (!course._glossary) return true; course._glossary.searchItemsAlert = '{{filteredItems.length}} found.'; return true; }); @@ -71,12 +73,10 @@ describe('Glossary - v2.1.0 to v2.1.1', async () => { }); checkContent('Glossary - check attribute clearSearch', async (content) => { - if (!course._glossary) return true; return course._glossary.clearSearch === ''; }); checkContent('Glossary - check attribute searchItemsAlert', async (content) => { - if (!course._glossary) return true; return course._glossary.searchItemsAlert === ''; }); diff --git a/migrations/v3.js b/migrations/v3.js index bc022a8..351741d 100644 --- a/migrations/v3.js +++ b/migrations/v3.js @@ -16,8 +16,12 @@ describe('Glossary - v2.1.3 to v3.0.0', async () => { whereFromPlugin('Glossary - from v2.1.3', { name: 'adapt-contrib-glossary', version: '<3.0.0' }); - mutateContent('Glossary - add globals if missing', async (content) => { + whereContent('Glossary - where configured', async (content) => { course = getCourse(content); + if (course._glossary) return true; + }); + + mutateContent('Glossary - add globals if missing', async (content) => { courseGlossaryGlobals = getGlobals(content); if (courseGlossaryGlobals) return true; course._globals._extensions = course._globals._extensions || {}; @@ -32,55 +36,52 @@ describe('Glossary - v2.1.3 to v3.0.0', async () => { }); mutateContent('Glossary - change default title', async (content) => { - if (course._glossary?.title !== '') return true; + if (course._glossary.title !== '') return true; course._glossary.title = 'Glossary'; return true; }); mutateContent('Glossary - change default description', async (content) => { - if (course._glossary?.description !== '') return true; + if (course._glossary.description !== '') return true; course._glossary.description = 'Select here to view the glossary for this course'; return true; }); mutateContent('Glossary - change default clearSearch', async (content) => { - if (course._glossary?.clearSearch !== '') return true; + if (course._glossary.clearSearch !== '') return true; course._glossary.clearSearch = 'Clear search'; return true; }); mutateContent('Glossary - change default searchItemsAlert', async (content) => { - if (course._glossary?.searchItemsAlert !== '{{filteredItems.length}} found.') return true; + if (course._glossary.searchItemsAlert !== '{{filteredItems.length}} found.') return true; course._glossary.searchItemsAlert = '{{filteredItems.length}} found'; return true; }); mutateContent('Glossary - change default searchPlaceholder', async (content) => { - if (course._glossary?.searchPlaceholder !== '') return true; + if (course._glossary.searchPlaceholder !== '') return true; course._glossary.searchPlaceholder = 'Search'; return true; }); mutateContent('Glossary - change default searchWithInDescriptionLabel', async (content) => { - if (course._glossary?.searchWithInDescriptionLabel !== '') return true; + if (course._glossary.searchWithInDescriptionLabel !== '') return true; course._glossary.searchWithInDescriptionLabel = 'Search within Description'; return true; }); mutateContent('Glossary - add attribute _isSearchEnabled', async (content) => { - if (!course._glossary) return true; course._glossary._isSearchEnabled = true; return true; }); mutateContent('Glossary - add attribute _isIndexEnabled', async (content) => { - if (!course._glossary) return true; course._glossary._isIndexEnabled = false; return true; }); mutateContent('Glossary - add attribute _isGroupHeadersEnabled', async (content) => { - if (!course._glossary) return true; course._glossary._isGroupHeadersEnabled = false; return true; }); @@ -93,48 +94,39 @@ describe('Glossary - v2.1.3 to v3.0.0', async () => { }); checkContent('Glossary - check default title', async (content) => { - return course._glossary?.title !== ''; + return course._glossary.title !== ''; }); checkContent('Glossary - check default description', async (content) => { - return course._glossary?.description !== ''; + return course._glossary.description !== ''; }); checkContent('Glossary - check default clearSearch', async (content) => { - return course._glossary?.clearSearch !== ''; + return course._glossary.clearSearch !== ''; }); checkContent('Glossary - check default searchItemsAlert', async (content) => { - return course._glossary?.searchItemsAlert !== '{{filteredItems.length}} found.'; + return course._glossary.searchItemsAlert !== '{{filteredItems.length}} found.'; }); checkContent('Glossary - check default searchPlaceholder', async (content) => { - return course._glossary?.searchPlaceholder !== ''; + return course._glossary.searchPlaceholder !== ''; }); checkContent('Glossary - check default searchWithInDescriptionLabel', async (content) => { - return course._glossary?.searchWithInDescriptionLabel !== ''; + return course._glossary.searchWithInDescriptionLabel !== ''; }); checkContent('Glossary - check attribute _isSearchEnabled', async (content) => { - return ( - !course._glossary || - course._glossary._isSearchEnabled === true - ); + return course._glossary._isSearchEnabled === true; }); checkContent('Glossary - check attribute _isIndexEnabled', async (content) => { - return ( - !course._glossary || - course._glossary._isIndexEnabled === false - ); + return course._glossary._isIndexEnabled === false; }); checkContent('Glossary - check attribute _isGroupHeadersEnabled', async (content) => { - return ( - !course._glossary || - course._glossary._isGroupHeadersEnabled === false - ); + return course._glossary._isGroupHeadersEnabled === false; }); updatePlugin('Glossary - update to v3.0.0', { name: 'adapt-contrib-glossary', version: '3.0.0', framework: '">=5' }); From 7eaeafd1b5a68630af517f905837bc31aa6f7295 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Wed, 5 Feb 2025 20:52:47 +0000 Subject: [PATCH 3/3] Review amendments --- migrations/v2.js | 45 +++++++++++++++++------------- migrations/v3.js | 72 ++++++++++++++++++++++++++++++++---------------- migrations/v4.js | 12 ++++---- 3 files changed, 82 insertions(+), 47 deletions(-) diff --git a/migrations/v2.js b/migrations/v2.js index 7593f7a..a3eb55a 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; }; @@ -18,16 +19,18 @@ describe('Glossary - v2.0.3 to v2.1.0', async () => { whereContent('Glossary - where configured', async (content) => { course = getCourse(content); - if (course._glossary) return true; + return course._glossary; }); - mutateContent('Glossary - add _drawerOrder attribute', async (content) => { + mutateContent('Glossary - add course attribute _drawerOrder', async (content) => { course._glossary._drawerOrder = 0; return true; }); - checkContent('Glossary - check _drawerOrder attribute', async (content) => { - return course._glossary._drawerOrder === 0; + checkContent('Glossary - check course attribute _drawerOrder', async (content) => { + const isValid = course._glossary._drawerOrder === 0; + if (!isValid) throw new Error('Glossary - course attribute _drawerOrder'); + return true; }); updatePlugin('Glossary - update to v2.1.0', { name: 'adapt-contrib-glossary', version: '2.1.0', framework: '">=2.2.0' }); @@ -42,42 +45,46 @@ describe('Glossary - v2.1.0 to v2.1.1', async () => { whereContent('Glossary - where configured', async (content) => { course = getCourse(content); - if (course._glossary) return true; + return course._glossary; }); mutateContent('Glossary - add globals if missing', async (content) => { - courseGlossaryGlobals = getGlobals(content); - if (courseGlossaryGlobals) return true; - course._globals._extensions = course._globals._extensions || {}; - courseGlossaryGlobals = course._globals._extensions._glossary = {}; + if (!_.has(course, '_globals._extensions._glossary')) _.set(course, '_globals._extensions._glossary', {}); + courseGlossaryGlobals = course._globals._extensions._glossary; return true; }); - mutateContent('Glossary - add new globals', async (content) => { + mutateContent('Glossary - add global attribute glossary', async (content) => { courseGlossaryGlobals.glossary = 'Glossary'; return true; }); - mutateContent('Glossary - add attribute clearSearch', async (content) => { + mutateContent('Glossary - add course attribute clearSearch', async (content) => { course._glossary.clearSearch = ''; return true; }); - mutateContent('Glossary - add attribute searchItemsAlert', async (content) => { + mutateContent('Glossary - add course attribute searchItemsAlert', async (content) => { course._glossary.searchItemsAlert = '{{filteredItems.length}} found.'; return true; }); - checkContent('Glossary - check new globals', async (content) => { - return getGlobals(content).glossary === 'Glossary'; + checkContent('Glossary - check global attribute glossary', async (content) => { + const isValid = getGlobals(content).glossary === 'Glossary'; + if (!isValid) throw new Error('Glossary - global attribute glossary'); + return true; }); - checkContent('Glossary - check attribute clearSearch', async (content) => { - return course._glossary.clearSearch === ''; + checkContent('Glossary - check course attribute clearSearch', async (content) => { + const isValid = course._glossary.clearSearch === ''; + if (!isValid) throw new Error('Glossary - course attribute clearSearch'); + return true; }); - checkContent('Glossary - check attribute searchItemsAlert', async (content) => { - return course._glossary.searchItemsAlert === ''; + checkContent('Glossary - check course attribute searchItemsAlert', async (content) => { + const isValid = course._glossary.searchItemsAlert === '{{filteredItems.length}} found.'; + if (!isValid) throw new Error('Glossary - course attribute searchItemsAlert'); + return true; }); updatePlugin('Glossary - update to v2.1.1', { name: 'adapt-contrib-glossary', version: '2.1.1', framework: '">=2.2.5' }); diff --git a/migrations/v3.js b/migrations/v3.js index 351741d..fcd0406 100644 --- a/migrations/v3.js +++ b/migrations/v3.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; }; @@ -18,19 +19,21 @@ describe('Glossary - v2.1.3 to v3.0.0', async () => { whereContent('Glossary - where configured', async (content) => { course = getCourse(content); - if (course._glossary) return true; + return course._glossary; }); mutateContent('Glossary - add globals if missing', async (content) => { - courseGlossaryGlobals = getGlobals(content); - if (courseGlossaryGlobals) return true; - course._globals._extensions = course._globals._extensions || {}; - courseGlossaryGlobals = course._globals._extensions._glossary = {}; + if (!_.has(course, '_globals._extensions._glossary')) _.set(course, '_globals._extensions._glossary', {}); + courseGlossaryGlobals = course._globals._extensions._glossary; return true; }); - mutateContent('Glossary - add new globals', async (content) => { + mutateContent('Glossary - add global attribute labelLink', async (content) => { courseGlossaryGlobals.labelLink = 'Terms beginning with'; + return true; + }); + + mutateContent('Glossary - add global attribute labelNavigation', async (content) => { courseGlossaryGlobals.labelNavigation = 'Glossary navigation'; return true; }); @@ -86,47 +89,70 @@ describe('Glossary - v2.1.3 to v3.0.0', async () => { return true; }); - checkContent('Glossary - check new globals', async (content) => { - return ( - getGlobals(content).labelLink === 'Terms beginning with' && - getGlobals(content).labelNavigation === 'Glossary navigation' - ); + checkContent('Glossary - check global attribute labelLink', async (content) => { + const isValid = getGlobals(content).labelLink === 'Terms beginning with'; + if (!isValid) throw new Error('Glossary - global attribute labelLink'); + return true; + }); + + checkContent('Glossary - check global attribute labelNavigation', async (content) => { + const isValid = getGlobals(content).labelNavigation === 'Glossary navigation'; + if (!isValid) throw new Error('Glossary - global attribute labelNavigation'); + return true; }); - checkContent('Glossary - check default title', async (content) => { - return course._glossary.title !== ''; + checkContent('Glossary - check course attribute title', async (content) => { + const isValid = course._glossary.title !== ''; + if (!isValid) throw new Error('Glossary - course attribute title'); + return true; }); - checkContent('Glossary - check default description', async (content) => { - return course._glossary.description !== ''; + checkContent('Glossary - check course attribute description', async (content) => { + const isValid = course._glossary.description !== ''; + if (!isValid) throw new Error('Glossary - course attribute description'); + return true; }); checkContent('Glossary - check default clearSearch', async (content) => { - return course._glossary.clearSearch !== ''; + const isValid = course._glossary.clearSearch !== ''; + if (!isValid) throw new Error('Glossary - course attribute clearSearch'); + return true; }); checkContent('Glossary - check default searchItemsAlert', async (content) => { - return course._glossary.searchItemsAlert !== '{{filteredItems.length}} found.'; + const isValid = course._glossary.searchItemsAlert !== '{{filteredItems.length}} found.'; + if (!isValid) throw new Error('Glossary - course attribute searchItemsAlert'); + return true; }); checkContent('Glossary - check default searchPlaceholder', async (content) => { - return course._glossary.searchPlaceholder !== ''; + const isValid = course._glossary.searchPlaceholder !== ''; + if (!isValid) throw new Error('Glossary - course attribute searchPlaceholder'); + return true; }); checkContent('Glossary - check default searchWithInDescriptionLabel', async (content) => { - return course._glossary.searchWithInDescriptionLabel !== ''; + const isValid = course._glossary.searchWithInDescriptionLabel !== ''; + if (!isValid) throw new Error('Glossary - course attribute searchWithInDescriptionLabel'); + return true; }); checkContent('Glossary - check attribute _isSearchEnabled', async (content) => { - return course._glossary._isSearchEnabled === true; + const isValid = course._glossary._isSearchEnabled === true; + if (!isValid) throw new Error('Glossary - course attribute _isSearchEnabled'); + return true; }); checkContent('Glossary - check attribute _isIndexEnabled', async (content) => { - return course._glossary._isIndexEnabled === false; + const isValid = course._glossary._isIndexEnabled === false; + if (!isValid) throw new Error('Glossary - course attribute _isIndexEnabled'); + return true; }); checkContent('Glossary - check attribute _isGroupHeadersEnabled', async (content) => { - return course._glossary._isGroupHeadersEnabled === false; + const isValid = course._glossary._isGroupHeadersEnabled === false; + if (!isValid) throw new Error('Glossary - course attribute _isGroupHeadersEnabled'); + return true; }); updatePlugin('Glossary - update to v3.0.0', { name: 'adapt-contrib-glossary', version: '3.0.0', framework: '">=5' }); diff --git a/migrations/v4.js b/migrations/v4.js index 49067e2..8aa6305 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -1,7 +1,7 @@ import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); + const course = content.find(({ _type }) => _type === 'course'); return course; }; @@ -14,16 +14,18 @@ describe('Glossary - v4.3.1 to v4.4.0', async () => { whereContent('Glossary has items', async content => { course = getCourse(content); - return course._glossary?._items?.length > 0; + return course._glossary?._items?.length; }); - mutateContent('Glossary - add attribute termAriaLabel', async (content) => { + mutateContent('Glossary - add item attribute termAriaLabel', async (content) => { course._glossary._items.forEach(item => (item.termAriaLabel = '')); return true; }); - checkContent('Glossary - check attribute termAriaLabel', async (content) => { - return course._glossary._items.every(item => item.termAriaLabel === ''); + checkContent('Glossary - check item attribute termAriaLabel', async (content) => { + const isValid = course._glossary._items.every(item => item.termAriaLabel === ''); + if (!isValid) throw new Error('Glossary - item attribute termAriaLabel'); + return true; }); updatePlugin('Glossary - update to v4.4.0', { name: 'adapt-contrib-glossary', version: '4.4.0', framework: '">=5.19.1' });