Skip to content

Commit 052c567

Browse files
committed
Add Step and QuizStep types
1 parent 4069df1 commit 052c567

File tree

6 files changed

+60
-14
lines changed

6 files changed

+60
-14
lines changed

examples/typescript/ts-step_shotgun_surgery-01_base/src/Application/GetStepDuration.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import StepId from '../Domain/StepId'
22
import StepRepository from '../Domain/StepRepository'
3+
import VideoStep from "../Domain/VideoStep";
34

45
class GetStepDuration {
56
constructor(private repository: StepRepository) {
67
}
78

89
execute(stepId: string): number {
910
const step = this.repository.find(new StepId(stepId))
10-
return step.getVideoDuration()
11+
return step instanceof VideoStep ?
12+
step.getVideoDuration() :
13+
step.totalQuestions;
1114
}
1215
}
1316

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Step from "./Step";
2+
import StepId from "./StepId";
3+
4+
class QuizStep extends Step {
5+
constructor(
6+
stepId: StepId,
7+
public readonly totalQuestions: Number
8+
) {
9+
super(stepId);
10+
}
11+
12+
type(): string {
13+
return 'quiz'
14+
}
15+
}
16+
17+
export default QuizStep
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import StepId from "./StepId";
22

3-
class Step {
4-
constructor(
5-
private id: StepId,
6-
private videoDuration: number
7-
) {}
3+
abstract class Step {
84

9-
type(): string {
10-
return 'video'
5+
protected constructor(private readonly _id: StepId) {
116
}
127

13-
getVideoDuration(): number {
14-
return this.videoDuration
15-
}
8+
abstract type();
169
}
1710

1811
export default Step

examples/typescript/ts-step_shotgun_surgery-01_base/src/Domain/StepRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Step from './Step'
21
import StepId from './StepId'
2+
import Step from "./Step";
33

44
interface StepRepository {
55
find(stepId: StepId): Step
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import StepId from "./StepId";
2+
import Step from "./Step";
3+
4+
class VideoStep extends Step {
5+
constructor(
6+
stepId: StepId,
7+
private videoDuration: number
8+
) {
9+
super(stepId)
10+
}
11+
12+
type(): string {
13+
return 'video'
14+
}
15+
16+
getVideoDuration(): number {
17+
return this.videoDuration
18+
}
19+
}
20+
21+
export default VideoStep
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import GetStepDuration from '../../src/Application/GetStepDuration';
22
import StepId from "../../src/Domain/StepId";
3-
import Step from "../../src/Domain/Step";
3+
import VideoStep from "../../src/Domain/VideoStep";
4+
import QuizStep from "../../src/Domain/QuizStep";
45

56
test('should get the video step duration', () => {
67
const stepId = new StepId('stepId')
7-
const step = new Step(stepId, 13)
8+
const step = new VideoStep(stepId, 13)
89
const stepRepository = {
910
find: jest.fn((stepId: StepId) => step)
1011
}
1112
const getStepDuration = new GetStepDuration(stepRepository)
1213

1314
expect(getStepDuration.execute(stepId.value())).toBe(13)
15+
});
16+
17+
test('should get the quiz step duration', () => {
18+
const stepId = new StepId('stepId')
19+
const step = new QuizStep(stepId, 5)
20+
const stepRepository = {
21+
find: jest.fn((stepId: StepId) => step)
22+
}
23+
const getStepDuration = new GetStepDuration(stepRepository)
24+
25+
expect(getStepDuration.execute(stepId.value())).toBe(5)
1426
});

0 commit comments

Comments
 (0)