lesson-topic: автозаполнение темы модуля на главной по отчёту о занятии
This commit is contained in:
@@ -314,6 +314,53 @@ async function main() {
|
||||
|
||||
const del = await api(`/api/lesson-reports/${plain.data.id}`, { token, method: 'DELETE' });
|
||||
ok('lesson-report: удаление', del.status === 200, del.status);
|
||||
|
||||
const publicSettings = await api('/api/public-settings');
|
||||
const appTz = (publicSettings.data && publicSettings.data.timezone) || 'Europe/Moscow';
|
||||
const fmt = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: appTz, year: 'numeric', month: '2-digit', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit', hourCycle: 'h23',
|
||||
});
|
||||
const parts = Object.fromEntries(fmt.formatToParts(new Date())
|
||||
.filter(p => p.type !== 'literal').map(p => [p.type, p.value]));
|
||||
const today = `${parts.year}-${parts.month}-${parts.day}`;
|
||||
const hm = `${parts.hour}:${parts.minute}`;
|
||||
|
||||
const badPublicGroup = await api('/api/public/lesson-topic?group_id=abc');
|
||||
ok('public lesson-topic: нечисловой group_id -> 400', badPublicGroup.status === 400, badPublicGroup.status);
|
||||
|
||||
let autofillGid = null;
|
||||
for (const grp of lrGroups.data) {
|
||||
const existing = await api(`/api/lesson-reports?group_id=${grp.id}&date_from=${today}&date_to=${today}`, { token });
|
||||
if (existing.status === 200 && !(existing.data.items || []).length) {
|
||||
autofillGid = grp.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (autofillGid) {
|
||||
const generated = await api('/api/lesson-reports', {
|
||||
token, method: 'POST',
|
||||
body: { group_id: autofillGid, lesson_date: today, lesson_time: hm, topic: 'Autofill Smoke 3/5', text: 'Тема занятия для public autofill.', ai_check: false },
|
||||
});
|
||||
if (generated.status === 201) {
|
||||
try {
|
||||
const filled = await api(`/api/public/lesson-topic?group_id=${autofillGid}`);
|
||||
ok('public lesson-topic: без токена, тема без нумерации',
|
||||
filled.status === 200 && filled.data.topic === 'Autofill Smoke',
|
||||
{ status: filled.status, topic: filled.data && filled.data.topic });
|
||||
} finally {
|
||||
await api(`/api/lesson-reports/${generated.data.id}`, { token, method: 'DELETE' });
|
||||
}
|
||||
const empty = await api(`/api/public/lesson-topic?group_id=${autofillGid}`);
|
||||
ok('public lesson-topic: нет отчёта -> topic=null',
|
||||
empty.status === 200 && empty.data.topic === null,
|
||||
{ status: empty.status, topic: empty.data && empty.data.topic });
|
||||
} else {
|
||||
ok('public lesson-topic: создание отчёта для проверки', false, generated.status);
|
||||
}
|
||||
} else {
|
||||
console.log('SKIP public lesson-topic: нет группы без отчёта на сегодня');
|
||||
}
|
||||
} else {
|
||||
ok('lesson-report: есть группа для проверки', false, 'no groups');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user