mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
- Rename DTOs to entities and move them to appropriate directories - Remove deprecated controllers and services - Update imports and dependencies - Implement new class transformer decorators for better serialization - Add VK authentication support - Improve error handling and validation - Update ESLint configuration and TypeScript settings - Refactor schedule parsing logic - Enhance user and authentication services - Update Prisma schema and related entities - Improve code organization and structure This commit introduces significant changes to improve the overall structure and maintainability of the codebase, including better organization of DTOs, enhanced authentication features, and updated tooling configurations.
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { ScheduleParser, ScheduleParseResult } from "./schedule-parser";
|
||
import { BasicXlsDownloader } from "../xls-downloader/basic-xls-downloader";
|
||
import Day from "../../entities/day.entity";
|
||
import Group from "../../entities/group.entity";
|
||
import instanceToInstance2 from "../../../utility/class-trasformer/instance-to-instance-2";
|
||
|
||
describe("ScheduleParser", () => {
|
||
let parser: ScheduleParser;
|
||
|
||
beforeEach(() => {
|
||
const xlsDownloader = new BasicXlsDownloader();
|
||
parser = new ScheduleParser(xlsDownloader);
|
||
});
|
||
|
||
describe("Ошибки", () => {
|
||
it("Должен вернуть ошибку из-за отсутствия ссылки на скачивание", async () => {
|
||
await expect(() => parser.getSchedule()).rejects.toThrow();
|
||
});
|
||
});
|
||
|
||
async function setLink(link: string): Promise<void> {
|
||
await parser.getXlsDownloader().setDownloadUrl(link);
|
||
}
|
||
|
||
const defaultTest = async () => {
|
||
const schedule = await parser.getSchedule();
|
||
|
||
expect(schedule).toBeDefined();
|
||
};
|
||
|
||
const nameTest = async () => {
|
||
const schedule = await parser.getSchedule();
|
||
expect(schedule).toBeDefined();
|
||
|
||
const group: Group | undefined = schedule.groups.get("ИС-214/23");
|
||
expect(group).toBeDefined();
|
||
|
||
const monday: Day = group.days[0];
|
||
expect(monday).toBeDefined();
|
||
|
||
const name = monday.name;
|
||
expect(name).toBeDefined();
|
||
expect(name.length).toBeGreaterThan(0);
|
||
};
|
||
//
|
||
// function mapReplacer(key: any, value: any) {
|
||
// if (value instanceof Map) {
|
||
// return Array.from(value.entries());
|
||
// } else {
|
||
// return value;
|
||
// }
|
||
// }
|
||
|
||
describe("Расписание", () => {
|
||
beforeEach(async () => {
|
||
await setLink(
|
||
"https://politehnikum-eng.ru/2024/poltavskaja_15_s_9_po_13.12-1-.xls",
|
||
);
|
||
});
|
||
|
||
it("Должен вернуть расписание", defaultTest);
|
||
it("Название дня не должно быть пустым или null", nameTest);
|
||
|
||
it("Зачёт с оценкой v2", async () => {
|
||
const schedule = await parser.getSchedule().then((v) =>
|
||
instanceToInstance2(ScheduleParseResult, v, {
|
||
groups: ["v2"],
|
||
}),
|
||
);
|
||
expect(schedule).toBeDefined();
|
||
|
||
const group: Group | undefined = schedule.groups.get("ИС-214/23");
|
||
expect(group).toBeDefined();
|
||
|
||
const day = group.days[0];
|
||
expect(day).toBeDefined();
|
||
|
||
expect(day.lessons.length).toBeGreaterThan(0);
|
||
});
|
||
});
|
||
});
|