use raqeem_core::{Endpoint, Transcriber};
#[test]
fn posts_multipart_with_auth_and_parses_arabic_text() {
let mut server = mockito::Server::new();
let mock = server
.mock("POST", "/v2/audio/transcriptions")
.match_header("authorization", "Bearer testkey")
.match_body(mockito::Matcher::AllOf(vec![
mockito::Matcher::Regex("cohere-transcribe-arabic".to_string()),
mockito::Matcher::Regex(
r#"(?s)name="model".*name="language".*name="file""#.to_string(),
),
]))
.with_status(200)
.with_header("content-type", "application/json")
.with_body(r#"{"text": "الطماطم بـ ١٢٫٥ جنيه"}"#)
.create();
let url = format!("{}/v2/audio/transcriptions", server.url());
let endpoint =
Endpoint::openai_compatible(url, "cohere-transcribe-arabic", Some("testkey".into()));
let audio = std::env::temp_dir().join("RAQEEM_test_clip.wav");
std::fs::write(&audio, b"RIFF....WAVEfake").unwrap();
let t = Transcriber::new(endpoint)
.language("ar")
.transcribe(&audio)
.expect("transcribe should succeed against the mock");
assert_eq!(t.text, "الطماطم بـ ١٢٫٥ جنيه"); assert!(t.text_normalized.contains("12.5")); assert!(!t.text_normalized.contains('ـ')); assert_eq!(t.language, "ar");
assert_eq!(t.provider, "openai-compatible");
mock.assert();
let _ = std::fs::remove_file(&audio);
}
#[test]
fn surfaces_api_errors_with_status_and_body() {
let mut server = mockito::Server::new();
let _mock = server
.mock("POST", "/v1/audio/transcriptions")
.with_status(401)
.with_body("unauthorized")
.create();
let url = format!("{}/v1/audio/transcriptions", server.url());
let endpoint = Endpoint::openai_compatible(url, "m", None);
let audio = std::env::temp_dir().join("RAQEEM_test_clip2.wav");
std::fs::write(&audio, b"x").unwrap();
let err = Transcriber::new(endpoint).transcribe(&audio).unwrap_err();
let msg = err.to_string();
assert!(msg.contains("401"), "expected status in error, got: {msg}");
let _ = std::fs::remove_file(&audio);
}