diff --git a/test.js b/test.js new file mode 100644 index 0000000..30479a3 --- /dev/null +++ b/test.js @@ -0,0 +1,47 @@ +// const chai = require('chai'); +// const axios = require('axios'); +import {expect} from 'chai'; +import axios from 'axios'; +//const expect = chai.expect; + +// 定义测试块 +describe('Express API calls Python backend', () => { + + // 测试随机获取学生 + it('should get a random student from Python API', async () => { + try { + // 调用 Express 服务器的 /get_random_student 端点 + const response = await axios.get('http://localhost:3000/get_random_student'); + + // 断言返回结果是否包含 student_id 和 name 字段 + expect(response.status).to.equal(200); + expect(response.data).to.have.property('student_id'); + expect(response.data).to.have.property('name'); + console.log("Random student fetched successfully:", response.data); + } catch (error) { + console.error("Error fetching random student:", error); + throw error; + } + }); + + // 测试更新出勤积分 + it('should update attendance score for a student', async () => { + try { + const studentId = 102201505; // 假设学生 + + // 调用 Express 服务器的 /update_attendance_score 端点 + const response = await axios.post('http://localhost:3000/update_attendance_score', { + student_id: studentId + }); + + // 断言返回结果是否包含成功信息 + expect(response.status).to.equal(200); + expect(response.data).to.have.property('message').that.equals('Attendance score updated'); + expect(response.data).to.have.property('student_id').that.equals(studentId); + console.log("Attendance score updated successfully:", response.data); + } catch (error) { + console.error("Error updating attendance score:", error); + throw error; + } + }); +});