<commit_before>const { expect } = require('chai');
const app = require('../../../../src/app');
const testObjects = require('../../helpers/testObjects')(app);

const adminStudentsService = app.service('/users/admin/students');
const classesService = app.service('/classes');
const gradeLevelService = app.service('/gradeLevels');

describe('AdminStudentsService', () => {
	let server;

	before((done) => {
		server = app.listen(0, done);
	});

	after((done) => {
		server.close(done);
	});

	it('is properly registered', () => {
		expect(adminStudentsService).to.not.equal(undefined);
	});

	it('builds class display names correctly', async () => {
		const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const student = await testObjects.createTestUser({ roles: ['student'] });

		await testObjects.createTestClass({
			name: 'staticName',
			userIds: [student._id],
			teacherIds: [teacher._id],
		});

		const gradeLevel = (await gradeLevelService.find({
			query: { name: '2' },
		})).data[0];
		const gradeLevelClass = await testObjects.createTestClass({
			name: 'A',
			userIds: [student._id],
			teacherIds: [teacher._id],
		});
		await classesService.patch(gradeLevelClass._id, {
			nameFormat: 'gradeLevel+name',
			gradeLevel: gradeLevel._id,
		});

		const params = {
			account: {
				userId: teacher._id,
			},
		};
		const result = await adminStudentsService.find(params);

		expect(result[0].classes).to.include('staticName');
		expect(result[0].classes).to.include('2A'); // gradeLevel+name
	});

	it('sorts students correctly', async () => {
		await testObjects.createTestUser({ firstName: 'Max', roles: ['student'] });
		await testObjects.createTestUser({ firstName: 'Moritz', roles: ['student'] });

		const params = {
			query: {
				$sort: {
					firstName: -1,
				},
			},
		};
		const result = await adminStudentsService.find(params);

		expect(result[0].firstName >= result[1].firstName);
	});

	it('filters students correctly', async () => {
		const student = await testObjects.createTestUser({ roles: ['student'] });

		const paramsMissing = {
			query: {
				cosentStatus: {
					$in: ['missing'],
				},
			},
		};
		const paramsOk = {
			query: {
				cosentStatus: {
					$in: ['ok'],
				},
			},
		};
		const resultMissing = await adminStudentsService.find(paramsMissing);
		resultMissing.map(e => e._id);
		const resultOk = await adminStudentsService.find(paramsOk);
		resultOk.map(e => e._id);

		expect(resultMissing.includes(student._id));
		expect(!resultOk.includes(student._id));
	});

	after(async () => {
		await testObjects.cleanup();
	});
});
<commit_msg>fixed tests for AdminUsers service<commit_after>const { expect } = require('chai');
const app = require('../../../../src/app');
const testObjects = require('../../helpers/testObjects')(app);

const adminStudentsService = app.service('/users/admin/students');
const classesService = app.service('/classes');
const gradeLevelService = app.service('/gradeLevels');

describe('AdminStudentsService', () => {
	let server;

	before((done) => {
		server = app.listen(0, done);
	});

	after((done) => {
		server.close(done);
	});

	it('is properly registered', () => {
		expect(adminStudentsService).to.not.equal(undefined);
	});

	it('builds class display names correctly', async () => {
		const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const student = await testObjects.createTestUser({ roles: ['student'] });

		await testObjects.createTestClass({
			name: 'staticName',
			userIds: [student._id],
			teacherIds: [teacher._id],
		});

		const gradeLevel = (await gradeLevelService.find({
			query: { name: '2' },
		})).data[0];
		const gradeLevelClass = await testObjects.createTestClass({
			name: 'A',
			userIds: [student._id],
			teacherIds: [teacher._id],
		});
		await classesService.patch(gradeLevelClass._id, {
			nameFormat: 'gradeLevel+name',
			gradeLevel: gradeLevel._id,
		});

		const params = {
			account: {
				userId: teacher._id,
			},
		};
		const result = await adminStudentsService.find(params);

		expect(result[0].classes).to.include('staticName');
		expect(result[0].classes).to.include('2A'); // gradeLevel+name
	});

	it('sorts students correctly', async () => {
		const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
		await testObjects.createTestUser({ firstName: 'Max', roles: ['student'] });
		await testObjects.createTestUser({ firstName: 'Moritz', roles: ['student'] });

		const params = {
			account: {
				userId: teacher._id,
			},
			$sort: {
				firstName: -1,
			},
		};
		const result = await adminStudentsService.find(params);

		expect(result[0].firstName >= result[1].firstName);
	});

	it('filters students correctly', async () => {
		const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const student = await testObjects.createTestUser({ roles: ['student'] });

		const paramsMissing = {
			account: {
				userId: teacher._id,
			},
			query: {
				consentStatus: {
					$in: ['missing'],
				},
			},
		};
		const paramsOk = {
			account: {
				userId: teacher._id,
			},
			query: {
				consentStatus: {
					$in: ['ok'],
				},
			},
		};
		const resultMissing = await adminStudentsService.find(paramsMissing);
		const idsMissing = resultMissing.map(e => e._id);
		const resultOk = await adminStudentsService.find(paramsOk);
		const idsOk = resultOk.map(e => e._id);

		expect(idsMissing).to.include(student._id);
		expect(idsOk).to.not.include(student._id);
	});

	after(async () => {
		await testObjects.cleanup();
	});
});

{'fraction_non_alphanumeric': 0.17886032716160344, 'fraction_numerical': 0.0032356642099586556, 'mean_word_length': 3.994614003590664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '3742840', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1744, 'n_words': 348}