File tree Expand file tree Collapse file tree 6 files changed +60
-14
lines changed
examples/typescript/ts-step_shotgun_surgery-01_base Expand file tree Collapse file tree 6 files changed +60
-14
lines changed Original file line number Diff line number Diff line change 1
1
import StepId from '../Domain/StepId'
2
2
import StepRepository from '../Domain/StepRepository'
3
+ import VideoStep from "../Domain/VideoStep" ;
3
4
4
5
class GetStepDuration {
5
6
constructor ( private repository : StepRepository ) {
6
7
}
7
8
8
9
execute ( stepId : string ) : number {
9
10
const step = this . repository . find ( new StepId ( stepId ) )
10
- return step . getVideoDuration ( )
11
+ return step instanceof VideoStep ?
12
+ step . getVideoDuration ( ) :
13
+ step . totalQuestions ;
11
14
}
12
15
}
13
16
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
1
import StepId from "./StepId" ;
2
2
3
- class Step {
4
- constructor (
5
- private id : StepId ,
6
- private videoDuration : number
7
- ) { }
3
+ abstract class Step {
8
4
9
- type ( ) : string {
10
- return 'video'
5
+ protected constructor ( private readonly _id : StepId ) {
11
6
}
12
7
13
- getVideoDuration ( ) : number {
14
- return this . videoDuration
15
- }
8
+ abstract type ( ) ;
16
9
}
17
10
18
11
export default Step
Original file line number Diff line number Diff line change 1
- import Step from './Step'
2
1
import StepId from './StepId'
2
+ import Step from "./Step" ;
3
3
4
4
interface StepRepository {
5
5
find ( stepId : StepId ) : Step
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
1
import GetStepDuration from '../../src/Application/GetStepDuration' ;
2
2
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" ;
4
5
5
6
test ( 'should get the video step duration' , ( ) => {
6
7
const stepId = new StepId ( 'stepId' )
7
- const step = new Step ( stepId , 13 )
8
+ const step = new VideoStep ( stepId , 13 )
8
9
const stepRepository = {
9
10
find : jest . fn ( ( stepId : StepId ) => step )
10
11
}
11
12
const getStepDuration = new GetStepDuration ( stepRepository )
12
13
13
14
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 )
14
26
} ) ;
You can’t perform that action at this time.
0 commit comments