Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
241 changes: 241 additions & 0 deletions migrations/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere, getComponents } from 'adapt-migrations';
import _ from 'lodash';

describe('Matching - v2.0.0 to v2.0.1', async () => {
let matchings;

whereFromPlugin('Matching - from v2.0.0', { name: 'adapt-contrib-matching', version: '>=2.0.0 <2.0.1' });

whereContent('Matching - where matching', async content => {
matchings = getComponents('matching');
return matchings.length;
});

mutateContent('Matching - add _recordInteraction attribute', async content => {
matchings.forEach(matching => { matching._recordInteraction = true; });
return true;
});

checkContent('Matching - check _recordInteraction attribute', async content => {
const isValid = matchings.every(({ _recordInteraction }) => _recordInteraction === true);
if (!isValid) throw new Error('Matching - _recordInteraction attribute invalid');
return true;
});

updatePlugin('Matching - update to v2.0.1', { name: 'adapt-contrib-matching', version: '2.0.1', framework: '^2.0.0' });

testSuccessWhere('matching component with empty course', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.0' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course' }
]
});

testStopWhere('no matching components', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.0' }],
content: [
{ _component: 'other' },
{ _type: 'course' }
]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.1' }]
});
});

describe('Matching - v2.0.2 to v2.0.3', async () => {
let matchings;

whereFromPlugin('Matching - from v2.0.2', { name: 'adapt-contrib-matching', version: '<2.0.3' });

whereContent('Matching - where matching', async content => {
matchings = getComponents('matching');
return matchings.length;
});

mutateContent('Matching - add _canShowModelAnswer attribute', async content => {
matchings.forEach(matching => { matching._canShowModelAnswer = true; });
return true;
});

checkContent('Matching - check _canShowModelAnswer attribute', async content => {
const isValid = matchings.every(({ _canShowModelAnswer }) => _canShowModelAnswer === true);
if (!isValid) throw new Error('Matching - _canShowModelAnswer attribute invalid');
return true;
});

updatePlugin('Matching - update to v2.0.3', { name: 'adapt-contrib-matching', version: '2.0.3', framework: '^2.0.0' });

testSuccessWhere('matching component with empty course', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.2' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course' }
]
});

testStopWhere('no matching components', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.2' }],
content: [
{ _component: 'other' },
{ _type: 'course' }
]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.3' }]
});
});

describe('Matching - v2.0.4 to v2.1.0', async () => {
let matchings;

whereFromPlugin('Matching - from v2.0.4', { name: 'adapt-contrib-matching', version: '<2.1.0' });

whereContent('Matching - where matching', async content => {
matchings = getComponents('matching');
return matchings.length;
});

mutateContent('Matching - add _canShowMarking attribute', async content => {
matchings.forEach(matching => { matching._canShowMarking = true; });
return true;
});

checkContent('Matching - check _canShowMarking attribute', async content => {
const isValid = matchings.every(({ _canShowMarking }) => _canShowMarking === true);
if (!isValid) throw new Error('Matching - _canShowMarking attribute invalid');
return true;
});

updatePlugin('Matching - update to v2.1.0', { name: 'adapt-contrib-matching', version: '2.1.0', framework: '^2.0.15' });

testSuccessWhere('matching component with empty course', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.2' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course' }
]
});

testStopWhere('no matching components', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.2' }],
content: [
{ _component: 'other' },
{ _type: 'course' }
]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.1.0' }]
});
});

describe('Matching - v2.1.1 to v2.1.2', async () => {
let matchings;

whereFromPlugin('Matching - from v2.1.1', { name: 'adapt-contrib-matching', version: '<2.1.2' });

whereContent('Matching - where matching', async content => {
matchings = getComponents('matching');
return matchings.length;
});

mutateContent('Matching - add _canShowFeedback attribute', async content => {
matchings.forEach(matching => { matching._canShowFeedback = true; });
return true;
});

checkContent('Matching - check _canShowFeedback attribute', async content => {
const isValid = matchings.every(({ _canShowFeedback }) => _canShowFeedback === true);
if (!isValid) throw new Error('Matching - _canShowFeedback attribute invalid');
return true;
});

updatePlugin('Matching - update to v2.1.2', { name: 'adapt-contrib-matching', version: '2.1.2', framework: '^2.0.15' });

testSuccessWhere('matching component with empty course', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.2' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course' }
]
});

testStopWhere('no matching components', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.0.2' }],
content: [
{ _component: 'other' },
{ _type: 'course' }
]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.1.0' }]
});
});

describe('Matching - v2.1.4 to v2.2.0', async () => {
let matchings;

whereFromPlugin('Matching - from v2.1.4', { name: 'adapt-contrib-matching', version: '<2.2.0' });

whereContent('Matching - where matching', async content => {
matchings = getComponents('matching');
return matchings.length;
});

mutateContent('Matching - add _shouldResetAllAnswers attribute', async content => {
matchings.forEach(matching => { matching._shouldResetAllAnswers = false; });
return true;
});

mutateContent('Matching - add _feedback.title attribute', async content => {
matchings.forEach(matching => {
_.set(matching, '_feedback.title', '');
console.log(matching);
});
return true;
});

checkContent('Matching - check _shouldResetAllAnswers attribute', async content => {
const isValid = matchings.every(({ _shouldResetAllAnswers }) => _shouldResetAllAnswers === false);
if (!isValid) throw new Error('Matching - _shouldResetAllAnswers attribute invalid');
return true;
});

checkContent('Matching - check _feedback.title attribute', async content => {
const isValid = matchings.every(({ _feedback }) => _feedback.title === '');
if (!isValid) throw new Error('Matching - _feedback.title attribute invalid');
return true;
});

updatePlugin('Matching - update to v2.2.0', { name: 'adapt-contrib-matching', version: '2.2.0', framework: '>=2.0.15' });

testSuccessWhere('matching component with empty course', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.1.0' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course' }
]
});

testStopWhere('no matching components', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.1.0' }],
content: [
{ _component: 'other' },
{ _type: 'course' }
]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.2.0' }]
});
});
91 changes: 91 additions & 0 deletions migrations/v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getCourse, testStopWhere, testSuccessWhere, getComponents } from 'adapt-migrations';
import _ from 'lodash';

describe('Matching - v2.3.0 to v3.0.0', async () => {
let matchings, course, courseMatchingGlobals;
const originalAriaRegion = 'This question component requires you to select the matching answer from a drop down list below. When you have selected your answers select the submit button.';
const newAriaRegion = 'Matching. Select from lists and then submit.';

whereFromPlugin('Matching - from v2.3.0', { name: 'adapt-contrib-matching', version: '<3.0.0' });

whereContent('Matching - where matching', async content => {
matchings = getComponents('matching');
return matchings.length;
});

mutateContent('Matching - add globals if missing', async (content) => {
course = getCourse();
if (!_.has(course, '_globals._components._matching.ariaRegion')) _.set(course, '_globals._components._matching.ariaRegion', newAriaRegion);
courseMatchingGlobals = course._globals._components._matching;
return true;
});

mutateContent('Matching - add globals ariaRegion attribute', async content => {
if (courseMatchingGlobals.ariaRegion !== originalAriaRegion) return true;
courseMatchingGlobals.ariaRegion = newAriaRegion;
return true;
});

checkContent('Matching - check globals object', async (content) => {
if (!courseMatchingGlobals) throw new Error('Matching - course globals object missing');
return true;
});

checkContent('Matching - check globals ariaRegion attribute', async (content) => {
if (courseMatchingGlobals) {
const isValid = courseMatchingGlobals.ariaRegion !== originalAriaRegion;
if (!isValid) throw new Error('Matching - ariaRegion attribute missing');
}
return true;
});

updatePlugin('Matching - update to v3.0.0', { name: 'adapt-contrib-matching', version: '3.0.0', framework: '>=2.0.16' });

testSuccessWhere('matching component with empty course', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.2.0' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course' }
]
});

testSuccessWhere('matching component with empty course._globals', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.2.0' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course', _globals: { _components: { _matching: {} } } }
]
});

testSuccessWhere('matching component with default course._globals', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.2.0' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course', _globals: { _components: { _matching: { ariaRegion: originalAriaRegion } } } }
]
});

testSuccessWhere('matching component with custom course._globals', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.2.0' }],
content: [
{ _id: 'c-100', _component: 'matching' },
{ _id: 'c-105', _component: 'matching' },
{ _type: 'course', _globals: { _components: { _matching: { ariaRegion: 'custom ariaRegion' } } } }
]
});

testStopWhere('no matching components', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '2.2.0' }],
content: [
{ _component: 'other' },
{ _type: 'course' }
]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-matching', version: '3.0.0' }]
});
});
Loading