From 4069df18b6a8f27cbb3bc015f5a0ecd8e394e164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=20Santamar=C3=ADa?= Date: Fri, 16 Apr 2021 17:09:19 +0200 Subject: [PATCH] add application service --- .../src/Application/GetStepDuration.ts | 14 ++++++++++++++ .../src/Domain/Step.ts | 18 ++++++++++++++++++ .../src/Domain/StepId.ts | 10 ++++++++++ .../src/Domain/StepRepository.ts | 8 ++++++++ .../src/index.ts | 9 --------- .../tests/Application/GetStepDuration.test.ts | 14 ++++++++++++++ .../tests/index.test.ts | 6 ------ 7 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 examples/typescript/ts-step_shotgun_surgery-01_base/src/Application/GetStepDuration.ts create mode 100644 examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/Step.ts create mode 100644 examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepId.ts create mode 100644 examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepRepository.ts delete mode 100644 examples/typescript/ts-step_shotgun_surgery-01_base/src/index.ts create mode 100644 examples/typescript/ts-step_shotgun_surgery-01_base/tests/Application/GetStepDuration.test.ts delete mode 100644 examples/typescript/ts-step_shotgun_surgery-01_base/tests/index.test.ts diff --git a/examples/typescript/ts-step_shotgun_surgery-01_base/src/Application/GetStepDuration.ts b/examples/typescript/ts-step_shotgun_surgery-01_base/src/Application/GetStepDuration.ts new file mode 100644 index 00000000..29b7c095 --- /dev/null +++ b/examples/typescript/ts-step_shotgun_surgery-01_base/src/Application/GetStepDuration.ts @@ -0,0 +1,14 @@ +import StepId from '../Domain/StepId' +import StepRepository from '../Domain/StepRepository' + +class GetStepDuration { + constructor(private repository: StepRepository) { + } + + execute(stepId: string): number { + const step = this.repository.find(new StepId(stepId)) + return step.getVideoDuration() + } +} + +export default GetStepDuration \ No newline at end of file diff --git a/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/Step.ts b/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/Step.ts new file mode 100644 index 00000000..0b8361d0 --- /dev/null +++ b/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/Step.ts @@ -0,0 +1,18 @@ +import StepId from "./StepId"; + +class Step { + constructor( + private id: StepId, + private videoDuration: number + ) {} + + type(): string { + return 'video' + } + + getVideoDuration(): number { + return this.videoDuration + } +} + +export default Step \ No newline at end of file diff --git a/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepId.ts b/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepId.ts new file mode 100644 index 00000000..2046471e --- /dev/null +++ b/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepId.ts @@ -0,0 +1,10 @@ +class StepId { + constructor(private stepId: string) { + } + + value(): string { + return this.stepId + } +} + +export default StepId \ No newline at end of file diff --git a/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepRepository.ts b/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepRepository.ts new file mode 100644 index 00000000..84d9cf80 --- /dev/null +++ b/examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepRepository.ts @@ -0,0 +1,8 @@ +import Step from './Step' +import StepId from './StepId' + +interface StepRepository { + find(stepId: StepId): Step +} + +export default StepRepository \ No newline at end of file diff --git a/examples/typescript/ts-step_shotgun_surgery-01_base/src/index.ts b/examples/typescript/ts-step_shotgun_surgery-01_base/src/index.ts deleted file mode 100644 index eff1ff0f..00000000 --- a/examples/typescript/ts-step_shotgun_surgery-01_base/src/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -interface Course { - title: string; -} - -function courseTitle(course: Course) { - return course.title; -} - -module.exports = courseTitle; \ No newline at end of file diff --git a/examples/typescript/ts-step_shotgun_surgery-01_base/tests/Application/GetStepDuration.test.ts b/examples/typescript/ts-step_shotgun_surgery-01_base/tests/Application/GetStepDuration.test.ts new file mode 100644 index 00000000..abaff3ce --- /dev/null +++ b/examples/typescript/ts-step_shotgun_surgery-01_base/tests/Application/GetStepDuration.test.ts @@ -0,0 +1,14 @@ +import GetStepDuration from '../../src/Application/GetStepDuration'; +import StepId from "../../src/Domain/StepId"; +import Step from "../../src/Domain/Step"; + +test('should get the video step duration', () => { + const stepId = new StepId('stepId') + const step = new Step(stepId, 13) + const stepRepository = { + find: jest.fn((stepId: StepId) => step) + } + const getStepDuration = new GetStepDuration(stepRepository) + + expect(getStepDuration.execute(stepId.value())).toBe(13) +}); \ No newline at end of file diff --git a/examples/typescript/ts-step_shotgun_surgery-01_base/tests/index.test.ts b/examples/typescript/ts-step_shotgun_surgery-01_base/tests/index.test.ts deleted file mode 100644 index a350f20f..00000000 --- a/examples/typescript/ts-step_shotgun_surgery-01_base/tests/index.test.ts +++ /dev/null @@ -1,6 +0,0 @@ -const courseTitle = require('../src'); - -test('gets the course title', () => { - const course = {title: 'Refactoring'} - expect(courseTitle(course)).toBe('Refactoring') -}); \ No newline at end of file