Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
santakadev committed Apr 19, 2021
1 parent 8488517 commit a235f20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import StepRepository from '../Domain/StepRepository'
import StepDurationCalculatorFactory from "../Domain/StepDurationCalculatorFactory";

class GetStepDuration {
constructor(private repository: StepRepository) {
}
constructor(private repository: StepRepository) {}

execute(stepId: string): number {
const step = this.repository.find(new StepId(stepId))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class StepId {
constructor(private stepId: string) {
}
constructor(private stepId: string) {}

value(): string {
return this.stepId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@ import GetStepDuration from '../../src/Application/GetStepDuration';
import StepId from "../../src/Domain/StepId";
import VideoStep from "../../src/Domain/VideoStep";
import QuizStep from "../../src/Domain/QuizStep";
import Step from "../../src/Domain/Step";
import StepRepository from "../../src/Domain/StepRepository";

test('should get the video step duration', () => {
test('should get video step duration', () => {
const stepId = new StepId('stepId')
const step = new VideoStep(stepId, 13)
const stepRepository = {
find: jest.fn(() => step)
}
const stepRepository = stepRepositoryWith(step)
const getStepDuration = new GetStepDuration(stepRepository)

expect(getStepDuration.execute(stepId.value())).toBe(14.3)
const duration = getStepDuration.execute(stepId.value())

expect(duration).toBe(14.3)
});

test('should get the quiz step duration', () => {
test('should get quiz step duration', () => {
const stepId = new StepId('stepId')
const step = new QuizStep(stepId, 5)
const stepRepository = {
find: jest.fn(() => step)
}
const stepRepository = stepRepositoryWith(step)
const getStepDuration = new GetStepDuration(stepRepository)

expect(getStepDuration.execute(stepId.value())).toBe(37.5)
});
const duration = getStepDuration.execute(stepId.value())

expect(duration).toBe(37.5)
});

function stepRepositoryWith(step: Step): StepRepository {
return {
find: jest.fn(() => step)
}
}

0 comments on commit a235f20

Please sign in to comment.