-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
element-hq/element-ios/issues/5114 - Added multi user and gappy sync …
…intregration tests. Added simple poll aggregator.
- Loading branch information
1 parent
780cf6b
commit 6686dda
Showing
8 changed files
with
479 additions
and
185 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Copyright 2021 The Matrix.org Foundation C.I.C | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
struct MXPollAnswerOption { | ||
let id: String | ||
let text: String | ||
} | ||
|
||
struct MXPoll { | ||
let text: String | ||
let answerOptions: [MXPollAnswerOption] | ||
} | ||
|
||
class MXPollAggregator { | ||
|
||
private let session: MXSession | ||
private let room: MXRoom | ||
private let pollStartEvent: MXEvent | ||
private let eventListener: Any | ||
|
||
deinit { | ||
room.removeListener(eventListener) | ||
} | ||
|
||
init(session: MXSession, room: MXRoom, pollStartEvent: MXEvent) { | ||
self.session = session | ||
self.room = room | ||
self.pollStartEvent = pollStartEvent | ||
|
||
let pollContent = MXEventContentPollStart(fromJSON: pollStartEvent.content)! | ||
|
||
let poll = MXPoll(text: pollContent.question, answerOptions: pollContent.answerOptions.compactMap({ answerOption in | ||
MXPollAnswerOption(id: answerOption.uuid, text: answerOption.text) | ||
})) | ||
|
||
eventListener = room.listen(toEventsOfTypes: [kMXEventTypeStringPollResponse, kMXEventTypeStringPollEnd]) { event, direction, state in | ||
|
||
} as Any | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// Copyright 2021 The Matrix.org Foundation C.I.C | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
class PollAggregatorTest: XCTestCase { | ||
private var matrixSDKTestsData: MatrixSDKTestsData! | ||
|
||
private var matrixSDKTestsE2EData: MatrixSDKTestsE2EData! | ||
|
||
private var pollAggregator: MXPollAggregator! | ||
|
||
override func setUp() { | ||
matrixSDKTestsData = MatrixSDKTestsData() | ||
matrixSDKTestsE2EData = MatrixSDKTestsE2EData(matrixSDKTestsData: matrixSDKTestsData) | ||
} | ||
|
||
override func tearDown() { | ||
matrixSDKTestsData = nil | ||
matrixSDKTestsE2EData = nil | ||
} | ||
|
||
func testAggregator() { | ||
self.createScenarioForBobAndAlice { bobSession, bobRoom, event, expectation in | ||
self.pollAggregator = MXPollAggregator(session: bobSession, room: bobRoom, pollStartEvent: event) | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 5) { | ||
expectation.fulfill() | ||
} | ||
|
||
} | ||
} | ||
|
||
func createScenarioForBobAndAlice(_ readyToTest: @escaping (MXSession, MXRoom, MXEvent, XCTestExpectation)->Void) { | ||
|
||
self.matrixSDKTestsData.doTestWithAliceAndBob(inARoom: self, aliceStore: MXMemoryStore(), bobStore: MXMemoryStore()) { aliceSession, bobSession, roomId, expectation in | ||
|
||
let room = bobSession?.room(withRoomId: roomId) | ||
|
||
let answerOptions = [MXEventContentPollStartAnswerOption(uuid: UUID().uuidString, text: "First answer"), | ||
MXEventContentPollStartAnswerOption(uuid: UUID().uuidString, text: "Second answer")] | ||
|
||
let pollStartContent = MXEventContentPollStart(question: "Question", kind: kMXMessageContentKeyExtensiblePollKindDisclosed, maxSelections: 1, answerOptions: answerOptions) | ||
|
||
room?.sendPollStart(withContent: pollStartContent, localEcho: nil, success: { pollStartEventId in | ||
|
||
bobSession?.event(withEventId: pollStartEventId, inRoom: roomId, success: { pollStartEvent in | ||
readyToTest(bobSession!, room!, pollStartEvent!, expectation!) | ||
|
||
let aliceRoom = aliceSession?.room(withRoomId: roomId) | ||
aliceRoom?.sendPollResponse(for: pollStartEvent, withAnswerIdentifiers: [pollStartContent.answerOptions.first!.uuid], localEcho: nil, success: { _ in | ||
|
||
}, failure: { error in | ||
XCTFail("The operation should not fail - NSError: \(String(describing: error))") | ||
expectation?.fulfill() | ||
}) | ||
|
||
}, failure: { error in | ||
XCTFail("The operation should not fail - NSError: \(String(describing: error))") | ||
expectation?.fulfill() | ||
}) | ||
}, failure: { error in | ||
XCTFail("The operation should not fail - NSError: \(String(describing: error))") | ||
expectation?.fulfill() | ||
}) | ||
} | ||
} | ||
} |
Oops, something went wrong.