<commit_before>import * as reviewHelper from 'helpers/reviewHelper';

describe('reviewHelper', () => {
    describe('getFileStates', () => {
        const generateParam = (jobs = []) => ({
            jobs
        });
        const defaultResult = (name) => ({
			report: null,
			error_count: 0,
			warning_count: 0,
			error_data: [],
			warning_data: [],
			file_type: name
        });
        it('returns an empty object if file_type is falsy', () => {
            expect(reviewHelper.getFileStates(generateParam())).toEqual({});
        });
        it('returns an object keyed by file type', () => {
            expect(reviewHelper.getFileStates(generateParam([
				{ file_type: 'test', error_data: [], warning_data: [] },
				{ file_type: 'test2', error_data: [], warning_data: [] }
			]))).toEqual({
				'test': defaultResult('test'),
				'test2': defaultResult('test2')
			});
		});
    });
});<commit_msg>[dev-2536] tests for reviewHelper utils<commit_after>import * as reviewHelper from "helpers/reviewHelper";

describe("reviewHelper", () => {
    describe("getFileStates", () => {
        const generateParam = (jobs = []) => ({
            jobs
        });
        const defaultResult = (name) => ({
            report: null,
            error_count: 0,
            warning_count: 0,
            error_data: [],
            warning_data: [],
            file_type: name
        });
        it("returns an empty object if file_type is falsy", () => {
            expect(reviewHelper.getFileStates(generateParam())).toEqual({});
        });
        it("returns an object keyed by file type", () => {
            expect(
                reviewHelper.getFileStates(
                    generateParam([
                        { file_type: "test", error_data: [], warning_data: [] },
                        { file_type: "test2", error_data: [], warning_data: [] }
                    ])
                )
            ).toEqual({
                test: defaultResult("test"),
                test2: defaultResult("test2")
            });
        });
        it("returns an object keyed by file type with error_count value based on error_data.occurrences", () => {
            const itemWithErrorData = Object.assign(defaultResult("test"), {
                error_data: [{ occurrences: "10" }]
            });
            const itemWithWarningData = Object.assign(defaultResult("test2"), {
                warning_data: [{ occurrences: "10" }]
            });
            expect(reviewHelper.getFileStates(generateParam([itemWithErrorData]))).toEqual({
                test: Object.assign(itemWithErrorData, { error_count: 10 })
            });
            expect(reviewHelper.getFileStates(generateParam([itemWithWarningData]))).toEqual({
                test2: Object.assign(itemWithWarningData, { warning_count: 10 })
            });
        });
    });

    describe("getCrossFileData", () => {
        // two params, data and type
        const data = {
            error_data: [
                { target_file: "appropriations", source_file: "program_activity" },
                { target_file: "not_valid", source_file: "not_valid" }
            ],
            warning_data: [
                { target_file: "appropriations", source_file: "program_activity" },
                { target_file: "not_valid", source_file: "not_valid" }
            ]
        };

        const types = ["warnings", "errors"];

        // iterates over each item in the type property, whose value is an array,
        // builds output object of shape:
        it("returns only valid source/target file paris", () => {
            const errors = reviewHelper.getCrossFileData(data, types[1]);
            const warnings = reviewHelper.getCrossFileData(data, types[0]);

            expect(Object.keys(errors).length).toEqual(1);
            expect(errors["appropriations-program_activity"]).toEqual([data.error_data[0]]);
            expect(Object.keys(warnings).length).toEqual(1);
            expect(warnings["appropriations-program_activity"]).toEqual([data.warning_data[0]]);
        });
    });
});
{'fraction_non_alphanumeric': 0.14348570031777072, 'fraction_numerical': 0.007333170373991689, 'mean_word_length': 2.104704097116844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '5982623', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1082, 'n_words': 215}