text: const request = require('supertest')
  const app = require('../app')
  const faker = require('faker')
  
  describe.only('Получаем данные о занятиях', () => {
  	test('Получение всех занятий', () => {
  		return request(app)
  			.get('/')
  			.set('Accept', 'application/json')
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				expect(res.body.lessons.length).toBeGreaterThanOrEqual(1)
  			})
  	})
  
  	const fakeLessonsPerPage = faker.datatype.number(1, 10)
  	test(`Где число занятий на одну страницу: ${fakeLessonsPerPage}`, () => {
  		return request(app)
  			.get(`/?lessonsPerPage=${JSON.stringify(fakeLessonsPerPage)}`)
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/json/)
  				expect(res.statusCode).toEqual(200)
  				expect(res.body.lessons.length).toBeLessThanOrEqual(fakeLessonsPerPage)
  			})
  	})
  
  	const fakePage = faker.datatype.number(1, 5)
  	test(`Где номер запрашиваемой страницы: ${fakePage}`, () => {
  		return request(app)
  			.get(`/?page=${JSON.stringify(fakePage)}`)
  			.set('Accept', 'application/json')
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				expect(res.body.lessons.length).toBeLessThanOrEqual(5)
  			})
  	})
  
  	test.skip('Где количество учеников: 1', () => {
  		return request(app)
  			.get('/?studentsCount=1')
  			.set('Accept', 'application/json')
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				res.body.lessons.map((lesson) => expect(lesson.Students).toHaveLength(1))
  			})
  	})
  
  	const fakeStudentsCountString = faker.datatype.string()
  	test('Где количество учеников некорректно', () => {
  		return request(app)
  			.get(`/?studentsCount=${fakeStudentsCountString}`)
  			.set('Accept', 'application/json')
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(400)
  			})
  	})
  
  	const fakeStudentsCountRange = []
  	for (let i = 0; i < 2; i++ ) {
  		let min = 1
  		if (i!=0) {
  			min = fakeStudentsCountRange[i - 1]
  		}
  		fakeStudentsCountRange[i] = faker.datatype.number(min, min+10)
  	}
  	test.each([
  		[0, 0],
  		[0, 2],
  		[5, 10],
  		[2, 2],
  	])('Где количество учеников в диапозоне (%i, %i)', (a, b) => {
  		return request(app)
  			.get(`/?studentsCount=${a},${b}`)
  			.set('Accept', 'application/json')
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				res.body.lessons.every((lesson) => {
  					expect(lesson.Students.length).toBeGreaterThanOrEqual(a)
  					expect(lesson.Students.length).toBeLessThanOrEqual(b)
  				})
  			})
  	})
  
  	const fakeDate = faker.date.between('2019-01-01', '2020-01-01')
  
  	test(`Где запрашиваемая дата: ${JSON.stringify(fakeDate)}`, () => {
  		return request(app)
  			.get(`/?date=${JSON.stringify(fakeDate)}`)
  			.set('Accept', 'application/json')
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				res.body.lessons.every((lesson) => {
  					expect(lesson.date.getTime()).toEqual(fakeDate.getTime())
  				})
  			})
  	})
  
  	test.each([
  		[faker.date.between('2019-01-01', '2020-01-01'), faker.date.between('2019-01-01', '2020-01-01')],
  		[faker.date.between('2019-01-01', '2020-01-01'), faker.date.between('2019-01-01', '2020-01-01')],
  		[faker.date.between('2019-01-01', '2020-01-01'), faker.date.between('2019-01-01', '2020-01-01')],
  		[faker.date.between('2019-01-01', '2020-01-01'), faker.date.between('2019-01-01', '2020-01-01')],
  	])('Где запрашиваемая дата в диапозоне: %i до %i', (a, b) => {
  		return request(app)
  			.get(`/?date=${JSON.stringify(a)},${JSON.stringify(b)}`)
  			.set('Accept', 'application/json')
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				res.body.lessons.every((lesson) => {
  					expect(lesson.date.getTime()).toBeGreaterThanOrEqual(a.getTime())
  					expect(lesson.date.getTime()).toBeLessThanOrEqual(b.getTime())
  				})
  			})
  	})
  
  	// Прогоним 10 раз тест, чтобы faker выдал 10 разных вариантов и проверил их на ответ системы
  	for (let testIterationIndex = 0; testIterationIndex < 10; testIterationIndex++) {
  		const fakeTeacherIds = []
  		for (let i = 0; i < faker.datatype.number(15); i++) {
  			fakeTeacherIds[i] = faker.datatype.number(1, 10)
  		}
  		test(`Где пары ведут учителя с ids: ${fakeTeacherIds}`, () => {
  			return request(app)
  				.get(`/?teacherIds=${JSON.stringify(fakeTeacherIds.join(','))}`)
  				.set('Accept', 'application/json')
  				.then((res) => {
  					expect(res.headers['content-type']).toMatch(/application\/json/)
  					expect(res.statusCode).toEqual(200)
  					res.body.lessons.every((lesson) => {
  						expect(fakeTeacherIds).toContain(lesson.Teachers.id)
  					})
  				})
  		})
  	}
  })
  
  describe.skip('Создаём занятия', () => {
  	const fakeFirstDate = faker.date.between(new Date(), new Date(new Date().getFullYear()+1, new Date().getMonth(), new Date().getDate()))
  	const fakeLesson = {
  		teacherIds: faker.datatype.array(6).map((item) => item = faker.datatype.number(5)),
  		title: faker.name.title(),
  		days: faker.datatype.array(6).map((item) => item = faker.datatype.number(5)),
  		firstDate: fakeFirstDate,
  		lessonsCount: faker.datatype.number(25),
  		lastDate: faker.date.future(0, fakeFirstDate),
  	}
  	test(`Только с lessonsCount(${JSON.stringify({...fakeLesson, lastDate: undefined})})`, () => {
  		return request(app)
  			.post('/lessons')
  			.set('Accept', 'application/json')
  			.send({...fakeLesson, lastDate: undefined})
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				expect(res.body.lessonsAdded).not.toBeUndefined()
  				expect(res.body.lessonsAdded.every((lessonId) => Number.isInteger(lessonId))).toBeTruthy()
  				expect(res.body.lessonsAdded.length).toBeLessThanOrEqual(300)
  			})
  	})
  
  	test(`Только с lastDate(${JSON.stringify({...fakeLesson, lessonsCount: undefined})})`, () => {
  		return request(app)
  			.post('/lessons')
  			.set('Accept', 'application/json')
  			.send({...fakeLesson, lessonsCount: undefined})
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				expect(res.body.lessonsAdded).not.toBeUndefined()
  				expect(res.body.lessonsAdded.every((lessonId) => Number.isInteger(lessonId))).toBeTruthy()
  				expect(res.body.lessonsAdded.length).toBeLessThanOrEqual(300)
  			})
  	})
  
  	test(`И с lastDate и lessonsCount(${JSON.stringify(fakeLesson)})`, () => {
  		return request(app)
  			.post('/lessons')
  			.set('Accept', 'application/json')
  			.send(fakeLesson)
  			.then((res) => {
  				expect(res.headers['content-type']).toMatch(/application\/json/)
  				expect(res.statusCode).toEqual(200)
  				expect(res.body.lessonsAdded).not.toBeUndefined()
  				expect(res.body.lessonsAdded.every((lessonId) => Number.isInteger(lessonId))).toBeTruthy()
  				expect(res.body.lessonsAdded.length).toBeLessThanOrEqual(300)
  			})
  	})
  })
  