<commit_before>import uuid from 'uuid';
import { UrlUtils } from 'api/utils/url';

export class MockedRequest {

  constructor({ id = uuid.v4(), active = true, method, url, headers, params, response }) {
    Object.assign(this, { id, active, method, url, headers, params, response });
  }

  getRequestHash() {
    return [this.method, this.url, this.params].join('|');
  }

  getResponse() {
    return { headers: this.headers, ...this.response };
  }

  update(request) {
    this.response.status = request.response.status;
    this.response.delay = request.response.delay;
    this.response.body = request.response.body;
    this.params = request.params;
    this.url = request.url;
    this.headers = Object.assign({}, request.headers);
  }

  toggle() {
    this.active = !this.active;
  }

  matches(request) {
    // Convert the string to regex (replace ? to \?, / to \/ etc.)
    // and replace all '*' with .*
    const preparedRegex = this.prepareRegex(this.url);

    return request.method === this.method &&
           this.matchParams(request.params) &&
           preparedRegex.test(request.url);
  }

  prepareRegex(value) {
    return new RegExp('^' +
      UrlUtils._escapeRegExp(value)
        .replace(/\*/g,'.*') + '$');
  }

  matchParams(params) {
    if (this.params === params) {
      return true;
    }

    return this.prepareRegex(this.params).test(params);
  }

  export() {
    const mock = Object.assign({}, this);

    if (mock.headers['content-type'].indexOf('application/json') > -1) {
      try {
        mock.params = JSON.parse(mock.params);
      } catch (ex) {
        // failed to parse params, reverting to string
      }


      try {
        mock.response.body = JSON.parse(mock.response.body);
      } catch (ex) {
        // failed to parse body, reverting to string
      }
    }

    return mock;
  }

}<commit_msg>fix(request matcher): Fix matching wildcard on non string values<commit_after>import uuid from 'uuid';
import { UrlUtils } from 'api/utils/url';

export class MockedRequest {

  constructor({ id = uuid.v4(), active = true, method, url, headers, params, response }) {
    Object.assign(this, { id, active, method, url, headers, params, response });
  }

  getRequestHash() {
    return [this.method, this.url, this.params].join('|');
  }

  getResponse() {
    return { headers: this.headers, ...this.response };
  }

  update(request) {
    this.response.status = request.response.status;
    this.response.delay = request.response.delay;
    this.response.body = request.response.body;
    this.params = request.params;
    this.url = request.url;
    this.headers = Object.assign({}, request.headers);
  }

  toggle() {
    this.active = !this.active;
  }

  matches(request) {
    // Convert the string to regex (replace ? to \?, / to \/ etc.)
    // and replace all '*' with .*
    const preparedRegex = this.prepareRegex(this.url);

    return request.method === this.method &&
           this.matchParams(request.params) &&
           preparedRegex.test(request.url);
  }

  prepareRegex(value) {
    return new RegExp('^' +
      UrlUtils._escapeRegExp(value)
        .replace(/\s/g, '')
        .replace(/\*/g,'.*') + '$');
  }

  matchParams(params) {
    if (this.params === params) {
      return true;
    }

    debugger;
    return this.prepareRegex(this.params).test(params);
  }

  export() {
    const mock = Object.assign({}, this);

    if (mock.headers['content-type'].indexOf('application/json') > -1) {
      try {
        mock.params = JSON.parse(mock.params);
      } catch (ex) {
        // failed to parse params, reverting to string
      }


      try {
        mock.response.body = JSON.parse(mock.response.body);
      } catch (ex) {
        // failed to parse body, reverting to string
      }
    }

    return mock;
  }

}
{'fraction_non_alphanumeric': 0.1548336389834949, 'fraction_numerical': 0.001047943411055803, 'mean_word_length': 2.535185185185185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3288538', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1174, 'n_words': 262}