All files / tools/ReFlex.TrackingServer/ClientApp/src/shared/services webSocket.service.mock.ts

88.23% Statements 15/17
66.66% Branches 4/6
100% Functions 6/6
86.66% Lines 13/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 451x     1x     1x         15x       15x       8x       8x       8x       8x   8x 25x 9x           8x      
import { Observable, of, Subject } from 'rxjs';
import { WebSocketService } from './webSocket.service';
 
export class WebSocketServiceMock implements Partial<WebSocketService> {
  private requestStream?: Subject<MessageEvent>;
 
  public constructor(private readonly responseSubject: Subject<MessageEvent>, private readonly desiredType: string) {
 
  }
 
  public get requestSubject(): Subject<MessageEvent> {
    Iif (this.requestStream === undefined) {
      return this.initRequestStream();
    }
 
    return this.requestStream;
  }
 
  public createSocket(): Subject<MessageEvent> {
    return this.initRequestStream();
  }
 
  public getResponseStream(): Observable<MessageEvent> {
    Iif (this.responseSubject === undefined) {
      return of();
    }
 
    return this.responseSubject;
  }
 
  private initRequestStream(): Subject<MessageEvent> {
    this.requestStream = new Subject<MessageEvent>();
 
    this.requestStream.subscribe((msg) => {
      if (this.desiredType === msg.type) {
        this.responseSubject.next(msg);
 
        // console.error(`### ${msg?.data} ###`);
      }
    });
 
    return this.requestStream;
  }
}