Fixed some issues with voice messages when sent from a bridge. (#2190)

This commit is contained in:
Nicolas Mauri
2023-11-30 17:39:54 +01:00
committed by GitHub
parent 9d9cf1c5a1
commit edbac5fe85
7 changed files with 47 additions and 6 deletions
@@ -171,8 +171,9 @@ class AudioPlayerStateTests: XCTestCase {
}
func testHandlingAudioPlayerActionDidFinishLoading() async throws {
let originalStateProgress = 0.4
await audioPlayerState.updateState(progress: originalStateProgress)
audioPlayerMock.duration = 10.0
audioPlayerState = AudioPlayerState(id: .timelineItemIdentifier(.random), duration: 0)
audioPlayerState.attachAudioPlayer(audioPlayerMock)
let deferred = deferFulfillment(audioPlayerState.$playbackState) { action in
@@ -189,6 +190,8 @@ class AudioPlayerStateTests: XCTestCase {
// The state is expected to be .readyToPlay
XCTAssertEqual(audioPlayerState.playbackState, .readyToPlay)
// The duration should have been updated with the player's duration
XCTAssertEqual(audioPlayerState.duration, audioPlayerMock.duration)
}
func testHandlingAudioPlayerActionDidStartPlaying() async throws {
@@ -52,6 +52,29 @@ class VoiceMessageMediaManagerTests: XCTestCase {
}
}
func testLoadVoiceMessageFromSourceMimeTypeWithParameters() async throws {
// URL representing the file loaded by the media provider
let loadedFile = URL("/some/url/loaded_file.ogg")
// URL representing the final cached file
let cachedConvertedFileURL = URL("/some/url/cached_converted_file.m4a")
voiceMessageCache.fileURLForReturnValue = nil
let mediaSource = MediaSourceProxy(url: someURL, mimeType: "audio/ogg; codecs=opus")
mediaProvider.loadFileFromSourceReturnValue = MediaFileHandleProxy.unmanaged(url: loadedFile)
voiceMessageCache.cacheMediaSourceUsingMoveReturnValue = .success(cachedConvertedFileURL)
voiceMessageMediaManager = VoiceMessageMediaManager(mediaProvider: mediaProvider,
voiceMessageCache: voiceMessageCache,
audioConverter: AudioConverterMock(),
backgroundTaskService: MockBackgroundTaskService())
do {
_ = try await voiceMessageMediaManager.loadVoiceMessageFromSource(mediaSource, body: nil)
} catch {
XCTFail("An unexpected error has occured: \(error)")
}
}
func testLoadVoiceMessageFromSourceAlreadyCached() async throws {
// Check if the file is already present in cache
voiceMessageCache.fileURLForReturnValue = URL("/converted_file/url")