Skip to content
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

New: migration scripts added to repo (fixes #208) #209

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions migrations/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
import _ from 'lodash';

const getCourse = content => {
const course = content.find(({ _type }) => _type === 'course');
return course;
};

const getGlobals = content => {
return getCourse(content)?._globals?._menu?._boxMenu;
};

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.3' });

mutateContent('Box menu - add globals if missing', async (content) => {
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) => {
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' });
});
47 changes: 47 additions & 0 deletions migrations/v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
import _ from 'lodash';

const getCourse = content => {
const course = content.find(({ _type }) => _type === 'course');
return course;
};

const getGlobals = content => {
return getCourse(content)?._globals?._menu?._boxMenu;
};

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' });

mutateContent('Box menu - add globals if missing', async (content) => {
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;
delete courseBoxMenuGlobals.menuEnd;
return true;
});

checkContent('Box menu - check globals', async (content) => {
const globals = getGlobals(content);
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' });
});
155 changes: 155 additions & 0 deletions migrations/v6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
import _ from 'lodash';

const getCourse = content => {
const course = content.find(({ _type }) => _type === 'course');
return course;
};

const getGlobals = content => {
return getCourse(content)?._globals?._menu?._boxMenu;
};

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) => {
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' });
});

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) => {
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' });
});

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) => {
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) => {
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' });
});

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: '<v6.3.10' });

mutateContent('Box menu - add globals if missing', async (content) => {
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.itemCount = itemCount;
return true;
});

checkContent('Box menu - check new globals', async (content) => {
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' });
});