-
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.
Bc 4572 rewrite courses to nest (#4358)
* change name of lesson entity, add method in lesson repo and in lesson service * modification in repos: lesson, course, coursegroup and add methon in lessonService * add method for course service * add service for courseGroup * tests for services * small changes * change lesson into lesoonEntity in one test * add method to course and courseGroup entity * fixes after review * fix tests in courseGroup entity * changes in testcases after review
- Loading branch information
1 parent
f13eb0e
commit cb7bf6d
Showing
42 changed files
with
675 additions
and
168 deletions.
There are no files selected for viewing
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
6 changes: 3 additions & 3 deletions
6
apps/server/src/modules/files-storage-client/interfaces/types.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Lesson, Submission, Task } from '@shared/domain'; | ||
import { LessonEntity, Submission, Task } from '@shared/domain'; | ||
|
||
export type EntitiesWithFiles = Task | Lesson | Submission; | ||
export type EntityWithEmbeddedFiles = Task | Lesson; | ||
export type EntitiesWithFiles = Task | LessonEntity | Submission; | ||
export type EntityWithEmbeddedFiles = Task | LessonEntity; |
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
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
71 changes: 71 additions & 0 deletions
71
apps/server/src/modules/learnroom/service/coursegroup.service.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,71 @@ | ||
import { createMock, DeepMocked } from '@golevelup/ts-jest'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { CourseGroupRepo, UserRepo } from '@shared/repo'; | ||
import { courseGroupFactory, setupEntities, userFactory } from '@shared/testing'; | ||
import { CourseGroupService } from './coursegroup.service'; | ||
|
||
describe('CourseGroupService', () => { | ||
let module: TestingModule; | ||
let courseGroupRepo: DeepMocked<CourseGroupRepo>; | ||
let courseGroupService: CourseGroupService; | ||
let userRepo: DeepMocked<UserRepo>; | ||
|
||
beforeAll(async () => { | ||
await setupEntities(); | ||
module = await Test.createTestingModule({ | ||
providers: [ | ||
CourseGroupService, | ||
{ | ||
provide: UserRepo, | ||
useValue: createMock<UserRepo>(), | ||
}, | ||
{ | ||
provide: CourseGroupRepo, | ||
useValue: createMock<CourseGroupRepo>(), | ||
}, | ||
], | ||
}).compile(); | ||
courseGroupRepo = module.get(CourseGroupRepo); | ||
courseGroupService = module.get(CourseGroupService); | ||
userRepo = module.get(UserRepo); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('when deleting by userId', () => { | ||
const setup = () => { | ||
const user = userFactory.buildWithId(); | ||
const courseGroup1 = courseGroupFactory.buildWithId({ students: [user] }); | ||
const courseGroup2 = courseGroupFactory.buildWithId({ students: [user] }); | ||
|
||
userRepo.findById.mockResolvedValue(user); | ||
courseGroupRepo.findByUserId.mockResolvedValue([[courseGroup1, courseGroup2], 2]); | ||
|
||
return { | ||
user, | ||
}; | ||
}; | ||
|
||
it('should call courseGroupRepo.findByUserId', async () => { | ||
const { user } = setup(); | ||
|
||
await courseGroupService.deleteUserDataFromCourseGroup(user.id); | ||
|
||
expect(courseGroupRepo.findByUserId).toBeCalledWith(user.id); | ||
}); | ||
|
||
it('should update courses without deleted user', async () => { | ||
const { user } = setup(); | ||
|
||
const result = await courseGroupService.deleteUserDataFromCourseGroup(user.id); | ||
|
||
expect(result).toEqual(2); | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
apps/server/src/modules/learnroom/service/coursegroup.service.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,18 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { EntityId } from '@shared/domain'; | ||
import { CourseGroupRepo } from '@shared/repo'; | ||
|
||
@Injectable() | ||
export class CourseGroupService { | ||
constructor(private readonly repo: CourseGroupRepo) {} | ||
|
||
public async deleteUserDataFromCourseGroup(userId: EntityId): Promise<number> { | ||
const [courseGroups, count] = await this.repo.findByUserId(userId); | ||
|
||
courseGroups.forEach((courseGroup) => courseGroup.removeStudent(userId)); | ||
|
||
await this.repo.save(courseGroups); | ||
|
||
return count; | ||
} | ||
} |
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
Oops, something went wrong.