Made the transcribing callable and per-call for the transcribing protocol in the Recording package target.
This commit is contained in:
@@ -312,7 +312,7 @@ struct RecordingViewModelTests {
|
||||
let recorder = RecordingServiceMock()
|
||||
let model = Model(
|
||||
recorder: recorder,
|
||||
transcriber: TranscribingServiceMock()
|
||||
transcribe: TranscribingMock()
|
||||
)
|
||||
|
||||
model.state = .processing
|
||||
@@ -348,7 +348,7 @@ struct RecordingViewModelTests {
|
||||
|
||||
@Test func `returns to not recording with a reset timer and a transcription`() async throws {
|
||||
let model = Model(
|
||||
transcriber: TranscribingServiceMock()
|
||||
transcribe: TranscribingMock()
|
||||
)
|
||||
|
||||
model.state = .recording
|
||||
@@ -372,12 +372,12 @@ struct RecordingViewModelTests {
|
||||
}
|
||||
|
||||
@Test func `clears the transcription when the transcriber fails`() async throws {
|
||||
let transcriber = TranscribingServiceMock()
|
||||
let transcriber = TranscribingMock()
|
||||
|
||||
transcriber.error = ErrorMock()
|
||||
|
||||
let model = Model(
|
||||
transcriber: transcriber
|
||||
transcribe: transcriber
|
||||
)
|
||||
|
||||
model.state = .processing
|
||||
@@ -392,7 +392,7 @@ struct RecordingViewModelTests {
|
||||
|
||||
@Test func `clears the transcription when a new recording starts`() async throws {
|
||||
let model = Model(
|
||||
transcriber: TranscribingServiceMock()
|
||||
transcribe: TranscribingMock()
|
||||
)
|
||||
|
||||
model.state = .processing
|
||||
@@ -472,7 +472,7 @@ private final class RecordingServiceMock: RecordingService {
|
||||
|
||||
/// A transcribing service with a configurable delay, output, and failure.
|
||||
@MainActor
|
||||
private final class TranscribingServiceMock: TranscribingService {
|
||||
private final class TranscribingMock: Transcribing {
|
||||
|
||||
/// The duration of the simulated transcription work.
|
||||
var delay: Duration = .seconds(0.2)
|
||||
@@ -483,14 +483,14 @@ private final class TranscribingServiceMock: TranscribingService {
|
||||
/// The transcription the service returns.
|
||||
var transcription = "This is a mocked transcription."
|
||||
|
||||
func transcribe(_ audio: Data) async throws -> String {
|
||||
func callAsFunction(_ audio: Data, locale: Locale) async throws -> Transcription {
|
||||
try await Task.sleep(for: delay)
|
||||
|
||||
if let error {
|
||||
throw error
|
||||
}
|
||||
|
||||
return transcription
|
||||
return .init(text: transcription)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user