import { Service } from 'typedi' ; import { Property } from '@mockingbird/reflect' ; import { PrimitiveHandler } from './primitive-handler' ; import { ValueHandler } from '../types/value-handler.interface' ; @ Service ( ) export class PrimitiveValueHandler implements ValueHandler { public constructor ( private readonly primitiveHandler ) { } public shouldHandle ( property ) { return this . primitiveHandler . isPrimitive ( property ) ; } public produceValue ( property ) { const { decoratorValue } = property ; if ( typeof decoratorValue . value !== 'undefined' ) { if ( decoratorValue . isMultiClass ( ) ) { throw new Error ( 'Type mismatch. Properties decorated with @Mock({ type: ClassType }) must be typed as array (e.g. prop: string[])' ) ; } return decoratorValue . value ; } return this . primitiveHandler . generateRandomValueFromPrimitive ( property . constructorName ) ; } }