Skip to content

Commit

Permalink
N21-1256 use course service in tool (#4415)
Browse files Browse the repository at this point in the history
* use course service in tool module instead of course repo
* changes imports for course service overall
  • Loading branch information
arnegns authored Sep 19, 2023
1 parent 8cf1dca commit b0e9f42
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { LegacyLogger } from '@src/core/logger';
import { CopyElementType, CopyHelperService, CopyStatus } from '@src/modules/copy-helper';
import { getResolvedValues } from '@src/modules/files-storage/helper';
import { LessonCopyService } from '@src/modules/lesson/service';
import { TaskCopyService } from '@src/modules/task';
import { TaskCopyService } from '@src/modules/task/service';
import { sortBy } from 'lodash';

type BoardCopyParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { ComponentType, Course, IComponentProperties, IComponentTextProperties, Lesson, Task } from '@shared/domain';
import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing';
import { CommonCartridgeExportService } from '@src/modules/learnroom/service/common-cartridge-export.service';
import { CourseService } from '@src/modules/learnroom/service/course.service';
import { CourseService } from '@src/modules/learnroom/service';
import { LessonService } from '@src/modules/lesson/service';
import { TaskService } from '@src/modules/task/service/task.service';
import AdmZip from 'adm-zip';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BoardExternalReference, BoardExternalReferenceType, EntityId } from '@s
import { BoardRepo, LessonRepo } from '@shared/repo';
import { boardFactory, courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing';
import { CardService, ColumnBoardService, ColumnService, ContentElementService } from '@src/modules/board';
import { TaskService } from '@src/modules/task';
import { TaskService } from '@src/modules/task/service';
import { ColumnBoardTargetService } from './column-board-target.service';
import { RoomsService } from './rooms.service';

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/learnroom/service/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
import { Board, BoardExternalReferenceType, ColumnBoardTarget, EntityId } from '@shared/domain';
import { BoardRepo, LessonRepo } from '@shared/repo';
import { ColumnBoardService } from '@src/modules/board';
import { TaskService } from '@src/modules/task';
import { TaskService } from '@src/modules/task/service';
import { ColumnBoardTargetService } from './column-board-target.service';

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@shared/testing';
import { CopyElementType, CopyHelperService, CopyStatus, CopyStatusEnum } from '@src/modules/copy-helper';
import { CopyFilesService } from '@src/modules/files-storage-client';
import { TaskCopyService } from '@src/modules/task';
import { TaskCopyService } from '@src/modules/task/service';
import { EtherpadService } from './etherpad.service';
import { LessonCopyService } from './lesson-copy.service';
import { NexboardService } from './nexboard.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { NotFoundException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { courseFactory, lessonFactory, setupEntities, shareTokenFactory, taskFactory } from '@shared/testing';
import { CourseService } from '@src/modules/learnroom/service/course.service';
import { CourseService } from '@src/modules/learnroom/service';
import { LessonService } from '@src/modules/lesson/service';
import { TaskService } from '@src/modules/task';
import { TaskService } from '@src/modules/task/service';
import { ObjectId } from 'bson';
import { ShareTokenContextType, ShareTokenParentType } from '../domainobject/share-token.do';
import { ShareTokenRepo } from '../repo/share-token.repo';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { CourseService } from '@src/modules/learnroom/service/course.service';
import { CourseService } from '@src/modules/learnroom/service';
import { LessonService } from '@src/modules/lesson/service';
import { TaskService } from '@src/modules/task';
import { TaskService } from '@src/modules/task/service';
import {
ShareTokenContext,
ShareTokenDO,
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/modules/sharing/uc/share-token.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { LegacyLogger } from '@src/core/logger';
import { Action, AuthorizableReferenceType, AuthorizationService } from '@src/modules/authorization';
import { CopyElementType, CopyStatus, CopyStatusEnum } from '@src/modules/copy-helper';
import { CourseCopyService } from '@src/modules/learnroom';
import { CourseService } from '@src/modules/learnroom/service/course.service';
import { CourseService } from '@src/modules/learnroom/service';
import { LessonCopyService } from '@src/modules/lesson/service';
import { TaskCopyService } from '@src/modules/task';
import { TaskCopyService } from '@src/modules/task/service';
import { ShareTokenContextType, ShareTokenParentType, ShareTokenPayload } from '../domainobject/share-token.do';
import { ShareTokenService } from '../service';
import { ShareTokenUC } from './share-token.uc';
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/modules/sharing/uc/share-token.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { LegacyLogger } from '@src/core/logger';
import { Action, AuthorizationService } from '@src/modules/authorization';
import { CopyStatus } from '@src/modules/copy-helper';
import { CourseCopyService } from '@src/modules/learnroom';
import { CourseService } from '@src/modules/learnroom/service/course.service';
import { CourseService } from '@src/modules/learnroom/service';
import { LessonCopyService } from '@src/modules/lesson/service';
import { TaskCopyService } from '@src/modules/task';
import { TaskCopyService } from '@src/modules/task/service';
import {
ShareTokenContext,
ShareTokenContextType,
Expand Down
1 change: 0 additions & 1 deletion apps/server/src/modules/task/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './task.module';
export { TaskCopyService, TaskService } from './service';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ObjectId } from '@mikro-orm/mongodb';
import { Injectable } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { Course, EntityId, SchoolDO } from '@shared/domain';
import { CourseRepo } from '@shared/repo';
import {
contextExternalToolFactory,
courseFactory,
Expand All @@ -13,7 +12,18 @@ import {
schoolExternalToolFactory,
setupEntities,
} from '@shared/testing';
import { CourseService } from '@src/modules/learnroom/service';
import { SchoolService } from '@src/modules/school';
import { CustomParameterEntry } from '../../../common/domain';
import {
CustomParameterLocation,
CustomParameterScope,
CustomParameterType,
ToolContextType,
} from '../../../common/enum';
import { ContextExternalTool } from '../../../context-external-tool/domain';
import { ExternalTool } from '../../../external-tool/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { MissingToolParameterValueLoggableException, ParameterTypeNotImplementedLoggableException } from '../../error';
import {
LaunchRequestMethod,
Expand All @@ -25,16 +35,6 @@ import {
} from '../../types';
import { AbstractLaunchStrategy } from './abstract-launch.strategy';
import { IToolLaunchParams } from './tool-launch-params.interface';
import {
CustomParameterLocation,
CustomParameterScope,
CustomParameterType,
ToolContextType,
} from '../../../common/enum';
import { ExternalTool } from '../../../external-tool/domain';
import { CustomParameterEntry } from '../../../common/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { ContextExternalTool } from '../../../context-external-tool/domain';

const concreteConfigParameter: PropertyData = {
location: PropertyLocation.QUERY,
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('AbstractLaunchStrategy', () => {
let launchStrategy: TestLaunchStrategy;

let schoolService: DeepMocked<SchoolService>;
let courseRepo: DeepMocked<CourseRepo>;
let courseService: DeepMocked<CourseService>;

beforeAll(async () => {
await setupEntities();
Expand All @@ -87,15 +87,15 @@ describe('AbstractLaunchStrategy', () => {
useValue: createMock<SchoolService>(),
},
{
provide: CourseRepo,
useValue: createMock<CourseRepo>(),
provide: CourseService,
useValue: createMock<CourseService>(),
},
],
}).compile();

launchStrategy = module.get(TestLaunchStrategy);
schoolService = module.get(SchoolService);
courseRepo = module.get(CourseRepo);
courseService = module.get(CourseService);
});

afterAll(async () => {
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('AbstractLaunchStrategy', () => {
);

schoolService.getSchoolById.mockResolvedValue(school);
courseRepo.findById.mockResolvedValue(course);
courseService.findById.mockResolvedValue(course);

const sortFn = (a: PropertyData, b: PropertyData) => {
if (a.name < b.name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { Injectable } from '@nestjs/common';
import { Course, EntityId, SchoolDO } from '@shared/domain';
import { CourseRepo } from '@shared/repo';
import { CourseService } from '@src/modules/learnroom/service';
import { SchoolService } from '@src/modules/school';
import { URLSearchParams } from 'url';
import { CustomParameter, CustomParameterEntry } from '../../../common/domain';
import {
CustomParameterLocation,
CustomParameterScope,
CustomParameterType,
ToolContextType,
} from '../../../common/enum';
import { ContextExternalTool } from '../../../context-external-tool/domain';
import { ExternalTool } from '../../../external-tool/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { MissingToolParameterValueLoggableException, ParameterTypeNotImplementedLoggableException } from '../../error';
import { ToolLaunchMapper } from '../../mapper';
import { LaunchRequestMethod, PropertyData, PropertyLocation, ToolLaunchData, ToolLaunchRequest } from '../../types';
import { IToolLaunchParams } from './tool-launch-params.interface';
import { IToolLaunchStrategy } from './tool-launch-strategy.interface';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { CustomParameter, CustomParameterEntry } from '../../../common/domain';
import { ContextExternalTool } from '../../../context-external-tool/domain';
import { ExternalTool } from '../../../external-tool/domain';

@Injectable()
export abstract class AbstractLaunchStrategy implements IToolLaunchStrategy {
constructor(private readonly schoolService: SchoolService, private readonly courseRepo: CourseRepo) {}
constructor(private readonly schoolService: SchoolService, private readonly courseService: CourseService) {}

public async createLaunchData(userId: EntityId, data: IToolLaunchParams): Promise<ToolLaunchData> {
const launchData: ToolLaunchData = this.buildToolLaunchDataFromExternalTool(data.externalTool);
Expand Down Expand Up @@ -216,7 +216,7 @@ export abstract class AbstractLaunchStrategy implements IToolLaunchStrategy {
}
case CustomParameterType.AUTO_CONTEXTNAME: {
if (contextExternalTool.contextRef.type === ToolContextType.COURSE) {
const course: Course = await this.courseRepo.findById(contextExternalTool.contextRef.id);
const course: Course = await this.courseService.findById(contextExternalTool.contextRef.id);

return course.name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { CourseRepo } from '@shared/repo';
import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing';
import { SchoolService } from '@src/modules/school';
import { CourseService } from '@src/modules/learnroom/service';
import { ContextExternalTool } from '../../../context-external-tool/domain';
import { ExternalTool } from '../../../external-tool/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { LaunchRequestMethod, PropertyData, PropertyLocation } from '../../types';
import { BasicToolLaunchStrategy } from './basic-tool-launch.strategy';
import { IToolLaunchParams } from './tool-launch-params.interface';
import { ExternalTool } from '../../../external-tool/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { ContextExternalTool } from '../../../context-external-tool/domain';

describe('BasicToolLaunchStrategy', () => {
let module: TestingModule;
Expand All @@ -23,8 +23,8 @@ describe('BasicToolLaunchStrategy', () => {
useValue: createMock<SchoolService>(),
},
{
provide: CourseRepo,
useValue: createMock<CourseRepo>(),
provide: CourseService,
useValue: createMock<CourseService>(),
},
],
}).compile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { InternalServerErrorException, UnprocessableEntityException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { Pseudonym, RoleName, UserDO } from '@shared/domain';
import { CourseRepo } from '@shared/repo';
import {
contextExternalToolFactory,
externalToolFactory,
Expand All @@ -15,6 +14,7 @@ import { SchoolService } from '@src/modules/school';
import { UserService } from '@src/modules/user';
import { ObjectId } from 'bson';
import { Authorization } from 'oauth-1.0a';
import { CourseService } from '@src/modules/learnroom/service';
import { LtiMessageType, LtiPrivacyPermission, LtiRole, ToolContextType } from '../../../common/enum';
import { ContextExternalTool } from '../../../context-external-tool/domain';
import { ExternalTool } from '../../../external-tool/domain';
Expand Down Expand Up @@ -53,8 +53,8 @@ describe('Lti11ToolLaunchStrategy', () => {
useValue: createMock<SchoolService>(),
},
{
provide: CourseRepo,
useValue: createMock<CourseRepo>(),
provide: CourseService,
useValue: createMock<CourseService>(),
},
],
}).compile();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable, InternalServerErrorException, UnprocessableEntityException } from '@nestjs/common';
import { EntityId, LtiPrivacyPermission, Pseudonym, RoleName, UserDO } from '@shared/domain';
import { RoleReference } from '@shared/domain/domainobject';
import { CourseRepo } from '@shared/repo';
import { PseudonymService } from '@src/modules/pseudonym';
import { SchoolService } from '@src/modules/school';
import { UserService } from '@src/modules/user';
import { Authorization } from 'oauth-1.0a';
import { CourseService } from '@src/modules/learnroom/service';
import { LtiRole } from '../../../common/enum';
import { ExternalTool } from '../../../external-tool/domain';
import { LtiRoleMapper } from '../../mapper';
Expand All @@ -21,9 +21,9 @@ export class Lti11ToolLaunchStrategy extends AbstractLaunchStrategy {
private readonly pseudonymService: PseudonymService,
private readonly lti11EncryptionService: Lti11EncryptionService,
schoolService: SchoolService,
courseRepo: CourseRepo
courseService: CourseService
) {
super(schoolService, courseRepo);
super(schoolService, courseService);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { CourseRepo } from '@shared/repo';
import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing';
import { SchoolService } from '@src/modules/school';
import { CourseService } from '@src/modules/learnroom/service';
import { ContextExternalTool } from '../../../context-external-tool/domain';
import { ExternalTool } from '../../../external-tool/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { LaunchRequestMethod, PropertyData } from '../../types';
import { OAuth2ToolLaunchStrategy } from './oauth2-tool-launch.strategy';
import { IToolLaunchParams } from './tool-launch-params.interface';
import { ExternalTool } from '../../../external-tool/domain';
import { ContextExternalTool } from '../../../context-external-tool/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';

describe('OAuth2ToolLaunchStrategy', () => {
let module: TestingModule;
Expand All @@ -23,8 +23,8 @@ describe('OAuth2ToolLaunchStrategy', () => {
useValue: createMock<SchoolService>(),
},
{
provide: CourseRepo,
useValue: createMock<CourseRepo>(),
provide: CourseService,
useValue: createMock<CourseService>(),
},
],
}).compile();
Expand Down
15 changes: 7 additions & 8 deletions apps/server/src/modules/tool/tool-launch/tool-launch.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Module } from '@nestjs/common';
import { PseudonymModule } from '@src/modules/pseudonym';
import { SchoolModule } from '@src/modules/school';
import { UserModule } from '@src/modules/user';
import { PseudonymModule } from '@src/modules/pseudonym';
import { CourseRepo } from '@shared/repo';
import { Lti11EncryptionService, ToolLaunchService } from './service';
import { SchoolExternalToolModule } from '../school-external-tool';
import { ExternalToolModule } from '../external-tool';
import { LearnroomModule } from '@src/modules/learnroom';
import { CommonToolModule } from '../common';
import { ContextExternalToolModule } from '../context-external-tool';
import { ExternalToolModule } from '../external-tool';
import { SchoolExternalToolModule } from '../school-external-tool';
import { Lti11EncryptionService, ToolLaunchService } from './service';
import { BasicToolLaunchStrategy, Lti11ToolLaunchStrategy, OAuth2ToolLaunchStrategy } from './service/strategy';
import { CommonToolModule } from '../common';

@Module({
imports: [
Expand All @@ -19,15 +19,14 @@ import { CommonToolModule } from '../common';
SchoolModule,
UserModule,
PseudonymModule,
LearnroomModule,
],
providers: [
ToolLaunchService,
BasicToolLaunchStrategy,
Lti11ToolLaunchStrategy,
OAuth2ToolLaunchStrategy,
Lti11EncryptionService,
// Importing the LearnroomModule instead of CourseRepo creates some kind of dependency cycle that lets unrelated tests fail
CourseRepo,
],
exports: [ToolLaunchService],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ObjectId } from 'bson';
import { teamFactory } from '@shared/testing/factory/team.factory';
import { NotFoundException } from '@nestjs/common/exceptions/not-found.exception';
import { teamUserFactory } from '@shared/testing/factory/teamuser.factory';
import { CourseService } from '@src/modules/learnroom/service/course.service';
import { CourseService } from '@src/modules/learnroom/service';
import { VideoConferenceService } from './video-conference.service';
import { ErrorStatus } from '../error/error-status.enum';
import { BBBRole } from '../bbb';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
AuthorizationContextBuilder,
AuthorizationService,
} from '@src/modules/authorization';
import { CourseService } from '@src/modules/learnroom/service/course.service';
import { CourseService } from '@src/modules/learnroom/service';
import { SchoolService } from '@src/modules/school';
import { UserService } from '@src/modules/user';
import { BBBRole } from '../bbb';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { roleFactory, setupEntities, userDoFactory } from '@shared/testing';
import { teamFactory } from '@shared/testing/factory/team.factory';
import { AuthorizationService, SchoolService, UserService } from '@src/modules';
import { ICurrentUser } from '@src/modules/authentication';
import { CourseService } from '@src/modules/learnroom/service/course.service';
import { CourseService } from '@src/modules/learnroom/service';
import { IScopeInfo, VideoConference, VideoConferenceJoin, VideoConferenceState } from './dto';
import { VideoConferenceDeprecatedUc } from './video-conference-deprecated.uc';
import {
Expand Down
Loading

0 comments on commit b0e9f42

Please sign in to comment.