Skip to content

Commit 99a05bb

Browse files
committed
test: update
1 parent b9da1d6 commit 99a05bb

File tree

14 files changed

+240
-239
lines changed

14 files changed

+240
-239
lines changed

AVOS/AVOS.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
D30B6A6E24A09D7B006ABE09 /* LCRequestOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841A6C1A5A79FF00C5C6C4 /* LCRequestOperation.h */; };
7474
D30B6A6F24A09D7B006ABE09 /* LCRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C841A6D1A5A79FF00C5C6C4 /* LCRequestOperation.m */; };
7575
D30B6A7024A09D7B006ABE09 /* LCPaasClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841A6E1A5A79FF00C5C6C4 /* LCPaasClient.h */; };
76-
D30B6A7124A09D7B006ABE09 /* LCPaasClient_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 83A2BD2E1CF33CDA0047B230 /* LCPaasClient_internal.h */; };
7776
D30B6A7224A09D7B006ABE09 /* LCPaasClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C841A6F1A5A79FF00C5C6C4 /* LCPaasClient.m */; };
7877
D30B6A7324A09D87006ABE09 /* LCRouter.h in Headers */ = {isa = PBXBuildFile; fileRef = 83F9A2C51CE014430002E21B /* LCRouter.h */; };
7978
D30B6A7424A09D87006ABE09 /* LCRouter_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = D34EBDCC211C20FF0092A538 /* LCRouter_Internal.h */; };
@@ -304,6 +303,7 @@
304303
D32AA482263BF39C0044E74E /* Realtime.h in Headers */ = {isa = PBXBuildFile; fileRef = D32AA481263BF39C0044E74E /* Realtime.h */; settings = {ATTRIBUTES = (Public, ); }; };
305304
D33127D326CBAD6D00BBDE09 /* LCFileTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */; };
306305
D33127D526CE391500BBDE09 /* LCLeaderboardTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33127D426CE391500BBDE09 /* LCLeaderboardTestCase.swift */; };
306+
D33127D726CFAC5100BBDE09 /* LCLeaderboard_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = D33127D626CFAC5100BBDE09 /* LCLeaderboard_Internal.h */; };
307307
D365E42426C3D29F00148DE8 /* LCLeaderboard.h in Headers */ = {isa = PBXBuildFile; fileRef = D365E42226C3D29F00148DE8 /* LCLeaderboard.h */; settings = {ATTRIBUTES = (Public, ); }; };
308308
D365E42526C3D29F00148DE8 /* LCLeaderboard.m in Sources */ = {isa = PBXBuildFile; fileRef = D365E42326C3D29F00148DE8 /* LCLeaderboard.m */; };
309309
D36A095A25BEA75000A4F312 /* IMMessageTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36A095925BEA75000A4F312 /* IMMessageTestCase.swift */; };
@@ -386,7 +386,6 @@
386386
838DD79E1B3D3FB600C95897 /* LCKeyValueStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCKeyValueStore.h; sourceTree = "<group>"; };
387387
838DD79F1B3D3FB600C95897 /* LCKeyValueStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCKeyValueStore.m; sourceTree = "<group>"; };
388388
838DD7A21B3D3FD100C95897 /* LCKeyValueSQL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCKeyValueSQL.h; sourceTree = "<group>"; };
389-
83A2BD2E1CF33CDA0047B230 /* LCPaasClient_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCPaasClient_internal.h; sourceTree = "<group>"; };
390389
83CFCB5E1B2A5D2700F97C92 /* LCIMKeyedConversation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCIMKeyedConversation.h; sourceTree = "<group>"; };
391390
83CFCB5F1B2A5D2700F97C92 /* LCIMKeyedConversation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCIMKeyedConversation.m; sourceTree = "<group>"; };
392391
83DF02A51AF86032000E289C /* LCDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCDatabase.h; sourceTree = "<group>"; };
@@ -554,6 +553,7 @@
554553
D32AA481263BF39C0044E74E /* Realtime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Realtime.h; sourceTree = "<group>"; };
555554
D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCFileTestCase.swift; sourceTree = "<group>"; };
556555
D33127D426CE391500BBDE09 /* LCLeaderboardTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCLeaderboardTestCase.swift; sourceTree = "<group>"; };
556+
D33127D626CFAC5100BBDE09 /* LCLeaderboard_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCLeaderboard_Internal.h; sourceTree = "<group>"; };
557557
D34C417D2483C3FD00CD2459 /* LCRTMConnection_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCRTMConnection_Internal.h; sourceTree = "<group>"; };
558558
D34EBDCC211C20FF0092A538 /* LCRouter_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCRouter_Internal.h; sourceTree = "<group>"; };
559559
D34FD72B2068CFE900B7C11B /* LCLiveQuery_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCLiveQuery_Internal.h; sourceTree = "<group>"; };
@@ -989,7 +989,6 @@
989989
8C841A6C1A5A79FF00C5C6C4 /* LCRequestOperation.h */,
990990
8C841A6D1A5A79FF00C5C6C4 /* LCRequestOperation.m */,
991991
8C841A6E1A5A79FF00C5C6C4 /* LCPaasClient.h */,
992-
83A2BD2E1CF33CDA0047B230 /* LCPaasClient_internal.h */,
993992
8C841A6F1A5A79FF00C5C6C4 /* LCPaasClient.m */,
994993
);
995994
path = Request;
@@ -1294,6 +1293,7 @@
12941293
isa = PBXGroup;
12951294
children = (
12961295
D365E42226C3D29F00148DE8 /* LCLeaderboard.h */,
1296+
D33127D626CFAC5100BBDE09 /* LCLeaderboard_Internal.h */,
12971297
D365E42326C3D29F00148DE8 /* LCLeaderboard.m */,
12981298
);
12991299
path = Leaderboard;
@@ -1377,6 +1377,7 @@
13771377
D30B6ADD24A09F1E006ABE09 /* LCGPBArray_PackagePrivate.h in Headers */,
13781378
D32AA482263BF39C0044E74E /* Realtime.h in Headers */,
13791379
D30B6AFB24A09F1F006ABE09 /* LCGPBProtocolBuffers.h in Headers */,
1380+
D33127D726CFAC5100BBDE09 /* LCLeaderboard_Internal.h in Headers */,
13801381
D30B6B2A24A09F66006ABE09 /* LCIMDynamicObject.h in Headers */,
13811382
D30B6AA824A09E35006ABE09 /* LCDatabaseMigrator.h in Headers */,
13821383
D30B6A9424A09DDF006ABE09 /* LCDatabaseQueue.h in Headers */,
@@ -1454,7 +1455,6 @@
14541455
D30B6ABF24A09EBC006ABE09 /* LCIMClientProtocol.h in Headers */,
14551456
D30B6A4424A09CF1006ABE09 /* LCCloud.h in Headers */,
14561457
D30B6B4D24A09F85006ABE09 /* LCIMFileMessage.h in Headers */,
1457-
D30B6A7124A09D7B006ABE09 /* LCPaasClient_internal.h in Headers */,
14581458
D30B6ADE24A09F1E006ABE09 /* LCGPBArray.h in Headers */,
14591459
D30B6A7024A09D7B006ABE09 /* LCPaasClient.h in Headers */,
14601460
D30B6ADB24A09F1E006ABE09 /* LCGPBApi.pbobjc.h in Headers */,

AVOS/LeanCloudObjcTests/BaseTestCase.swift

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,32 @@ class BaseTestCase: XCTestCase {
2525
let id: String
2626
let key: String
2727
let serverURL: String
28+
let masterKey: String
2829
}
2930

3031
static let cnApp = AppInfo(
3132
id: "S5vDI3IeCk1NLLiM1aFg3262-gzGzoHsz",
3233
key: "7g5pPsI55piz2PRLPWK5MPz0",
33-
serverURL: "https://s5vdi3ie.lc-cn-n1-shared.com")
34+
serverURL: "https://s5vdi3ie.lc-cn-n1-shared.com",
35+
masterKey: "Q26gTodbyi1Ki7lM9vtncF6U,master")
3436

3537
static let ceApp = AppInfo(
3638
id: "skhiVsqIk7NLVdtHaUiWn0No-9Nh9j0Va",
3739
key: "T3TEAIcL8Ls5XGPsGz41B1bz",
38-
serverURL: "https://skhivsqi.lc-cn-e1-shared.com")
40+
serverURL: "https://skhivsqi.lc-cn-e1-shared.com",
41+
masterKey: "FTPdEcG7vLKxNqKxYhTFdK4g,master")
3942

4043
static let usApp = AppInfo(
4144
id: "jenSt9nvWtuJtmurdE28eg5M-MdYXbMMI",
4245
key: "8VLPsDlskJi8KsKppED4xKS0",
43-
serverURL: "")
46+
serverURL: "",
47+
masterKey: "fasiJXz8jvSwn3G2B2QeraRe,master")
48+
49+
static let appInfoTable = [
50+
cnApp.id : cnApp,
51+
ceApp.id : ceApp,
52+
usApp.id : usApp,
53+
]
4454

4555
override class func setUp() {
4656
super.setUp()
@@ -103,3 +113,22 @@ extension BaseTestCase {
103113
wait(for: [exp], timeout: seconds)
104114
}
105115
}
116+
117+
extension BaseTestCase {
118+
119+
func useMasterKey(_ application: LCApplication = .default()) {
120+
guard let appInfo = BaseTestCase.appInfoTable[application.identifier],
121+
!appInfo.masterKey.isEmpty else {
122+
return
123+
}
124+
application.setWithIdentifier(appInfo.id, key: appInfo.masterKey)
125+
}
126+
127+
func useCommonKey(_ application: LCApplication = .default()) {
128+
guard let appInfo = BaseTestCase.appInfoTable[application.identifier],
129+
!appInfo.masterKey.isEmpty else {
130+
return
131+
}
132+
application.setWithIdentifier(appInfo.id, key: appInfo.key)
133+
}
134+
}

AVOS/LeanCloudObjcTests/LCLeaderboardTestCase.swift

Lines changed: 99 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -27,57 +27,9 @@ class LCLeaderboardTestCase: BaseTestCase {
2727
exp.fulfill()
2828
}
2929
}
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-
}
7030
}
7131

7232
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-
8133
expecting { exp in
8234
LCLeaderboard.updateCurrentUserStatistics([:]) { statistics, error in
8335
XCTAssertNil(statistics)
@@ -95,7 +47,7 @@ class LCLeaderboardTestCase: BaseTestCase {
9547
}
9648

9749
expecting { exp in
98-
LCLeaderboard.getStatisticsWithUserId("", statisticNames: nil, option: nil) { statistics, error in
50+
LCLeaderboard.getStatisticsWithUserId("", statisticNames: nil) { statistics, error in
9951
XCTAssertNil(statistics)
10052
XCTAssertNotNil(error)
10153
exp.fulfill()
@@ -105,22 +57,16 @@ class LCLeaderboardTestCase: BaseTestCase {
10557
let leaderboard = LCLeaderboard(statisticName: uuid)
10658

10759
expecting { exp in
108-
leaderboard.getStatisticsWithUserIds([], option: nil) { statistics, error in
60+
leaderboard.getStatisticsWithUserIds([]) { statistics, error in
10961
XCTAssertNil(statistics)
11062
XCTAssertNotNil(error)
11163
exp.fulfill()
11264
}
11365
}
114-
115-
LCUser.logOut()
11666
}
11767

11868
func testGetUserStatistics() {
119-
let object = LCObject()
120-
XCTAssertTrue(object.save())
12169
let user = LCUser()
122-
let objectFieldKey = "objectField"
123-
user[objectFieldKey] = object
12470
expecting { exp in
12571
user.login(withAuthData: ["openid" : uuid], platformId: "test", options: nil) { _, error in
12672
XCTAssertNil(error)
@@ -132,8 +78,8 @@ class LCLeaderboardTestCase: BaseTestCase {
13278
return
13379
}
13480

135-
let statisticName0 = "test0"
136-
let statisticName1 = "test1"
81+
let statisticName0 = "test-user-0"
82+
let statisticName1 = "test-user-1"
13783

13884
expecting { exp in
13985
LCLeaderboard.updateCurrentUserStatistics(
@@ -152,15 +98,10 @@ class LCLeaderboardTestCase: BaseTestCase {
15298
}
15399
}
154100

155-
let option = LCLeaderboardQueryOption()
156-
option.selectKeys = ["username", objectFieldKey]
157-
option.includeKeys = [objectFieldKey]
158-
159101
expecting { exp in
160102
LCLeaderboard.getStatisticsWithUserId(
161103
userObjectId,
162-
statisticNames: [statisticName0, statisticName1],
163-
option: option)
104+
statisticNames: [statisticName0, statisticName1])
164105
{ statistics, error in
165106
XCTAssertEqual(statistics?.count, 2)
166107
XCTAssertNil(error)
@@ -169,8 +110,7 @@ class LCLeaderboardTestCase: BaseTestCase {
169110
XCTAssertTrue([statisticName0, statisticName1].contains(item.name ?? ""))
170111
XCTAssertEqual(item.value, 100)
171112
XCTAssertGreaterThanOrEqual(item.version, 0)
172-
XCTAssertNotNil(item.user?["username"])
173-
XCTAssertTrue(item.user?[objectFieldKey] is LCObject)
113+
XCTAssertNotNil(item.user)
174114
XCTAssertNil(item.object)
175115
XCTAssertNil(item.entity)
176116
}
@@ -182,26 +122,24 @@ class LCLeaderboardTestCase: BaseTestCase {
182122
let leaderboard1 = LCLeaderboard(statisticName: statisticName1)
183123

184124
expecting(count: 2) { exp in
185-
leaderboard0.getStatisticsWithUserIds([userObjectId], option: option) { statistics, error in
125+
leaderboard0.getStatisticsWithUserIds([userObjectId]) { statistics, error in
186126
// XCTAssertEqual(statistics?.count, 1)
187127
// XCTAssertNil(error)
188128
// XCTAssertEqual(leaderboard0.statisticName, statistics?.first?.name)
189129
// XCTAssertEqual(statistics?.first?.value, 100)
190130
// XCTAssertGreaterThanOrEqual(statistics?.first?.version ?? -1, 0)
191-
// XCTAssertNotNil(statistics?.first?.user?["username"])
192-
// XCTAssertTrue(statistics?.first?.user?[objectFieldKey] is LCObject)
131+
// XCTAssertNotNil(statistics?.first?.user)
193132
// XCTAssertNil(statistics?.first?.object)
194133
// XCTAssertNil(statistics?.first?.entity)
195134
exp.fulfill()
196135
}
197-
leaderboard1.getStatisticsWithUserIds([userObjectId], option: option) { statistics, error in
136+
leaderboard1.getStatisticsWithUserIds([userObjectId]) { statistics, error in
198137
// XCTAssertEqual(statistics?.count, 1)
199138
// XCTAssertNil(error)
200139
// XCTAssertEqual(leaderboard1.statisticName, statistics?.first?.name)
201140
// XCTAssertEqual(statistics?.first?.value, 100)
202141
// XCTAssertGreaterThanOrEqual(statistics?.first?.version ?? -1, 0)
203-
// XCTAssertNotNil(statistics?.first?.user?["username"])
204-
// XCTAssertTrue(statistics?.first?.user?[objectFieldKey] is LCObject)
142+
// XCTAssertNotNil(statistics?.first?.user)
205143
// XCTAssertNil(statistics?.first?.object)
206144
// XCTAssertNil(statistics?.first?.entity)
207145
exp.fulfill()
@@ -219,5 +157,93 @@ class LCLeaderboardTestCase: BaseTestCase {
219157
LCUser.logOut()
220158
}
221159

222-
160+
func testGetObjectStatistics() {
161+
let object = LCObject()
162+
let objectFieldKey = "objectField"
163+
object[objectFieldKey] = LCObject()
164+
XCTAssertTrue(object.save())
165+
guard let objectId = object.objectId else {
166+
XCTFail()
167+
return
168+
}
169+
170+
let statisticName0 = "test-object-0"
171+
let statisticName1 = "test-object-1"
172+
173+
useMasterKey()
174+
expecting { exp in
175+
LCLeaderboard.update(
176+
withIdentity: objectId,
177+
leaderboardPath: .objects,
178+
statistics: [
179+
statisticName0 : 100,
180+
statisticName1 : 100,
181+
])
182+
{ statistics, error in
183+
XCTAssertEqual(statistics?.count, 2)
184+
XCTAssertNil(error)
185+
XCTAssertNotEqual(statistics?.first?.name, statistics?.last?.name)
186+
for item in statistics ?? [] {
187+
XCTAssertTrue([statisticName0, statisticName1].contains(item.name ?? ""))
188+
XCTAssertEqual(item.value, 100)
189+
XCTAssertGreaterThanOrEqual(item.version, 0)
190+
}
191+
exp.fulfill()
192+
}
193+
}
194+
useCommonKey()
195+
196+
let option = LCLeaderboardQueryOption()
197+
option.selectKeys = [objectFieldKey]
198+
option.includeKeys = [objectFieldKey]
199+
200+
expecting { exp in
201+
LCLeaderboard.getStatisticsWithObjectId(
202+
objectId,
203+
statisticNames: [statisticName0, statisticName1],
204+
option: option)
205+
{ statistics, error in
206+
XCTAssertEqual(statistics?.count, 2)
207+
XCTAssertNil(error)
208+
XCTAssertNotEqual(statistics?.first?.name, statistics?.last?.name)
209+
for item in statistics ?? [] {
210+
XCTAssertTrue([statisticName0, statisticName1].contains(item.name ?? ""))
211+
XCTAssertEqual(item.value, 100)
212+
XCTAssertGreaterThanOrEqual(item.version, 0)
213+
XCTAssertNotNil((item.object?[objectFieldKey] as? LCObject)?.createdAt)
214+
XCTAssertNil(item.user)
215+
XCTAssertNil(item.entity)
216+
}
217+
exp.fulfill()
218+
}
219+
}
220+
221+
let leaderboard0 = LCLeaderboard(statisticName: statisticName0)
222+
let leaderboard1 = LCLeaderboard(statisticName: statisticName1)
223+
224+
expecting(count: 2) { exp in
225+
leaderboard0.getStatisticsWithObjectIds([objectId], option: option) { statistics, error in
226+
XCTAssertEqual(statistics?.count, 1)
227+
XCTAssertNil(error)
228+
XCTAssertEqual(leaderboard0.statisticName, statistics?.first?.name)
229+
XCTAssertEqual(statistics?.first?.value, 100)
230+
XCTAssertGreaterThanOrEqual(statistics?.first?.version ?? -1, 0)
231+
XCTAssertNotNil((statistics?.first?.object?[objectFieldKey] as? LCObject)?.createdAt)
232+
XCTAssertNil(statistics?.first?.user)
233+
XCTAssertNil(statistics?.first?.entity)
234+
exp.fulfill()
235+
}
236+
leaderboard1.getStatisticsWithObjectIds([objectId], option: option) { statistics, error in
237+
XCTAssertEqual(statistics?.count, 1)
238+
XCTAssertNil(error)
239+
XCTAssertEqual(leaderboard1.statisticName, statistics?.first?.name)
240+
XCTAssertEqual(statistics?.first?.value, 100)
241+
XCTAssertGreaterThanOrEqual(statistics?.first?.version ?? -1, 0)
242+
XCTAssertNotNil((statistics?.first?.object?[objectFieldKey] as? LCObject)?.createdAt)
243+
XCTAssertNil(statistics?.first?.user)
244+
XCTAssertNil(statistics?.first?.entity)
245+
exp.fulfill()
246+
}
247+
}
248+
}
223249
}

AVOS/LeanCloudObjcTests/LeanCloudObjcTests-Bridging-Header.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#import "LCErrorUtils.h"
77
#import "LCApplication_Internal.h"
88
#import "LCRouter_Internal.h"
9-
#import "LCPaasClient_internal.h"
9+
#import "LCPaasClient.h"
1010
#import "LCIMClient_Internal.h"
1111
#import "LCRTMConnection_Internal.h"
1212
#import "LCIMMessage_Internal.h"
13+
#import "LCLeaderboard_Internal.h"

0 commit comments

Comments
 (0)