chore(release): 1.3.3 发布并退役旧联动
This commit is contained in:
1 parent
b7cdc7c9ea
commit
c0ebf88138
184 files changed
+5450
-11705
No files matched your search
+98
-12
@@ -8,13 +8,17 @@
|
||||
*
|
||||
* 做法:用管理员账号建一个随机班级码的临时班级 → 设为冒烟客户端的登录账号 →
|
||||
* 顺手给它备一份"当天的作业"(新班没有种子数据,作业看板用例要有东西可看)→ 收尾删掉。
|
||||
* 拿不到管理员账号(离线 / 没给凭据)时返回 null,调用方自行回退到"复用演示班级"。
|
||||
* 拿不到管理员账号时返回 null,调用方应中止联网验收,不得回退到真实班级或重置其密码。
|
||||
*/
|
||||
export async function provisionSmokeClass(options = {}) {
|
||||
const cleanups = [];
|
||||
const cleanup = async () => {
|
||||
for (const remove of [...cleanups].reverse()) await remove().catch(() => undefined);
|
||||
cleanups.length = 0;
|
||||
};
|
||||
const base = options.base ?? process.env.ELECTRON_SMOKE_API ?? 'http://127.0.0.1:4000/api';
|
||||
const admin = options.admin ?? process.env.ELECTRON_SMOKE_ADMIN ?? 'admin';
|
||||
const adminPassword =
|
||||
options.adminPassword ?? process.env.ELECTRON_SMOKE_ADMIN_PASSWORD ?? 'admin123';
|
||||
const adminPassword = options.adminPassword ?? process.env.ELECTRON_SMOKE_ADMIN_PASSWORD ?? 'admin123';
|
||||
const password = options.password ?? process.env.ELECTRON_SMOKE_CLASS_PASSWORD ?? 'smoke123456';
|
||||
const className = options.className ?? '冒烟验证班';
|
||||
const code = `SMOKE${Math.random().toString(36).slice(2, 7).toUpperCase()}`;
|
||||
@@ -35,19 +39,104 @@ export async function provisionSmokeClass(options = {}) {
|
||||
if (!token) return null;
|
||||
const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' };
|
||||
|
||||
const teacherUsername = `smoke_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
||||
const teacherPassword = 'smoke-test-password';
|
||||
const teacher = await fetch(`${base}/teachers`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
username: teacherUsername,
|
||||
password: teacherPassword,
|
||||
name: '冒烟验证老师',
|
||||
role: 'TEACHER',
|
||||
}),
|
||||
}).then((response) => response.json());
|
||||
const teacherId = teacher?.data?.id;
|
||||
if (!teacherId) throw new Error('无法创建独立验证教师');
|
||||
cleanups.push(() => fetch(`${base}/teachers/${teacherId}`, { method: 'DELETE', headers }));
|
||||
|
||||
const created = await fetch(`${base}/classes`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({ name: className, grade: '验证', code }),
|
||||
body: JSON.stringify({
|
||||
name: className,
|
||||
grade: '验证',
|
||||
code,
|
||||
teacherId,
|
||||
enrollmentYear: 2099,
|
||||
classIndex: 1 + Math.floor(Math.random() * 99),
|
||||
}),
|
||||
}).then((response) => response.json());
|
||||
const classId = created?.data?.id;
|
||||
if (!classId) return null;
|
||||
if (!classId) throw new Error('无法创建独立验证班级');
|
||||
cleanups.push(() => fetch(`${base}/classes/${classId}`, { method: 'DELETE', headers }));
|
||||
|
||||
await fetch(`${base}/classes/${classId}/class-account`, {
|
||||
method: 'PATCH',
|
||||
headers,
|
||||
body: JSON.stringify({ code, password }),
|
||||
});
|
||||
const course = await fetch(`${base}/courses`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({ classId, name: '语文', teacherId }),
|
||||
}).then((response) => response.json());
|
||||
const courseId = course?.data?.id;
|
||||
if (!courseId) throw new Error('无法创建验证课程');
|
||||
const student = await fetch(`${base}/students`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({ classId, studentNo: code, name: '冒烟验证同学' }),
|
||||
}).then((response) => response.json());
|
||||
const studentId = student?.data?.id;
|
||||
if (!studentId) throw new Error('无法创建验证学生');
|
||||
for (const [route, body] of [
|
||||
['/grades', { classId, courseId, studentId, examName: '冒烟验证', score: 80, totalScore: 100 }],
|
||||
[
|
||||
'/schedules',
|
||||
{
|
||||
classId,
|
||||
courseId,
|
||||
dayOfWeek: new Date().getDay() || 7,
|
||||
startTime: '08:00',
|
||||
endTime: '08:45',
|
||||
weekStart: 1,
|
||||
weekEnd: 20,
|
||||
},
|
||||
],
|
||||
]) {
|
||||
const response = await fetch(`${base}${route}`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!response.ok) throw new Error(`无法创建验证数据:${route}`);
|
||||
}
|
||||
// 图表回归需要不同科目的得分率及不同人数的等级分布。
|
||||
for (const [name, score] of [
|
||||
['英语', 80],
|
||||
['历史', 40],
|
||||
]) {
|
||||
const extra = await fetch(`${base}/courses`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({ classId, name, teacherId }),
|
||||
}).then((response) => response.json());
|
||||
if (!extra?.data?.id) throw new Error('无法创建图表验证课程');
|
||||
const response = await fetch(`${base}/grades`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
classId,
|
||||
courseId: extra.data.id,
|
||||
studentId,
|
||||
examName: '冒烟验证',
|
||||
score,
|
||||
totalScore: 100,
|
||||
}),
|
||||
});
|
||||
if (!response.ok) throw new Error('无法创建图表验证成绩');
|
||||
}
|
||||
|
||||
// 作业看板用例需要"某天有作业":临时班没有种子数据,这里补一条当天的
|
||||
await fetch(`${base}/homeworks`, {
|
||||
@@ -66,16 +155,13 @@ export async function provisionSmokeClass(options = {}) {
|
||||
password,
|
||||
classId,
|
||||
className,
|
||||
teacherUsername,
|
||||
teacherPassword,
|
||||
/** 收尾:删掉临时班级(连带它的班级账号/作业/通知) */
|
||||
async cleanup() {
|
||||
try {
|
||||
await fetch(`${base}/classes/${classId}`, { method: 'DELETE', headers });
|
||||
} catch {
|
||||
// 清理失败不影响结论
|
||||
}
|
||||
},
|
||||
cleanup,
|
||||
};
|
||||
} catch {
|
||||
await cleanup();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user