Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-1885 refactor ctl dos #5004

Merged
merged 32 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cf7d978
N21-1885 WIP
arnegns May 14, 2024
db74662
N21-1885 WIP
arnegns May 14, 2024
2d92197
Merge branch 'main' into N21-1885-refactor-ctl-dos
arnegns May 14, 2024
1bb20bf
N21-1885 WIP
arnegns May 14, 2024
50c0521
Merge branch 'main' into N21-1885-refactor-ctl-dos
arnegns May 15, 2024
5cabc6f
N21-1885 some test fixes
arnegns May 15, 2024
960adc2
N21-1885 moving factories
arnegns May 15, 2024
26057c7
N21-1885 adjust repos
arnegns May 15, 2024
ccbdef6
Merge branch 'main' into N21-1885-refactor-ctl-dos
arnegns May 15, 2024
b2ee8c6
N21-1885 updates imports for linter
arnegns May 15, 2024
929826a
Merge branch 'main' into N21-1885-refactor-ctl-dos
arnegns May 15, 2024
0f83d46
N21-1885 updates imports 2
arnegns May 15, 2024
0ae2792
N21-1885 fixes tests
arnegns May 15, 2024
d83f5bf
N21-1885 fixes tests 2
arnegns May 15, 2024
fe480c9
Merge branch 'main' into N21-1885-refactor-ctl-dos
arnegns May 16, 2024
1a94f03
N21-1885 fixes tests 3
arnegns May 16, 2024
36c1d71
N21-1885 external tool entity without basedorepo
arnegns May 16, 2024
29859cd
Merge branch 'main' into N21-1885-refactor-ctl-dos
arnegns May 16, 2024
b031a26
N21-1885 adds tests
arnegns May 16, 2024
5ddc60e
N21-1885 fixes linter
arnegns May 16, 2024
d607f99
N21-1885 fixes import
arnegns May 16, 2024
6fddf72
N21-1885 fixes linter
arnegns May 16, 2024
0b52a77
N21-1885 fixes tests
arnegns May 16, 2024
4168220
fix a few tests
IgorCapCoder May 16, 2024
569d7be
N21-1885 fixes tests
arnegns May 17, 2024
69fec8d
N21-1885 fixes tests 2
arnegns May 17, 2024
134f22e
N21-1885 fixes uncovered lines
arnegns May 17, 2024
a4174a1
N21-1885 revert repo save change
arnegns May 17, 2024
e489ee3
N21-1885 adds id to update
arnegns May 17, 2024
0f3a219
N21-1885 fixes update
arnegns May 17, 2024
54a4fee
N21-1885 review fixes
arnegns May 17, 2024
1956aef
fix do setter
IgorCapCoder May 17, 2024
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
@@ -1,16 +1,10 @@
import { SchoolExternalTool } from '@modules/tool/school-external-tool/domain';
import { SchoolExternalToolEntity } from '@modules/tool/school-external-tool/entity';
import { schoolExternalToolEntityFactory } from '@modules/tool/school-external-tool/testing';
import { schoolExternalToolEntityFactory, schoolExternalToolFactory } from '@modules/tool/school-external-tool/testing';
import { Test, TestingModule } from '@nestjs/testing';
import { Role, User } from '@shared/domain/entity';
import { Permission } from '@shared/domain/interface';
import {
roleFactory,
schoolEntityFactory,
schoolExternalToolFactory,
setupEntities,
userFactory,
} from '@shared/testing';
import { roleFactory, schoolEntityFactory, setupEntities, userFactory } from '@shared/testing';
import { AuthorizationHelper } from '../service/authorization.helper';
import { Action } from '../type';
import { SchoolExternalToolRule } from './school-external-tool.rule';
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/modules/board/repo/board-do.repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { CollaborativeTextEditorService } from '@modules/collaborative-text-edit
import { FilesStorageClientAdapterService } from '@modules/files-storage-client';
import { DrawingElementAdapterService } from '@modules/tldraw-client';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { contextExternalToolEntityFactory } from '@modules/tool/context-external-tool/testing';
import {
contextExternalToolEntityFactory,
contextExternalToolFactory,
} from '@modules/tool/context-external-tool/testing';
import { NotFoundException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import {
Expand All @@ -33,7 +36,6 @@ import {
columnBoardNodeFactory,
columnFactory,
columnNodeFactory,
contextExternalToolFactory,
courseFactory,
externalToolElementNodeFactory,
fileElementFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { CollaborativeTextEditorService } from '@modules/collaborative-text-edit
import { FileDto, FilesStorageClientAdapterService } from '@modules/files-storage-client';
import { DrawingElementAdapterService } from '@modules/tldraw-client';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { contextExternalToolFactory } from '@modules/tool/context-external-tool/testing';
import { Test, TestingModule } from '@nestjs/testing';
import {
collaborativeTextEditorElementFactory,
columnBoardFactory,
columnFactory,
contextExternalToolFactory,
drawingElementFactory,
externalToolElementFactory,
fileElementFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { FileRecordParentType } from '@infra/rabbitmq';
import { ObjectId } from '@mikro-orm/mongodb';
import { CopyElementType, CopyStatus, CopyStatusEnum } from '@modules/copy-helper';
import { ContextExternalTool } from '@modules/tool/context-external-tool/domain';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { contextExternalToolFactory } from '@modules/tool/context-external-tool/testing';
import { ToolFeatures } from '@modules/tool/tool-config';
import { Test, TestingModule } from '@nestjs/testing';
import {
Card,
Expand All @@ -28,7 +31,6 @@ import {
cardFactory,
columnBoardFactory,
columnFactory,
contextExternalToolFactory,
drawingElementFactory,
externalToolElementFactory,
fileElementFactory,
Expand All @@ -38,8 +40,6 @@ import {
submissionContainerElementFactory,
submissionItemFactory,
} from '@shared/testing';
import { ObjectId } from '@mikro-orm/mongodb';
import { ToolFeatures } from '@modules/tool/tool-config';
import { BoardDoCopyService } from './board-do-copy.service';
import { SchoolSpecificFileCopyService } from './school-specific-file-copy.interface';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {
import { InputFormat } from '@shared/domain/types';
import {
cardFactory,
contextExternalToolFactory,
drawingElementFactory,
fileElementFactory,
linkElementFactory,
richTextElementFactory,
setupEntities,
submissionContainerElementFactory,
} from '@shared/testing';
import { contextExternalToolFactory } from '@src/modules/tool/context-external-tool/testing';
import {
DrawingContentBody,
FileContentBody,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ import { ExternalToolService } from '@modules/tool';
import { CustomParameterScope, ToolContextType } from '@modules/tool/common/enum';
import { ContextExternalToolService } from '@modules/tool/context-external-tool';
import { ContextExternalTool } from '@modules/tool/context-external-tool/domain';
import { contextExternalToolFactory } from '@modules/tool/context-external-tool/testing';
import { ExternalTool } from '@modules/tool/external-tool/domain';
import { ExternalToolLogoService } from '@modules/tool/external-tool/service';
import { externalToolFactory } from '@modules/tool/external-tool/testing';
import { SchoolExternalToolService } from '@modules/tool/school-external-tool';
import { SchoolExternalTool } from '@modules/tool/school-external-tool/domain';
import { schoolExternalToolFactory } from '@modules/tool/school-external-tool/testing';
import { Test, TestingModule } from '@nestjs/testing';
import { MediaAvailableLine, MediaBoard, MediaExternalToolElement, Page } from '@shared/domain/domainobject';
import { User } from '@shared/domain/entity';
import {
contextExternalToolFactory,
externalToolFactory,
mediaBoardFactory,
mediaExternalToolElementFactory,
schoolExternalToolFactory,
setupEntities,
userFactory,
} from '@shared/testing';
import { mediaBoardFactory, mediaExternalToolElementFactory, setupEntities, userFactory } from '@shared/testing';
import { MediaAvailableLineService } from './media-available-line.service';

describe(MediaAvailableLineService.name, () => {
Expand Down Expand Up @@ -82,7 +77,7 @@ describe(MediaAvailableLineService.name, () => {
.buildWithId();

const usedContextExternalTool: ContextExternalTool = contextExternalToolFactory
.withSchoolExternalToolRef(usedSchoolExternalTool.id as string, user.school.id)
.withSchoolExternalToolRef(usedSchoolExternalTool.id, user.school.id)
.buildWithId();

const mediaExternalToolElement: MediaExternalToolElement = mediaExternalToolElementFactory.build({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { createMock, type DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { ToolContextType } from '@modules/tool/common/enum';
import type { ContextExternalToolWithId } from '@modules/tool/context-external-tool/domain';
import { ContextExternalTool } from '@modules/tool/context-external-tool/domain';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { SchoolExternalToolWithId } from '@modules/tool/school-external-tool/domain';
import { contextExternalToolFactory } from '@modules/tool/context-external-tool/testing';
import { SchoolExternalTool } from '@modules/tool/school-external-tool/domain';
import { schoolExternalToolFactory } from '@modules/tool/school-external-tool/testing';
import { NotFoundException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import {
contextExternalToolFactory,
mediaBoardFactory,
mediaExternalToolElementFactory,
mediaLineFactory,
schoolExternalToolFactory,
setupEntities,
userFactory,
} from '@shared/testing';
Expand Down Expand Up @@ -106,14 +106,12 @@ describe(MediaElementService.name, () => {
describe('when creating a new context external tool', () => {
const setup = () => {
const user = userFactory.build();
const schoolExternalTool = schoolExternalToolFactory
.withSchoolId(user.school.id)
.build() as SchoolExternalToolWithId;
const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.withSchoolId(user.school.id).build();
const mediaBoard = mediaBoardFactory.build();
const contextExternalTool = contextExternalToolFactory
const contextExternalTool: ContextExternalTool = contextExternalToolFactory
.withSchoolExternalToolRef(schoolExternalTool.id, user.school.id)
.withContextRef(mediaBoard.id, ToolContextType.MEDIA_BOARD)
.buildWithId() as ContextExternalToolWithId;
.buildWithId();

contextExternalToolService.saveContextExternalTool.mockResolvedValueOnce(contextExternalTool);

Expand All @@ -130,39 +128,42 @@ describe(MediaElementService.name, () => {

const result = await service.createContextExternalToolForMediaBoard(user, schoolExternalTool, mediaBoard);

expect(result).toEqual({
id: contextExternalTool.id,
displayName: contextExternalTool.displayName,
schoolToolRef: {
schoolId: user.school.id,
schoolToolId: schoolExternalTool.id,
},
contextRef: {
id: mediaBoard.id,
type: ToolContextType.MEDIA_BOARD,
},
toolVersion: contextExternalTool.toolVersion,
parameters: contextExternalTool.parameters,
});
expect(result).toEqual(
new ContextExternalTool({
id: expect.any(String),
displayName: contextExternalTool.displayName,
schoolToolRef: {
schoolId: user.school.id,
schoolToolId: schoolExternalTool.id,
},
contextRef: {
id: mediaBoard.id,
type: ToolContextType.MEDIA_BOARD,
},
parameters: contextExternalTool.parameters,
})
);
});

it('should save the new context external tool', async () => {
const { user, schoolExternalTool, mediaBoard } = setup();

await service.createContextExternalToolForMediaBoard(user, schoolExternalTool, mediaBoard);

expect(contextExternalToolService.saveContextExternalTool).toHaveBeenCalledWith({
schoolToolRef: {
schoolId: user.school.id,
schoolToolId: schoolExternalTool.id,
},
contextRef: {
id: mediaBoard.id,
type: ToolContextType.MEDIA_BOARD,
},
toolVersion: 0,
parameters: [],
});
expect(contextExternalToolService.saveContextExternalTool).toHaveBeenCalledWith(
new ContextExternalTool({
id: expect.any(String),
schoolToolRef: {
schoolId: user.school.id,
schoolToolId: schoolExternalTool.id,
},
contextRef: {
id: mediaBoard.id,
type: ToolContextType.MEDIA_BOARD,
},
parameters: [],
})
);
});
});
});
Expand All @@ -171,7 +172,7 @@ describe(MediaElementService.name, () => {
describe('when creating a new element', () => {
const setup = () => {
const line = mediaLineFactory.build();
const contextExternalTool = contextExternalToolFactory.buildWithId() as ContextExternalToolWithId;
const contextExternalTool: ContextExternalTool = contextExternalToolFactory.buildWithId();

return {
line,
Expand Down Expand Up @@ -250,8 +251,10 @@ describe(MediaElementService.name, () => {
describe('checkElementExists', () => {
describe('when an element exists', () => {
const setup = () => {
const schoolExternalTool = schoolExternalToolFactory.buildWithId() as SchoolExternalToolWithId;
const contextExternalTool = contextExternalToolFactory.withSchoolExternalToolRef(schoolExternalTool.id).build();
const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.buildWithId();
const contextExternalTool: ContextExternalTool = contextExternalToolFactory
.withSchoolExternalToolRef(schoolExternalTool.id)
.build();
const element = mediaExternalToolElementFactory.build({ contextExternalToolId: contextExternalTool.id });
const line = mediaLineFactory.addChild(element).build();
const mediaBoard = mediaBoardFactory.addChild(line).build();
Expand All @@ -275,8 +278,10 @@ describe(MediaElementService.name, () => {

describe('when an element does not exist', () => {
const setup = () => {
const schoolExternalTool = schoolExternalToolFactory.buildWithId() as SchoolExternalToolWithId;
const contextExternalTool = contextExternalToolFactory.withSchoolExternalToolRef(schoolExternalTool.id).build();
const schoolExternalTool: SchoolExternalTool = schoolExternalToolFactory.buildWithId();
const contextExternalTool: ContextExternalTool = contextExternalToolFactory
.withSchoolExternalToolRef(schoolExternalTool.id)
.build();
const element = mediaExternalToolElementFactory.build({ contextExternalToolId: new ObjectId().toHexString() });
const line = mediaLineFactory.addChild(element).build();
const mediaBoard = mediaBoardFactory.addChild(line).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { ToolContextType } from '@modules/tool/common/enum';
import { ContextExternalToolService } from '@modules/tool/context-external-tool';
import { ContextExternalTool, ContextExternalToolWithId, ContextRef } from '@modules/tool/context-external-tool/domain';
import { SchoolExternalToolRefDO, SchoolExternalToolWithId } from '@modules/tool/school-external-tool/domain';
import { ContextExternalTool, ContextRef } from '@modules/tool/context-external-tool/domain';
import { SchoolExternalTool, SchoolExternalToolRef } from '@modules/tool/school-external-tool/domain';
import { Injectable, NotFoundException } from '@nestjs/common';
import {
AnyBoardDo,
Expand Down Expand Up @@ -35,10 +35,7 @@ export class MediaElementService {
return element;
}

public async checkElementExists(
mediaBoard: MediaBoard,
schoolExternalTool: SchoolExternalToolWithId
): Promise<boolean> {
public async checkElementExists(mediaBoard: MediaBoard, schoolExternalTool: SchoolExternalTool): Promise<boolean> {
const contextExternalTools: ContextExternalTool[] = await this.contextExternalToolService.findContextExternalTools({
schoolToolRef: { schoolToolId: schoolExternalTool.id },
});
Expand All @@ -52,26 +49,25 @@ export class MediaElementService {

public async createContextExternalToolForMediaBoard(
user: User,
schoolExternalTool: SchoolExternalToolWithId,
schoolExternalTool: SchoolExternalTool,
mediaBoard: MediaBoard
): Promise<ContextExternalToolWithId> {
const contextExternalTool: ContextExternalToolWithId =
await this.contextExternalToolService.saveContextExternalTool(
new ContextExternalTool({
schoolToolRef: new SchoolExternalToolRefDO({ schoolId: user.school.id, schoolToolId: schoolExternalTool.id }),
contextRef: new ContextRef({ id: mediaBoard.id, type: ToolContextType.MEDIA_BOARD }),
toolVersion: 0,
parameters: [],
})
);
): Promise<ContextExternalTool> {
const contextExternalTool: ContextExternalTool = await this.contextExternalToolService.saveContextExternalTool(
new ContextExternalTool({
id: new ObjectId().toHexString(),
schoolToolRef: new SchoolExternalToolRef({ schoolId: user.school.id, schoolToolId: schoolExternalTool.id }),
contextRef: new ContextRef({ id: mediaBoard.id, type: ToolContextType.MEDIA_BOARD }),
parameters: [],
})
);

return contextExternalTool;
}

public async createExternalToolElement(
parent: MediaLine,
position: number,
contextExternalTool: ContextExternalToolWithId
contextExternalTool: ContextExternalTool
): Promise<MediaExternalToolElement> {
const element: MediaExternalToolElement = new MediaExternalToolElement({
id: new ObjectId().toHexString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { AuthorizationService } from '@modules/authorization';
import { ExternalTool } from '@modules/tool/external-tool/domain';
import { externalToolFactory } from '@modules/tool/external-tool/testing';
import { SchoolExternalTool } from '@modules/tool/school-external-tool/domain';
import { schoolExternalToolFactory } from '@modules/tool/school-external-tool/testing';
import { MediaUserLicense, mediaUserLicenseFactory, UserLicenseService } from '@modules/user-license';
import { MediaUserLicenseService } from '@modules/user-license/service';
import { ConfigService } from '@nestjs/config';
Expand All @@ -18,12 +20,10 @@ import {
import { User } from '@shared/domain/entity';
import {
boardDoAuthorizableFactory,
externalToolFactory,
mediaAvailableLineElementFactory,
mediaAvailableLineFactory,
mediaBoardFactory,
mediaExternalToolElementFactory,
schoolExternalToolFactory,
setupEntities,
userFactory,
} from '@shared/testing';
Expand Down
Loading
Loading