Skip to content

Commit eb9a866

Browse files
committed
test: update
1 parent 94b2b6c commit eb9a866

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

LeanCloudTests/IMConversationTestCase.swift

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -208,56 +208,55 @@ class IMConversationTestCase: RTMBaseTestCase {
208208
break
209209
}
210210
}
211-
try? clientA.createConversation(clientIDs: [clientA.ID, clientB.ID], completion: { (result) in
212-
if let conv: IMConversation = result.value {
213-
XCTAssertTrue(type(of: conv) == IMConversation.self)
214-
XCTAssertEqual(conv.rawData["objectId"] as? String, conv.ID)
215-
XCTAssertEqual(conv.rawData["conv_type"] as? Int, 1)
216-
XCTAssertEqual(conv.convType, .normal)
217-
XCTAssertTrue(conv.isUnique)
218-
XCTAssertNotNil(conv.uniqueID)
219-
} else {
220-
XCTFail()
221-
}
222-
exp1.fulfill()
223-
})
211+
let existingKey = "existingKey"
212+
let existingValue = "existingValue"
213+
try? clientA.createConversation(
214+
clientIDs: [clientA.ID, clientB.ID],
215+
attributes: [existingKey : existingValue],
216+
completion: { (result) in
217+
if let conv: IMConversation = result.value {
218+
XCTAssertTrue(type(of: conv) == IMConversation.self)
219+
XCTAssertEqual(conv.rawData["objectId"] as? String, conv.ID)
220+
XCTAssertEqual(conv.rawData["conv_type"] as? Int, 1)
221+
XCTAssertEqual(conv.convType, .normal)
222+
XCTAssertTrue(conv.isUnique)
223+
XCTAssertNotNil(conv.uniqueID)
224+
XCTAssertFalse(conv.isOutdated)
225+
XCTAssertEqual(conv.attributes?[existingKey] as? String, existingValue)
226+
} else {
227+
XCTFail()
228+
}
229+
exp1.fulfill()
230+
})
224231
wait(for: [exp1], timeout: timeout)
225232

226233
delegatorA.conversationEvent = nil
227234
delegatorB.conversationEvent = nil
228235

229-
let exp2 = expectation(description: "create unique conversation")
230-
exp2.expectedFulfillmentCount = 5
231-
delegatorA.conversationEvent = { _, _, event in
232-
switch event {
233-
case .joined:
234-
exp2.fulfill()
235-
case .membersJoined:
236-
exp2.fulfill()
237-
default:
238-
break
239-
}
240-
}
241-
delegatorB.conversationEvent = { _, _, event in
242-
switch event {
243-
case .joined:
244-
exp2.fulfill()
245-
case .membersJoined:
246-
exp2.fulfill()
247-
default:
248-
break
249-
}
250-
}
236+
delay(seconds: 5)
237+
238+
clientB.convCollection.removeAll()
239+
240+
let exp2 = expectation(description: "recreate unique conversation")
251241
try? clientB.createConversation(clientIDs: [clientA.ID, clientB.ID], completion: { (result) in
252242
if let conv: IMConversation = result.value {
253243
XCTAssertTrue(type(of: conv) == IMConversation.self)
254244
XCTAssertEqual(conv.convType, .normal)
255245
XCTAssertTrue(conv.isUnique)
256246
XCTAssertNotNil(conv.uniqueID)
247+
XCTAssertTrue(conv.isOutdated)
248+
XCTAssertNil(conv.attributes?[existingKey])
249+
try? conv.refresh { result in
250+
XCTAssertTrue(result.isSuccess)
251+
XCTAssertNil(result.error)
252+
XCTAssertFalse(conv.isOutdated)
253+
XCTAssertEqual(conv.attributes?[existingKey] as? String, existingValue)
254+
exp2.fulfill()
255+
}
257256
} else {
258257
XCTFail()
258+
exp2.fulfill()
259259
}
260-
exp2.fulfill()
261260
})
262261
wait(for: [exp2], timeout: timeout)
263262

0 commit comments

Comments
 (0)