import { test } from './sinon-tape' ; import { registerRule , getRule } from '../src/RulesRegistry' ; import * as Rule from '../src/Rule' ; test ( 'RulesRegistry' , t => { console . log ( 'hello1' ) ; const createRule = t . stub ( Rule , 'createRule' ) ; t . equals ( registerRule ( 'id1' , { } ) , 'id1' , '`registerRule` should return an index starting with 1 for each registered rule' ) ; t . notCalled ( createRule , '`registerRule` should not create rule right away' ) ; t . throws ( ( ) => registerRule ( 'id1' , { } ) , 'registerRule should throws if we try to register 2 rules with the same id' ) ; t . ok ( typeof registerRule ( '' , { } ) === 'string' , 'resiter rule should generate an id if not provided' ) ; const rule = { } ; createRule . reset ( ) ; createRule . returns ( rule ) ; registerRule ( 'id3' , { } ) ; t . equals ( getRule ( 'id3' ) , rule , '`getRule` should create the rule and return it if it has not been created' ) ; getRule ( 'id3' ) ; t . calledOnce ( createRule , '`getRule` should not recreated the rule if it has already been created' ) ; t . equals ( getRule ( 'id4' ) , undefined , '`getRule` should return `undefined` if the is no rule associated to the given id' ) ; t . end ( ) ; } ) ;