171 lines
5.1 KiB
Go
171 lines
5.1 KiB
Go
package xuexitong
|
|
|
|
import (
|
|
"context"
|
|
"likedream-goframe/internal/framework/errors"
|
|
"likedream-goframe/internal/utils"
|
|
"testing"
|
|
)
|
|
|
|
func TestSchedule(t *testing.T) {
|
|
ctx := context.Background()
|
|
xuexitongLogin := NewXuexitongLogin(ctx)
|
|
err := xuexitongLogin.Login(context.Background(), "13151832241", "yyz@083422", 5)
|
|
utils.OkOrPanic(err)
|
|
|
|
client := xuexitongLogin.GetClient()
|
|
courseService := NewXuexitongCourse(client)
|
|
|
|
// 人人必修的人工智能课
|
|
err = courseService.AutoStudyByCourseID(ctx, "258109701")
|
|
if err != nil {
|
|
utils.OkOrPanic(errors.NewBusinessErrorWithDetail(503, "刷课失败", err))
|
|
}
|
|
}
|
|
|
|
func TestXuexitongLogin(t *testing.T) {
|
|
xuexitongLogin := NewXuexitongLogin(context.Background())
|
|
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
|
utils.OkOrPanic(err)
|
|
}
|
|
|
|
func TestPullCourse(t *testing.T) {
|
|
xuexitongLogin := NewXuexitongLogin(context.Background())
|
|
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
|
utils.OkOrPanic(err)
|
|
client := xuexitongLogin.GetClient()
|
|
courseAction := NewXuexitongCourse(client)
|
|
list := courseAction.PullCourseList(context.Background())
|
|
utils.OkOrPanic(err)
|
|
t.Log(list)
|
|
}
|
|
|
|
func TestPullChapter(t *testing.T) {
|
|
xuexitongLogin := NewXuexitongLogin(context.Background())
|
|
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
|
utils.OkOrPanic(err)
|
|
|
|
client := xuexitongLogin.GetClient()
|
|
courseAction := NewXuexitongCourse(client)
|
|
|
|
// 先获取课程列表
|
|
courseList := courseAction.PullCourseList(context.Background())
|
|
if len(courseList) == 0 {
|
|
t.Fatal("没有找到课程")
|
|
}
|
|
|
|
// 获取第一个课程的章节
|
|
chapters := courseAction.PullCourseChapterList(context.Background(), courseList[0])
|
|
t.Logf("课程 %s 的章节数量: %d", courseList[0].CourseName, len(chapters))
|
|
|
|
for _, chapter := range chapters {
|
|
t.Logf("章节: %s, 任务点数量: %d", chapter.Name, chapter.JobCount)
|
|
}
|
|
}
|
|
|
|
func TestFetchChapterCards(t *testing.T) {
|
|
xuexitongLogin := NewXuexitongLogin(context.Background())
|
|
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
|
utils.OkOrPanic(err)
|
|
|
|
client := xuexitongLogin.GetClient()
|
|
courseAction := NewXuexitongCourse(client)
|
|
|
|
// 获取课程列表
|
|
courseList := courseAction.PullCourseList(context.Background())
|
|
if len(courseList) == 0 {
|
|
t.Fatal("没有找到课程")
|
|
}
|
|
|
|
course := courseList[0]
|
|
|
|
// 获取章节列表
|
|
chapters := courseAction.PullCourseChapterList(context.Background(), course)
|
|
if len(chapters) == 0 {
|
|
t.Fatal("没有找到章节")
|
|
}
|
|
|
|
// 找一个有任务点的章节
|
|
var targetChapterID int
|
|
for _, ch := range chapters {
|
|
if ch.JobCount > 0 {
|
|
targetChapterID = ch.ID
|
|
break
|
|
}
|
|
}
|
|
|
|
if targetChapterID == 0 {
|
|
t.Fatal("没有找到有任务点的章节")
|
|
}
|
|
|
|
// 获取任务点卡片
|
|
cards, points, err := courseAction.FetchChapterCards(context.Background(), course, targetChapterID)
|
|
utils.OkOrPanic(err)
|
|
|
|
t.Logf("卡片数量: %d", len(cards))
|
|
if points != nil {
|
|
t.Logf("视频数量: %d, 文档数量: %d, 作业数量: %d, 外链数量: %d, 直播数量: %d",
|
|
len(points.Videos), len(points.Documents), len(points.Works),
|
|
len(points.Hyperlinks), len(points.Lives))
|
|
|
|
for _, video := range points.Videos {
|
|
t.Logf("视频任务点: JobID=%s, ObjectID=%s", video.JobID, video.ObjectID)
|
|
}
|
|
for _, doc := range points.Documents {
|
|
t.Logf("文档任务点: JobID=%s, Type=%s", doc.JobID, doc.Type)
|
|
}
|
|
for _, work := range points.Works {
|
|
t.Logf("作业任务点: JobID=%s, WorkID=%s", work.JobID, work.WorkID)
|
|
}
|
|
for _, link := range points.Hyperlinks {
|
|
t.Logf("外链任务点: JobID=%s", link.JobID)
|
|
}
|
|
for _, live := range points.Lives {
|
|
t.Logf("直播任务点: JobID=%s, LiveId=%s, Title=%s", live.JobID, live.LiveId, live.Title)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestAutoStudyByCourseID 测试通过课程ID刷课(定时任务使用)
|
|
func TestAutoStudyByCourseID(t *testing.T) {
|
|
// 登录
|
|
xuexitongLogin := NewXuexitongLogin(context.Background())
|
|
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
|
utils.OkOrPanic(err)
|
|
|
|
// 创建课程实例
|
|
courseAction := NewXuexitongCourse(xuexitongLogin.GetClient())
|
|
|
|
// 先获取课程列表,拿到第一个课程的ID
|
|
courseList := courseAction.PullCourseList(context.Background())
|
|
if len(courseList) == 0 {
|
|
t.Fatal("没有找到课程")
|
|
}
|
|
|
|
courseID := courseList[0].CourseID
|
|
t.Logf("准备刷课程ID: %s", courseID)
|
|
|
|
// 一键刷指定课程的所有任务(定时任务就调用这一个方法)
|
|
err = courseAction.AutoStudyByCourseID(context.Background(), courseID)
|
|
utils.OkOrPanic(err)
|
|
|
|
t.Log("指定课程刷课完成")
|
|
}
|
|
|
|
// TestAutoStudyAllCourses 测试自动刷所有课程
|
|
func TestAutoStudyAllCourses(t *testing.T) {
|
|
// 登录
|
|
xuexitongLogin := NewXuexitongLogin(context.Background())
|
|
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
|
utils.OkOrPanic(err)
|
|
|
|
// 创建课程实例
|
|
courseAction := NewXuexitongCourse(xuexitongLogin.GetClient())
|
|
|
|
// 一键刷所有课程
|
|
err = courseAction.AutoStudyAllCourses(context.Background())
|
|
utils.OkOrPanic(err)
|
|
|
|
t.Log("所有课程刷课完成")
|
|
}
|