File tree Expand file tree Collapse file tree 3 files changed +53
-12
lines changed
Expand file tree Collapse file tree 3 files changed +53
-12
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ class LCUserTestCase: BaseTestCase {
1414 static let testablePhoneNumber = " +8618622223333 "
1515 static let testableSMSCode = " 170402 "
1616
17+ /*
1718 func testVerifyPhoneNumberBySMSCode() {
18- /*
1919 let user = LCUser()
2020 let username = uuid
2121 let password = uuid
@@ -58,11 +58,11 @@ class LCUserTestCase: BaseTestCase {
5858 exp.fulfill()
5959 }
6060 }
61- */
6261 }
62+ */
6363
64+ /*
6465 func testUpdatePhoneNumberBySMSCode() {
65- /*
6666 let user = LCUser()
6767 let username = uuid
6868 let password = uuid
@@ -105,7 +105,40 @@ class LCUserTestCase: BaseTestCase {
105105 exp.fulfill()
106106 }
107107 }
108- */
108+ }
109+ */
110+
111+ func testLogOut( ) {
112+ var uid1 : String ?
113+ expecting { exp in
114+ LCUser . loginAnonymously { user, error in
115+ uid1 = user? . objectId
116+ XCTAssertNotNil ( uid1)
117+ XCTAssertNil ( error)
118+ exp. fulfill ( )
119+ }
120+ }
121+
122+ LCUser . logOut ( withClearingAnonymousId: false )
123+
124+ expecting { exp in
125+ LCUser . loginAnonymously { user, error in
126+ XCTAssertEqual ( uid1, user? . objectId)
127+ XCTAssertNil ( error)
128+ exp. fulfill ( )
129+ }
130+ }
131+
132+ LCUser . logOut ( )
133+
134+ expecting { exp in
135+ LCUser . loginAnonymously { user, error in
136+ XCTAssertNotNil ( user? . objectId)
137+ XCTAssertNotEqual ( uid1, user? . objectId)
138+ XCTAssertNil ( error)
139+ exp. fulfill ( )
140+ }
141+ }
109142 }
110143
111144 func testFriendshipRequestAccept( ) {
Original file line number Diff line number Diff line change @@ -322,14 +322,16 @@ FOUNDATION_EXPORT LeanCloudSocialPlatform const LeanCloudSocialPlatformWeiXin;
322322 password : (NSString *)password
323323 block : (LCUserResultBlock)block ;
324324
325+ // MARK: Log out
325326
326- /* * @name Logging Out */
327-
328- /* !
329- Logs out the currently logged in user on disk.
330- */
327+ // / Clearing local persistent cache data of the current user and set it to `nil`.
328+ // / It will also clearing local persistent cache of anonymous id.
331329+ (void )logOut ;
332330
331+ // / Clearing local persistent cache data of the current user and set it to `nil`.
332+ // / @param clearingAnonymousId `true` means clearing local persistent cache of anonymous id, `false` means NOT.
333+ + (void )logOutWithClearingAnonymousId : (BOOL )clearingAnonymousId ;
334+
333335/* * @name Requesting a Password Reset */
334336
335337
Original file line number Diff line number Diff line change @@ -647,11 +647,17 @@ + (void)signUpOrLoginWithMobilePhoneNumberInBackground:(NSString *)phoneNumber
647647 }];
648648}
649649
650- // MARK: - logout
650+ // MARK: Log out
651651
652652+ (void )logOut {
653- [[NSUserDefaults standardUserDefaults ] removeObjectForKey: AnonymousIdKey];
654- [[self class ] changeCurrentUser: nil save: YES ];
653+ [self logOutWithClearingAnonymousId: true ];
654+ }
655+
656+ + (void )logOutWithClearingAnonymousId : (BOOL )clearingAnonymousId {
657+ if (clearingAnonymousId) {
658+ [[NSUserDefaults standardUserDefaults ] removeObjectForKey: AnonymousIdKey];
659+ }
660+ [self changeCurrentUser: nil save: true ];
655661}
656662
657663// MARK: - password reset
You can’t perform that action at this time.
0 commit comments