Skip to content

Commit 4069df1

Browse files
committed
add application service
1 parent 2634a94 commit 4069df1

File tree

7 files changed

+64
-15
lines changed

7 files changed

+64
-15
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import StepId from '../Domain/StepId'
2+
import StepRepository from '../Domain/StepRepository'
3+
4+
class GetStepDuration {
5+
constructor(private repository: StepRepository) {
6+
}
7+
8+
execute(stepId: string): number {
9+
const step = this.repository.find(new StepId(stepId))
10+
return step.getVideoDuration()
11+
}
12+
}
13+
14+
export default GetStepDuration
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import StepId from "./StepId";
2+
3+
class Step {
4+
constructor(
5+
private id: StepId,
6+
private videoDuration: number
7+
) {}
8+
9+
type(): string {
10+
return 'video'
11+
}
12+
13+
getVideoDuration(): number {
14+
return this.videoDuration
15+
}
16+
}
17+
18+
export default Step
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class StepId {
2+
constructor(private stepId: string) {
3+
}
4+
5+
value(): string {
6+
return this.stepId
7+
}
8+
}
9+
10+
export default StepId
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Step from './Step'
2+
import StepId from './StepId'
3+
4+
interface StepRepository {
5+
find(stepId: StepId): Step
6+
}
7+
8+
export default StepRepository

examples/typescript/ts-step_shotgun_surgery-01_base/src/index.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import GetStepDuration from '../../src/Application/GetStepDuration';
2+
import StepId from "../../src/Domain/StepId";
3+
import Step from "../../src/Domain/Step";
4+
5+
test('should get the video step duration', () => {
6+
const stepId = new StepId('stepId')
7+
const step = new Step(stepId, 13)
8+
const stepRepository = {
9+
find: jest.fn((stepId: StepId) => step)
10+
}
11+
const getStepDuration = new GetStepDuration(stepRepository)
12+
13+
expect(getStepDuration.execute(stepId.value())).toBe(13)
14+
});

examples/typescript/ts-step_shotgun_surgery-01_base/tests/index.test.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)