-
Notifications
You must be signed in to change notification settings - Fork 11
/
set_test.go
140 lines (133 loc) · 5.78 KB
/
set_test.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package scryfall
import (
"context"
"fmt"
"net/http"
"reflect"
"testing"
"time"
)
func TestListSets(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"object": "list", "has_more": false, "data": [{"object": "set", "code": "dom", "mtgo_code": "dar", "arena_code": "dar", "tcgplayer_id": 2199, "name": "Dominaria", "uri": "https://api.scryfall.com/sets/dom", "scryfall_uri": "https://scryfall.com/sets/dom", "search_uri": "https://api.scryfall.com/cards/search?order=set&q=e%3Adom&unique=prints", "released_at": "2018-04-27", "set_type": "expansion", "card_count": 142, "digital": false, "foil": false, "icon_svg_uri": "https://assets.scryfall.com/assets/sets/dom.svg"}, {"object": "set", "code": "a25", "mtgo_code": "a25", "arena_code": "a25", "tcgplayer_id": 2189, "name": "Masters 25", "uri": "https://api.scryfall.com/sets/a25", "scryfall_uri": "https://scryfall.com/sets/a25", "search_uri": "https://api.scryfall.com/cards/search?order=set&q=e%3Aa25&unique=prints", "released_at": "2018-03-16", "set_type": "masters", "card_count": 249, "digital": false, "foil": false, "icon_svg_uri": "https://assets.scryfall.com/assets/sets/a25.svg"},{"object":"set","code":"rix","mtgo_code":"rix","arena_code":"rix","tcgplayer_id":2098,"name":"Rivals of Ixalan","uri":"https://api.scryfall.com/sets/rix","scryfall_uri":"https://scryfall.com/sets/rix","search_uri":"https://api.scryfall.com/cards/search?order=set\u0026q=e%3Arix\u0026unique=prints","released_at":"2018-01-19","set_type":"expansion","card_count":205,"digital":false,"foil":false,"block_code":"xln","block":"Ixalan","icon_svg_uri":"https://assets.scryfall.com/assets/sets/rix.svg"}]}`)
})
client, ts, err := setupTestServer("/sets", handler)
if err != nil {
t.Fatalf("Error setting up test server: %v", err)
}
defer ts.Close()
ctx := context.Background()
sets, err := client.ListSets(ctx)
if err != nil {
t.Fatalf("Error listing sets: %v", err)
}
mtgoCodes := []string{
"dar",
"a25",
"rix",
}
arenaCodes := []string{
"dar",
"a25",
"rix",
}
tcgplayerIDs := []int{
2199,
2189,
2098,
}
want := []Set{
{
Code: "dom",
MTGOCode: &mtgoCodes[0],
ArenaCode: &arenaCodes[0],
TCGplayerID: &tcgplayerIDs[0],
Name: "Dominaria",
URI: "https://api.scryfall.com/sets/dom",
ScryfallURI: "https://scryfall.com/sets/dom",
SearchURI: "https://api.scryfall.com/cards/search?order=set&q=e%3Adom&unique=prints",
ReleasedAt: &Date{Time: time.Date(2018, 04, 27, 0, 0, 0, 0, time.FixedZone("UTC-8", -8*60*60))},
SetType: "expansion",
CardCount: 142,
Digital: false,
FoilOnly: false,
IconSVGURI: "https://assets.scryfall.com/assets/sets/dom.svg",
},
{
Code: "a25",
MTGOCode: &mtgoCodes[1],
ArenaCode: &arenaCodes[1],
TCGplayerID: &tcgplayerIDs[1],
Name: "Masters 25",
URI: "https://api.scryfall.com/sets/a25",
ScryfallURI: "https://scryfall.com/sets/a25",
SearchURI: "https://api.scryfall.com/cards/search?order=set&q=e%3Aa25&unique=prints",
ReleasedAt: &Date{Time: time.Date(2018, 03, 16, 0, 0, 0, 0, time.FixedZone("UTC-8", -8*60*60))},
SetType: "masters",
CardCount: 249,
Digital: false,
FoilOnly: false,
IconSVGURI: "https://assets.scryfall.com/assets/sets/a25.svg",
},
{
Code: "rix",
MTGOCode: &mtgoCodes[2],
ArenaCode: &arenaCodes[2],
TCGplayerID: &tcgplayerIDs[2],
Name: "Rivals of Ixalan",
URI: "https://api.scryfall.com/sets/rix",
ScryfallURI: "https://scryfall.com/sets/rix",
SearchURI: "https://api.scryfall.com/cards/search?order=set&q=e%3Arix&unique=prints",
ReleasedAt: &Date{Time: time.Date(2018, 01, 19, 0, 0, 0, 0, time.FixedZone("UTC-8", -8*60*60))},
SetType: "expansion",
CardCount: 205,
Digital: false,
FoilOnly: false,
BlockCode: stringPointer("xln"),
Block: stringPointer("Ixalan"),
IconSVGURI: "https://assets.scryfall.com/assets/sets/rix.svg",
},
}
if !reflect.DeepEqual(sets, want) {
t.Errorf("got: %#v want: %#v", sets, want)
}
}
func TestGetSet(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"object": "set", "code": "aer", "mtgo_code": "aer", "name": "Aether Revolt", "uri": "https://api.scryfall.com/sets/aer", "scryfall_uri": "https://scryfall.com/sets/aer", "search_uri": "https://api.scryfall.com/cards/search?order=set&q=e%3Aaer&unique=prints", "released_at": "2017-01-20", "set_type": "expansion", "card_count": 194, "digital": false, "foil": false, "block_code": "kld", "block": "Kaladesh", "icon_svg_uri": "https://assets.scryfall.com/assets/sets/aer.svg"}`)
})
client, ts, err := setupTestServer("/sets/aer", handler)
if err != nil {
t.Fatalf("Error setting up test server: %v", err)
}
defer ts.Close()
ctx := context.Background()
set, err := client.GetSet(ctx, "aer")
if err != nil {
t.Fatalf("Error getting set: %v", err)
}
aetherSetCode := "aer"
aetherRevoltBlockCode := "kld"
aetherRevoltBlock := "Kaladesh"
want := Set{
Code: aetherSetCode,
MTGOCode: &aetherSetCode,
ArenaCode: nil,
TCGplayerID: nil,
Name: "Aether Revolt",
URI: "https://api.scryfall.com/sets/aer",
ScryfallURI: "https://scryfall.com/sets/aer",
SearchURI: "https://api.scryfall.com/cards/search?order=set&q=e%3Aaer&unique=prints",
ReleasedAt: &Date{Time: time.Date(2017, 01, 20, 0, 0, 0, 0, time.FixedZone("UTC-8", -8*60*60))},
SetType: "expansion",
CardCount: 194,
Digital: false,
FoilOnly: false,
BlockCode: &aetherRevoltBlockCode,
Block: &aetherRevoltBlock,
IconSVGURI: "https://assets.scryfall.com/assets/sets/aer.svg",
}
if !reflect.DeepEqual(set, want) {
t.Errorf("got: %#v want: %#v", set, want)
}
}