-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
begin injection of course rule and reference loader
- Loading branch information
Showing
6 changed files
with
110 additions
and
11 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
.../server/src/modules/authorization/domain/reference-loader/course.reference-loader.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { createMock, DeepMocked } from '@golevelup/ts-jest'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AuthorizableReferenceType, AuthorizationInjectionService } from '@src/modules/authorization'; | ||
import { CourseReferenceLoader } from './course.reference-loader'; | ||
import { CourseDoService } from '@src/modules/learnroom'; | ||
import { courseFactory } from '@src/modules/learnroom/testing'; | ||
|
||
describe('Course Reference Loader', () => { | ||
let module: TestingModule; | ||
let service: CourseReferenceLoader; | ||
|
||
let courseDoService: DeepMocked<CourseDoService>; | ||
let injectionService: DeepMocked<AuthorizationInjectionService>; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
providers: [ | ||
CourseReferenceLoader, | ||
{ | ||
provide: CourseDoService, | ||
useValue: createMock<CourseDoService>(), | ||
}, | ||
{ | ||
provide: AuthorizationInjectionService, | ||
useValue: createMock<AuthorizationInjectionService>(), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get(CourseReferenceLoader); | ||
courseDoService = module.get(CourseDoService); | ||
injectionService = module.get(AuthorizationInjectionService); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('constructor', () => { | ||
it('should inject itself into the AuthorizationInjectionService', () => { | ||
expect(injectionService.injectReferenceLoader).toHaveBeenCalledWith(AuthorizableReferenceType.Course, service); | ||
}); | ||
}); | ||
|
||
describe('findById', () => { | ||
describe('when id is given', () => { | ||
const setup = () => { | ||
const course = courseFactory.buildWithId(); | ||
courseDoService.findById.mockResolvedValue(course); | ||
|
||
return { | ||
course, | ||
}; | ||
}; | ||
|
||
it('should return a contextExternalTool', async () => { | ||
const { course } = setup(); | ||
|
||
const result = await service.findById(course.id); | ||
|
||
expect(result).toEqual(course); | ||
}); | ||
}); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
apps/server/src/modules/authorization/domain/reference-loader/course.reference-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
AuthorizableReferenceType, | ||
AuthorizationInjectionService, | ||
AuthorizationLoaderServiceGeneric, | ||
} from '@modules/authorization'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { EntityId } from '@shared/domain/types'; | ||
import { CourseDoService } from '@src/modules/learnroom'; | ||
import { Course } from '@src/modules/learnroom/domain'; | ||
|
||
@Injectable() | ||
export class CourseReferenceLoader implements AuthorizationLoaderServiceGeneric<Course> { | ||
constructor(private readonly courseService: CourseDoService, injectionService: AuthorizationInjectionService) { | ||
injectionService.injectReferenceLoader(AuthorizableReferenceType.User, this); | ||
} | ||
|
||
public async findById(courseId: EntityId): Promise<Course> { | ||
const course: Course = await this.courseService.findById(courseId); | ||
|
||
return course; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters