import * as crypto from 'crypto' ; import { Factory } from '../../src/core/common-interfaces' ; import { sample } from './sampling' ; export abstract class Dummy < T > implements Factory < T > { abstract create ( ... extras ) ; } export function createDummies < T > ( dummy , count , extras = [ ] ) { const list = [ ] ; for ( let i = 0 ; i < count ; i ++ ) { list . push ( dummy . create ( ... extras ) ) ; } return list ; } export class StringIdDummy extends Dummy < string > { private id = 0 ; constructor ( private readonly namespace = 'id' ) { super ( ) ; } create ( ) { return `${ this . namespace }-${ this . id ++ }` ; } } export class TextDummy extends Dummy < string > { private count = 0 ; constructor ( private readonly baseText = 'Text' ) { super ( ) ; } create ( ) { return `${ this . baseText }-${ this . count ++ }` ; } } export class EmailDummy extends Dummy < string > { private text : TextDummy ; constructor ( private readonly user = 'developer' , private readonly domain = 'i_love_google.com' ) { super ( ) ; this . text = new TextDummy ( user ) ; } create ( ) { return `${ this . text . create ( ) }@${ this . domain }` ; } } export class TypesDummy < T > extends Dummy < T > { constructor ( readonly types ) { super ( ) ; } create ( ) { return sample ( this . types ) ; } } export class DatetimeDummy extends Dummy < number > { constructor ( private date ? ) { super ( ) ; } create ( ) { if ( this . date ) { return this . date . getTime ( ) ; } return new Date ( ) . getTime ( ) ; } } export class SHADummy extends Dummy < string > { private context : TextDummy ; constructor ( public readonly contextBase = 'geeks-diary' ) { super ( ) ; this . context = new TextDummy ( contextBase ) ; } create ( ) { const hash = crypto . createHash ( 'sha256' ) ; hash . update ( this . context . create ( ) ) ; return hash . digest ( 'hex' ) ; } }