<commit_before>const { expect } = require('chai');
const { check, oneOf } = require('../check');
const { matchedData } = require('./');

describe('filter: matchedData', () => {
  it('includes only valid data in the request', () => {
    const req = {
      query: { foo: '123', bar: 'abc', baz: 'def' },
      body: { foo: 'abc' }
    };

    return check(['foo', 'bar']).isInt()(req, {}, () => {}).then(() => {
      const data = matchedData(req);
      expect(data).to.eql({ foo: '123' });
    });
  });

  it('sets paths properly even when using wildcards', () => {
    const req = {
      body: { foo: [10, 20, 30] },
      query: { bar: { baz: { qux: 123 } } }
    };

    return check(['foo.*', '*.*.qux']).isInt()(req, {}, () => {}).then(() => {
      const data = matchedData(req);

      expect(data).to.eql({
        foo: [10, 20, 30],
        bar: { baz: { qux: 123 } }
      });
    });
  });

  describe('when option onlyValidData is set to false', () => {
    it('returns object with all data validated in the request', () => {<commit_msg>filter: add failing test for matchedData use with oneOf<commit_after>const { expect } = require('chai');
const { check, oneOf } = require('../check');
const { matchedData } = require('./');

describe('filter: matchedData', () => {
  it('includes only valid data in the request', () => {
    const req = {
      query: { foo: '123', bar: 'abc', baz: 'def' },
      body: { foo: 'abc' }
    };

    return check(['foo', 'bar']).isInt()(req, {}, () => {}).then(() => {
      const data = matchedData(req);
      expect(data).to.eql({ foo: '123' });
    });
  });

  it('sets paths properly even when using wildcards', () => {
    const req = {
      body: { foo: [10, 20, 30] },
      query: { bar: { baz: { qux: 123 } } }
    };

    return check(['foo.*', '*.*.qux']).isInt()(req, {}, () => {}).then(() => {
      const data = matchedData(req);

      expect(data).to.eql({
        foo: [10, 20, 30],
        bar: { baz: { qux: 123 } }
      });
    });
  });

  it('includes data only from the successful chain in oneOf by default', () => {
    const req = {
      headers: { foo: 'foo', bar: '123', baz: 'baz' }
    };

    return oneOf([
      check('foo').isInt(),
      check('bar').isInt()
    ])(req, {}, () => {}).then(() => {
      const data = matchedData(req);
      expect(data).to.eql({ bar: '123' });
    });
  });

  describe('when option onlyValidData is set to false', () => {
    it('returns object with all data validated in the request', () => {
{'fraction_non_alphanumeric': 0.23281684545093365, 'fraction_numerical': 0.021454112038140644, 'mean_word_length': 2.571631205673759, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '7528380', 'n_tokens_mistral': 894, 'n_tokens_neox': 832, 'n_words': 224}