<commit_before>"use strict";

const Cache = IdealPostcodes.Cache;

describe("Cache", () => {
	let cache;

	beforeEach(() => {
		cache = new Cache();
	});

	describe(".initialiseStore", () => {
		it ("resets store", () => {
			cache.store = "foo";
			cache.initialiseStore();
			expect(cache.store.postcodeStore).toBeDefined();
			expect(cache.store.addressStore).toBeDefined();
			expect(cache.store.autocompleteStore).toBeDefined();
			expect(cache.store.udprnStore).toBeDefined();
			expect(cache.store.umprnStore).toBeDefined();
		});
	});

	describe(".cacheAddressQuery", () => {
		it ("caches a query response", () => {
			cache.cacheAddressQuery({query: "foo"}, { bar: "baz" });
			expect(cache.getAddressQuery({query: "foo"}).bar).toEqual("baz");
		});
		it ("does not cache when disabled", () => {
			cache.disable();
			cache.cacheAddressQuery({query: "1", page: 0}, {page: "0"});
			Object.keys(cache.store).forEach(storeName => {
				const store = cache.store[storeName];
				expect(Object.keys(store).length).toEqual(0);
			});
		});
		it ("separates cache responses by non-query parameters", () => {
			cache.cacheAddressQuery({query: "1", page: 0}, {page: "0"});
			cache.cacheAddressQuery({query: "1", page: 1}, {page: "1"});
			expect(cache.getAddressQuery({query: "1", page: 0}).page).toEqual("0");
			expect(cache.getAddressQuery({query: "1", page: 1}).page).toEqual("1");
		});
	});

	describe(".cachePostcodeQuery", () => {
		it ("caches a query response", () => {
			cache.cachePostcodeQuery({query: "foo"}, { bar: "baz" });
			expect(cache.getPostcodeQuery({query: "foo"}).bar).toEqual("baz");
		});
		it ("does not cache when disabled", () => {
			cache.disable();
			cache.cachePostcodeQuery({query: "1", page: 0}, {page: "0"});
			Object.keys(cache.store).forEach(storeName => {
				const store = cache.store[storeName];
				expect(Object.keys(store).length).toEqual(0);
			});
		});
		it ("separates cache responses by non-query parameters", () => {
			cache.cachePostcodeQuery({query: "1", page: 0}, {page: "0"});
			cache.cachePostcodeQuery({query: "1", page: 1}, {page: "1"});
			expect(cache.getPostcodeQuery({query: "1", page: 0}).page).toEqual("0");
			expect(cache.getPostcodeQuery({query: "1", page: 1}).page).toEqual("1");
		});
	});

	describe(".cacheAutocompleteQuery", () => {
		it ("caches a query response", () => {
			cache.cacheAutocompleteQuery({query: "foo"}, { bar: "baz" });
			expect(cache.getAutocompleteQuery({query: "foo"}).bar).toEqual("baz");
		});
		it ("does not cache when disabled", () => {
			cache.disable();
			cache.cacheAutocompleteQuery({query: "1", page: 0}, {page: "0"});
			Object.keys(cache.store).forEach(storeName => {
				const store = cache.store[storeName];
				expect(Object.keys(store).length).toEqual(0);
			});
		});
		it ("separates cache responses by non-query parameters", () => {
			cache.cacheAutocompleteQuery({query: "1", page: 0}, {page: "0"});
			cache.cacheAutocompleteQuery({query: "1", page: 1}, {page: "1"});
			expect(cache.getAutocompleteQuery({query: "1", page: 0}).page).toEqual("0");
			expect(cache.getAutocompleteQuery({query: "1", page: 1}).page).toEqual("1");
		});
	});

	describe(".cacheUdprnQuery", () => {<commit_msg>Additional testing<commit_after>"use strict";

const Cache = IdealPostcodes.Cache;

describe("Cache", () => {
	let cache;

	beforeEach(() => {
		cache = new Cache();
	});

	describe(".initialiseStore", () => {
		it ("resets store", () => {
			cache.store = "foo";
			cache.initialiseStore();
			expect(cache.store.postcodeStore).toBeDefined();
			expect(cache.store.addressStore).toBeDefined();
			expect(cache.store.autocompleteStore).toBeDefined();
			expect(cache.store.udprnStore).toBeDefined();
			expect(cache.store.umprnStore).toBeDefined();
		});
	});

	describe(".cacheAddressQuery", () => {
		it ("caches a query response", () => {
			cache.cacheAddressQuery({query: "foo"}, { bar: "baz" });
			cache.cacheAddressQuery({query: "qux"}, { quux: "quuz" });
			expect(Object.keys(cache.store.addressStore).length).toEqual(2);
			expect(cache.getAddressQuery({query: "foo"}).bar).toEqual("baz");
			expect(cache.getAddressQuery({query: "qux"}).quux).toEqual("quuz");
		});
		it ("does not cache when disabled", () => {
			cache.disable();
			cache.cacheAddressQuery({query: "1", page: 0}, {page: "0"});
			Object.keys(cache.store).forEach(storeName => {
				const store = cache.store[storeName];
				expect(Object.keys(store).length).toEqual(0);
			});
		});
		it ("separates cache responses by non-query parameters", () => {
			cache.cacheAddressQuery({query: "1", page: 0}, {page: "0"});
			cache.cacheAddressQuery({query: "1", page: 1}, {page: "1"});
			expect(cache.getAddressQuery({query: "1", page: 0}).page).toEqual("0");
			expect(cache.getAddressQuery({query: "1", page: 1}).page).toEqual("1");
		});
	});

	describe(".cachePostcodeQuery", () => {
		it ("caches a query response", () => {
			cache.cachePostcodeQuery({query: "foo"}, { bar: "baz" });
			cache.cachePostcodeQuery({query: "qux"}, { quux: "quuz" });
			expect(Object.keys(cache.store.postcodeStore).length).toEqual(2);
			expect(cache.getPostcodeQuery({query: "foo"}).bar).toEqual("baz");
			expect(cache.getPostcodeQuery({query: "qux"}).quux).toEqual("quuz");
		});
		it ("does not cache when disabled", () => {
			cache.disable();
			cache.cachePostcodeQuery({query: "1", page: 0}, {page: "0"});
			Object.keys(cache.store).forEach(storeName => {
				const store = cache.store[storeName];
				expect(Object.keys(store).length).toEqual(0);
			});
		});
		it ("separates cache responses by non-query parameters", () => {
			cache.cachePostcodeQuery({query: "1", page: 0}, {page: "0"});
			cache.cachePostcodeQuery({query: "1", page: 1}, {page: "1"});
			expect(cache.getPostcodeQuery({query: "1", page: 0}).page).toEqual("0");
			expect(cache.getPostcodeQuery({query: "1", page: 1}).page).toEqual("1");
		});
	});

	describe(".cacheAutocompleteQuery", () => {
		it ("caches a query response", () => {
			cache.cacheAutocompleteQuery({query: "foo"}, { bar: "baz" });
			cache.cacheAutocompleteQuery({query: "qux"}, { quux: "quuz" });
			expect(Object.keys(cache.store.autocompleteStore).length).toEqual(2);
			expect(cache.getAutocompleteQuery({query: "foo"}).bar).toEqual("baz");
			expect(cache.getAutocompleteQuery({query: "qux"}).quux).toEqual("quuz");
		});
		it ("does not cache when disabled", () => {
			cache.disable();
			cache.cacheAutocompleteQuery({query: "1", page: 0}, {page: "0"});
			Object.keys(cache.store).forEach(storeName => {
				const store = cache.store[storeName];
				expect(Object.keys(store).length).toEqual(0);
			});
		});
		it ("separates cache responses by non-query parameters", () => {
			cache.cacheAutocompleteQuery({query: "1", page: 0}, {page: "0"});
			cache.cacheAutocompleteQuery({query: "1", page: 1}, {page: "1"});
			expect(cache.getAutocompleteQuery({query: "1", page: 0}).page).toEqual("0");
			expect(cache.getAutocompleteQuery({query: "1", page: 1}).page).toEqual("1");
		});
	});

	describe(".cacheUdprnQuery", () => {
{'fraction_non_alphanumeric': 0.22316624185783066, 'fraction_numerical': 0.014018691588785047, 'mean_word_length': 4.803615447822515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '7339906', 'n_tokens_mistral': 2665, 'n_tokens_neox': 2335, 'n_words': 414}