<commit_before>"use strict";

const log = require("../../src/log");
const expect = require("chai").expect;
const mergeConfig = require("../../src/helper").mergeConfig;

describe("mergeConfig", function() {
	it("should mutate object", function() {
		const config = {
			ip: "default",
		};

		expect(mergeConfig(config, {
			ip: "overridden",
		})).to.deep.equal({
			ip: "overridden",
		});

		expect(config).to.deep.equal({
			ip: "overridden",
		});
	});

	it("should merge new properties", function() {
		expect(mergeConfig({
			ip: "default",
			newProp: "this should appear too",
		}, {
			ip: "overridden",
		})).to.deep.equal({
			ip: "overridden",
			newProp: "this should appear too",
		});
	});

	it("should extend objects", function() {
		expect(mergeConfig({
			tlsOptions: {},
		}, {
			tlsOptions: {
				user: "test",
				thing: 123,
			},
		})).to.deep.equal({
			tlsOptions: {
				user: "test",
				thing: 123,
			},
		});
	});

	it("should allow changing nulls", function() {
		expect(mergeConfig({
			oidentd: null,
		}, {
			oidentd: "some path",
		})).to.deep.equal({
			oidentd: "some path",
		});
	});

	it("should keep new properties inside of objects", function() {
		expect(mergeConfig({
			nestedOnce: {
				ip: "default",
			},
			nestedTwice: {
				thing: "default",
				nested: {
					otherThing: "also default",
					newThing: "but also this",
				},
			},
		}, {
			nestedOnce: {},<commit_msg>Hide unknown key warning in mergeConfig test<commit_after>"use strict";

const log = require("../../src/log");
const expect = require("chai").expect;
const stub = require("sinon").stub;
const mergeConfig = require("../../src/helper").mergeConfig;

describe("mergeConfig", function() {
	it("should mutate object", function() {
		const config = {
			ip: "default",
		};

		expect(mergeConfig(config, {
			ip: "overridden",
		})).to.deep.equal({
			ip: "overridden",
		});

		expect(config).to.deep.equal({
			ip: "overridden",
		});
	});

	it("should merge new properties", function() {
		expect(mergeConfig({
			ip: "default",
			newProp: "this should appear too",
		}, {
			ip: "overridden",
		})).to.deep.equal({
			ip: "overridden",
			newProp: "this should appear too",
		});
	});

	it("should extend objects", function() {
		let warning = "";
		stub(log, "warn").callsFake((str) => warning += str);

		expect(mergeConfig({
			tlsOptions: {},
		}, {
			tlsOptions: {
				user: "test",
				thing: 123,
			},
		})).to.deep.equal({
			tlsOptions: {
				user: "test",
				thing: 123,
			},
		});

		log.warn.restore();
		expect(warning).to.contain("Unknown key");
	});

	it("should allow changing nulls", function() {
		expect(mergeConfig({
			oidentd: null,
		}, {
			oidentd: "some path",
		})).to.deep.equal({
			oidentd: "some path",
		});
	});

	it("should keep new properties inside of objects", function() {
		expect(mergeConfig({
			nestedOnce: {
				ip: "default",
			},
			nestedTwice: {
				thing: "default",
				nested: {
					otherThing: "also default",
					newThing: "but also this",
				},
			},
		}, {
			nestedOnce: {},
{'fraction_non_alphanumeric': 0.19738562091503267, 'fraction_numerical': 0.00392156862745098, 'mean_word_length': 3.1589673913043477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '7557263', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1050, 'n_words': 236}