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

describe('Resources - v2.0.1 to v2.0.2', async () => {
let course;
whereFromPlugin('Resources - from v2.0.1', { name: 'adapt-contrib-resources', version: '>=2.0.0 <2.0.2' });

whereContent('Resources - where Resources', async (content) => {
course = getCourse();
return course?._resources;
});

mutateContent('Resources - add _isEnabled attribute', async (content) => {
course._resources._isEnabled = true;
return true;
});

checkContent('Resources - check _isEnabled attribute', async (content) => {
const isValid = _.has(course, '_resources._isEnabled');
if (!isValid) throw new Error('Resources - _isEnabled attribute not updated');
return true;
});

updatePlugin('Resources - update to v2.0.2', { name: 'adapt-contrib-resources', version: '2.0.2', framework: '^2.0.0' });

testSuccessWhere('resources with course._resources', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.0.1' }],
content: [
{ _type: 'course', _resources: {} }
]
});

testStopWhere('resources with empty course', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.0.1' }],
content: [
{ _type: 'course' }
]
});

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

describe('Resources - v2.0.5 to v2.0.6', async () => {
let course;
whereFromPlugin('Resources - from v2.0.5', { name: 'adapt-contrib-resources', version: '<2.0.6' });

whereContent('Resources - where Resources', async (content) => {
course = getCourse();
return course?._resources?._resourcesItems;
});

mutateContent('Resources - add _resourcesItems filename attribute', async (content) => {
course._resources._resourcesItems.forEach(item => {
item.filename = '';
});
return true;
});

checkContent('Resources - check _resourcesItems filename attribute', async (content) => {
const isValid = course._resources._resourcesItems.every(item => _.has(item, 'filename'));
if (!isValid) throw new Error('Resources - _resourcesItems filename attribute not updated');
return true;
});

updatePlugin('Resources - update to v2.0.6', { name: 'adapt-contrib-resources', version: '2.0.6', framework: '^2.0.0' });

testSuccessWhere('resources with course._resources_resourcesItems', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.0.5' }],
content: [
{ _type: 'course', _resources: { _resourcesItems: [ { title: 'Item 1' }, { title: 'Item 2' } ] } }
]
});

testStopWhere('resources with empty course', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.0.5' }],
content: [
{ _type: 'course' }
]
});

testStopWhere('resources with no _resourcesItems', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.0.5' }],
content: [
{ _type: 'course', _resources: {} }
]
});

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

describe('Resources - v2.0.6 to v2.1.0', async () => {
let course;
whereFromPlugin('Resources - from v2.0.6', { name: 'adapt-contrib-resources', version: '<2.1.0' });

whereContent('Resources - where Resources', async (content) => {
course = getCourse();
return course?._resources;
});

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

checkContent('Resources - check _drawerOrder attribute', async (content) => {
const isValid = _.has(course, '_resources._drawerOrder');
if (!isValid) throw new Error('Resources - _drawerOrder attribute not updated');
return true;
});

updatePlugin('Resources - update to v2.1.0', { name: 'adapt-contrib-resources', version: '2.1.0', framework: '>=2.2.0' });

testSuccessWhere('resources with course._resources', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.0.6' }],
content: [
{ _type: 'course', _resources: {} }
]
});

testStopWhere('resources with empty course', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.0.6' }],
content: [
{ _type: 'course' }
]
});

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

describe('Resources - v2.1.3 to v3.0.0', async () => {
let course, courseResourcesGlobals;
const originalDescriptionDefault = 'Click here to view resources for this course';
whereFromPlugin('Resources - from v2.1.3', { name: 'adapt-contrib-resources', version: '<3.0.0' });

whereContent('Resources - where Resources', async (content) => {
course = getCourse();
return course?._resources;
});

mutateContent('Resources - modify description default', async (content) => {
if (course._resources.description === originalDescriptionDefault) course._resources.description = 'Select here to view resources for this course';
return true;
});

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

mutateContent('Resources - replace globals resourcesEnd with resources', async (content) => {
if (_.has(courseResourcesGlobals, 'resourcesEnd')) delete courseResourcesGlobals.resourcesEnd;
courseResourcesGlobals.resources = 'Additional resources.';
return true;
});

checkContent('Resources - check description default', async (content) => {
const isValid = course._resources.description !== originalDescriptionDefault;
if (!isValid) throw new Error('Resources - description default not updated');
return true;
});

checkContent('Resources - check globals exist', async (content) => {
const isValid = _.has(course, '_globals._extensions._resources');
if (!isValid) throw new Error('Resources - globals do not exist');
return true;
});

checkContent('Resources - check globals resourcesEnd replaced', async (content) => {
const isValid = !_.has(courseResourcesGlobals, 'resourcesEnd') && _.has(courseResourcesGlobals, 'resources');
if (!isValid) throw new Error('Resources - globals resourcesEnd not replaced');
return true;
});

updatePlugin('Resources - update to v3.0.0', { name: 'adapt-contrib-resources', version: '3.0.0', framework: '>=2.2.0' });

testSuccessWhere('resources with course._resources, no globals', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.1.3' }],
content: [
{ _type: 'course', _resources: {} }
]
});

testSuccessWhere('resources with course._resources and globals', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.1.3' }],
content: [
{ _type: 'course', _resources: {}, _globals: { _extensions: { _resources: {} } } }
]
});

testStopWhere('resources with empty course', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '2.1.3' }],
content: [
{ _type: 'course' }
]
});

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

describe('Resources - v3.0.3 to v4.0.0', async () => {
let course;
const originalDescriptionDefault = 'Click here to view resources for this course';
whereFromPlugin('Resources - from v3.0.3', { name: 'adapt-contrib-resources', version: '<4.0.0' });

whereContent('Resources - where Resources', async (content) => {
course = getCourse();
return course?._resources;
});

mutateContent('Resources - modify description default', async (content) => {
if (course._resources.description === originalDescriptionDefault) course._resources.description = 'Select here to view resources for this course';
return true;
});

checkContent('Resources - check description default', async (content) => {
const isValid = course._resources.description !== originalDescriptionDefault;
if (!isValid) throw new Error('Resources - description default not updated');
return true;
});

updatePlugin('Resources - update to v4.0.0', { name: 'adapt-contrib-resources', version: '4.0.0', framework: '>=5.0.0' });

testSuccessWhere('resources with course._resources', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '3.0.3' }],
content: [
{ _type: 'course', _resources: {} }
]
});

testStopWhere('resources with empty course', {
fromPlugins: [{ name: 'adapt-contrib-resources', version: '3.0.3' }],
content: [
{ _type: 'course' }
]
});

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