Transition voice messages to the new in thread sending mechanism

This commit is contained in:
Stefan Ceriu
2025-07-22 10:41:30 +03:00
committed by Stefan Ceriu
parent ed98f64a35
commit 3fcbc8c60a
8 changed files with 76 additions and 69 deletions
@@ -192,13 +192,12 @@ class VoiceMessageRecorderTests: XCTestCase {
}
func testSendVoiceMessage_NoRecordingFile() async throws {
let roomProxy = JoinedRoomProxyMock()
let timelineController = MockTimelineController()
// If there is no recording file, an error is expected
audioRecorder.audioFileURL = nil
guard case .failure(.missingRecordingFile) = await voiceMessageRecorder.sendVoiceMessage(inRoom: roomProxy,
audioConverter: audioConverter,
threadRootEventID: nil) else {
guard case .failure(.missingRecordingFile) = await voiceMessageRecorder.sendVoiceMessage(timelineController: timelineController,
audioConverter: audioConverter) else {
XCTFail("An error is expected")
return
}
@@ -209,10 +208,9 @@ class VoiceMessageRecorderTests: XCTestCase {
// If the converter returns an error
audioConverter.convertToOpusOggSourceURLDestinationURLThrowableError = AudioConverterError.conversionFailed(nil)
let roomProxy = JoinedRoomProxyMock()
guard case .failure(.failedSendingVoiceMessage) = await voiceMessageRecorder.sendVoiceMessage(inRoom: roomProxy,
audioConverter: audioConverter,
threadRootEventID: nil) else {
let timelineController = MockTimelineController()
guard case .failure(.failedSendingVoiceMessage) = await voiceMessageRecorder.sendVoiceMessage(timelineController: timelineController,
audioConverter: audioConverter) else {
XCTFail("An error is expected")
return
}
@@ -229,12 +227,10 @@ class VoiceMessageRecorderTests: XCTestCase {
}
let timelineProxy = TimelineProxyMock()
let roomProxy = JoinedRoomProxyMock()
roomProxy.timeline = timelineProxy
timelineProxy.sendVoiceMessageUrlAudioInfoWaveformThreadRootEventIDRequestHandleReturnValue = .failure(.sdkError(SDKError.generic))
guard case .failure(.failedSendingVoiceMessage) = await voiceMessageRecorder.sendVoiceMessage(inRoom: roomProxy,
audioConverter: audioConverter,
threadRootEventID: nil) else {
let timelineController = MockTimelineController(timelineProxy: timelineProxy)
timelineProxy.sendVoiceMessageUrlAudioInfoWaveformRequestHandleReturnValue = .failure(.sdkError(SDKError.generic))
guard case .failure(.failedSendingVoiceMessage) = await voiceMessageRecorder.sendVoiceMessage(timelineController: timelineController,
audioConverter: audioConverter) else {
XCTFail("An error is expected")
return
}
@@ -252,12 +248,10 @@ class VoiceMessageRecorderTests: XCTestCase {
}
let timelineProxy = TimelineProxyMock()
let roomProxy = JoinedRoomProxyMock()
roomProxy.timeline = timelineProxy
timelineProxy.sendVoiceMessageUrlAudioInfoWaveformThreadRootEventIDRequestHandleReturnValue = .failure(.sdkError(SDKError.generic))
guard case .failure(.failedSendingVoiceMessage) = await voiceMessageRecorder.sendVoiceMessage(inRoom: roomProxy,
audioConverter: audioConverter,
threadRootEventID: nil) else {
let timelineController = MockTimelineController(timelineProxy: timelineProxy)
timelineProxy.sendVoiceMessageUrlAudioInfoWaveformRequestHandleReturnValue = .failure(.sdkError(SDKError.generic))
guard case .failure(.failedSendingVoiceMessage) = await voiceMessageRecorder.sendVoiceMessage(timelineController: timelineController,
audioConverter: audioConverter) else {
XCTFail("An error is expected")
return
}
@@ -277,12 +271,10 @@ class VoiceMessageRecorderTests: XCTestCase {
// If the media upload fails
let timelineProxy = TimelineProxyMock()
let roomProxy = JoinedRoomProxyMock()
roomProxy.timeline = timelineProxy
timelineProxy.sendVoiceMessageUrlAudioInfoWaveformThreadRootEventIDRequestHandleReturnValue = .failure(.sdkError(SDKError.generic))
guard case .failure(.failedSendingVoiceMessage) = await voiceMessageRecorder.sendVoiceMessage(inRoom: roomProxy,
audioConverter: audioConverter,
threadRootEventID: nil) else {
let timelineController = MockTimelineController(timelineProxy: timelineProxy)
timelineProxy.sendVoiceMessageUrlAudioInfoWaveformRequestHandleReturnValue = .failure(.sdkError(SDKError.generic))
guard case .failure(.failedSendingVoiceMessage) = await voiceMessageRecorder.sendVoiceMessage(timelineController: timelineController,
audioConverter: audioConverter) else {
XCTFail("An error is expected")
return
}
@@ -295,8 +287,7 @@ class VoiceMessageRecorderTests: XCTestCase {
}
let timelineProxy = TimelineProxyMock()
let roomProxy = JoinedRoomProxyMock()
roomProxy.timeline = timelineProxy
let timelineController = MockTimelineController(timelineProxy: timelineProxy)
audioRecorder.currentTime = 42
audioRecorder.audioFileURL = imageFileURL
_ = await voiceMessageRecorder.startRecording()
@@ -317,7 +308,7 @@ class VoiceMessageRecorderTests: XCTestCase {
XCTAssertEqual(destination.pathExtension, "ogg")
}
timelineProxy.sendVoiceMessageUrlAudioInfoWaveformThreadRootEventIDRequestHandleClosure = { url, audioInfo, waveform, _, _ in
timelineProxy.sendVoiceMessageUrlAudioInfoWaveformRequestHandleClosure = { url, audioInfo, waveform, _ in
XCTAssertEqual(url, convertedFileURL)
XCTAssertEqual(audioInfo.duration, self.audioRecorder.currentTime)
XCTAssertEqual(audioInfo.size, convertedFileSize)
@@ -327,13 +318,13 @@ class VoiceMessageRecorderTests: XCTestCase {
return .success(())
}
guard case .success = await voiceMessageRecorder.sendVoiceMessage(inRoom: roomProxy, audioConverter: audioConverter, threadRootEventID: nil) else {
guard case .success = await voiceMessageRecorder.sendVoiceMessage(timelineController: timelineController, audioConverter: audioConverter) else {
XCTFail("A success is expected")
return
}
XCTAssert(audioConverter.convertToOpusOggSourceURLDestinationURLCalled)
XCTAssert(timelineProxy.sendVoiceMessageUrlAudioInfoWaveformThreadRootEventIDRequestHandleCalled)
XCTAssert(timelineProxy.sendVoiceMessageUrlAudioInfoWaveformRequestHandleCalled)
// the converted file must have been deleted
if let convertedFileURL {