fix: return attendance checkin metadata as objects
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.118im.com/im_team/im_workbench/internal/store"
|
||||
)
|
||||
|
||||
func TestAttendanceCheckinPayloadReturnsJSONObjectFields(t *testing.T) {
|
||||
now := time.Date(2026, 9, 18, 1, 27, 49, 0, time.UTC)
|
||||
payload := attendanceCheckinPayload(store.AttendanceCheckin{
|
||||
CheckinID: "attc_1",
|
||||
Action: "check_in",
|
||||
ClientTime: now,
|
||||
ServerTime: now,
|
||||
Result: "normal",
|
||||
Location: `{"name":"当前位置","latitude":22.929670335639365}`,
|
||||
Wifi: `{}`,
|
||||
Device: `{"platform":"ios","device_id":"C7A76C6A-FC57-4CED-B1C1-CE5199944F8C"}`,
|
||||
})
|
||||
|
||||
location, ok := payload["location"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("location=%T, want map[string]any", payload["location"])
|
||||
}
|
||||
if location["name"] != "当前位置" {
|
||||
t.Fatalf("location=%v", location)
|
||||
}
|
||||
if _, ok := payload["wifi"].(map[string]any); !ok {
|
||||
t.Fatalf("wifi=%T, want map[string]any", payload["wifi"])
|
||||
}
|
||||
device, ok := payload["device"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("device=%T, want map[string]any", payload["device"])
|
||||
}
|
||||
if device["platform"] != "ios" {
|
||||
t.Fatalf("device=%v", device)
|
||||
}
|
||||
}
|
||||
@@ -164,9 +164,9 @@ func attendanceCheckinPayload(checkin store.AttendanceCheckin) map[string]any {
|
||||
"client_time": checkin.ClientTime.UTC().Format(time.RFC3339Nano),
|
||||
"server_time": checkin.ServerTime.UTC().Format(time.RFC3339Nano),
|
||||
"result": checkin.Result,
|
||||
"location": checkin.Location,
|
||||
"wifi": checkin.Wifi,
|
||||
"device": checkin.Device,
|
||||
"location": jsonObject(checkin.Location),
|
||||
"wifi": jsonObject(checkin.Wifi),
|
||||
"device": jsonObject(checkin.Device),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user