mirror of
https://github.com/sstent/go-garth.git
synced 2026-02-06 06:22:10 +00:00
feat(refactor): Implement 1A.1 Package Structure Refactoring
This commit implements the package structure refactoring as outlined in phase1.md (Task 1A.1). Key changes include: - Reorganized packages into `pkg/garmin` for public API and `internal/` for internal implementations. - Updated all import paths to reflect the new structure. - Consolidated types and client logic into their respective new packages. - Updated `cmd/garth/main.go` to use the new public API. - Fixed various compilation and test issues encountered during the refactoring process. - Converted `internal/api/client/auth_test.go` to a functional test. This establishes a solid foundation for future enhancements and improves maintainability.
This commit is contained in:
122
internal/data/body_battery_test.go
Normal file
122
internal/data/body_battery_test.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseBodyBatteryReadings(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input [][]any
|
||||
expected []BodyBatteryReading
|
||||
}{
|
||||
{
|
||||
name: "valid readings",
|
||||
input: [][]any{
|
||||
{1000, "ACTIVE", 75, 1.0},
|
||||
{2000, "ACTIVE", 70, 1.0},
|
||||
{3000, "REST", 65, 1.0},
|
||||
},
|
||||
expected: []BodyBatteryReading{
|
||||
{1000, "ACTIVE", 75, 1.0},
|
||||
{2000, "ACTIVE", 70, 1.0},
|
||||
{3000, "REST", 65, 1.0},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid readings",
|
||||
input: [][]any{
|
||||
{1000, "ACTIVE", 75}, // missing version
|
||||
{2000, "ACTIVE"}, // missing level and version
|
||||
{3000}, // only timestamp
|
||||
{"invalid", "ACTIVE", 75, 1.0}, // wrong timestamp type
|
||||
},
|
||||
expected: []BodyBatteryReading{},
|
||||
},
|
||||
{
|
||||
name: "empty input",
|
||||
input: [][]any{},
|
||||
expected: []BodyBatteryReading{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := ParseBodyBatteryReadings(tt.input)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseStressReadings(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input [][]int
|
||||
expected []StressReading
|
||||
}{
|
||||
{
|
||||
name: "valid readings",
|
||||
input: [][]int{
|
||||
{1000, 25},
|
||||
{2000, 30},
|
||||
{3000, 20},
|
||||
},
|
||||
expected: []StressReading{
|
||||
{1000, 25},
|
||||
{2000, 30},
|
||||
{3000, 20},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid readings",
|
||||
input: [][]int{
|
||||
{1000}, // missing stress level
|
||||
{2000, 30, 1}, // extra value
|
||||
{}, // empty
|
||||
},
|
||||
expected: []StressReading{},
|
||||
},
|
||||
{
|
||||
name: "empty input",
|
||||
input: [][]int{},
|
||||
expected: []StressReading{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := ParseStressReadings(tt.input)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDailyBodyBatteryStress(t *testing.T) {
|
||||
now := time.Now()
|
||||
d := DailyBodyBatteryStress{
|
||||
CalendarDate: now,
|
||||
BodyBatteryValuesArray: [][]any{
|
||||
{1000, "ACTIVE", 75, 1.0},
|
||||
{2000, "ACTIVE", 70, 1.0},
|
||||
},
|
||||
StressValuesArray: [][]int{
|
||||
{1000, 25},
|
||||
{2000, 30},
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("body battery readings", func(t *testing.T) {
|
||||
readings := ParseBodyBatteryReadings(d.BodyBatteryValuesArray)
|
||||
assert.Len(t, readings, 2)
|
||||
assert.Equal(t, 75, readings[0].Level)
|
||||
})
|
||||
|
||||
t.Run("stress readings", func(t *testing.T) {
|
||||
readings := ParseStressReadings(d.StressValuesArray)
|
||||
assert.Len(t, readings, 2)
|
||||
assert.Equal(t, 25, readings[0].StressLevel)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user