Files
likedream/internal/application/moguding/moguding_test.go
T
2025-11-27 10:36:54 +08:00

158 lines
3.6 KiB
Go

package moguding
import (
"context"
"likedream-goframe/internal/application/moguding/entity"
"testing"
)
func TestMogudingLogin(t *testing.T) {
ctx := context.Background()
client := NewMogudingClient(ctx)
// 替换为实际的测试账号
username := "13307425047"
password := "wgz2021322L"
err := client.Login(ctx, username, password)
if err != nil {
t.Fatalf("登录失败: %v", err)
}
t.Logf("登录成功,UserId: %s, Token: %s", client.user.UserId, client.user.Token)
}
func TestMogudingGetPlanId(t *testing.T) {
ctx := context.Background()
client := NewMogudingClient(ctx)
// 先登录
username := "your_username"
password := "your_password"
err := client.Login(ctx, username, password)
if err != nil {
t.Fatalf("登录失败: %v", err)
}
// 获取 PlanId
err = client.GetPlanId(ctx)
if err != nil {
t.Fatalf("获取 PlanId 失败: %v", err)
}
t.Logf("获取 PlanId 成功,PlanId: %s, PlanName: %s", client.user.PlanId, client.user.PlanName)
}
func TestMogudingSign(t *testing.T) {
ctx := context.Background()
client := NewMogudingClient(ctx)
// 先登录
username := "your_username"
password := "your_password"
err := client.Login(ctx, username, password)
if err != nil {
t.Fatalf("登录失败: %v", err)
}
// 获取 PlanId
err = client.GetPlanId(ctx)
if err != nil {
t.Fatalf("获取 PlanId 失败: %v", err)
}
// 打卡签到
signReq := &entity.SignRequest{
Country: "中国",
Address: "四川省 · 成都市 · 武侯区 · 咕噜咕噜",
Province: "四川省",
City: "成都市",
State: "1",
Area: "武侯区",
Latitude: "33.100039",
Longitude: "101.987848",
Description: "测试打卡",
Type: "START", // START 表示上班打卡,END 表示下班打卡
Device: "Android",
}
err = client.Sign(ctx, signReq)
if err != nil {
t.Fatalf("打卡失败: %v", err)
}
t.Logf("打卡成功")
}
func TestMogudingFullProcess(t *testing.T) {
ctx := context.Background()
client := NewMogudingClient(ctx)
// 1. 登录
username := "your_username"
password := "your_password"
t.Log("步骤1: 登录")
err := client.Login(ctx, username, password)
if err != nil {
t.Fatalf("登录失败: %v", err)
}
t.Logf("登录成功,UserId: %s", client.user.UserId)
// 2. 获取 PlanId
t.Log("步骤2: 获取实习计划")
err = client.GetPlanId(ctx)
if err != nil {
t.Fatalf("获取 PlanId 失败: %v", err)
}
t.Logf("获取 PlanId 成功,PlanId: %s, PlanName: %s", client.user.PlanId, client.user.PlanName)
// 3. 上班打卡
t.Log("步骤3: 上班打卡")
signInReq := &entity.SignRequest{
Country: "中国",
Address: "四川省 · 成都市 · 武侯区 · 咕噜咕噜",
Province: "四川省",
City: "成都市",
State: "1",
Area: "武侯区",
Latitude: "33.100039",
Longitude: "101.987848",
Description: "上班打卡",
Type: "START",
Device: "Android",
}
err = client.Sign(ctx, signInReq)
if err != nil {
t.Fatalf("上班打卡失败: %v", err)
}
t.Log("上班打卡成功")
// 4. 下班打卡(可选)
t.Log("步骤4: 下班打卡")
signOutReq := &entity.SignRequest{
Country: "中国",
Address: "四川省 · 成都市 · 武侯区 · 咕噜咕噜",
Province: "四川省",
City: "成都市",
State: "1",
Area: "武侯区",
Latitude: "33.100039",
Longitude: "101.987848",
Description: "下班打卡",
Type: "END",
Device: "Android",
}
err = client.Sign(ctx, signOutReq)
if err != nil {
t.Fatalf("下班打卡失败: %v", err)
}
t.Log("下班打卡成功")
t.Log("完整流程测试通过!")
}