import 'mocha' ; import { expect } from 'chai' ; import { IScriptingLanguageFactory } from '@/application/Common/ScriptingLanguage/IScriptingLanguageFactory' ; import { ScriptingLanguage } from '@/domain/ScriptingLanguage' ; import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner' ; export class ScriptingLanguageFactoryTestRunner < T > { private expectedTypes = new Map < ScriptingLanguage , T > ( ) ; public expect ( language , resultType ) { this . expectedTypes . set ( language , resultType ) ; return this ; } public testCreateMethod ( sut ) { if ( ! sut ) { throw new Error ( 'undefined sut' ) ; } testLanguageValidation ( sut ) ; testExpectedInstanceTypes ( sut , this . expectedTypes ) ; } } function testExpectedInstanceTypes < T > ( sut , expectedTypes ) { describe ( 'create returns expected instances' , ( ) => { for ( const language of expectedTypes . keys ( ) ) { it ( ScriptingLanguage [ language ] , ( ) => { const expected = expectedTypes . get ( language ) ; const result = sut . create ( language ) ; expect ( result ) . to . be . instanceOf ( expected , `Actual was: ${ result . constructor . name }` ) ; } ) ; } } ) ; } function testLanguageValidation < T > ( sut ) { describe ( 'validates language' , ( ) => { const validValue = ScriptingLanguage . batchfile ; const act = ( value ) => sut . create ( value ) ; new EnumRangeTestRunner ( act ) . testOutOfRangeThrows ( ) . testUndefinedValueThrows ( ) . testValidValueDoesNotThrow ( validValue ) ; } ) ; }