Files
pipeline_backend/workers/transcribe/internal/models/models_test.go

59 lines
1.3 KiB
Go
Raw Normal View History

2026-06-24 18:58:35 +03:00
package models
import (
"encoding/json"
"testing"
)
func TestAudioTaskRoundTrip(t *testing.T) {
src := AudioTask{
TaskID: "01HX",
FilePath: "/data/processing/01HX.wav",
Filename: "call.wav",
Size: 2048,
CreatedAt: 1717843200,
}
body, err := json.Marshal(src)
if err != nil {
t.Fatal(err)
}
var got AudioTask
if err := json.Unmarshal(body, &got); err != nil {
t.Fatal(err)
}
if got != src {
t.Fatalf("round-trip mismatch: %+v vs %+v", got, src)
}
}
func TestTranscriptionResultRoundTrip(t *testing.T) {
src := TranscriptionResult{
TaskID: "01HX",
Filename: "call.wav",
FilePath: "/data/processing/01HX.wav",
Transcription: "текст звонка",
Language: "ru",
Segments: []Segment{
{Start: 0, End: 1.2, Text: "текст"},
},
Prompts: []Prompt{
{ID: 1, IDSection: 1, Name: "behavioral", Prompt: "analyze", DtCreate: "2026-01-01"},
},
TranscribedAt: 1717843200,
}
body, err := json.Marshal(src)
if err != nil {
t.Fatal(err)
}
var got TranscriptionResult
if err := json.Unmarshal(body, &got); err != nil {
t.Fatal(err)
}
if got.TaskID != src.TaskID || got.Transcription != src.Transcription {
t.Fatalf("mismatch: %+v", got)
}
if len(got.Segments) != 1 || len(got.Prompts) != 1 {
t.Fatalf("nested fields lost: %+v", got)
}
}