-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Artur-Poffo/feat-mark-class-and-module-as…
…-completed Feat(Module, Class, Enrollment): Mark classes and modules as completed
- Loading branch information
Showing
26 changed files
with
609 additions
and
24 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
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
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
7 changes: 7 additions & 0 deletions
7
...ent/application/use-cases/errors/all-classes-in-the-module-must-be-marked-as-completed.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,7 @@ | ||
import { type UseCaseError } from '@/core/errors/use-case-error' | ||
|
||
export class AllClassesInTheModuleMustBeMarkedAsCompleted extends Error implements UseCaseError { | ||
constructor(moduleName: string) { | ||
super(`All classes in the module: ${moduleName}, must be marked as completed`) | ||
} | ||
} |
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
146 changes: 146 additions & 0 deletions
146
src/domain/course-management/application/use-cases/mark-class-as-completed.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,146 @@ | ||
import { NotAllowedError } from '@/core/errors/errors/not-allowed-error' | ||
import { ResourceNotFoundError } from '@/core/errors/errors/resource-not-found-error' | ||
import { makeClass } from '../../../../../test/factories/make-class' | ||
import { makeCourse } from '../../../../../test/factories/make-course' | ||
import { makeEnrollment } from '../../../../../test/factories/make-enrollment' | ||
import { makeInstructor } from '../../../../../test/factories/make-instructor' | ||
import { makeModule } from '../../../../../test/factories/make-module' | ||
import { makeStudent } from '../../../../../test/factories/make-student' | ||
import { InMemoryClassesRepository } from '../../../../../test/repositories/in-memory-classes-repository' | ||
import { InMemoryCoursesRepository } from '../../../../../test/repositories/in-memory-courses-repository' | ||
import { InMemoryEnrollmentsRepository } from '../../../../../test/repositories/in-memory-enrollments-repository' | ||
import { InMemoryStudentsRepository } from '../../../../../test/repositories/in-memory-students-repository' | ||
import { InMemoryInstructorRepository } from './../../../../../test/repositories/in-memory-instructors-repository' | ||
import { InMemoryModulesRepository } from './../../../../../test/repositories/in-memory-modules-repository' | ||
import { MarkClassAsCompletedUseCase } from './mark-class-as-completed' | ||
|
||
let inMemoryEnrollmentsRepository: InMemoryEnrollmentsRepository | ||
let inMemoryStudentsRepository: InMemoryStudentsRepository | ||
let inMemoryClassesRepository: InMemoryClassesRepository | ||
let inMemoryInstructorsRepository: InMemoryInstructorRepository | ||
let inMemoryModulesRepository: InMemoryModulesRepository | ||
let inMemoryCoursesRepository: InMemoryCoursesRepository | ||
let sut: MarkClassAsCompletedUseCase | ||
|
||
describe('Mark class as completed use case', () => { | ||
beforeEach(() => { | ||
inMemoryStudentsRepository = new InMemoryStudentsRepository() | ||
inMemoryClassesRepository = new InMemoryClassesRepository() | ||
inMemoryInstructorsRepository = new InMemoryInstructorRepository() | ||
|
||
inMemoryModulesRepository = new InMemoryModulesRepository(inMemoryClassesRepository) | ||
|
||
inMemoryEnrollmentsRepository = new InMemoryEnrollmentsRepository( | ||
inMemoryClassesRepository, inMemoryModulesRepository | ||
) | ||
inMemoryCoursesRepository = new InMemoryCoursesRepository( | ||
inMemoryModulesRepository, inMemoryInstructorsRepository, inMemoryEnrollmentsRepository, inMemoryStudentsRepository | ||
) | ||
|
||
sut = new MarkClassAsCompletedUseCase( | ||
inMemoryEnrollmentsRepository, inMemoryCoursesRepository, inMemoryModulesRepository, inMemoryClassesRepository, inMemoryStudentsRepository | ||
) | ||
}) | ||
|
||
it('should be able to mark a class of a enrollment as completed', async () => { | ||
const instructor = makeInstructor() | ||
await inMemoryInstructorsRepository.create(instructor) | ||
|
||
const course = makeCourse({ instructorId: instructor.id }) | ||
await inMemoryCoursesRepository.create(course) | ||
|
||
const module = makeModule({ | ||
courseId: course.id, | ||
moduleNumber: 1 | ||
}) | ||
await inMemoryModulesRepository.create(module) | ||
|
||
const classToMarkAsCompleted = makeClass({ name: 'John Doe Class', moduleId: module.id, classNumber: 1 }) | ||
await inMemoryClassesRepository.create(classToMarkAsCompleted) | ||
|
||
const student = makeStudent() | ||
await inMemoryStudentsRepository.create(student) | ||
|
||
const enrollment = makeEnrollment({ studentId: student.id, courseId: course.id }) | ||
await inMemoryEnrollmentsRepository.create(enrollment) | ||
|
||
const result = await sut.exec({ | ||
enrollmentId: enrollment.id.toString(), | ||
classId: classToMarkAsCompleted.id.toString(), | ||
studentId: student.id.toString() | ||
}) | ||
|
||
expect(result.isRight()).toBe(true) | ||
expect(result.value).toMatchObject({ | ||
class: expect.objectContaining({ | ||
name: 'John Doe Class' | ||
}) | ||
}) | ||
}) | ||
|
||
it('should not be able to mark a inexistent class as completed', async () => { | ||
const instructor = makeInstructor() | ||
await inMemoryInstructorsRepository.create(instructor) | ||
|
||
const course = makeCourse({ instructorId: instructor.id }) | ||
await inMemoryCoursesRepository.create(course) | ||
|
||
const module = makeModule({ | ||
courseId: course.id, | ||
moduleNumber: 1 | ||
}) | ||
await inMemoryModulesRepository.create(module) | ||
|
||
const student = makeStudent() | ||
await inMemoryStudentsRepository.create(student) | ||
|
||
const enrollment = makeEnrollment({ studentId: student.id, courseId: course.id }) | ||
await inMemoryEnrollmentsRepository.create(enrollment) | ||
|
||
const result = await sut.exec({ | ||
enrollmentId: enrollment.id.toString(), | ||
classId: 'inexistentClassId', | ||
studentId: student.id.toString() | ||
}) | ||
|
||
expect(result.isLeft()).toBe(true) | ||
expect(result.value).toBeInstanceOf(ResourceNotFoundError) | ||
}) | ||
|
||
it('should not be able to mark a class of a enrollment as completed if the student not is the owner of the enrollment', async () => { | ||
const instructor = makeInstructor() | ||
await inMemoryInstructorsRepository.create(instructor) | ||
|
||
const course = makeCourse({ instructorId: instructor.id }) | ||
await inMemoryCoursesRepository.create(course) | ||
|
||
const module = makeModule({ | ||
courseId: course.id, | ||
moduleNumber: 1 | ||
}) | ||
await inMemoryModulesRepository.create(module) | ||
|
||
const classToMarkAsCompleted = makeClass({ name: 'John Doe Class', moduleId: module.id, classNumber: 1 }) | ||
await inMemoryClassesRepository.create(classToMarkAsCompleted) | ||
|
||
const correctStudent = makeStudent() | ||
const wrongStudent = makeStudent() | ||
|
||
await Promise.all([ | ||
inMemoryStudentsRepository.create(correctStudent), | ||
inMemoryStudentsRepository.create(wrongStudent) | ||
]) | ||
|
||
const enrollment = makeEnrollment({ studentId: correctStudent.id, courseId: course.id }) | ||
await inMemoryEnrollmentsRepository.create(enrollment) | ||
|
||
const result = await sut.exec({ | ||
enrollmentId: enrollment.id.toString(), | ||
classId: classToMarkAsCompleted.id.toString(), | ||
studentId: wrongStudent.id.toString() | ||
}) | ||
|
||
expect(result.isLeft()).toBe(true) | ||
expect(result.value).toBeInstanceOf(NotAllowedError) | ||
}) | ||
}) |
Oops, something went wrong.