340fca7bd7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014FsEKyJrYF69Cj9ZXzFLRi
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
//go:build live
|
||
|
||
package lkgateway
|
||
|
||
import (
|
||
"bytes"
|
||
"context"
|
||
"fmt"
|
||
"os"
|
||
"regexp"
|
||
"strings"
|
||
"testing"
|
||
|
||
"git.zetit.ru/zuevav/Bridge-and-Join-s/internal/m2mcore"
|
||
)
|
||
|
||
// Путь заявки на живых данных: go test -c -tags live; запуск от bj с TL_ID=<id сделки>.
|
||
func TestTimelineLive(t *testing.T) {
|
||
rc, err := NewRuntimeConfig("/var/lib/bj/.bj/setup.json")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
globalRC = rc
|
||
globalOutgoingStore = NewOutgoingStore()
|
||
repo, err := m2mcore.NewPostgresRepository(context.Background(), rc.Snapshot().Postgres.DSN)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
svc := NewService(Config{Repository: repo})
|
||
for _, id := range strings.Split(os.Getenv("TL_ID"), ",") {
|
||
v, err := svc.GetClaim(context.Background(), id)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
v.Timeline = buildClaimTimeline(context.Background(), v)
|
||
fmt.Printf("=== %s создана %s обновлена(сделка) %s, последнее событие %s\n", id[:8], v.CreatedAt.Format("15:04:05 MST"), v.UpdatedAt.Format("15:04:05 MST"), timelineLast(v.Timeline).Format("15:04:05"))
|
||
for _, e := range v.Timeline {
|
||
fmt.Printf(" %-9s %-8s [%s] %s — %s\n", e.Time.Format("15:04:05"), e.Since, e.Kind, e.Title, e.Detail)
|
||
}
|
||
if os.Getenv("TL_HTML") != "" {
|
||
a, _ := newAdmin()
|
||
var b bytes.Buffer
|
||
if err := a.claim.ExecuteTemplate(&b, "layout", claimData{page: page{Title: "Заявка"}, Claim: v, Watch: globalOrderWatch.Get(string(v.M2MGUID))}); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
txt := regexp.MustCompile(`(?s)<style.*?</style>|<script.*?</script>`).ReplaceAllString(b.String(), "")
|
||
txt = regexp.MustCompile(`<[^>]+>`).ReplaceAllString(txt, " ")
|
||
txt = regexp.MustCompile(`\s+`).ReplaceAllString(txt, " ")
|
||
i := strings.Index(txt, "Заявка ")
|
||
fmt.Println(txt[i:min(len(txt), i+1500)])
|
||
}
|
||
}
|
||
}
|