musora-content-services 1.0.172 → 1.0.173

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.173](https://github.com/railroadmedia/musora-content-services/compare/v1.0.172...v1.0.173) (2024-11-14)
6
+
5
7
  ### [1.0.172](https://github.com/railroadmedia/musora-content-services/compare/v1.0.171...v1.0.172) (2024-11-13)
6
8
 
7
9
  ### [1.0.171](https://github.com/railroadmedia/musora-content-services/compare/v1.0.170...v1.0.171) (2024-11-12)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.172",
3
+ "version": "1.0.173",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.d.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
 
14
14
  import {
15
15
  assignmentStatusCompleted,
16
+ assignmentStatusReset,
16
17
  contentStatusCompleted,
17
18
  contentStatusReset,
18
19
  getAllCompleted,
@@ -132,6 +133,7 @@ declare module 'musora-content-services' {
132
133
  export {
133
134
  addItemToPlaylist,
134
135
  assignmentStatusCompleted,
136
+ assignmentStatusReset,
135
137
  contentStatusCompleted,
136
138
  contentStatusReset,
137
139
  countAssignmentsAndLessons,
package/src/index.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
 
14
14
  import {
15
15
  assignmentStatusCompleted,
16
+ assignmentStatusReset,
16
17
  contentStatusCompleted,
17
18
  contentStatusReset,
18
19
  getAllCompleted,
@@ -131,6 +132,7 @@ import {
131
132
  export {
132
133
  addItemToPlaylist,
133
134
  assignmentStatusCompleted,
135
+ assignmentStatusReset,
134
136
  contentStatusCompleted,
135
137
  contentStatusReset,
136
138
  countAssignmentsAndLessons,
@@ -151,24 +151,40 @@ function getChildrenToDepth(parentId, hierarchy, depth = 1) {
151
151
  }
152
152
 
153
153
 
154
+ export async function assignmentStatusReset(assignmentId, contentId) {
155
+ await dataContext.update(
156
+ async function (localContext) {
157
+ let hierarchy = await fetchHierarchy(contentId);
158
+ resetStatusInLocalContext(localContext, assignmentId, hierarchy);
159
+ },
160
+ async function () {
161
+ return postContentReset(contentId);
162
+ });
163
+ }
164
+
154
165
  export async function contentStatusReset(contentId) {
155
166
  await dataContext.update(
156
167
  async function (localContext) {
157
168
  let hierarchy = await fetchHierarchy(contentId);
158
- let allChildIds = getChildrenToDepth(contentId, hierarchy, 5);
159
- allChildIds.push(contentId);
160
- allChildIds.forEach(id => {
161
- const index = Object.keys(localContext.data).indexOf(id.toString());
162
- if (index > -1) { // only splice array when item is found
163
- delete localContext.data[id];
164
- }
165
- });
169
+ resetStatusInLocalContext(localContext, contentId, hierarchy);
166
170
  },
167
171
  async function () {
168
172
  return postContentReset(contentId);
169
173
  });
170
174
  }
171
175
 
176
+ function resetStatusInLocalContext(localContext, contentId, hierarchy) {
177
+ let allChildIds = getChildrenToDepth(contentId, hierarchy, 5);
178
+ allChildIds.push(contentId);
179
+ allChildIds.forEach(id => {
180
+ const index = Object.keys(localContext.data).indexOf(id.toString());
181
+ if (index > -1) { // only splice array when item is found
182
+ delete localContext.data[id];
183
+ }
184
+ });
185
+ bubbleProgress(hierarchy, contentId, localContext);
186
+ }
187
+
172
188
  /**
173
189
  * Record watch session
174
190
  * @return {string} sessionId - provide in future calls to update progress
@@ -230,17 +246,13 @@ function bubbleProgress(hierarchy, contentId, localContext) {
230
246
  let parentId = hierarchy.parents[contentId];
231
247
  if (!parentId) return;
232
248
  let data = localContext.data[parentId] ?? {};
233
- let progress = data[DATA_KEY_PROGRESS];
234
- let status = data[DATA_KEY_STATUS];
235
- if (status !== STATE_COMPLETED && progress !== 100) {
236
- let childProgress = hierarchy.children[parentId].map(function (childId) {
237
- return localContext.data[childId]?.[DATA_KEY_PROGRESS] ?? 0;
238
- });
239
- progress = Math.round(childProgress.reduce((a, b) => a + b, 0) / childProgress.length);
240
- data[DATA_KEY_PROGRESS] = progress;
241
- data[DATA_KEY_STATUS] = progress === 100 ? STATE_COMPLETED : STATE_STARTED;
242
- localContext.data[parentId] = data;
243
- }
249
+ let childProgress = hierarchy.children[parentId].map(function (childId) {
250
+ return localContext.data[childId]?.[DATA_KEY_PROGRESS] ?? 0;
251
+ });
252
+ let progress = Math.round(childProgress.reduce((a, b) => a + b, 0) / childProgress.length);
253
+ data[DATA_KEY_PROGRESS] = progress;
254
+ data[DATA_KEY_STATUS] = progress === 100 ? STATE_COMPLETED : STATE_STARTED;
255
+ localContext.data[parentId] = data;
244
256
  bubbleProgress(hierarchy, parentId, localContext);
245
257
  }
246
258
 
@@ -7,7 +7,7 @@ import {
7
7
  getProgressStateByIds,
8
8
  getAllStarted,
9
9
  getAllCompleted,
10
- contentStatusCompleted, assignmentStatusCompleted, contentStatusReset
10
+ contentStatusCompleted, assignmentStatusCompleted, contentStatusReset, assignmentStatusReset
11
11
  } from "../src/services/contentProgress";
12
12
  import {initializeTestService} from "./initializeTests";
13
13
  import {postContentCompleted} from "../src";
@@ -148,6 +148,33 @@ describe('contentProgressDataContext', function () {
148
148
  // state = await getProgressState(contentId); //assignment
149
149
  // expect(state).toBe("completed");
150
150
  // });
151
+ //
152
+ // test('assignmentCompleteResetBubblingMultiple', async () => {
153
+ // let contentId = 281709;
154
+ //
155
+ // let state = await getProgressState(contentId);
156
+ // expect(state).toBe("");
157
+ //
158
+ // let assignmentIds = [281710, 281711, 281712, 281713, 281714, 281715];
159
+ // for (const assignmentId of assignmentIds) {
160
+ // await assignmentStatusCompleted(assignmentId, contentId);
161
+ // state = await getProgressState(assignmentId);
162
+ // expect(state).toBe("completed");
163
+ // }
164
+ //
165
+ // state = await getProgressState(contentId);
166
+ // expect(state).toBe("completed");
167
+ //
168
+ // await assignmentStatusReset(assignmentIds[0], contentId);
169
+ // state = await getProgressState(assignmentIds[0]);
170
+ // expect(state).toBe("");
171
+ // state = await getProgressState(contentId);
172
+ // expect(state).toBe("started");
173
+ // let percentage = await getProgressPercentage(contentId);
174
+ // expect(percentage).toBe(83);
175
+ // });
176
+
177
+
151
178
  //
152
179
  // test('completeBubbling', async () => {
153
180
  // let state = await getProgressState(276698);
@@ -181,5 +208,4 @@ describe('contentProgressDataContext', function () {
181
208
  // });
182
209
 
183
210
 
184
-
185
211
  });
@@ -2,7 +2,7 @@ import {
2
2
  recordWatchSession,
3
3
  getProgressPercentage,
4
4
  dataContext,
5
- getProgressState, contentStatusCompleted, contentStatusReset
5
+ getProgressState, contentStatusCompleted, contentStatusReset, assignmentStatusCompleted
6
6
  } from "../../src/services/contentProgress";
7
7
  import {initializeTestService} from "../initializeTests";
8
8
 
@@ -80,6 +80,35 @@ describe('contentProgressDataContextLocal', function () {
80
80
  expect(result).toBe("");
81
81
  }, 100000);
82
82
 
83
+ test('assignmentCompleteBubblingToCompletedMultiple', async () => {
84
+ let contentId = 281709;
85
+ await contentStatusReset(contentId);
86
+
87
+ let state = await getProgressState(contentId);
88
+ expect(state).toBe("");
89
+
90
+ let assignmentIds = [281710, 281711, 281712, 281713, 281714, 281715];
91
+ for (const assignmentId of assignmentIds) {
92
+ await assignmentStatusCompleted(assignmentId, contentId);
93
+ state = await getProgressState(assignmentId);
94
+ expect(state).toBe("completed");
95
+ }
96
+
97
+ state = await getProgressState(contentId); //assignment
98
+ expect(state).toBe("completed");
99
+
100
+ dataContext.clearCache();
101
+
102
+ state = await getProgressState(contentId); //assignment
103
+ expect(state).toBe("completed");
104
+
105
+ for (const assignmentId of assignmentIds) {
106
+ state = await getProgressState(assignmentId);
107
+ expect(state).toBe("completed");
108
+ }
109
+
110
+ }, 100000);
111
+
83
112
 
84
113
  //
85
114
  // test('progressBubbling', async () => {