-
Notifications
You must be signed in to change notification settings - Fork 30
New: migration scripts added to repo (fixes #208) #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4eddad4
Added migration scripts
chris-steele fa3b643
Migration corrections
chris-steele 915d063
Migration corrections
chris-steele 61cafe9
Review amendments
chris-steele 1cb30e6
Migration scripts review amendments
chris-steele 7632560
Migration scripts review amendments
chris-steele 9a9f10d
Migration scripts review amendments
chris-steele 196246a
automated testing added to migrations
joe-allen-89 57d74ce
amended check for _boxMenu._backgroundImage
joe-allen-89 a793226
Extend migrations to content objects
chris-steele 427d630
Rename variable
chris-steele f446fb2
additional tests added
joe-allen-89 6c6eae0
nested ifs replaced with return early
joe-allen-89 f5d8ec4
simplified menu check as per review
joe-allen-89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { describe, getCourse, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere } from 'adapt-migrations'; | ||
import _ from 'lodash'; | ||
|
||
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 course, courseBoxMenuGlobals; | ||
const durationLabel = 'Duration:'; | ||
|
||
whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '>=2.0.0 <2.0.3' }); | ||
|
||
mutateContent('Box menu - add globals if missing', async (content) => { | ||
course = getCourse(); | ||
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) => { | ||
const isValid = courseBoxMenuGlobals.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' }); | ||
|
||
testSuccessWhere('boxMenu with empty course', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '2.0.2' }], | ||
content: [ | ||
{ _type: 'course' } | ||
] | ||
}); | ||
|
||
testSuccessWhere('boxMenu with course globals', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '2.0.2' }], | ||
content: [ | ||
{ _type: 'course', _globals: { _menu: { _boxMenu: {} } } } | ||
] | ||
}); | ||
|
||
testStopWhere('incorrect version', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '2.0.3' }] | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { describe, getCourse, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere, whereContent } from 'adapt-migrations'; | ||
import _ from 'lodash'; | ||
|
||
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 course, courseBoxMenuGlobals; | ||
|
||
whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.0' }); | ||
|
||
whereContent('Box menu - where globals', async (content) => { | ||
course = getCourse(); | ||
if (!_.has(course, '_globals._menu._boxMenu')) return false; | ||
courseBoxMenuGlobals = course._globals._menu._boxMenu; | ||
return true; | ||
}); | ||
|
||
mutateContent('Box menu - remove global attribute ariaRegion', async (content) => { | ||
delete courseBoxMenuGlobals.ariaRegion; | ||
return true; | ||
}); | ||
|
||
mutateContent('Box menu - remove globals attribute menuItem', async (content) => { | ||
delete courseBoxMenuGlobals.menuItem; | ||
return true; | ||
}); | ||
|
||
mutateContent('Box menu - remove globals attribute menuEnd', async (content) => { | ||
delete courseBoxMenuGlobals.menuEnd; | ||
return true; | ||
}); | ||
|
||
checkContent('Box menu - check global attribute ariaRegion', async (content) => { | ||
const isValid = !_.has(courseBoxMenuGlobals, 'ariaRegion'); | ||
if (!isValid) throw new Error('Box menu - global attribute ariaRegion'); | ||
return true; | ||
}); | ||
|
||
checkContent('Box menu - check global attribute menuItem', async (content) => { | ||
const isValid = !_.has(courseBoxMenuGlobals, 'menuItem'); | ||
if (!isValid) throw new Error('Box menu - global attribute menuItem'); | ||
return true; | ||
}); | ||
|
||
checkContent('Box menu - check global attribute menuEnd', async (content) => { | ||
const isValid = !_.has(courseBoxMenuGlobals, 'menuEnd'); | ||
if (!isValid) throw new Error('Box menu - global attribute menuEnd'); | ||
return true; | ||
}); | ||
|
||
updatePlugin('Box menu - update to v4.0.0', { name: 'adapt-contrib-boxMenu', version: '4.0.0', framework: '">=4' }); | ||
|
||
testStopWhere('boxMenu with empty course', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '3.0.0' }], | ||
content: [ | ||
{ _type: 'course' } | ||
] | ||
}); | ||
|
||
testSuccessWhere('boxMenu with course globals', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '3.0.0' }], | ||
content: [ | ||
{ | ||
_type: 'course', | ||
_globals: { | ||
_menu: { | ||
_boxMenu: { | ||
ariaRegion: 'ariaRegion', | ||
menuItem: 'menuItem', | ||
menuEnd: 'menuEnd' | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}); | ||
|
||
testSuccessWhere('boxMenu with empty course globals', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '3.0.0' }], | ||
content: [ | ||
{ _type: 'course', _globals: { _menu: { _boxMenu: {} } } } | ||
] | ||
}); | ||
|
||
testStopWhere('incorrect version', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '4.0.0' }] | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,249 @@ | ||
import { describe, getCourse, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere } from 'adapt-migrations'; | ||
import _ from 'lodash'; | ||
|
||
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 menusWithHeaders; | ||
const defaultTextAlignment = { | ||
_title: '', | ||
_body: '', | ||
_instruction: '' | ||
}; | ||
|
||
whereFromPlugin('Box menu - from v6.0.2', { name: 'adapt-contrib-boxMenu', version: '<6.1.0' }); | ||
|
||
whereContent('Box menu - where menus have _menuHeader', async (content) => { | ||
const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; | ||
menusWithHeaders = candidates.filter(({ _boxMenu }) => _boxMenu?._menuHeader); | ||
return menusWithHeaders.length; | ||
}); | ||
|
||
mutateContent('Box menu - add _textAlignment attribute', async (content) => { | ||
menusWithHeaders.forEach(({ _boxMenu }) => (_boxMenu._menuHeader._textAlignment = defaultTextAlignment)); | ||
return true; | ||
}); | ||
|
||
checkContent('Box menu - check _textAlignment attribute', async (content) => { | ||
const isValid = menusWithHeaders.every(({ _boxMenu }) => _.isEqual(_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' }); | ||
|
||
testSuccessWhere('boxMenu with course _boxMenu._menuHeader', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], | ||
content: [ | ||
{ _type: 'course', _boxMenu: { _menuHeader: {} } }, | ||
{ _type: 'menu', _boxMenu: { _menuHeader: {} } } | ||
] | ||
}); | ||
|
||
testStopWhere('boxMenu with empty course', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], | ||
content: [ | ||
{ _type: 'course' } | ||
] | ||
}); | ||
|
||
testStopWhere('boxMenu with empty course _boxMenu', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], | ||
content: [ | ||
{ _type: 'course', _boxMenu: {} } | ||
] | ||
}); | ||
|
||
testStopWhere('incorrect version', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.1.0' }] | ||
}); | ||
}); | ||
|
||
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 menus; | ||
const defaultGraphic = { | ||
_src: '', | ||
alt: '' | ||
}; | ||
|
||
whereFromPlugin('Box menu - from v6.2.0', { name: 'adapt-contrib-boxMenu', version: '<6.2.1' }); | ||
|
||
whereContent('Box menu - where menus are configured', async (content) => { | ||
const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; | ||
menus = candidates.filter(({ _boxMenu }) => _boxMenu); | ||
return menus.length; | ||
}); | ||
|
||
mutateContent('Box menu - add _graphic attribute', async (content) => { | ||
menus.forEach(({ _boxMenu }) => (_boxMenu._graphic = defaultGraphic)); | ||
return true; | ||
}); | ||
|
||
checkContent('Box menu - check _graphic attribute', async (content) => { | ||
const isValid = menus.every(({ _boxMenu }) => _.isEqual(_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' }); | ||
|
||
testSuccessWhere('boxMenu with course _boxMenu', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.0' }], | ||
content: [ | ||
{ _type: 'course', _boxMenu: {} }, | ||
{ _type: 'menu', _boxMenu: {} } | ||
] | ||
}); | ||
|
||
testStopWhere('boxMenu with empty course', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.0' }], | ||
content: [ | ||
{ _type: 'course' }, | ||
{ _type: 'menu' } | ||
] | ||
}); | ||
|
||
testStopWhere('incorrect version', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.1' }] | ||
}); | ||
}); | ||
|
||
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 menusWithBgImage; | ||
|
||
whereFromPlugin('Box menu - from v6.3.8', { name: 'adapt-contrib-boxMenu', version: '<6.3.9' }); | ||
|
||
whereContent('Box menu - where menus have _backgroundImage', async (content) => { | ||
const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; | ||
menusWithBgImage = candidates.filter(({ _boxMenu }) => ( | ||
_boxMenu?._backgroundImage || | ||
_boxMenu?._menuHeader?._backgroundImage | ||
)); | ||
return menusWithBgImage.length; | ||
}); | ||
|
||
mutateContent('Box menu - add _xlarge attribute', async (content) => { | ||
menusWithBgImage.forEach(({ _boxMenu }) => { | ||
if (_.has(_boxMenu, '_backgroundImage')) { | ||
_boxMenu._backgroundImage._xlarge = ''; | ||
} | ||
joe-allen-89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
return true; | ||
}); | ||
|
||
mutateContent('Box menu - add _xlarge attribute to _menuHeader', async (content) => { | ||
menusWithBgImage.forEach(({ _boxMenu }) => { | ||
if (_.has(_boxMenu, '_menuHeader._backgroundImage')) { | ||
_boxMenu._menuHeader._backgroundImage._xlarge = ''; | ||
} | ||
}); | ||
return true; | ||
}); | ||
|
||
checkContent('Box menu - check _xlarge attribute', async (content) => { | ||
const isValid = menusWithBgImage.every(({ _boxMenu }) => ( | ||
!_boxMenu._backgroundImage || _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) => { | ||
const isValid = menusWithBgImage.every(({ _boxMenu }) => ( | ||
!_boxMenu._menuHeader?._backgroundImage || _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' }); | ||
|
||
testSuccessWhere('boxMenu with course._boxMenu._backgroundImage', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], | ||
content: [ | ||
{ _type: 'course', _boxMenu: { _backgroundImage: {} } }, | ||
{ _type: 'menu', _boxMenu: { _backgroundImage: {} } } | ||
] | ||
}); | ||
|
||
testSuccessWhere('boxMenu with course._boxMenu._menuHeader._backgroundImage', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], | ||
content: [ | ||
{ _type: 'course', _boxMenu: { _menuHeader: { _backgroundImage: {} } } }, | ||
{ _type: 'menu', _boxMenu: { _menuHeader: { _backgroundImage: {} } } } | ||
] | ||
}); | ||
|
||
testStopWhere('boxMenu with empty course', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], | ||
content: [ | ||
{ _type: 'course' } | ||
] | ||
}); | ||
|
||
testStopWhere('boxMenu with course._boxMenu', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], | ||
content: [ | ||
{ _type: 'course', _boxMenu: {} } | ||
] | ||
}); | ||
|
||
testStopWhere('incorrect version', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.9' }] | ||
}); | ||
}); | ||
|
||
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 course, courseBoxMenuGlobals; | ||
const itemCount = 'Item {{_nthChild}} of {{_totalChild}}'; | ||
|
||
whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: '<6.3.10' }); | ||
|
||
mutateContent('Box menu - add globals if missing', async (content) => { | ||
course = getCourse(); | ||
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.itemCount = itemCount; | ||
return true; | ||
}); | ||
|
||
checkContent('Box menu - check new globals', async (content) => { | ||
const isValid = courseBoxMenuGlobals.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: '6.3.10', framework: '">=5.24.2' }); | ||
|
||
testSuccessWhere('boxMenu with empty course', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.9' }], | ||
content: [ | ||
{ _type: 'course' } | ||
] | ||
}); | ||
|
||
testSuccessWhere('boxMenu with course globals', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.9' }], | ||
content: [ | ||
{ _type: 'course', _globals: { _menu: { _boxMenu: {} } } } | ||
] | ||
}); | ||
|
||
testStopWhere('incorrect version', { | ||
fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.10' }] | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))];
this is really complicated for what it does.Maybe something a bit easier to read?