use serde_json::json;usesuper::*;usecrate::media::keys::{media_limits, meeting_full_key, meeting_full_key_of, MediaKind};const WS: &str = "ws-1";fn ws() -> cotton_store::file_identity::FileId { cotton_store::file_identity::FileId::for_tests(WS)}/// THE TWO TABLES ARE ONE CONTRACT. An extension whose canonical type the/// server will not sign is a recording the phone files and the pipeline can/// never fetch — the key exists, the upload is refused 415, and the meeting/// waits for bytes that are never coming.#[test]fn every_containers_canonical_type_is_one_the_store_accepts() {for (ext, mime) in MEETING_AUDIO_FORMATS { assert!( MEETING_AUDIO_TYPES.contains(mime),"`{ext}` is written as `{mime}`, which the meeting limit does not accept" ); }// And the other way: the limit IS this list, so a type added to one and not// the other cannot hide. assert_eq!( media_limits(MediaKind::Meeting).content_types, MEETING_AUDIO_TYPES );}#[test]fn takes_the_containers_a_shared_voice_note_actually_arrives_in() {for mime in [// WhatsApp, which is the one the owner shares most."audio/ogg","audio/opus",// Voice Memos and the recorder."audio/mp4","audio/x-m4a",// Files."audio/mpeg","audio/wav","audio/flac","audio/amr","audio/x-caf", ] { assert!(MEETING_AUDIO_TYPES.contains(&mime), "meeting {mime}"); }// Not an audio file at all, and not silently accepted.for mime in ["application/pdf", "video/mp4", "image/jpeg", "text/plain"] { assert!(!MEETING_AUDIO_TYPES.contains(&mime), "meeting {mime}"); }}#[test]fn reads_a_container_off_an_extension_however_it_was_spelled() { assert_eq!(meeting_audio_mime_for_ext("opus"), Some("audio/ogg")); assert_eq!(meeting_audio_mime_for_ext(".OPUS"), Some("audio/ogg")); assert_eq!(meeting_audio_mime_for_ext(" m4a "), Some("audio/mp4")); assert_eq!(meeting_audio_mime_for_ext("mp3"), Some("audio/mpeg")); assert_eq!(meeting_audio_mime_for_ext("txt"), None); assert_eq!(meeting_audio_mime_for_ext(""), None); assert!(is_meeting_audio_ext("wav")); assert!(!is_meeting_audio_ext("pdf"));}/// The pipeline's own question, and the reason the constant `audio/m4a` had to/// go: an Ogg object announced as an m4a is a lie told to whichever vendor/// reads the multipart leg's content type.#[test]fn names_the_container_a_key_is_actually_in() { assert_eq!( meeting_audio_mime_of_key(&meeting_full_key_of(&ws(), "m-1", "opus")),"audio/ogg" ); assert_eq!( meeting_audio_mime_of_key(&meeting_full_key(&ws(), "m-1")),"audio/mp4" );// A key with no extension at all — nothing writes one, and it answers the// default container rather than an empty header. assert_eq!(meeting_audio_mime_of_key("ws-1/meetings/m-1/full"), "audio/mp4");}#[test]fn a_row_with_no_manifest_means_the_well_known_key() { assert_eq!( meeting_audio_object(&ws(), "m-1", &json!([])),MeetingAudioObject::At(meeting_full_key(&ws(), "m-1")) ); assert_eq!( meeting_audio_object(&ws(), "m-1", &serde_json::Value::Null),MeetingAudioObject::At(meeting_full_key(&ws(), "m-1")) );}/// The import's own shape: ONE entry, and it is where the real container lives.#[test]fn one_entry_names_the_object_the_import_wrote() {let key = meeting_full_key_of(&ws(), "m-1", "opus");let manifest = one_segment_manifest(&key, Some(90_000)); assert_eq!(manifest[0]["seq"], json!(0)); assert_eq!(manifest[0]["path"], json!(key)); assert_eq!(manifest[0]["durationMs"], json!(90_000)); assert_eq!(manifest[0]["uploadedAt"], serde_json::Value::Null); assert_eq!( meeting_audio_object(&ws(), "m-1", &manifest),MeetingAudioObject::At(key) );}#[test]fn a_lost_segment_is_a_gap_marker_and_not_an_input() {let manifest = json!([ { "seq": 0, "path": "ws-1/meetings/m-1/segments/000.m4a", "lost": true }, { "seq": 1, "path": "ws-1/meetings/m-1/segments/001.m4a" }, ]); assert_eq!( meeting_audio_object(&ws(), "m-1", &manifest),MeetingAudioObject::At("ws-1/meetings/m-1/segments/001.m4a".to_string()) );}#[test]fn two_usable_segments_are_refused_rather_than_half_transcribed() {let manifest = json!([ { "seq": 0, "path": "ws-1/meetings/m-1/segments/000.m4a" }, { "seq": 1, "path": "ws-1/meetings/m-1/segments/001.m4a" }, ]); assert_eq!( meeting_audio_object(&ws(), "m-1", &manifest),MeetingAudioObject::ManyObjects );}