<commit_before>import path from 'path';
import { DataEntity, debugLogger } from '@terascope/utils';
import {
    SelectionPhase, Loader, OperationsManager, SelectorConfig
} from '../../src';

describe('selector phase', () => {
    const logger = debugLogger('selectorPhaseTest');
    const opManager = new OperationsManager();

    async function getConfigList(fileName: string): Promise<SelectorConfig[]> {
        const filePath = path.join(__dirname, `../fixtures/${fileName}`);
        const myFileLoader = new Loader({ rules: [filePath] }, logger);
        const { selectors } = await myFileLoader.load(opManager);
        return selectors;
    }
    // file_path is only used in loader
    const transformOpconfig = { rules: ['some/path'] };

    it('can instantiate', async () => {
        const configList = await getConfigList('transformRules1.txt');

        expect(() => new SelectionPhase(transformOpconfig, configList, opManager)).not.toThrow();
    });

    it('has the proper properties', async () => {
        const configList = await getConfigList('transformRules1.txt');
        const selectorPhase = new SelectionPhase(transformOpconfig, configList, opManager);

        expect(selectorPhase.selectionPhase).toBeDefined();
        expect(selectorPhase.selectionPhase.length).toEqual(6);
    });

    it('can run data to match based on selector and types', async () => {
        const configList = await getConfigList('transformRules1.txt');
        const myOpConfig = Object.assign({}, transformOpconfig, { types: { location: 'geo' } });
        const selectorPhase = new SelectionPhase(myOpConfig, configList, opManager);
        const data = DataEntity.makeArray([
            { some: 'data', isTall: true },
            { some: 'thing else', person: {} },
            { hostname: 'www.example.com', bytes: 1000 },
            { location: '33.435967,-111.867710', zip: 94302 },
            {}
        ]);

        const results = selectorPhase.run(data);

        expect(results.length).toEqual(3);
        expect(results[0]).toEqual(data[0]);
        expect(results[1]).toEqual(data[2]);
        expect(results[2]).toEqual(data[3]);
    });

    it('can match all', async () => {
        const configList = await getConfigList('transformRules3.txt');
        const selectorPhase = new SelectionPhase(transformOpconfig, configList, opManager);
        const data = DataEntity.makeArray([
            { some: 'data', isTall: true },<commit_msg>fix test<commit_after>import path from 'path';
import { DataEntity, debugLogger } from '@terascope/utils';
import {
    SelectionPhase, Loader, OperationsManager, SelectorConfig
} from '../../src';

describe('selector phase', () => {
    const logger = debugLogger('selectorPhaseTest');
    const opManager = new OperationsManager();

    async function getConfigList(fileName: string): Promise<SelectorConfig[]> {
        const filePath = path.join(__dirname, `../fixtures/${fileName}`);
        const myFileLoader = new Loader({ rules: [filePath] }, logger);
        const { selectors } = await myFileLoader.load(opManager);
        return selectors;
    }
    // file_path is only used in loader
    const transformOpconfig = { rules: ['some/path'] };

    it('can instantiate', async () => {
        const configList = await getConfigList('transformRules1.txt');

        expect(() => new SelectionPhase(transformOpconfig, configList, opManager)).not.toThrow();
    });

    it('has the proper properties', async () => {
        const configList = await getConfigList('transformRules1.txt');
        const selectorPhase = new SelectionPhase(transformOpconfig, configList, opManager);

        expect(selectorPhase.selectionPhase).toBeDefined();
        expect(selectorPhase.selectionPhase.length).toEqual(6);
    });

    it('can run data to match based on selector and types', async () => {
        const configList = await getConfigList('transformRules1.txt');
        const myOpConfig = Object.assign({}, transformOpconfig, { type_config: { location: 'geo' } });
        const selectorPhase = new SelectionPhase(myOpConfig, configList, opManager);
        const data = DataEntity.makeArray([
            { some: 'data', isTall: true },
            { some: 'thing else', person: {} },
            { hostname: 'www.example.com', bytes: 1000 },
            { location: '33.435967,-111.867710', zip: 94302 },
            {}
        ]);

        const results = selectorPhase.run(data);

        expect(results.length).toEqual(3);
        expect(results[0]).toEqual(data[0]);
        expect(results[1]).toEqual(data[2]);
        expect(results[2]).toEqual(data[3]);
    });

    it('can match all', async () => {
        const configList = await getConfigList('transformRules3.txt');
        const selectorPhase = new SelectionPhase(transformOpconfig, configList, opManager);
        const data = DataEntity.makeArray([
            { some: 'data', isTall: true },
{'fraction_non_alphanumeric': 0.13917630350983973, 'fraction_numerical': 0.015418949076891864, 'mean_word_length': 3.1850594227504243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '933869', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1319, 'n_words': 323}