<commit_before>import { Observable, AjaxResponse, AjaxError } from 'rxjs';

import { formatResponse, formatError, formatAjaxStream } from '../streamFormatters';

describe('streamFormatters', () => {
  it('formats a ajax response', () => {
    const ajaxResponse = new AjaxResponse(
      new Event('ajaxResponse'),
      new XMLHttpRequest(),
      {},
    );

    ajaxResponse.response = 'OK';

    expect(formatResponse(ajaxResponse)).toEqual('OK');
  });

  it('formats a ajax error', () => {
    const ajaxError = new AjaxError(
      'Cannot find this jedi',
      new XMLHttpRequest(),
      {},
    );

    const apiError = formatError(ajaxError);

    expect(apiError).toBeInstanceOf(Error);
    expect(apiError.message).toEqual('Cannot find this jedi');
  });

  it('formats an ajax stream without config', () => {
    expect(() => formatAjaxStream(<any>{}))
      .toThrowError('Missing config parameter');
  });

  it('formats an ajax stream without stream$', () => {
    expect(() => formatAjaxStream(<any>{ config: { isList: true } }))
      .toThrowError('Missing stream$ parameter');
  });

  it('formats an ajax stream of one value', async () => {
    const ajaxResponse = new AjaxResponse(
      new Event('ajaxResponse'),
      new XMLHttpRequest(),
      {},
    );
    ajaxResponse.response = {
      id: '5',
      name: 'Yoda',
    };

    const params = {
      config: { isList: false },
      stream$: Observable.of(ajaxResponse),
    };

    const r = await formatAjaxStream(params)
      .toPromise();

    expect(r.id).toEqual('5');
    expect(r.name).toEqual('Yoda');
    expect(r.requestedAt).toBeInstanceOf(Date);
  });

  it('formats an ajax stream of a list', async () => {
    const ajaxResponse = new AjaxResponse(
      new Event('ajaxResponse'),
      new XMLHttpRequest(),
      {},
    );
    ajaxResponse.response = {
      member: [
        {
          id: '5',
          name: 'Yoda',
        },
        {
          id: '6',
          name: '<NAME>',
        }
      ]
    };

    const params = {
      config: { isList: true },
      stream$: Observable.of(ajaxResponse),
    };

    const r = await formatAjaxStream(params)
      .toPromise();
<commit_msg>[fix]: linter<commit_after>import { Observable, AjaxResponse, AjaxError } from 'rxjs';

import { formatResponse, formatError, formatAjaxStream } from '../streamFormatters';

describe('streamFormatters', () => {
  it('formats a ajax response', () => {
    const ajaxResponse = new AjaxResponse(
      new Event('ajaxResponse'),
      new XMLHttpRequest(),
      {},
    );

    ajaxResponse.response = 'OK';

    expect(formatResponse(ajaxResponse)).toEqual('OK');
  });

  it('formats a ajax error', () => {
    const ajaxError = new AjaxError(
      'Cannot find this jedi',
      new XMLHttpRequest(),
      {},
    );

    const apiError = formatError(ajaxError);

    expect(apiError).toBeInstanceOf(Error);
    expect(apiError.message).toEqual('Cannot find this jedi');
  });

  it('formats an ajax stream without config', () => {
    expect(() => formatAjaxStream(<any>{}))
      .toThrowError('Missing config parameter');
  });

  it('formats an ajax stream without stream$', () => {
    expect(() => formatAjaxStream(<any>{ config: { isList: true } }))
      .toThrowError('Missing stream$ parameter');
  });

  it('formats an ajax stream of one value', async () => {
    const ajaxResponse = new AjaxResponse(
      new Event('ajaxResponse'),
      new XMLHttpRequest(),
      {},
    );
    ajaxResponse.response = {
      id: '5',
      name: 'Yoda',
    };

    const params = {
      config: { isList: false },
      stream$: Observable.of(ajaxResponse),
    };

    const r = await formatAjaxStream(params)
      .toPromise();

    expect(r.id).toEqual('5');
    expect(r.name).toEqual('Yoda');
    expect(r.requestedAt).toBeInstanceOf(Date);
  });

  it('formats an ajax stream of a list', async () => {
    const ajaxResponse = new AjaxResponse(
      new Event('ajaxResponse'),
      new XMLHttpRequest(),
      {},
    );
    ajaxResponse.response = {
      member: [
        {
          id: '5',
          name: 'Yoda',
        },
        {
          id: '6',
          name: '<NAME>an',
        },
      ],
    };

    const params = {
      config: { isList: true },
      stream$: Observable.of(ajaxResponse),
    };

    const r = await formatAjaxStream(params)
      .toPromise();

{'fraction_non_alphanumeric': 0.15773944620971403, 'fraction_numerical': 0.0018157058556513845, 'mean_word_length': 2.606382978723404, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2495255', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1288, 'n_words': 301}