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: added migration scripts (fixes #79) #80

Open
wants to merge 3 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
91 changes: 91 additions & 0 deletions migrations/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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?._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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an advantage to moving this to a function? The common practice so far has been to keep the find function within the whereContent.

Best to use find rather than filter as we'll only have a single instance of course.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joe-allen-89 I just moved it to a function as I use it several times.

return course._glossary;
});

mutateContent('Glossary - add course attribute _drawerOrder', async (content) => {
course._glossary._drawerOrder = 0;
return true;
});

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

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

whereContent('Glossary - where configured', async (content) => {
course = getCourse(content);
return course._glossary;
});

mutateContent('Glossary - add globals if missing', async (content) => {
if (!_.has(course, '_globals._extensions._glossary')) _.set(course, '_globals._extensions._glossary', {});
courseGlossaryGlobals = course._globals._extensions._glossary;
return true;
});

mutateContent('Glossary - add global attribute glossary', async (content) => {
courseGlossaryGlobals.glossary = 'Glossary';
return true;
});

mutateContent('Glossary - add course attribute clearSearch', async (content) => {
course._glossary.clearSearch = '';
return true;
});

mutateContent('Glossary - add course attribute searchItemsAlert', async (content) => {
course._glossary.searchItemsAlert = '{{filteredItems.length}} found.';
return true;
});

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 course attribute clearSearch', async (content) => {
const isValid = course._glossary.clearSearch === '';
if (!isValid) throw new Error('Glossary - course attribute clearSearch');
return true;
});

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' });
});
159 changes: 159 additions & 0 deletions migrations/v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
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?._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' });

whereContent('Glossary - where configured', async (content) => {
course = getCourse(content);
return course._glossary;
});

mutateContent('Glossary - add globals if missing', async (content) => {
if (!_.has(course, '_globals._extensions._glossary')) _.set(course, '_globals._extensions._glossary', {});
courseGlossaryGlobals = course._globals._extensions._glossary;
return true;
});

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

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;
Comment on lines +48 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we can condense this slightly, thoughts?

Suggested change
if (course._glossary.description !== '') return true;
course._glossary.description = 'Select here to view the glossary for this course';
return true;
if (course._glossary.description === '') 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) => {
course._glossary._isSearchEnabled = true;
return true;
});

mutateContent('Glossary - add attribute _isIndexEnabled', async (content) => {
course._glossary._isIndexEnabled = false;
return true;
});

mutateContent('Glossary - add attribute _isGroupHeadersEnabled', async (content) => {
course._glossary._isGroupHeadersEnabled = false;
return true;
});

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 course attribute title', async (content) => {
const isValid = course._glossary.title !== '';
if (!isValid) throw new Error('Glossary - course attribute title');
return true;
});

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) => {
const isValid = course._glossary.clearSearch !== '';
if (!isValid) throw new Error('Glossary - course attribute clearSearch');
return true;
});

checkContent('Glossary - check default searchItemsAlert', async (content) => {
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) => {
const isValid = course._glossary.searchPlaceholder !== '';
if (!isValid) throw new Error('Glossary - course attribute searchPlaceholder');
return true;
});

checkContent('Glossary - check default searchWithInDescriptionLabel', async (content) => {
const isValid = course._glossary.searchWithInDescriptionLabel !== '';
if (!isValid) throw new Error('Glossary - course attribute searchWithInDescriptionLabel');
return true;
});

checkContent('Glossary - check attribute _isSearchEnabled', async (content) => {
const isValid = course._glossary._isSearchEnabled === true;
if (!isValid) throw new Error('Glossary - course attribute _isSearchEnabled');
return true;
});

checkContent('Glossary - check attribute _isIndexEnabled', async (content) => {
const isValid = course._glossary._isIndexEnabled === false;
if (!isValid) throw new Error('Glossary - course attribute _isIndexEnabled');
return true;
});

checkContent('Glossary - check attribute _isGroupHeadersEnabled', async (content) => {
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' });
});
32 changes: 32 additions & 0 deletions migrations/v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';

const getCourse = content => {
const course = content.find(({ _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;
});

mutateContent('Glossary - add item attribute termAriaLabel', async (content) => {
course._glossary._items.forEach(item => (item.termAriaLabel = ''));
return true;
});

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