Skip to content

Commit ef8cfee

Browse files
committed
test: add case
1 parent 6bd41c2 commit ef8cfee

File tree

2 files changed

+228
-1
lines changed

2 files changed

+228
-1
lines changed

AVOS/AVOS.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@
302302
D313718026BBDAC200123756 /* LCQueryTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D313717F26BBDAC200123756 /* LCQueryTestCase.swift */; };
303303
D32AA480263BF2F30044E74E /* Foundation.h in Headers */ = {isa = PBXBuildFile; fileRef = D32AA47F263BF2F30044E74E /* Foundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
304304
D32AA482263BF39C0044E74E /* Realtime.h in Headers */ = {isa = PBXBuildFile; fileRef = D32AA481263BF39C0044E74E /* Realtime.h */; settings = {ATTRIBUTES = (Public, ); }; };
305+
D33127D326CBAD6D00BBDE09 /* LCFileTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */; };
306+
D33127D526CE391500BBDE09 /* LCLeaderboardTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33127D426CE391500BBDE09 /* LCLeaderboardTestCase.swift */; };
305307
D365E42426C3D29F00148DE8 /* LCLeaderboard.h in Headers */ = {isa = PBXBuildFile; fileRef = D365E42226C3D29F00148DE8 /* LCLeaderboard.h */; settings = {ATTRIBUTES = (Public, ); }; };
306308
D365E42526C3D29F00148DE8 /* LCLeaderboard.m in Sources */ = {isa = PBXBuildFile; fileRef = D365E42326C3D29F00148DE8 /* LCLeaderboard.m */; };
307-
D33127D326CBAD6D00BBDE09 /* LCFileTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */; };
308309
D36A095A25BEA75000A4F312 /* IMMessageTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36A095925BEA75000A4F312 /* IMMessageTestCase.swift */; };
309310
D39724C424A5CD3C0099A518 /* RTMBaseTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39724C324A5CD3C0099A518 /* RTMBaseTestCase.swift */; };
310311
D39724C624A852400099A518 /* IMClientTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39724C524A852400099A518 /* IMClientTestCase.swift */; };
@@ -552,6 +553,7 @@
552553
D32AA47F263BF2F30044E74E /* Foundation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Foundation.h; sourceTree = "<group>"; };
553554
D32AA481263BF39C0044E74E /* Realtime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Realtime.h; sourceTree = "<group>"; };
554555
D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCFileTestCase.swift; sourceTree = "<group>"; };
556+
D33127D426CE391500BBDE09 /* LCLeaderboardTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCLeaderboardTestCase.swift; sourceTree = "<group>"; };
555557
D34C417D2483C3FD00CD2459 /* LCRTMConnection_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCRTMConnection_Internal.h; sourceTree = "<group>"; };
556558
D34EBDCC211C20FF0092A538 /* LCRouter_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCRouter_Internal.h; sourceTree = "<group>"; };
557559
D34FD72B2068CFE900B7C11B /* LCLiveQuery_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCLiveQuery_Internal.h; sourceTree = "<group>"; };
@@ -1239,6 +1241,7 @@
12391241
D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */,
12401242
D313717F26BBDAC200123756 /* LCQueryTestCase.swift */,
12411243
D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */,
1244+
D33127D426CE391500BBDE09 /* LCLeaderboardTestCase.swift */,
12421245
D39724C324A5CD3C0099A518 /* RTMBaseTestCase.swift */,
12431246
D3A397F024A5A4670087D6F8 /* RTMConnectionTestCase.swift */,
12441247
D39724C524A852400099A518 /* IMClientTestCase.swift */,
@@ -1797,6 +1800,7 @@
17971800
D313718026BBDAC200123756 /* LCQueryTestCase.swift in Sources */,
17981801
D36A095A25BEA75000A4F312 /* IMMessageTestCase.swift in Sources */,
17991802
D3AD74AB24BC216200D1BBEE /* LCUserTestCase.swift in Sources */,
1803+
D33127D526CE391500BBDE09 /* LCLeaderboardTestCase.swift in Sources */,
18001804
D33127D326CBAD6D00BBDE09 /* LCFileTestCase.swift in Sources */,
18011805
D3A397F124A5A4670087D6F8 /* RTMConnectionTestCase.swift in Sources */,
18021806
D39724C624A852400099A518 /* IMClientTestCase.swift in Sources */,
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
//
2+
// LCLeaderboardTestCase.swift
3+
// LeanCloudObjcTests
4+
//
5+
// Created by pzheng on 2021/08/19.
6+
// Copyright © 2021 LeanCloud Inc. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import LeanCloudObjc
11+
12+
class LCLeaderboardTestCase: BaseTestCase {
13+
14+
func testWithoutCurrentUser() {
15+
expecting { exp in
16+
LCLeaderboard.updateCurrentUserStatistics([uuid : uuid]) { statistics, error in
17+
XCTAssertNil(statistics)
18+
XCTAssertNotNil(error)
19+
exp.fulfill()
20+
}
21+
}
22+
23+
expecting { exp in
24+
LCLeaderboard.deleteCurrentUserStatistics([uuid]) { succeeded, error in
25+
XCTAssertFalse(succeeded)
26+
XCTAssertNotNil(error)
27+
exp.fulfill()
28+
}
29+
}
30+
31+
let option = LCLeaderboardQueryOption()
32+
option.selectKeys = [uuid]
33+
option.includeKeys = [uuid]
34+
35+
expecting { exp in
36+
LCLeaderboard.getStatisticsWithUserId(uuid, statisticNames: nil, option: option) { statistics, error in
37+
XCTAssertNil(statistics)
38+
XCTAssertNotNil(error)
39+
exp.fulfill()
40+
}
41+
}
42+
43+
let leaderboard = LCLeaderboard(statisticName: uuid)
44+
45+
expecting { exp in
46+
leaderboard.getStatisticsWithUserIds([uuid], option: option) { statistics, error in
47+
XCTAssertNil(statistics)
48+
XCTAssertNotNil(error)
49+
exp.fulfill()
50+
}
51+
}
52+
53+
expecting { exp in
54+
leaderboard.getUserResults(with: option) { rankings, count, error in
55+
XCTAssertNil(rankings)
56+
XCTAssertEqual(count, -1)
57+
XCTAssertNotNil(error)
58+
exp.fulfill()
59+
}
60+
}
61+
62+
expecting { exp in
63+
leaderboard.getUserResultsAroundUser(uuid, option: option) { rankings, count, error in
64+
XCTAssertNil(rankings)
65+
XCTAssertEqual(count, -1)
66+
XCTAssertNotNil(error)
67+
exp.fulfill()
68+
}
69+
}
70+
}
71+
72+
func testInvalidParameter() {
73+
let user = LCUser()
74+
expecting { exp in
75+
user.login(withAuthData: ["openid" : uuid], platformId: "test", options: nil) { _, error in
76+
XCTAssertNil(error)
77+
exp.fulfill()
78+
}
79+
}
80+
81+
expecting { exp in
82+
LCLeaderboard.updateCurrentUserStatistics([:]) { statistics, error in
83+
XCTAssertNil(statistics)
84+
XCTAssertNotNil(error)
85+
exp.fulfill()
86+
}
87+
}
88+
89+
expecting { exp in
90+
LCLeaderboard.deleteCurrentUserStatistics([]) { succeeded, error in
91+
XCTAssertFalse(succeeded)
92+
XCTAssertNotNil(error)
93+
exp.fulfill()
94+
}
95+
}
96+
97+
expecting { exp in
98+
LCLeaderboard.getStatisticsWithUserId("", statisticNames: nil, option: nil) { statistics, error in
99+
XCTAssertNil(statistics)
100+
XCTAssertNotNil(error)
101+
exp.fulfill()
102+
}
103+
}
104+
105+
let leaderboard = LCLeaderboard(statisticName: uuid)
106+
107+
expecting { exp in
108+
leaderboard.getStatisticsWithUserIds([], option: nil) { statistics, error in
109+
XCTAssertNil(statistics)
110+
XCTAssertNotNil(error)
111+
exp.fulfill()
112+
}
113+
}
114+
115+
LCUser.logOut()
116+
}
117+
118+
func testGetUserStatistics() {
119+
let object = LCObject()
120+
XCTAssertTrue(object.save())
121+
let user = LCUser()
122+
let objectFieldKey = "objectField"
123+
user[objectFieldKey] = object
124+
expecting { exp in
125+
user.login(withAuthData: ["openid" : uuid], platformId: "test", options: nil) { _, error in
126+
XCTAssertNil(error)
127+
exp.fulfill()
128+
}
129+
}
130+
guard let userObjectId = user.objectId else {
131+
XCTFail()
132+
return
133+
}
134+
135+
let statisticName0 = "test0"
136+
let statisticName1 = "test1"
137+
138+
expecting { exp in
139+
LCLeaderboard.updateCurrentUserStatistics(
140+
[statisticName0 : 100,
141+
statisticName1 : 100])
142+
{ statistics, error in
143+
XCTAssertEqual(statistics?.count, 2)
144+
XCTAssertNil(error)
145+
XCTAssertNotEqual(statistics?.first?.name, statistics?.last?.name)
146+
for item in statistics ?? [] {
147+
XCTAssertTrue([statisticName0, statisticName1].contains(item.name ?? ""))
148+
XCTAssertEqual(item.value, 100)
149+
XCTAssertGreaterThanOrEqual(item.version, 0)
150+
}
151+
exp.fulfill()
152+
}
153+
}
154+
155+
let option = LCLeaderboardQueryOption()
156+
option.selectKeys = ["username", objectFieldKey]
157+
option.includeKeys = [objectFieldKey]
158+
159+
expecting { exp in
160+
LCLeaderboard.getStatisticsWithUserId(
161+
userObjectId,
162+
statisticNames: [statisticName0, statisticName1],
163+
option: option)
164+
{ statistics, error in
165+
XCTAssertEqual(statistics?.count, 2)
166+
XCTAssertNil(error)
167+
XCTAssertNotEqual(statistics?.first?.name, statistics?.last?.name)
168+
for item in statistics ?? [] {
169+
XCTAssertTrue([statisticName0, statisticName1].contains(item.name ?? ""))
170+
XCTAssertEqual(item.value, 100)
171+
XCTAssertGreaterThanOrEqual(item.version, 0)
172+
XCTAssertNotNil(item.user?["username"])
173+
XCTAssertTrue(item.user?[objectFieldKey] is LCObject)
174+
XCTAssertNil(item.object)
175+
XCTAssertNil(item.entity)
176+
}
177+
exp.fulfill()
178+
}
179+
}
180+
181+
let leaderboard0 = LCLeaderboard(statisticName: statisticName0)
182+
let leaderboard1 = LCLeaderboard(statisticName: statisticName1)
183+
184+
expecting(count: 2) { exp in
185+
leaderboard0.getStatisticsWithUserIds([userObjectId], option: option) { statistics, error in
186+
// XCTAssertEqual(statistics?.count, 1)
187+
// XCTAssertNil(error)
188+
// XCTAssertEqual(leaderboard0.statisticName, statistics?.first?.name)
189+
// XCTAssertEqual(statistics?.first?.value, 100)
190+
// XCTAssertGreaterThanOrEqual(statistics?.first?.version ?? -1, 0)
191+
// XCTAssertNotNil(statistics?.first?.user?["username"])
192+
// XCTAssertTrue(statistics?.first?.user?[objectFieldKey] is LCObject)
193+
// XCTAssertNil(statistics?.first?.object)
194+
// XCTAssertNil(statistics?.first?.entity)
195+
exp.fulfill()
196+
}
197+
leaderboard1.getStatisticsWithUserIds([userObjectId], option: option) { statistics, error in
198+
// XCTAssertEqual(statistics?.count, 1)
199+
// XCTAssertNil(error)
200+
// XCTAssertEqual(leaderboard1.statisticName, statistics?.first?.name)
201+
// XCTAssertEqual(statistics?.first?.value, 100)
202+
// XCTAssertGreaterThanOrEqual(statistics?.first?.version ?? -1, 0)
203+
// XCTAssertNotNil(statistics?.first?.user?["username"])
204+
// XCTAssertTrue(statistics?.first?.user?[objectFieldKey] is LCObject)
205+
// XCTAssertNil(statistics?.first?.object)
206+
// XCTAssertNil(statistics?.first?.entity)
207+
exp.fulfill()
208+
}
209+
}
210+
211+
expecting { exp in
212+
LCLeaderboard.deleteCurrentUserStatistics([statisticName0, statisticName1]) { succeeded, error in
213+
XCTAssertTrue(succeeded)
214+
XCTAssertNil(error)
215+
exp.fulfill()
216+
}
217+
}
218+
219+
LCUser.logOut()
220+
}
221+
222+
223+
}

0 commit comments

Comments
 (0)