test(core): test cases for effects.combiner
ADD
packages/core/src/effects/effects.combiner.spec.ts
+import { of } from 'rxjs';
+import { tap } from 'rxjs/operators';
+import { Middleware } from './effects.interface';
+import { combineMiddlewareEffects } from './effects.combiner';
+import { HttpResponse, HttpRequest } from '../http.interface';
+import { Marbles } from '../../../util/marbles.spec-util';
+
+const createMockRes = () => ({} as HttpResponse);
+const createMockReq = (url = '/') => ({ url } as HttpRequest);
+
+describe('Effects combiner', () => {
+
+ test('#combineMiddlewareEffects combines middlewares into one stream', () => {
+ // given
+ const a$: Middleware = req$ => req$.pipe(tap(req => { req.test = 1; }));
+ const b$: Middleware = req$ => req$.pipe(tap(req => { req.test = req.test + 1; }));
+ const c$: Middleware = req$ => req$.pipe(tap(req => { req.test = req.test + 1; }));
+
+ // when
+ const req = createMockReq();
+ const res = createMockRes();
+ const combinedEffect = combineMiddlewareEffects([ a$, b$, c$ ]);
+ const http$ = combinedEffect(of(req), res, undefined);
+
+ // then
+ Marbles.assertCombinedEffects(http$, [
+ '(a|)', {
+ a: { url: '/', test: 3 }
+ }
+ ]);
+ });
+
+ test('#combineMiddlewareEffects returns stream even if middlewares are not provided', () => {
+ // given
+ const emptyMiddlewaresCollection = [];
+
+ // when
+ const req = createMockReq();
+ const res = createMockRes();
+ const combinedEffect = combineMiddlewareEffects(emptyMiddlewaresCollection);
+ const http$ = combinedEffect(of(req), res, undefined);
+
+ // then
+ Marbles.assertCombinedEffects(http$, [
+ '(a|)', {
+ a: { url: '/' }
+ }
+ ]);
+ });
+
+});

MODIFY
packages/core/src/effects/effects.combiner.ts
packages/core/src/effects/effects.combiner.ts
import { from } from 'rxjs';
import { concatMap, last } from 'rxjs/operators';
import { HttpRequest, HttpResponse } from '../http.interface';
-import { Middleware, MiddlewareCombiner } from './effects.interface';
+import { Middleware } from './effects.interface';
import { Observable } from 'rxjs/Observable';
-export const combineMiddlewareEffects: MiddlewareCombiner = (effects: Middleware[]): Middleware => {
+export const combineMiddlewareEffects = (effects: Middleware[]): Middleware => {
const middlewaresObservable = from(middlewaresGuard(effects));
return (req$: Observable<HttpRequest>, res: HttpResponse, metadata: any) => {
@@ -16,7 +16,7 @@ export const combineMiddlewareEffects: MiddlewareCombiner = (effects: Middleware
};
const middlewaresGuard = (middlewares: Middleware[]) => {
- const emptyMiddleware: Middleware = req => req;
+ const emptyMiddleware: Middleware = req$ => req$;
return middlewares.length
? middlewares
: [emptyMiddleware];

MODIFY
packages/core/src/effects/effects.interface.ts
packages/core/src/effects/effects.interface.ts
@@ -9,10 +9,6 @@ export interface EffectResponse {
export type Middleware = Effect<HttpRequest>;
-export interface MiddlewareCombiner {
- (effects: Middleware[]): Middleware;
-}
-
export type Effect<T = EffectResponse, U = any> = (
request$: Observable<HttpRequest>,
response: HttpResponse,

test(core): test cases for effects.combiner