import { Observable } from 'rxjs' ; import { mapTo } from 'rxjs/operators' ; import { combineRoutes } from '../http.router.combiner' ; import { r } from '../http.router.ixbuilder' ; import { HttpMiddlewareEffect } from '../../effects/http.effects.interface' ; import { HttpRequest } from '../../http.interface' ; describe ( '#combineRoutes' , ( ) => { test ( 'factorizes combined routes for effects only' , ( ) => { const effect$ = ( req$ ) => req$ . pipe ( mapTo ( { } ) ) ; const a$ = r . pipe ( r . matchPath ( '/a' ) , r . matchType ( 'GET' ) , r . useEffect ( effect$ ) ) ; const b$ = r . pipe ( r . matchPath ( '/b' ) , r . matchType ( 'GET' ) , r . useEffect ( effect$ ) ) ; const combiner = combineRoutes ( '/test' , [ a$ , b$ ] ) ; expect ( combiner ) . toEqual ( { path : '/test' , middlewares : [ ] , effects : [ a$ , b$ ] , } ) ; } ) ; test ( 'factorizes combined routes for effects with middlewares' , ( ) => { const effect$ = ( req$ ) => req$ . pipe ( mapTo ( { } ) ) ; const a$ = r . pipe ( r . matchPath ( '/a' ) , r . matchType ( 'GET' ) , r . useEffect ( effect$ ) ) ; const b$ = r . pipe ( r . matchPath ( '/b' ) , r . matchType ( 'GET' ) , r . useEffect ( effect$ ) ) ; const m1$ = req$ => req$ ; const m2$ = req$ => req$ ; const combiner = combineRoutes ( '/test' , { middlewares : [ m1$ , m2$ ] , effects : [ a$ , b$ ] , } ) ; expect ( combiner ) . toEqual ( { path : '/test' , middlewares : [ m1$ , m2$ ] , effects : [ a$ , b$ ] , } ) ; } ) ; test ( 'factorizes combined routes for effects with empty middlewares' , ( ) => { const effect$ = ( req$ ) => req$ . pipe ( mapTo ( { } ) ) ; const a$ = r . pipe ( r . matchPath ( '/a' ) , r . matchType ( 'GET' ) , r . useEffect ( effect$ ) ) ; const b$ = r . pipe ( r . matchPath ( '/b' ) , r . matchType ( 'GET' ) , r . useEffect ( effect$ ) ) ; const combiner = combineRoutes ( '/test' , { effects : [ a$ , b$ ] , } ) ; expect ( combiner ) . toEqual ( { path : '/test' , middlewares : [ ] , effects : [ a$ , b$ ] , } ) ; } ) ; } ) ;