Skip to content

Commit

Permalink
Refactor(Error): Errors names
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur-Poffo committed Jan 29, 2024
1 parent 3e71424 commit 38c7deb
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { InMemoryCoursesRepository } from '../../../../../test/repositories/in-m
import { InMemoryInstructorRepository } from './../../../../../test/repositories/in-memory-instructors-repository'
import { InMemoryModulesRepository } from './../../../../../test/repositories/in-memory-modules-repository'
import { AddClassToModuleUseCase } from './add-class-to-module'
import { ClassAlreadyExistsInThisModule } from './errors/class-already-exists-in-this-module'
import { ClassNumberIsAlreadyInUse } from './errors/class-number-is-already-in-use'
import { ClassAlreadyExistsInThisModuleError } from './errors/class-already-exists-in-this-module-error'
import { ClassNumberIsAlreadyInUseError } from './errors/class-number-is-already-in-use-error'

let inMemoryModulesRepository: InMemoryModulesRepository
let inMemoryCoursesRepository: InMemoryCoursesRepository
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('Add class to a module use case', () => {
})

expect(result.isLeft()).toBe(true)
expect(result.value).toBeInstanceOf(ClassAlreadyExistsInThisModule)
expect(result.value).toBeInstanceOf(ClassAlreadyExistsInThisModuleError)
})

it('should not be able to add a class to a module in same number/position twice', async () => {
Expand Down Expand Up @@ -180,6 +180,6 @@ describe('Add class to a module use case', () => {
})

expect(result.isLeft()).toBe(true)
expect(result.value).toBeInstanceOf(ClassNumberIsAlreadyInUse)
expect(result.value).toBeInstanceOf(ClassNumberIsAlreadyInUseError)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Class } from '../../enterprise/entities/class'
import { type ClassesRepository } from '../repositories/classes-repository'
import { type CoursesRepository } from '../repositories/courses-repository'
import { type ModulesRepository } from '../repositories/modules-repository'
import { ClassAlreadyExistsInThisModule } from './errors/class-already-exists-in-this-module'
import { ClassNumberIsAlreadyInUse } from './errors/class-number-is-already-in-use'
import { ClassAlreadyExistsInThisModuleError } from './errors/class-already-exists-in-this-module-error'
import { ClassNumberIsAlreadyInUseError } from './errors/class-number-is-already-in-use-error'

interface AddClassToModuleUseCaseRequest {
name: string
Expand All @@ -21,7 +21,7 @@ interface AddClassToModuleUseCaseRequest {
}

type AddClassToModuleUseCaseResponse = Either<
ResourceNotFoundError | NotAllowedError | ClassAlreadyExistsInThisModule | ClassNumberIsAlreadyInUse,
ResourceNotFoundError | NotAllowedError | ClassAlreadyExistsInThisModuleError | ClassNumberIsAlreadyInUseError,
{
class: Class
}
Expand Down Expand Up @@ -65,13 +65,13 @@ export class AddClassToModuleUseCase implements UseCase<AddClassToModuleUseCaseR
const classWithSameNameInSameModule = classesInThisModule.find(classToCompare => classToCompare.name === name)

if (classWithSameNameInSameModule) {
return left(new ClassAlreadyExistsInThisModule(moduleId))
return left(new ClassAlreadyExistsInThisModuleError(moduleId))
}

const classWithSamePositionInThisModule = classesInThisModule.find(classToCompare => classToCompare.classNumber === classNumber)

if (classWithSamePositionInThisModule) {
return left(new ClassNumberIsAlreadyInUse(classNumber))
return left(new ClassNumberIsAlreadyInUseError(classNumber))
}

const classToAdd = Class.create({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type UseCaseError } from '@/core/errors/use-case-error'

export class ClassAlreadyExistsInThisModule extends Error implements UseCaseError {
export class ClassAlreadyExistsInThisModuleError extends Error implements UseCaseError {
constructor(moduleId: string) {
super(`Class already exists in this module: module ID ${moduleId}.`)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type UseCaseError } from '@/core/errors/use-case-error'

export class ClassNumberIsAlreadyInUse extends Error implements UseCaseError {
export class ClassNumberIsAlreadyInUseError extends Error implements UseCaseError {
constructor(classPosition: number) {
super(`Class position ${classPosition} is already in use`)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type UseCaseError } from '@/core/errors/use-case-error'

export class CourseAlreadyExistsInThisAccount extends Error implements UseCaseError {
export class CourseAlreadyExistsInThisAccountError extends Error implements UseCaseError {
constructor(instructorEmail: string) {
super(`Course already exists in this account, account email: ${instructorEmail}.`)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type UseCaseError } from '@/core/errors/use-case-error'

export class ModuleAlreadyExistsInThisCourse extends Error implements UseCaseError {
export class ModuleAlreadyExistsInThisCourseError extends Error implements UseCaseError {
constructor(identifier: string) {
super(`Module "${identifier}" already exists in this course.`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InMemoryCoursesRepository } from './../../../../../test/repositories/in
import { InMemoryInstructorRepository } from './../../../../../test/repositories/in-memory-instructors-repository'
import { InMemoryModulesRepository } from './../../../../../test/repositories/in-memory-modules-repository'
import { InMemoryStudentsRepository } from './../../../../../test/repositories/in-memory-students-repository'
import { CourseAlreadyExistsInThisAccount } from './errors/course-already-exists-in-this-account'
import { CourseAlreadyExistsInThisAccountError } from './errors/course-already-exists-in-this-account-error'
import { RegisterCourseUseCase } from './register-course'

let inMemoryModulesRepository: InMemoryModulesRepository
Expand Down Expand Up @@ -88,6 +88,6 @@ describe('Register course use case', () => {
})

expect(result.isLeft()).toBe(true)
expect(result.value).toBeInstanceOf(CourseAlreadyExistsInThisAccount)
expect(result.value).toBeInstanceOf(CourseAlreadyExistsInThisAccountError)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type UseCase } from '@/core/use-cases/use-case'
import { Course } from '../../enterprise/entities/course'
import { type CoursesRepository } from '../repositories/courses-repository'
import { type InstructorsRepository } from '../repositories/instructors-repository'
import { CourseAlreadyExistsInThisAccount } from './errors/course-already-exists-in-this-account'
import { CourseAlreadyExistsInThisAccountError } from './errors/course-already-exists-in-this-account-error'

interface RegisterCourseUseCaseRequest {
name: string
Expand All @@ -14,7 +14,7 @@ interface RegisterCourseUseCaseRequest {
}

type RegisterCourseUseCaseResponse = Either<
ResourceNotFoundError | CourseAlreadyExistsInThisAccount,
ResourceNotFoundError | CourseAlreadyExistsInThisAccountError,
{
course: Course
}
Expand All @@ -40,7 +40,7 @@ export class RegisterCourseUseCase implements UseCase<RegisterCourseUseCaseReque
const courseWithSameNameInSameAccount = instructorWithCourses.courses.find(courseToCompare => courseToCompare.name === name)

if (courseWithSameNameInSameAccount) {
return left(new CourseAlreadyExistsInThisAccount(instructorWithCourses.instructor.email))
return left(new CourseAlreadyExistsInThisAccountError(instructorWithCourses.instructor.email))
}

const course = Course.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InMemoryClassesRepository } from '../../../../../test/repositories/in-m
import { InMemoryCoursesRepository } from './../../../../../test/repositories/in-memory-courses-repository'
import { InMemoryInstructorRepository } from './../../../../../test/repositories/in-memory-instructors-repository'
import { InMemoryModulesRepository } from './../../../../../test/repositories/in-memory-modules-repository'
import { ModuleAlreadyExistsInThisCourse } from './errors/module-already-exists-in-this-course'
import { ModuleAlreadyExistsInThisCourseError } from './errors/module-already-exists-in-this-course-error'
import { RegisterModuleToCourseUseCase } from './register-module-to-course'

let inMemoryCoursesRepository: InMemoryCoursesRepository
Expand Down Expand Up @@ -111,6 +111,6 @@ describe('Register module to a course use case', () => {
})

expect(result.isLeft()).toBe(true)
expect(result.value).toBeInstanceOf(ModuleAlreadyExistsInThisCourse)
expect(result.value).toBeInstanceOf(ModuleAlreadyExistsInThisCourseError)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type UseCase } from '@/core/use-cases/use-case'
import { Module } from '../../enterprise/entities/module'
import { type CoursesRepository } from '../repositories/courses-repository'
import { type ModulesRepository } from '../repositories/modules-repository'
import { ModuleAlreadyExistsInThisCourse } from './errors/module-already-exists-in-this-course'
import { ModuleAlreadyExistsInThisCourseError } from './errors/module-already-exists-in-this-course-error'

interface RegisterModuleToCourseUseCaseRequest {
name: string
Expand All @@ -17,7 +17,7 @@ interface RegisterModuleToCourseUseCaseRequest {
}

type RegisterModuleToCourseUseCaseResponse = Either<
ResourceNotFoundError | ModuleAlreadyExistsInThisCourse | NotAllowedError,
ResourceNotFoundError | ModuleAlreadyExistsInThisCourseError | NotAllowedError,
{
module: Module
}
Expand Down Expand Up @@ -49,7 +49,7 @@ export class RegisterModuleToCourseUseCase implements UseCase<RegisterModuleToCo
const moduleWithSameNameInSameCourse = completeCourse.modules.find(moduleToCompare => moduleToCompare.name === name)

if (moduleWithSameNameInSameCourse) {
return left(new ModuleAlreadyExistsInThisCourse(name))
return left(new ModuleAlreadyExistsInThisCourseError(name))
}

const module = Module.create({
Expand Down

0 comments on commit 38c7deb

Please sign in to comment.