dana-medical-site/internal/api/report_sberhealth_large_test.go
2026-10-14 13:33:13 +00:00

50 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package api
import (
"os"
"testing"
"time"
"dana/internal/sberhealth"
)
// Opt-in регрессия на большую выгрузку СберЗдоровья (> 8 КБ, общая таблица строк идёт через CONTINUE).
// Файл берётся только из локальной переменной окружения, в репозиторий не копируется и не печатается.
// Эталон снят независимым читателем (xlrd): 209 записей и 186 уникальных телефонов за 06.07–05.10.2026
// (в трёх ячейках по нескольку номеров; считая только первый номер ячейки, было бы 183).
// Прежняя библиотека (extrame/xls) смещала значения: давала 154 телефона и неверные даты в 57 строках.
func TestSberHealthLargeExportSample(t *testing.T) {
path := os.Getenv("DANA_SBER_LARGE_SAMPLE_FILE")
if path == "" {
t.Skip("local large sample not supplied")
}
data, err := os.ReadFile(path)
if err != nil {
t.Fatal("cannot read local sample")
}
rows, err := sberhealth.ReadXLS(data)
if err != nil {
t.Fatal(err)
}
from := time.Date(2026, 7, 6, 0, 0, 0, 0, moscow)
to := time.Date(2026, 10, 6, 0, 0, 0, 0, moscow)
phones, records, total, err := parseSberHealthRows(rows, from, to)
if err != nil {
t.Fatal(err)
}
if len(phones) != 186 || records != 209 || total != 209 {
t.Fatalf("large sample does not reconcile: phones=%d records=%d total=%d", len(phones), records, total)
}
// Тот же файл, приложенный к отчёту пользователем.
opts, err := sberhealthUploadOpts(data, from, to)
if err != nil || opts.sberhealthInfo == nil || opts.sberhealthInfo.Records != 209 || opts.sberhealthInfo.Phones != 186 ||
len(opts.pbxLists["сберздоровье"]) != 186 {
t.Fatal("uploaded export was not applied to the channel", err)
}
// Файл не за тот период (записи есть, но в период отчёта не попадают): явная ошибка, а не пустой канал.
if _, err := sberhealthUploadOpts(data, time.Date(2026, 1, 1, 0, 0, 0, 0, moscow), time.Date(2026, 1, 8, 0, 0, 0, 0, moscow)); err == nil {
t.Fatal("export for another period accepted")
}
}