<commit_before>const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const { ObjectId } = require('mongoose').Types;
const { Forbidden } = require('@feathersjs/errors');

const app = require('./../../../src/app');
const { cleanup } = require('../helpers/testObjects')(app);
const { create: createSchool } = require('./../helpers/services/schools')(app);
const { generateRequestParamsFromUser } = require('./../helpers/services/login')(app);
const { create: createUser } = require('./../helpers/services/users')(app);
const { create: createSystem } = require('./../helpers/services/testSystem')(app);
const { create: createYear } = require('./../helpers/services/years');

chai.use(chaiAsPromised);
const { expect } = chai;

describe('school maintenance mode', () => {
	const maintenanceService = app.service('schools/:schoolId/maintenance');

	let server;

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

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

	describe('status route', () => {
		describe('for non-LDAP schools', () => {
			it('should give information about the current and next school year', async () => {
				const currentYear = await createYear();
				const nextYear = await createYear();
				maintenanceService.years = [currentYear, nextYear];
				const school = await createSchool({ currentYear });
				const params = {
					route: { schoolId: school._id.toString() },
				};

				const result = await maintenanceService.find(params);
				expect(result).to.not.equal(undefined);
				expect(result.currentYear._id.toString()).to.equal(currentYear._id.toString());
				expect(result.nextYear._id.toString()).to.equal(nextYear._id.toString());
				expect(result.schoolUsesLdap).to.equal(false);
				expect(result.maintenance.active).to.equal(false);
			});

			it('should react to the school being in maintenance mode', async () => {
				const currentYear = await createYear();
				const school = await createSchool({ currentYear, inMaintenanceSince: new Date() });
				const params = {
					route: { schoolId: school._id.toString() },
				};

				const result = await maintenanceService.find(params);<commit_msg>Add explanatory comment<commit_after>const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const { ObjectId } = require('mongoose').Types;
const { Forbidden } = require('@feathersjs/errors');

const app = require('./../../../src/app');
const { cleanup } = require('../helpers/testObjects')(app);
const { create: createSchool } = require('./../helpers/services/schools')(app);
const { generateRequestParamsFromUser } = require('./../helpers/services/login')(app);
const { create: createUser } = require('./../helpers/services/users')(app);
const { create: createSystem } = require('./../helpers/services/testSystem')(app);
const { create: createYear } = require('./../helpers/services/years');

chai.use(chaiAsPromised);
const { expect } = chai;

describe('school maintenance mode', () => {
	const maintenanceService = app.service('schools/:schoolId/maintenance');

	let server;

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

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

	describe('status route', () => {
		describe('for non-LDAP schools', () => {
			it('should give information about the current and next school year', async () => {
				const currentYear = await createYear();
				const nextYear = await createYear();
				// override years cache  (created on service initialization) with mock years:
				maintenanceService.years = [currentYear, nextYear];
				const school = await createSchool({ currentYear });
				const params = {
					route: { schoolId: school._id.toString() },
				};

				const result = await maintenanceService.find(params);
				expect(result).to.not.equal(undefined);
				expect(result.currentYear._id.toString()).to.equal(currentYear._id.toString());
				expect(result.nextYear._id.toString()).to.equal(nextYear._id.toString());
				expect(result.schoolUsesLdap).to.equal(false);
				expect(result.maintenance.active).to.equal(false);
			});

			it('should react to the school being in maintenance mode', async () => {
				const currentYear = await createYear();
				const school = await createSchool({ currentYear, inMaintenanceSince: new Date() });
				const params = {
					route: { schoolId: school._id.toString() },
				};

				const result = await maintenanceService.find(params);
{'fraction_non_alphanumeric': 0.17240598096964205, 'fraction_numerical': 0.00045310376076121433, 'mean_word_length': 4.27479091995221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '250716', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1265, 'n_words': 275}