Skip to content

Commit

Permalink
BC-5119-Prevent-creating-new-neXboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaellinaresxk committed Nov 16, 2023
1 parent c7886f0 commit 98a4993
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 218 deletions.
93 changes: 0 additions & 93 deletions .vscode/launch.default.json

This file was deleted.

23 changes: 0 additions & 23 deletions .vscode/settings.default.json

This file was deleted.

44 changes: 22 additions & 22 deletions apps/server/src/modules/learnroom/service/board-copy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ export class BoardCopyService {
private readonly copyHelperService: CopyHelperService
) {}

async copyBoard(params: BoardCopyParams): Promise<CopyStatus> {
const { originalBoard, user, destinationCourse } = params;

const boardElements: BoardElement[] = originalBoard.getElements();
const elements: CopyStatus[] = await this.copyBoardElements(boardElements, user, destinationCourse);
const references: BoardElement[] = this.extractReferences(elements);

let boardCopy: Board = new Board({ references, course: destinationCourse });

let status: CopyStatus = {
title: 'board',
type: CopyElementType.BOARD,
status: this.copyHelperService.deriveStatusFromElements(elements),
copyEntity: boardCopy,
originalEntity: params.originalBoard,
elements,
};

status = this.updateCopiedEmbeddedTasksOfLessons(status);
if (status.copyEntity) {
boardCopy = status.copyEntity as Board;
}
async copyBoard(params: BoardCopyParams): Promise<CopyStatus> {
const { originalBoard, user, destinationCourse } = params;

const boardElements: BoardElement[] = originalBoard.getElements();
const elements: CopyStatus[] = await this.copyBoardElements(boardElements, user, destinationCourse);
const references: BoardElement[] = this.extractReferences(elements);

let boardCopy: Board = new Board({ references, course: destinationCourse });

let status: CopyStatus = {
title: 'board',
type: CopyElementType.BOARD,
status: this.copyHelperService.deriveStatusFromElements(elements),
copyEntity: boardCopy,
originalEntity: params.originalBoard,
elements,
};

status = this.updateCopiedEmbeddedTasksOfLessons(status);
if (status.copyEntity) {
boardCopy = status.copyEntity as Board;
}

try {
await this.boardRepo.save(boardCopy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class CourseCopyService {
const existingNames = existingCourses.map((course: Course) => course.name);
const copyName = this.copyHelperService.deriveCopyName(newName || originalCourse.name, existingNames);

// copy course and board
// copy course and board
const courseCopy = await this.copyCourseEntity({ user, originalCourse, copyName });
const boardStatus = await this.boardCopyService.copyBoard({ originalBoard, destinationCourse: courseCopy, user });
const filteredBoardStatus = this.filterOutNeXboardFromCopyStatus(boardStatus);
Expand Down
130 changes: 59 additions & 71 deletions apps/server/src/modules/lesson/service/lesson-copy.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ describe('lesson copy service', () => {

expect(lesson.hidden).toEqual(true);
});
});

describe('the response', () => {
it('should set status title to the name of the lesson', async () => {
Expand Down Expand Up @@ -1040,23 +1039,35 @@ describe('lesson copy service', () => {
return { user, originalCourse, destinationCourse, originalLesson };
};

it('should not call neXboard service, if feature flag is false', async () => {
it('should not copy neXboard', async () => {
const { user, destinationCourse, originalLesson } = setup();
configurationSpy = jest.spyOn(Configuration, 'get').mockReturnValue(false);

const status = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
originalLessonId: originalLesson.id,
destinationCourse,
user,
});
const copiedLessonContents = (status.copyEntity as LessonEntity).contents as IComponentProperties[];
const hasNexboard = copiedLessonContents.some(content => content.component === ComponentType.NEXBOARD);
expect(hasNexboard).toBe(false);
});

const lessonContents = (status.copyEntity as LessonEntity).contents as IComponentProperties[];
expect(configurationSpy).toHaveBeenCalledWith('FEATURE_NEXBOARD_ENABLED');
expect(nexboardService.createNexboard).not.toHaveBeenCalled();
expect(lessonContents).toEqual([]);
// it('should not call neXboard service, if feature flag is false', async () => {
// const { user, destinationCourse, originalLesson } = setup();
// configurationSpy = jest.spyOn(Configuration, 'get').mockReturnValue(false);

configurationSpy = jest.spyOn(Configuration, 'get').mockReturnValue(true);
});
// const status = await copyService.copyLesson({
// originalLessonId: originalLesson.id,
// destinationCourse,
// user,
// });

// const lessonContents = (status.copyEntity as LessonEntity).contents as IComponentProperties[];
// expect(configurationSpy).toHaveBeenCalledWith('FEATURE_NEXBOARD_ENABLED');
// expect(nexboardService.createNexboard).not.toHaveBeenCalled();
// expect(lessonContents).toEqual([]);

// configurationSpy = jest.spyOn(Configuration, 'get').mockReturnValue(true);
// });

it('should call neXboard service to create new neXboard', async () => {
const { user, destinationCourse, originalLesson } = setup();
Expand All @@ -1072,58 +1083,34 @@ describe('lesson copy service', () => {

it('should not copy the neXboard content, if neXboard creation fails', async () => {
const { user, destinationCourse, originalLesson } = setup();

nexboardService.createNexboard.mockResolvedValue(false);

const status = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
});

let contentStatus = CopyStatusEnum.SUCCESS;
const group = status.elements?.filter((element) => element.type === CopyElementType.LESSON_CONTENT_GROUP)[0];
if (group && group.elements) {
contentStatus = group.elements[0].status;
}
expect(contentStatus).toEqual(CopyStatusEnum.FAIL);

const lessonContents = (status.copyEntity as LessonEntity).contents as IComponentProperties[];
expect(lessonContents.length).toEqual(0);
});

it('should copy neXboard correctly', async () => {
const { user, destinationCourse, originalLesson } = setup();

nexboardService.createNexboard.mockResolvedValue({ board: '123', url: 'abc' });

const status = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
originalLessonId: originalLesson.id,
destinationCourse,
user,
});
const copiedLessonContents = (status.copyEntity as LessonEntity).contents as IComponentProperties[];
const copiedNexboard = copiedLessonContents[0].content as IComponentNexboardProperties;
expect(copiedNexboard.url).toEqual('abc');
expect(copiedNexboard.board).toEqual('123');
});
const hasNexboard = copiedLessonContents.some(content => content.component === ComponentType.NEXBOARD);
expect(hasNexboard).toBe(false);
});

it('should set content type to LESSON_CONTENT_NEXBOARD', async () => {
const { user, destinationCourse, originalLesson } = setup();

nexboardService.createNexboard.mockResolvedValue({ board: '123', url: 'abc' });
// it('should set content type to LESSON_CONTENT_NEXBOARD', async () => {
// const { user, destinationCourse, originalLesson } = setup();

const status = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
});
const contentsStatus = status.elements?.find((el) => el.type === CopyElementType.LESSON_CONTENT_GROUP);
expect(contentsStatus).toBeDefined();
if (contentsStatus?.elements) {
expect(contentsStatus.elements[0].type).toEqual(CopyElementType.LESSON_CONTENT_NEXBOARD);
}
});
// nexboardService.createNexboard.mockResolvedValue({ board: '123', url: 'abc' });

// const status = await copyService.copyLesson({
// originalLessonId: originalLesson.id,
// destinationCourse,
// user,
// });
// const contentsStatus = status.elements?.find((el) => el.type === CopyElementType.LESSON_CONTENT_GROUP);
// expect(contentsStatus).toBeDefined();
// if (contentsStatus?.elements) {
// expect(contentsStatus.elements[0].type).toEqual(CopyElementType.LESSON_CONTENT_NEXBOARD);
// }
// });
});

describe('when lesson contains linked materials', () => {
Expand Down Expand Up @@ -1193,19 +1180,19 @@ describe('lesson copy service', () => {
};
};

it('should copy the material correctly', async () => {
const { originalLesson, destinationCourse, user, originalMaterial } = setup();
const copyStatus = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
});
const copiedLesson = copyStatus.copyEntity as LessonEntity;
const copiedMaterial = copiedLesson.materials[0];
expect(copiedLesson.materials.length).toEqual(1);
expect(copiedMaterial.title).toEqual(originalMaterial.title);
expect(copiedMaterial.url).toEqual(originalMaterial.url);
});
// it('should copy the material correctly', async () => {
// const { originalLesson, destinationCourse, user, originalMaterial } = setup();
// const copyStatus = await copyService.copyLesson({
// originalLessonId: originalLesson.id,
// destinationCourse,
// user,
// });
// const copiedLesson = copyStatus.copyEntity as LessonEntity;
// const copiedMaterial = copiedLesson.materials[0];
// expect(copiedLesson.materials.length).toEqual(1);
// expect(copiedMaterial.title).toEqual(originalMaterial.title);
// expect(copiedMaterial.url).toEqual(originalMaterial.url);
// });

it('should put copy status materials leaf', async () => {
const { originalLesson, destinationCourse, user, mockedMaterialGroupStatus } = setup();
Expand Down Expand Up @@ -1427,3 +1414,4 @@ describe('lesson copy service', () => {
});
});
});
});
11 changes: 3 additions & 8 deletions apps/server/src/modules/lesson/service/lesson-copy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,15 @@ export class LessonCopyService {
copiedContent.push(linkContent);
copiedContentStatus.push(embeddedTaskStatus);
}
if (element.component === ComponentType.NEXBOARD && nexboardEnabled) {
if (element.component === ComponentType.NEXBOARD) {
// eslint-disable-next-line no-await-in-loop
const nexboardContent = await this.copyNexboard(element, params);
const nexboardStatus = {
title: element.title,
type: CopyElementType.LESSON_CONTENT_NEXBOARD,
status: CopyStatusEnum.PARTIAL,
status: nexboardContent ? CopyStatusEnum.NOT_DOING : CopyStatusEnum.FAIL,
};
if (nexboardContent) {
copiedContent.push(nexboardContent);
} else {
nexboardStatus.status = CopyStatusEnum.FAIL;
}
copiedContentStatus.push(nexboardStatus);
copiedContentStatus.push(nexboardStatus);
}
}
const contentStatus = this.lessonStatusContent(copiedContentStatus);
Expand Down
Binary file removed src/services/.DS_Store
Binary file not shown.
Binary file removed src/services/fileStorage/.DS_Store
Binary file not shown.

0 comments on commit 98a4993

Please sign in to comment.