-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_test.go
322 lines (305 loc) · 9.58 KB
/
client_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package client
import (
"context"
"reflect"
"testing"
"github.com/gerbenjacobs/go-habbo/habbo"
)
var (
habboKoeientemmer = &habbo.Habbo{
UniqueID: "hhus-9cd61b156972c2eb33a145d69918f965",
Name: "koeientemmer",
FigureString: "hd-195-1.ch-215-75.lg-3290-91.sh-905-1408.ha-1015.wa-2001",
Motto: "Oldskooler than Dionysus!",
MemberSince: *habbo.NewTime("2001-10-06T12:21:53.000+0000"),
ProfileVisible: true,
SelectedBadges: []habbo.Badge{
{
BadgeIndex: 1,
Code: "YODUK",
Name: "Master Yoduck",
Description: "Use the nondescript motion imparting field!",
},
{
BadgeIndex: 2,
Code: "UK183",
Name: "The Sims - Katy Perry Sweet Treats",
Description: "I beat the The Sims Katy Perry Sweet Treats Quiz!",
},
{
BadgeIndex: 3,
Code: "Z63_HHUK",
Name: "Valued BETA tester",
Description: "Helped shape the new Habbo June 2009",
},
{
BadgeIndex: 4,
Code: "Z64_HHUK",
Name: "Official BETA tester",
Description: "Helped shape the new Habbo June 2009",
},
{
BadgeIndex: 5,
Code: "UK119",
Name: "Master Shifu's Badge of Honour",
Description: "Kung Fu Panda 2 visited Habbo December 2010",
},
},
}
habboJohno = &habbo.Habbo{
UniqueID: "hhs2-15cdd228b60baf1fcd72283ab29d1527",
Name: "Johno",
FigureString: "hr-165-31.hd-180-1.ch-215-1408.lg-280-1408.sh-300-1408.fa-1201",
Motto: "null",
Online: false,
LastAccessTime: habbo.NewTime("2020-12-07T15:43:37.000+0000"),
MemberSince: *habbo.NewTime("2004-07-19T10:14:20.000+0000"),
ProfileVisible: true,
CurrentLevel: 7,
CurrentLevelCompletePercent: 75,
TotalExperience: 110,
StarGemCount: 18,
SelectedBadges: []habbo.Badge{
{
BadgeIndex: 2,
Code: "ADM",
Name: "",
Description: "",
},
{
BadgeIndex: 4,
Code: "ACH_HappyHour1",
Name: "Happy hour",
Description: "For logging in during happy hour.",
},
{
BadgeIndex: 5,
Code: "ACH_AllTimeHotelPresence7",
Name: "Online time VII - Cyclone",
Description: "For spending total of 1440 hours in hotel.",
},
},
}
habboGerben = &habbo.Habbo{
UniqueID: "hhnl-d47ce47a95c35b2d3f027d207e3d0515",
Name: "Gerben",
FigureString: "hr-802-36.hd-195-1.ch-3030-64.lg-3088-81-80.sh-290-64.ha-3454.cc-3389-64-90",
Motto: "Duikt de kast weer in!",
Online: false,
LastAccessTime: habbo.NewTime("2020-12-31T13:50:01.000+0000"),
MemberSince: *habbo.NewTime("2004-02-11T19:00:40.000+0000"),
ProfileVisible: true,
CurrentLevel: 26,
CurrentLevelCompletePercent: 18,
TotalExperience: 1429,
StarGemCount: 60,
SelectedBadges: []habbo.Badge{
{
BadgeIndex: 1,
Code: "APC13",
Name: "Ze houden je in de gaten...maar hebben je niet gezien!",
Description: "Habbocalyps 2015",
},
{
BadgeIndex: 2,
Code: "SB7",
Name: "Streets of Bobba - 1",
Description: "Eerste plaats",
},
},
}
)
func TestGetHabbo_ValidateUniqueID(t *testing.T) {
tests := []struct {
name string
hotel string
habboName string
wantErr bool
errorType error
}{
{name: "valid", hotel: "com", habboName: "hhus-9cd61b156972c2eb33a145d69918f965", wantErr: false},
{name: "invalid hotel", hotel: "invalid", habboName: "hhus-9cd61b156972c2eb33a145d69918f965", wantErr: true, errorType: ErrInvalidHotel},
{name: "invalid unique ID", hotel: "com", habboName: "invalid", wantErr: true, errorType: ErrInvalidUniqueID},
{name: "sandbox ID", hotel: "com", habboName: "hhs2-15cdd228b60baf1fcd72283ab29d1527", wantErr: false},
}
for _, tt := range tests {
api := &HabboAPI{
parser: NewParserMock(),
}
t.Run(tt.name, func(t *testing.T) {
_, err := api.GetHabbo(context.Background(), tt.hotel, tt.habboName)
if (err != nil) != tt.wantErr {
t.Errorf("GetHabboByName() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr && err.Error() != tt.errorType.Error() {
t.Errorf("GetHabboByName() error = %v, wantErr %v", err, tt.errorType)
}
})
}
}
func TestGetHabbo_Parsing(t *testing.T) {
tests := []struct {
name string
hotel string
habboID string
file string
want *habbo.Habbo
wantErr bool
}{
{
name: "valid for koeientemmer",
hotel: "com",
habboID: "hhus-9cd61b156972c2eb33a145d69918f965",
file: "tests/data/com_koeientemmer_gethabbo.json",
want: habboKoeientemmer,
wantErr: false,
},
{
name: "valid sandbox hotel for johno",
hotel: "com", // not 100%, but it's good enough for this test
habboID: "hhs2-15cdd228b60baf1fcd72283ab29d1527",
file: "tests/data/sandbox_johno_gethabbo.json",
want: habboJohno,
wantErr: false,
},
{
name: "valid for gerben",
hotel: "nl",
habboID: "hhnl-d47ce47a95c35b2d3f027d207e3d0515",
file: "tests/data/nl_gerben_gethabbo.json",
want: habboGerben,
wantErr: false,
},
}
for _, tt := range tests {
pm := NewParserMock()
api := &HabboAPI{
parser: pm,
}
t.Run(tt.name, func(t *testing.T) {
pm.loadHabbo(tt.file)
got, err := api.GetHabbo(context.Background(), tt.hotel, tt.habboID)
if (err != nil) != tt.wantErr {
t.Errorf("GetHabbo() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetHabbo() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetProfile_Koeientemmer(t *testing.T) {
pm := NewParserMock()
pm.loadProfile("tests/data/com_koeientemmer_getprofile.json")
api := &HabboAPI{
parser: pm,
}
p, err := api.GetProfile(context.Background(), "com", "hhus-9cd61b156972c2eb33a145d69918f965")
if err != nil {
t.Error(err)
}
// check user entity
if !reflect.DeepEqual(p.Habbo, *habboKoeientemmer) {
t.Errorf("GetProfile() got = \n%#v, want \n%#v", p.Habbo, *habboKoeientemmer)
}
// check badges
if len(p.Badges) != 204 {
t.Errorf("GetProfile() got = %v, want %v", len(p.Badges), 204)
}
expectedBadge := habbo.Badge{
Code: "THI41",
Name: "...will go on!!!",
Description: "Winner of broken hearts 2/2",
}
if !reflect.DeepEqual(p.Badges[0], expectedBadge) {
t.Errorf("GetProfile() got = \n%#v, want \n%#v", p.Badges[0], expectedBadge)
}
// check rooms
if len(p.Rooms) != 5 {
t.Errorf("GetProfile() got = %v, want %v", len(p.Rooms), 5)
}
expectedRoom := habbo.Room{
ID: 31159787,
Name: "Venice Beach Rollercoaster",
Description: "Ahh well..",
CreationTime: habbo.NewRoomTime("2010-06-10T09:02:16.000+00:00"),
MaximumVisitors: 25,
Tags: []string{
"habbies",
},
ShowOwnerName: true,
OwnerName: "koeientemmer",
OwnerUniqueId: "hhus-9cd61b156972c2eb33a145d69918f965",
ThumbnailURL: "https://habbo-stories-content.s3.amazonaws.com/navigator-thumbnail/hhus/31159787.png",
ImageURL: "https://habbo-stories-content.s3.amazonaws.com/fullroom-photo/hhus/31159787.png",
Rating: 116,
Categories: []string{
"navigator.flatcategory.global.CHAT",
},
UniqueID: "r-hhus-a091e0f1d891108b49ca7af953386f0f",
}
if !reflect.DeepEqual(p.Rooms[0], expectedRoom) {
t.Errorf("GetProfile() got = \n%#v, want \n%#v", p.Rooms[0], expectedRoom)
}
// check groups
if len(p.Groups) != 10 {
t.Errorf("GetProfile() got = %v, want %v", len(p.Groups), 10)
}
expectedGroup := habbo.Group{
ID: "g-hhus-1332dcd15645042afc396f726351721d",
Name: "Ditch the Label",
Description: "The official Ditch the Label anti-bullying public group. Join now and support our cause! Find out more at www.DitchtheLabel.org",
Type: "NORMAL",
RoomID: "r-hhus-a08de337a9dc601102b0139194164f78",
BadgeCode: "b13114s19134a55aa7427bc0a3f0c083e94232fb3475",
PrimaryColour: "242424",
SecondaryColour: "ffffff",
IsAdmin: false,
}
if !reflect.DeepEqual(p.Groups[0], expectedGroup) {
t.Errorf("GetProfile() got = \n%#v, want \n%#v", p.Groups[0], expectedGroup)
}
// check friends
if len(p.Friends) != 146 {
t.Errorf("GetProfile() got = %v, want %v", len(p.Friends), 146)
}
expectedFriend := habbo.Habbo{
Name: "!!!toon!!!",
Motto: "Puhekupla.com",
UniqueID: "hhus-eafa7f30310f817172231ac9ba3a3baa",
FigureString: "hr-155-48.hd-180-1.ch-215-1408.lg-3023-64.sh-3068-1408-85.wa-2001.cp-3286",
}
if !reflect.DeepEqual(p.Friends[0], expectedFriend) {
t.Errorf("GetProfile() got = \n%#v, want \n%#v", p.Friends[0], expectedFriend)
}
}
func TestGetProfile_Johno(t *testing.T) {
pm := NewParserMock()
pm.loadProfile("tests/data/sandbox_johno_getprofile.json")
api := &HabboAPI{
parser: pm,
}
p, err := api.GetProfile(context.Background(), "com", "hhs2-15cdd228b60baf1fcd72283ab29d1527")
if err != nil {
t.Error(err)
}
// check user entity
if !reflect.DeepEqual(p.Habbo, *habboJohno) {
t.Errorf("GetProfile() got = \n%#v, want \n%#v", p.Habbo, *habboJohno)
}
// check counts
if len(p.Friends) != 14 {
t.Errorf("Friends got = %v, want %v", len(p.Friends), 14)
}
if len(p.Rooms) != 2 {
t.Errorf("Rooms got = %v, want %v", len(p.Rooms), 2)
}
if len(p.Groups) != 0 {
t.Errorf("Groups got = %v, want %v", len(p.Groups), 0)
}
if len(p.Badges) != 33 {
t.Errorf("Badges got = %v, want %v", len(p.Badges), 33)
}
}