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


describe('lesson copy service', () => {
	let app;
	let lessonCopyService;

	before(async () => {
		app = await appPromise;
		lessonCopyService = app.service('lessons/copy');
	});

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

	it('can copy a lesson within a course', async () => {
		const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const course = await testObjects.createTestCourse({ teacherIds: [teacher._id] });
		const lesson = await testObjects.createTestLesson({ courseId: course._id });

		const copy = await lessonCopyService.create({
			lessonId: lesson._id,
			newCourseId: course._id,
			userId: teacher._id,
		});
		expect(copy._id.toString()).to.not.equal(lesson._id.toString());
		expect(copy.courseId.toString()).to.equal(course._id.toString());
		expect(copy.description).to.eq(lesson.description);
	});

	it('can copy a lesson with a homework', async () => {
		const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const course = await testObjects.createTestCourse({ teacherIds: [teacher._id] });
		const lesson = await testObjects.createTestLesson({ courseId: course._id });
		const homework = await testObjects.createTestHomework({
			teacherId: teacher._id,
			name: 'Testaufgabe',
			description: '\u003cp\u003eAufgabenbeschreibung\u003c/p\u003e\r\n',
			availableDate: Date.now(),
			lessonId: lesson._id,
		});

		const copy = await lessonCopyService.create({
			lessonId: lesson._id,
			newCourseId: course._id,
			userId: teacher._id,
		});
		expect(copy._id.toString()).to.not.equal(lesson._id.toString());
		expect(copy.courseId.toString()).to.equal(course._id.toString());
		expect(copy.description).to.eq(lesson.description);
		const homeworkCopies = await app.service('homework').find({ query: { lessonId: copy._id } });
		expect(homeworkCopies.total).to.equal(1);
		expect(homeworkCopies.data[0]._id.toString()).to.not.equal(homework._id.toString());
	});

	it('can copy a lesson for a different user', async () => {
		const originalTeacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const targetTeacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const originalCourse = await testObjects.createTestCourse({ teacherIds: [originalTeacher._id] });
		const targetCourse = await testObjects.createTestCourse({ teacherIds: [originalTeacher._id] });
		const shareToken = `<PASSWORD>${Date.<PASSWORD>()}`;
		const lesson = await testObjects.createTestLesson({ courseId: originalCourse._id, shareToken });

		const copy = await lessonCopyService.create({
			lessonId: lesson._id,
			newCourseId: targetCourse._id,
			userId: targetTeacher._id,
			shareToken,
		});
		expect(copy._id.toString()).to.not.equal(lesson._id.toString());
		expect(copy.courseId.toString()).to.equal(targetCourse._id.toString());
		expect(copy.description).to.eq(lesson.description);
	});

	it('can copy a lesson for a different school', async () => {
		const originalSchool = await testObjects.createTestSchool();
		const targetSchool = await testObjects.createTestSchool();
		const originalTeacher = await testObjects.createTestUser({ roles: ['teacher'], schoolId: originalSchool._id });
		const targetTeacher = await testObjects.createTestUser({ roles: ['teacher'], schoolId: targetSchool._id });
		const originalCourse = await testObjects.createTestCourse({
			teacherIds: [originalTeacher._id],
			schoolId: originalSchool._id,
		});
		const targetCourse = await testObjects.createTestCourse({
			teacherIds: [originalTeacher._id],
			schoolId: targetSchool._id,
		});
		const shareToken = `share<PASSWORD>${Date.now()}`;
		const lesson = await testObjects.createTestLesson({ courseId: originalCourse._id, shareToken });

		const copy = await lessonCopyService.create({
			lessonId: lesson._id,
			newCourseId: targetCourse._id,
			userId: targetTeacher._id,
			shareToken,
		});
		expect(copy._id.toString()).to.not.equal(lesson._id.toString());
		expect(copy.courseId.toString()).to.equal(targetCourse._id.toString());
		expect(copy.description).to.eq(lesson.description);
	});
});
<commit_msg>start server in tests to register services<commit_after>const { expect } = require('chai');
const appPromise = require('../../../src/app');
const testObjects = require('../helpers/testObjects')(appPromise);

describe('lesson copy service', () => {
	let app;
	let server;
	let lessonCopyService;

	before(async () => {
		app = await appPromise;
		server = await app.listen(0);

		lessonCopyService = app.service('lessons/copy');
	});

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

	it('can copy a lesson within a course', async () => {
		const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const course = await testObjects.createTestCourse({ teacherIds: [teacher._id] });
		const lesson = await testObjects.createTestLesson({ courseId: course._id });

		const copy = await lessonCopyService.create({
			lessonId: lesson._id,
			newCourseId: course._id,
			userId: teacher._id,
		});
		expect(copy._id.toString()).to.not.equal(lesson._id.toString());
		expect(copy.courseId.toString()).to.equal(course._id.toString());
		expect(copy.description).to.eq(lesson.description);
	});

	it('can copy a lesson with a homework', async () => {
		const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const course = await testObjects.createTestCourse({ teacherIds: [teacher._id] });
		const lesson = await testObjects.createTestLesson({ courseId: course._id });
		const homework = await testObjects.createTestHomework({
			teacherId: teacher._id,
			name: 'Testaufgabe',
			description: '\u003cp\u003eAufgabenbeschreibung\u003c/p\u003e\r\n',
			availableDate: Date.now(),
			lessonId: lesson._id,
		});

		const copy = await lessonCopyService.create({
			lessonId: lesson._id,
			newCourseId: course._id,
			userId: teacher._id,
		});
		expect(copy._id.toString()).to.not.equal(lesson._id.toString());
		expect(copy.courseId.toString()).to.equal(course._id.toString());
		expect(copy.description).to.eq(lesson.description);
		const homeworkCopies = await app.service('homework').find({ query: { lessonId: copy._id } });
		expect(homeworkCopies.total).to.equal(1);
		expect(homeworkCopies.data[0]._id.toString()).to.not.equal(homework._id.toString());
	});

	it('can copy a lesson for a different user', async () => {
		const originalTeacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const targetTeacher = await testObjects.createTestUser({ roles: ['teacher'] });
		const originalCourse = await testObjects.createTestCourse({ teacherIds: [originalTeacher._id] });
		const targetCourse = await testObjects.createTestCourse({ teacherIds: [originalTeacher._id] });
		const shareToken = `<PASSWORD>${Date.now()}`;
		const lesson = await testObjects.createTestLesson({ courseId: originalCourse._id, shareToken });

		const copy = await lessonCopyService.create({
			lessonId: lesson._id,
			newCourseId: targetCourse._id,
			userId: targetTeacher._id,
			shareToken,
		});
		expect(copy._id.toString()).to.not.equal(lesson._id.toString());
		expect(copy.courseId.toString()).to.equal(targetCourse._id.toString());
		expect(copy.description).to.eq(lesson.description);
	});

	it('can copy a lesson for a different school', async () => {
		const originalSchool = await testObjects.createTestSchool();
		const targetSchool = await testObjects.createTestSchool();
		const originalTeacher = await testObjects.createTestUser({ roles: ['teacher'], schoolId: originalSchool._id });
		const targetTeacher = await testObjects.createTestUser({ roles: ['teacher'], schoolId: targetSchool._id });
		const originalCourse = await testObjects.createTestCourse({
			teacherIds: [originalTeacher._id],
			schoolId: originalSchool._id,
		});
		const targetCourse = await testObjects.createTestCourse({
			teacherIds: [originalTeacher._id],
			schoolId: targetSchool._id,
		});
		const shareToken = `<PASSWORD>${Date.now()}`;
		const lesson = await testObjects.createTestLesson({ courseId: originalCourse._id, shareToken });

		const copy = await lessonCopyService.create({
			lessonId: lesson._id,
			newCourseId: targetCourse._id,
			userId: targetTeacher._id,
			shareToken,
		});
		expect(copy._id.toString()).to.not.equal(lesson._id.toString());
		expect(copy.courseId.toString()).to.equal(targetCourse._id.toString());
		expect(copy.description).to.eq(lesson.description);
	});
});

{'fraction_non_alphanumeric': 0.15470383275261324, 'fraction_numerical': 0.0033681765389082462, 'mean_word_length': 5.094125973106864, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 22, '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': '6639305', 'n_tokens_mistral': 2905, 'n_tokens_neox': 2614, 'n_words': 524}