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
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
retryFailedCopy: withChangeTracker(function(changeTracker) {
this.updateContentNode({
id: this.nodeId,
checkComplete: true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably don't need to check complete here either.

[COPYING_STATUS]: COPYING_STATUS_VALUES.COPYING,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,12 @@
saveFromDiffTracker(id) {
if (this.diffTracker[id]) {
this.changed = true;
return this.updateContentNode({ id, ...this.diffTracker[id] }).then(() => {
delete this.diffTracker[id];
return this.changed;
});
return this.updateContentNode({ id, checkComplete: true, ...this.diffTracker[id] }).then(
() => {
delete this.diffTracker[id];
return this.changed;
}
);
}
return Promise.resolve(this.changed);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,11 @@

if (completeCheck !== node.complete) {
validationPromises.push(
vm.updateContentNode({ id: nodeId, complete: completeCheck })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess technically, we don't need to rerun the complete check here, because we already ran it above?

vm.updateContentNode({
id: nodeId,
complete: completeCheck,
checkComplete: true,
})
);
}
});
Expand Down Expand Up @@ -578,7 +582,12 @@
inheritMetadata(metadata) {
const setMetadata = () => {
for (const nodeId of this.newNodeIds) {
this.updateContentNode({ id: nodeId, ...metadata, mergeMapFields: true });
this.updateContentNode({
id: nodeId,
...metadata,
mergeMapFields: true,
checkComplete: true,
});
}
this.newNodeIds = [];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('contentNode actions', () => {
});
});
describe('updateContentNode action for an existing contentNode', () => {
it('should call ContentNode.update', () => {
it('should call ContentNode.update without complete if completeCheck is false', () => {
store.commit('contentNode/ADD_CONTENTNODE', {
id,
title: 'test',
Expand All @@ -125,6 +125,32 @@ describe('contentNode actions', () => {
language: 'no',
learning_activities: { test: true },
})
.then(() => {
expect(updateSpy).toHaveBeenCalledWith(id, {
title: 'notatest',
description: 'very',
language: 'no',
changed: true,
learning_activities: { test: true },
});
updateSpy.mockRestore();
});
});
it('should call ContentNode.update with complete false if completeCheck is true', () => {
store.commit('contentNode/ADD_CONTENTNODE', {
id,
title: 'test',
});
const updateSpy = jest.spyOn(ContentNode, 'update');
return store
.dispatch('contentNode/updateContentNode', {
id,
title: 'notatest',
description: 'very',
language: 'no',
learning_activities: { test: true },
checkComplete: true,
})
.then(() => {
expect(updateSpy).toHaveBeenCalledWith(id, {
title: 'notatest',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import flatMap from 'lodash/flatMap';
import uniq from 'lodash/uniq';
import isEmpty from 'lodash/isEmpty';
import { NEW_OBJECT, NOVALUE, DescendantsUpdatableFields } from 'shared/constants';
import client from 'shared/client';
import {
Expand Down Expand Up @@ -349,10 +350,16 @@ const mapFields = [
'tags',
];

export function updateContentNode(context, { id, mergeMapFields, ...payload } = {}) {
export function updateContentNode(
context,
{ id, mergeMapFields, checkComplete = false, ...payload } = {}
) {
if (!id) {
throw ReferenceError('id must be defined to update a contentNode');
}
if (isEmpty(payload)) {
return Promise.resolve();
}
let contentNodeData = generateContentNodeData(payload);

const node = context.getters.getContentNode(id);
Expand Down Expand Up @@ -421,19 +428,21 @@ export function updateContentNode(context, { id, mergeMapFields, ...payload } =
}
}

const newNode = {
...node,
...contentNodeData,
};
const complete = isNodeComplete({
nodeDetails: newNode,
assessmentItems: context.rootGetters['assessmentItem/getAssessmentItems'](id),
files: context.rootGetters['file/getContentNodeFiles'](id),
});
contentNodeData = {
...contentNodeData,
complete,
};
if (checkComplete) {
const newNode = {
...node,
...contentNodeData,
};
const complete = isNodeComplete({
nodeDetails: newNode,
assessmentItems: context.rootGetters['assessmentItem/getAssessmentItems'](id),
files: context.rootGetters['file/getContentNodeFiles'](id),
});
contentNodeData = {
...contentNodeData,
complete,
};
}

context.commit('ADD_CONTENTNODE', { id, ...contentNodeData });
return ContentNode.update(id, contentNodeData);
Expand Down