Skip to content

Commit

Permalink
isolate lesson repo from authorisation service
Browse files Browse the repository at this point in the history
  • Loading branch information
Metauriel committed Nov 10, 2023
1 parent 7199ada commit 5cff010
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { BoardDoAuthorizableService } from '@modules/board';
import { ContextExternalToolAuthorizableService } from '@modules/tool';
import { NotImplementedException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { EntityId } from '@shared/domain';
import {
CourseGroupRepo,
CourseRepo,
LessonRepo,
SchoolExternalToolRepo,
LegacySchoolRepo,
SchoolExternalToolRepo,
SubmissionRepo,
TaskRepo,
TeamsRepo,
UserRepo,
} from '@shared/repo';
import { setupEntities, userFactory } from '@shared/testing';
import { BoardDoAuthorizableService } from '@modules/board';
import { ContextExternalToolAuthorizableService } from '@modules/tool/context-external-tool/service/context-external-tool-authorizable.service';
import { ReferenceLoader } from './reference.loader';
import { LessonService } from '@src/modules/lesson';
import { AuthorizableReferenceType } from '../type';
import { ReferenceLoader } from './reference.loader';

describe('reference.loader', () => {
let service: ReferenceLoader;
Expand All @@ -27,7 +27,7 @@ describe('reference.loader', () => {
let courseGroupRepo: DeepMocked<CourseGroupRepo>;
let taskRepo: DeepMocked<TaskRepo>;
let schoolRepo: DeepMocked<LegacySchoolRepo>;
let lessonRepo: DeepMocked<LessonRepo>;
let lessonService: DeepMocked<LessonService>;
let teamsRepo: DeepMocked<TeamsRepo>;
let submissionRepo: DeepMocked<SubmissionRepo>;
let schoolExternalToolRepo: DeepMocked<SchoolExternalToolRepo>;
Expand Down Expand Up @@ -62,8 +62,8 @@ describe('reference.loader', () => {
useValue: createMock<LegacySchoolRepo>(),
},
{
provide: LessonRepo,
useValue: createMock<LessonRepo>(),
provide: LessonService,
useValue: createMock<LessonService>(),
},
{
provide: TeamsRepo,
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('reference.loader', () => {
courseGroupRepo = await module.get(CourseGroupRepo);
taskRepo = await module.get(TaskRepo);
schoolRepo = await module.get(LegacySchoolRepo);
lessonRepo = await module.get(LessonRepo);
lessonService = await module.get(LessonService);
teamsRepo = await module.get(TeamsRepo);
submissionRepo = await module.get(SubmissionRepo);
schoolExternalToolRepo = await module.get(SchoolExternalToolRepo);
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('reference.loader', () => {
it('should call lessonRepo.findById', async () => {
await service.loadAuthorizableObject(AuthorizableReferenceType.Lesson, entityId);

expect(lessonRepo.findById).toBeCalledWith(entityId);
expect(lessonService.findById).toBeCalledWith(entityId);
});

it('should call teamsRepo.findById', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { BoardDoAuthorizableService } from '@modules/board';
import { ContextExternalToolAuthorizableService } from '@modules/tool';
import { Injectable, NotImplementedException } from '@nestjs/common';
import { BaseDO, EntityId } from '@shared/domain';
import { AuthorizableObject } from '@shared/domain/domain-object';
import {
CourseGroupRepo,
CourseRepo,
LessonRepo,
SchoolExternalToolRepo,
LegacySchoolRepo,
SchoolExternalToolRepo,
SubmissionRepo,
TaskRepo,
TeamsRepo,
UserRepo,
} from '@shared/repo';
import { BoardDoAuthorizableService } from '@modules/board';
import { ContextExternalToolAuthorizableService } from '@modules/tool/context-external-tool/service';
import { LessonService } from '@src/modules/lesson';
import { AuthorizableReferenceType } from '../type';

type RepoType =
| TaskRepo
| CourseRepo
| UserRepo
| LegacySchoolRepo
| LessonRepo
| TeamsRepo
| CourseGroupRepo
| SubmissionRepo
| SchoolExternalToolRepo
| BoardDoAuthorizableService
| ContextExternalToolAuthorizableService;
| ContextExternalToolAuthorizableService
| LessonService;

interface IRepoLoader {
repo: RepoType;
Expand All @@ -44,7 +44,7 @@ export class ReferenceLoader {
private readonly courseGroupRepo: CourseGroupRepo,
private readonly taskRepo: TaskRepo,
private readonly schoolRepo: LegacySchoolRepo,
private readonly lessonRepo: LessonRepo,
private readonly lessonRepo: LessonService,
private readonly teamsRepo: TeamsRepo,
private readonly submissionRepo: SubmissionRepo,
private readonly schoolExternalToolRepo: SchoolExternalToolRepo,
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/modules/lesson/service/lesson.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { FilesStorageClientAdapterService } from '@modules/files-storage-client'
import { Injectable } from '@nestjs/common';
import { Counted, EntityId, IComponentProperties, LessonEntity } from '@shared/domain';
import { LessonRepo } from '@shared/repo';
import { AuthorizationLoaderService } from '@src/modules/authorization';

@Injectable()
export class LessonService {
export class LessonService implements AuthorizationLoaderService {
constructor(
private readonly lessonRepo: LessonRepo,
private readonly filesStorageClientAdapterService: FilesStorageClientAdapterService
Expand Down
5 changes: 3 additions & 2 deletions apps/server/src/modules/tool/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './school-external-tool/entity/school-external-tool.entity';
export * from './common/entity/custom-parameter-entry.entity';
export * from './common/interface';
export * from './context-external-tool/entity';
export * from './context-external-tool/service/context-external-tool-authorizable.service';
export * from './external-tool';
export * from './school-external-tool/entity/school-external-tool.entity';
export * from './tool.module';
export * from './common/interface';

0 comments on commit 5cff010

Please sign in to comment.