Skip to content
Open
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
47 changes: 47 additions & 0 deletions migrations/v6.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getCourse, testSuccessWhere, testStopWhere, getConfig } from 'adapt-migrations';
import _ from 'lodash';

describe('core - update to v6.0.0', async () => {
let course;

const isObject = (value) => (typeof value === 'object' && value !== null && !Array.isArray(value));

whereFromPlugin('core - from less than v6.0.0', { name: 'adapt-contrib-core', version: '<6.0.0' });

whereContent('core - where course menuSettings is not an object', async (content) => {
course = getCourse();
return course && !isObject(course.menuSettings);
});

mutateContent('core - normalise course.menuSettings to an object', async (content) => {
_.set(course, 'menuSettings', {});
return true;
});

checkContent('core - check course.menuSettings is an object', async (content) => {
if (!isObject(_.get(course, 'menuSettings'))) throw new Error('core - menuSettings not normalised to an object');
return true;
});

updatePlugin('core - update to v6.0.0', { name: 'adapt-contrib-core', version: '6.0.0', framework: '>=5.17.0' });

testSuccessWhere('legacy string menuSettings', {
fromPlugins: [{ name: 'adapt-contrib-core', version: '5.12.0' }],
content: [
{ _type: 'course', menuSettings: '' }
]
});

testStopWhere('menuSettings already an object', {
fromPlugins: [{ name: 'adapt-contrib-core', version: '5.12.0' }],
content: [
{ _type: 'course', menuSettings: {} }
]
});

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

testStopWhere('no course', {
content: [{ _type: 'config' }]
});
});

describe('core - update to v6.22.0', async () => {
let course;
const defaultNavigation = {
Expand Down
Loading