<commit_before>const { expect } = require('chai');
const { ObjectId } = require('mongoose').Types;
const { BadRequest } = require('@feathersjs/errors');
const {
	isArray,
	isArrayWithElement,
	isObject,
	isString,
	hasKey,
	isDefined,
	isUndefined,
	isNull,
	isObjectId,
	isObjectIdWithTryToCast,
	throwErrorIfNotObjectId,
	bsonIdToString,
	isSameId,
	isFunction,
} = require('../../../../src/services/teams/hooks/collection.js');

describe('collection helpers', () => {
	describe('isArray', () => {
		it('returns true for empty arrays', () => {
			expect(isArray([])).to.equal(true);
			expect(isArray(new Array())).to.equal(true);
		});

		it('returns true for given arrays', () => {
			expect(isArray([1, 2, 3])).to.equal(true);
			expect(isArray(['a', 'b', 4, 5])).to.equal(true);
		});

		it('returns false for non-arrays', () => {
			expect(isArray({})).to.equal(false);
			expect(isArray(1)).to.equal(false);
			expect(isArray('Hello World')).to.equal(false);
		});

		it('works for huge arrays', () => {
			const array = new Array(Math.pow(2, 20)).fill(1);
			expect(isArray(array)).to.equal(true);
		});
	});

	describe('isArrayWithElement', () => {
		it('returns false for empty arrays', () => {
			expect(isArrayWithElement([])).to.equal(false);
			expect(isArrayWithElement(new Array())).to.equal(false);
		});

		it('returns true for given arrays', () => {
			expect(isArrayWithElement([1, 2, 3])).to.equal(true);
			expect(isArrayWithElement(['a', 'b', 4, 5])).to.equal(true);
		});

		it('returns false for non-arrays', () => {
			expect(isArrayWithElement({})).to.equal(false);
			expect(isArrayWithElement(1)).to.equal(false);
			expect(isArrayWithElement('Hello World')).to.equal(false);
		});

		it('works for huge arrays', () => {
			const array = new Array(Math.pow(2, 20)).fill(1);
			expect(isArrayWithElement(array)).to.equal(true);
		});
	});

	describe('isObject', () => {
		it('returns true for plain objects', () => {
			expect(isObject({})).to.equal(true);
			expect(isObject({ a: 123, b: 42 })).to.equal(true);
		});

		it('returns false for other types', () => {
			expect(isObject(123)).to.equal(false);
			expect(isObject([1, 2, 3])).to.equal(false);
			expect(isObject('foo bar')).to.equal(false);
		});
	});

	describe('isString', () => {
		it('should return true for strings', () => {
			expect(isString('')).to.equal(true);
			expect(isString('foobar')).to.equal(true);
		});

		it('should return false for other types', () => {
			expect(isString(123)).to.equal(false);
			expect(isString([])).to.equal(false);
			expect(isString(new Promise(() => {}))).to.equal(false);
			expect(isString(() => {})).to.equal(false);
		});
	});

	describe('hasKey', () => {
		it('should return true if a given object has a given key', () => {
			expect(hasKey({ a: 'b' }, 'a')).to.equal(true);
			expect(hasKey({ foo: 123 }, 'foo')).to.equal(true);
		});

		it('should return false otherwise', () => {
			expect(hasKey({}, 'foo')).to.equal(false);
			expect(hasKey({ a: 123 }, 'b')).to.equal(false);
			expect(hasKey(this, 4)).to.equal(false);
		});

		it('should not break due to broken arguments', () => {
			expect(hasKey()).to.equal(false);
			expect(hasKey({}, void 0)).to.equal(false);
			expect(hasKey(void 0, 4)).to.equal(false);
		});
	});

	describe('isDefined', () => {
		it('should work', () => {
			expect(isDefined(undefined)).to.equal(false);
			expect(isDefined(void 0)).to.equal(false);
			expect(isDefined(null)).to.equal(true);
			expect(isDefined(1)).to.equal(true);
			expect(isDefined(true)).to.equal(true);
			expect(isDefined(false)).to.equal(true);
			expect(isDefined({})).to.equal(true);
		});

		it('should work for lists of values', () => {
			expect(isDefined([1, 2], 'AND')).to.equal(true);
			expect(isDefined([3, 4], 'OR')).to.equal(true);
			expect(isDefined([undefined, 4], 'AND')).to.equal(false);
			expect(isDefined([undefined, 5], 'OR')).to.equal(true);
			expect(isDefined([void 0, void 0], 'OR')).to.equal(false);
		});
	});

	describe('isUndefined', () => {
		it('should work', () => {
			expect(isUndefined(undefined)).to.equal(true);
			expect(isUndefined(void 0)).to.equal(true);
			expect(isUndefined(null)).to.equal(false);
			expect(isUndefined(1)).to.equal(false);
			expect(isUndefined(true)).to.equal(false);
			expect(isUndefined(false)).to.equal(false);
			expect(isUndefined({})).to.equal(false);
		});

		it('should work for lists of values', () => {
			expect(isUndefined([1, 2], 'AND')).to.equal(false);
			expect(isUndefined([3, 4], 'OR')).to.equal(false);
			expect(isUndefined([undefined, 4], 'AND')).to.equal(false);
			expect(isUndefined([undefined, 5], 'OR')).to.equal(true);
			expect(isUndefined([void 0, void 0], 'OR')).to.equal(true);
		});
	});

	describe('isNull', () => {
		it('should work', () => {
			expect(isNull(undefined)).to.equal(false);
			expect(isNull(void 0)).to.equal(false);
			expect(isNull(null)).to.equal(true);
			expect(isNull(1)).to.equal(false);
			expect(isNull(true)).to.equal(false);
			expect(isNull(false)).to.equal(false);
			expect(isNull({})).to.equal(false);
		});
	});

	describe('isObjectId', () => {
		it('should return true for MongoDB ObjectIds', () => {
			const oid = new ObjectId();
			expect(isObjectId(oid)).to.equal(true);
		});
<commit_msg>Fix "no-void" lint issues<commit_after>const { expect } = require('chai');
const { ObjectId } = require('mongoose').Types;
const { BadRequest } = require('@feathersjs/errors');
const {
	isArray,
	isArrayWithElement,
	isObject,
	isString,
	hasKey,
	isDefined,
	isUndefined,
	isNull,
	isObjectId,
	isObjectIdWithTryToCast,
	throwErrorIfNotObjectId,
	bsonIdToString,
	isSameId,
	isFunction,
} = require('../../../../src/services/teams/hooks/collection.js');

describe('collection helpers', () => {
	describe('isArray', () => {
		it('returns true for empty arrays', () => {
			expect(isArray([])).to.equal(true);
			expect(isArray(new Array())).to.equal(true);
		});

		it('returns true for given arrays', () => {
			expect(isArray([1, 2, 3])).to.equal(true);
			expect(isArray(['a', 'b', 4, 5])).to.equal(true);
		});

		it('returns false for non-arrays', () => {
			expect(isArray({})).to.equal(false);
			expect(isArray(1)).to.equal(false);
			expect(isArray('Hello World')).to.equal(false);
		});

		it('works for huge arrays', () => {
			const array = new Array(Math.pow(2, 20)).fill(1);
			expect(isArray(array)).to.equal(true);
		});
	});

	describe('isArrayWithElement', () => {
		it('returns false for empty arrays', () => {
			expect(isArrayWithElement([])).to.equal(false);
			expect(isArrayWithElement(new Array())).to.equal(false);
		});

		it('returns true for given arrays', () => {
			expect(isArrayWithElement([1, 2, 3])).to.equal(true);
			expect(isArrayWithElement(['a', 'b', 4, 5])).to.equal(true);
		});

		it('returns false for non-arrays', () => {
			expect(isArrayWithElement({})).to.equal(false);
			expect(isArrayWithElement(1)).to.equal(false);
			expect(isArrayWithElement('Hello World')).to.equal(false);
		});

		it('works for huge arrays', () => {
			const array = new Array(Math.pow(2, 20)).fill(1);
			expect(isArrayWithElement(array)).to.equal(true);
		});
	});

	describe('isObject', () => {
		it('returns true for plain objects', () => {
			expect(isObject({})).to.equal(true);
			expect(isObject({ a: 123, b: 42 })).to.equal(true);
		});

		it('returns false for other types', () => {
			expect(isObject(123)).to.equal(false);
			expect(isObject([1, 2, 3])).to.equal(false);
			expect(isObject('foo bar')).to.equal(false);
		});
	});

	describe('isString', () => {
		it('should return true for strings', () => {
			expect(isString('')).to.equal(true);
			expect(isString('foobar')).to.equal(true);
		});

		it('should return false for other types', () => {
			expect(isString(123)).to.equal(false);
			expect(isString([])).to.equal(false);
			expect(isString(new Promise(() => {}))).to.equal(false);
			expect(isString(() => {})).to.equal(false);
		});
	});

	describe('hasKey', () => {
		it('should return true if a given object has a given key', () => {
			expect(hasKey({ a: 'b' }, 'a')).to.equal(true);
			expect(hasKey({ foo: 123 }, 'foo')).to.equal(true);
		});

		it('should return false otherwise', () => {
			expect(hasKey({}, 'foo')).to.equal(false);
			expect(hasKey({ a: 123 }, 'b')).to.equal(false);
			expect(hasKey(this, 4)).to.equal(false);
		});

		it('should not break due to broken arguments', () => {
			expect(hasKey()).to.equal(false);
			expect(hasKey({}, undefined)).to.equal(false);
			expect(hasKey(undefined, 4)).to.equal(false);
		});
	});

	describe('isDefined', () => {
		it('should work', () => {
			expect(isDefined(undefined)).to.equal(false);
			expect(isDefined(null)).to.equal(true);
			expect(isDefined(1)).to.equal(true);
			expect(isDefined(true)).to.equal(true);
			expect(isDefined(false)).to.equal(true);
			expect(isDefined({})).to.equal(true);
		});

		it('should work for lists of values', () => {
			expect(isDefined([1, 2], 'AND')).to.equal(true);
			expect(isDefined([3, 4], 'OR')).to.equal(true);
			expect(isDefined([undefined, 4], 'AND')).to.equal(false);
			expect(isDefined([undefined, 5], 'OR')).to.equal(true);
			expect(isDefined([undefined, undefined], 'OR')).to.equal(false);
		});
	});

	describe('isUndefined', () => {
		it('should work', () => {
			expect(isUndefined(undefined)).to.equal(true);
			expect(isUndefined(null)).to.equal(false);
			expect(isUndefined(1)).to.equal(false);
			expect(isUndefined(true)).to.equal(false);
			expect(isUndefined(false)).to.equal(false);
			expect(isUndefined({})).to.equal(false);
		});

		it('should work for lists of values', () => {
			expect(isUndefined([1, 2], 'AND')).to.equal(false);
			expect(isUndefined([3, 4], 'OR')).to.equal(false);
			expect(isUndefined([undefined, 4], 'AND')).to.equal(false);
			expect(isUndefined([undefined, 5], 'OR')).to.equal(true);
			expect(isUndefined([undefined, undefined], 'OR')).to.equal(true);
		});
	});

	describe('isNull', () => {
		it('should work', () => {
			expect(isNull(undefined)).to.equal(false);
			expect(isNull(null)).to.equal(true);
			expect(isNull(1)).to.equal(false);
			expect(isNull(true)).to.equal(false);
			expect(isNull(false)).to.equal(false);
			expect(isNull({})).to.equal(false);
		});
	});

	describe('isObjectId', () => {
		it('should return true for MongoDB ObjectIds', () => {
			const oid = new ObjectId();
			expect(isObjectId(oid)).to.equal(true);
		});

{'fraction_non_alphanumeric': 0.23462938134457, 'fraction_numerical': 0.011779352614441678, 'mean_word_length': 4.6570964247020585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 69, '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': '5704605', 'n_tokens_mistral': 4134, 'n_tokens_neox': 3710, 'n_words': 565}