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 11import StepId from '../Domain/StepId'
22import StepRepository from '../Domain/StepRepository'
3+ import VideoStep from "../Domain/VideoStep" ;
34
45class 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
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 11import 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
1811export default Step
Original file line number Diff line number Diff line change 1- import Step from './Step'
21import StepId from './StepId'
2+ import Step from "./Step" ;
33
44interface StepRepository {
55 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 11import GetStepDuration from '../../src/Application/GetStepDuration' ;
22import 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
56test ( '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} ) ;
You can’t perform that action at this time.
0 commit comments