From 87d3034bc04d9ff57cff199fb8c8311f57077da1 Mon Sep 17 00:00:00 2001 From: Zhuang <2157780849@qq.com> Date: Fri, 11 Oct 2024 17:09:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B61?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test.js 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; + } + }); +});