Skip to content

Commit 5667f35

Browse files
chris-steelejoe-allen-89oliverfoster
authored
Update: added migration scripts (fixes #242 (#243)
* Added migration scripts * Convention amendments * automated testing added to migrations * Typo * String reuse, line spacing, task description * Removed whitespace * Removed whitespace * check globals updated * amended add globals as per review --------- Co-authored-by: joe-allen-89 <[email protected]> Co-authored-by: Oliver Foster <[email protected]>
1 parent 131813c commit 5667f35

File tree

6 files changed

+1002
-0
lines changed

6 files changed

+1002
-0
lines changed

migrations/v2.js

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import { describe, getCourse, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere } from 'adapt-migrations';
2+
import _ from 'lodash';
3+
4+
describe('Page level progress - v2.0.1 to v2.0.2', async () => {
5+
// https://github.com/adaptlearning/adapt-contrib-pageLevelProgress/compare/v2.0.1..v2.0.2
6+
7+
let course, coursePlpGlobals;
8+
const plpOptionalContentNew = 'Optional Content';
9+
const plpIndicatorBarDefaultOld = 'You have completed ';
10+
const plpIndicatorBarDefaultNew = 'Progress bar. Select here to view your current progress, and select an item to navigate to it. You have completed ';
11+
12+
whereFromPlugin('Page level progress - from v2.0.1', { name: 'adapt-contrib-pageLevelProgress', version: '>=2.0.0 <2.0.2' });
13+
14+
whereContent('Page level progress is configured', content => {
15+
course = getCourse();
16+
return course._pageLevelProgress;
17+
});
18+
19+
mutateContent('Page level progress - add globals if missing', async (content) => {
20+
if (!_.has(course, '_globals._extensions._pageLevelProgress')) {
21+
_.set(course, '_globals._extensions._pageLevelProgress', {});
22+
}
23+
coursePlpGlobals = course._globals._extensions._pageLevelProgress;
24+
if (!_.has(coursePlpGlobals, 'pageLevelProgressIndicatorBar')) {
25+
_.set(coursePlpGlobals, 'pageLevelProgressIndicatorBar', plpIndicatorBarDefaultNew);
26+
}
27+
return true;
28+
});
29+
30+
mutateContent('Page level progress - global attribute pageLevelProgressMenuBar', async (content) => {
31+
coursePlpGlobals.pageLevelProgressMenuBar = plpIndicatorBarDefaultOld;
32+
return true;
33+
});
34+
35+
mutateContent('Page level progress - global attribute optionalContent', async (content) => {
36+
coursePlpGlobals.optionalContent = plpOptionalContentNew;
37+
return true;
38+
});
39+
40+
mutateContent('Page level progress - update attribute default', async (content) => {
41+
if (coursePlpGlobals.pageLevelProgressIndicatorBar !== plpIndicatorBarDefaultOld) return true;
42+
coursePlpGlobals.pageLevelProgressIndicatorBar = plpIndicatorBarDefaultNew;
43+
return true;
44+
});
45+
46+
checkContent('Page level progress - check global attribute pageLevelProgressMenuBar', async (content) => {
47+
const isValid = coursePlpGlobals.pageLevelProgressMenuBar === plpIndicatorBarDefaultOld;
48+
if (!isValid) throw new Error('Page level progress - global attribute pageLevelProgressMenuBar');
49+
return true;
50+
});
51+
52+
checkContent('Page level progress - check global attribute optionalContent', async (content) => {
53+
const isValid = coursePlpGlobals.optionalContent === plpOptionalContentNew;
54+
if (!isValid) throw new Error('Page level progress - global attribute optionalContent');
55+
return true;
56+
});
57+
58+
checkContent('Page level progress - check global attribute pageLevelProgressIndicatorBar', async (content) => {
59+
const isValid = coursePlpGlobals.pageLevelProgressIndicatorBar !== plpIndicatorBarDefaultOld;
60+
if (!isValid) throw new Error('Page level progress - global attribute pageLevelProgressIndicatorBar');
61+
return true;
62+
});
63+
64+
updatePlugin('Page level progress - update to v2.0.2', { name: 'adapt-contrib-pageLevelProgress', version: '2.0.2', framework: '=>2.0.0' });
65+
66+
testSuccessWhere('pageLevelProgress with no course globals', {
67+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }],
68+
content: [
69+
{ _type: 'course', _pageLevelProgress: {} }
70+
]
71+
});
72+
73+
testSuccessWhere('pageLevelProgress with empty course globals', {
74+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }],
75+
content: [
76+
{ _type: 'course', _pageLevelProgress: {}, _globals: { _extensions: { _pageLevelProgress: {} } } }
77+
]
78+
});
79+
80+
testSuccessWhere('pageLevelProgress with default course globals', {
81+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }],
82+
content: [
83+
{ _type: 'course', _pageLevelProgress: {}, _globals: { _extensions: { _pageLevelProgress: { pageLevelProgressIndicatorBar: plpIndicatorBarDefaultOld } } } }
84+
]
85+
});
86+
87+
testSuccessWhere('pageLevelProgress with custom course globals', {
88+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }],
89+
content: [
90+
{ _type: 'course', _pageLevelProgress: {}, _globals: { _extensions: { _pageLevelProgress: { pageLevelProgressIndicatorBar: 'custom progress indicator' } } } }
91+
]
92+
});
93+
94+
testStopWhere('no pageLevelProgress', {
95+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }],
96+
content: [
97+
{ _type: 'course' }
98+
]
99+
});
100+
101+
testStopWhere('incorrect version', {
102+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.2' }]
103+
});
104+
});
105+
106+
describe('Page level progress - v2.0.3 to v2.0.4', async () => {
107+
// https://github.com/adaptlearning/adapt-contrib-pageLevelProgress/compare/v2.0.3..v2.0.4
108+
109+
let course, configuredContentObjects;
110+
111+
whereFromPlugin('Page level progress - from v2.0.3', { name: 'adapt-contrib-pageLevelProgress', version: '<2.0.4' });
112+
113+
whereContent('Page level progress is configured', content => {
114+
course = getCourse();
115+
configuredContentObjects = content.filter(({ _type, _pageLevelProgress }) => {
116+
if (!_pageLevelProgress) return false;
117+
return _type === 'page' || _type === 'menu';
118+
});
119+
return course._pageLevelProgress || configuredContentObjects.length;
120+
});
121+
122+
mutateContent('Page level progress - add course attribute _showPageCompletion', async (content) => {
123+
if (course._pageLevelProgress) course._pageLevelProgress._showPageCompletion = true;
124+
return true;
125+
});
126+
127+
mutateContent('Page level progress - add content object attribute _showPageCompletion', async (content) => {
128+
configuredContentObjects.forEach(co => (co._pageLevelProgress._showPageCompletion = true));
129+
return true;
130+
});
131+
132+
checkContent('Page level progress - check course attribute _showPageCompletion', async (content) => {
133+
const isValid = !course._pageLevelProgress || course._pageLevelProgress._showPageCompletion === true;
134+
if (!isValid) throw new Error('Page level progress - course attribute _showPageCompletion');
135+
return true;
136+
});
137+
138+
checkContent('Page level progress - check content object attribute _showPageCompletion', async (content) => {
139+
const isValid = configuredContentObjects.every(co => co._pageLevelProgress._showPageCompletion === true);
140+
if (!isValid) throw new Error('Page level progress - content object attribute _showPageCompletion');
141+
return true;
142+
});
143+
144+
updatePlugin('Page level progress - update to v2.0.4', { name: 'adapt-contrib-pageLevelProgress', version: '2.0.4', framework: '=>2.0.0' });
145+
146+
testSuccessWhere('course pageLevelProgress and contentObject with/without pageLevelProgress', {
147+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.3' }],
148+
content: [
149+
{ _type: 'course', _pageLevelProgress: {} },
150+
{ _type: 'page', _pageLevelProgress: {} },
151+
{ _type: 'page' }
152+
]
153+
});
154+
155+
testSuccessWhere('course pageLevelProgress and contentObject without pageLevelProgress', {
156+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.3' }],
157+
content: [
158+
{ _type: 'course', _pageLevelProgress: {} },
159+
{ _type: 'page' },
160+
{ _type: 'page' }
161+
]
162+
});
163+
164+
testSuccessWhere('pageLevelProgress with no contentObjects', {
165+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.3' }],
166+
content: [
167+
{ _type: 'course', _pageLevelProgress: {} }
168+
]
169+
});
170+
171+
testStopWhere('no pageLevelProgress', {
172+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.3' }],
173+
content: [
174+
{ _type: 'course' }
175+
]
176+
});
177+
178+
testStopWhere('incorrect version', {
179+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.4' }]
180+
});
181+
});

migrations/v3.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere } from 'adapt-migrations';
2+
3+
describe('Page level progress - v3.0.0 to v3.1.0', async () => {
4+
// https://github.com/adaptlearning/adapt-contrib-pageLevelProgress/compare/v3.0.0..v3.1.0
5+
6+
let configuredContentObjects;
7+
8+
whereFromPlugin('Page level progress - from v3.0.0', { name: 'adapt-contrib-pageLevelProgress', version: '<3.1.0' });
9+
10+
whereContent('Page level progress is configured', content => {
11+
configuredContentObjects = content.filter(({ _type, _pageLevelProgress }) => {
12+
if (!_pageLevelProgress) return false;
13+
return _type === 'page' || _type === 'menu';
14+
});
15+
return configuredContentObjects.length;
16+
});
17+
18+
mutateContent('Page level progress - add content object attribute _excludeAssessments', async (content) => {
19+
configuredContentObjects.forEach(co => (co._pageLevelProgress._excludeAssessments = false));
20+
return true;
21+
});
22+
23+
checkContent('Page level progress - check content object attribute _excludeAssessments', async (content) => {
24+
const isValid = configuredContentObjects.every(co => co._pageLevelProgress._excludeAssessments === false);
25+
if (!isValid) throw new Error('Page level progress - content object attribute _excludeAssessments');
26+
return true;
27+
});
28+
29+
updatePlugin('Page level progress - update to v3.1.0', { name: 'adapt-contrib-pageLevelProgress', version: '3.1.0', framework: '=>2.2.0' });
30+
31+
testSuccessWhere('contentObject with/without pageLevelProgress', {
32+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '3.0.0' }],
33+
content: [
34+
{ _type: 'page', _pageLevelProgress: {} },
35+
{ _type: 'page' }
36+
]
37+
});
38+
39+
testSuccessWhere('no course pageLevelProgress with content objects', {
40+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '3.0.0' }],
41+
content: [
42+
{ _type: 'course' },
43+
{ _type: 'page', _pageLevelProgress: {} }
44+
]
45+
});
46+
47+
testStopWhere('pageLevelProgress with no contentObjects', {
48+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '3.0.0' }],
49+
content: [
50+
{ _type: 'course', _pageLevelProgress: {} }
51+
]
52+
});
53+
54+
testStopWhere('contentObject without pageLevelProgress', {
55+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '3.0.0' }],
56+
content: [
57+
{ _type: 'page' },
58+
{ _type: 'page' }
59+
]
60+
});
61+
62+
testStopWhere('incorrect version', {
63+
fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '3.1.0' }]
64+
});
65+
});

0 commit comments

Comments
 (0)