diff --git a/apps/server/src/modules/board/service/board-do-copy-service/board-do-copy.service.spec.ts b/apps/server/src/modules/board/service/board-do-copy-service/board-do-copy.service.spec.ts index 0023ece7ad2..d3417a587cc 100644 --- a/apps/server/src/modules/board/service/board-do-copy-service/board-do-copy.service.spec.ts +++ b/apps/server/src/modules/board/service/board-do-copy-service/board-do-copy.service.spec.ts @@ -511,12 +511,12 @@ describe('recursive board copy visitor', () => { expect(copy.id).not.toEqual(original.id); }); - it('should show status successful', async () => { + it('should show status partial', async () => { const { original, fileCopyService } = setup(); const result = await service.copy({ original, fileCopyService }); - expect(result.status).toEqual(CopyStatusEnum.SUCCESS); + expect(result.status).toEqual(CopyStatusEnum.PARTIAL); }); it('should show type RichTextElement', async () => { diff --git a/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.ts b/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.ts index f8c00f4fdbd..212e07cc292 100644 --- a/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.ts +++ b/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.ts @@ -148,7 +148,7 @@ export class RecursiveCopyVisitor implements BoardCompositeVisitorAsync { this.resultMap.set(original.id, { copyEntity: copy, type: CopyElementType.DRAWING_ELEMENT, - status: CopyStatusEnum.SUCCESS, + status: CopyStatusEnum.PARTIAL, }); this.copyMap.set(original.id, copy); diff --git a/apps/server/src/modules/copy-helper/service/copy-helper.service.spec.ts b/apps/server/src/modules/copy-helper/service/copy-helper.service.spec.ts index 337178ecbb8..fb44adb6e64 100644 --- a/apps/server/src/modules/copy-helper/service/copy-helper.service.spec.ts +++ b/apps/server/src/modules/copy-helper/service/copy-helper.service.spec.ts @@ -13,6 +13,21 @@ function createStates(elementStates: CopyStatusEnum[]): CopyStatus[] { return elementState; }); } +function createNestedStates(elementStates: CopyStatusEnum[]): CopyStatus { + const elementState = elementStates.shift(); + const element: CopyStatus = { + title: `title-${Math.floor(Math.random() * 1000)}-${elementStates.length}`, + type: CopyElementType.LEAF, + status: CopyStatusEnum.SUCCESS, + }; + + if (elementState) { + element.status = elementState; + element.elements = elementStates.length ? [createNestedStates(elementStates)] : []; + } + + return element; +} describe('copy helper service', () => { let module: TestingModule; @@ -35,6 +50,23 @@ describe('copy helper service', () => { }); describe('deriveStatusFromElements', () => { + describe('setup cases', () => { + it('should run method multiple times for nested structure', () => { + const derivedStatusSpy = jest.spyOn(copyHelperService, 'deriveStatusFromElements'); + const element = createNestedStates([ + CopyStatusEnum.SUCCESS, + CopyStatusEnum.SUCCESS, + CopyStatusEnum.SUCCESS, + CopyStatusEnum.SUCCESS, + ]); + + copyHelperService.deriveStatusFromElements([element]); + + expect(derivedStatusSpy).toHaveBeenCalledTimes(4); + derivedStatusSpy.mockRestore(); + }); + }); + describe('successful cases', () => { it('should return success, if no elements were given', () => { const derivedStatus = copyHelperService.deriveStatusFromElements([]); @@ -90,6 +122,17 @@ describe('copy helper service', () => { const elements = createStates([CopyStatusEnum.FAIL, CopyStatusEnum.NOT_DOING]); const derivedStatus = copyHelperService.deriveStatusFromElements(elements); + expect(derivedStatus).toEqual(CopyStatusEnum.FAIL); + }); + it('should return fail if the last and only nested child is FAIL ', () => { + const element = createNestedStates([ + CopyStatusEnum.SUCCESS, + CopyStatusEnum.SUCCESS, + CopyStatusEnum.SUCCESS, + CopyStatusEnum.FAIL, + ]); + const derivedStatus = copyHelperService.deriveStatusFromElements([element]); + expect(derivedStatus).toEqual(CopyStatusEnum.FAIL); }); }); diff --git a/apps/server/src/modules/copy-helper/service/copy-helper.service.ts b/apps/server/src/modules/copy-helper/service/copy-helper.service.ts index b3a42dac7df..3a578c2618b 100644 --- a/apps/server/src/modules/copy-helper/service/copy-helper.service.ts +++ b/apps/server/src/modules/copy-helper/service/copy-helper.service.ts @@ -8,6 +8,12 @@ const isAtLeastPartialSuccessfull = (status) => status === CopyStatusEnum.PARTIA @Injectable() export class CopyHelperService { deriveStatusFromElements(elements: CopyStatus[]): CopyStatusEnum { + for (const element of elements) { + if (element.elements?.length) { + element.status = this.deriveStatusFromElements(element.elements); + } + } + const elementsStatuses = elements.map((el) => el.status); const filtered = elementsStatuses.filter((status) => status !== CopyStatusEnum.NOT_DOING);