-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_providers_test.go
More file actions
100 lines (96 loc) · 2.67 KB
/
import_providers_test.go
File metadata and controls
100 lines (96 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"context"
"strings"
"testing"
)
func TestParseESPNLeaguePayload(t *testing.T) {
payload := espnLeaguePayload{
ID: 12345,
SeasonID: 2026,
}
payload.Settings.Name = "Test ESPN League"
payload.Members = []struct {
ID string "json:\"id\""
DisplayName string "json:\"displayName\""
FirstName string "json:\"firstName\""
LastName string "json:\"lastName\""
}{
{ID: "owner-1", DisplayName: "Alice"},
}
payload.Teams = []struct {
ID int "json:\"id\""
Location string "json:\"location\""
Nickname string "json:\"nickname\""
Abbrev string "json:\"abbrev\""
Owners []string "json:\"owners\""
Roster struct {
Entries []struct {
PlayerPoolEntry struct {
Player struct {
FullName string "json:\"fullName\""
DefaultPositionID int "json:\"defaultPositionId\""
} "json:\"player\""
} "json:\"playerPoolEntry\""
} "json:\"entries\""
} "json:\"roster\""
}{
{
ID: 1,
Location: "Alpha",
Nickname: "Squad",
Owners: []string{"owner-1"},
},
}
payload.Teams[0].Roster.Entries = []struct {
PlayerPoolEntry struct {
Player struct {
FullName string "json:\"fullName\""
DefaultPositionID int "json:\"defaultPositionId\""
} "json:\"player\""
} "json:\"playerPoolEntry\""
}{
{
PlayerPoolEntry: struct {
Player struct {
FullName string "json:\"fullName\""
DefaultPositionID int "json:\"defaultPositionId\""
} "json:\"player\""
}{
Player: struct {
FullName string "json:\"fullName\""
DefaultPositionID int "json:\"defaultPositionId\""
}{
FullName: "Josh Allen",
DefaultPositionID: 1,
},
},
},
}
league := parseESPNLeaguePayload(payload)
if league.Provider != "espn" {
t.Fatalf("expected espn provider, got %q", league.Provider)
}
if league.LeagueName != "Test ESPN League" {
t.Fatalf("unexpected league name: %q", league.LeagueName)
}
if len(league.Teams) != 1 {
t.Fatalf("expected 1 team, got %d", len(league.Teams))
}
if league.Teams[0].Owner != "Alice" {
t.Fatalf("expected owner Alice, got %q", league.Teams[0].Owner)
}
if len(league.Teams[0].Roster) != 1 || league.Teams[0].Roster[0].Position != "QB" {
t.Fatalf("expected parsed QB roster entry, got %#v", league.Teams[0].Roster)
}
}
func TestYahooImporterReturnsScaffoldError(t *testing.T) {
y := &yahooImporter{}
_, err := y.ImportLeague(context.Background(), ImportOptions{LeagueID: "1"})
if err == nil {
t.Fatalf("expected yahoo scaffold error")
}
if !strings.Contains(strings.ToLower(err.Error()), "scaffold") {
t.Fatalf("expected scaffold message, got %v", err)
}
}