feat(通知): SafeW 只发正文并注入推送时间
去掉渠道标题前缀,模板可用 pushedAt 显示本地推送时间。
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"aiaa-notification-service/internal/engine"
|
||||
@@ -28,9 +29,15 @@ func (f *fakeTemplates) GetTemplate(context.Context, int) (*model.Template, erro
|
||||
return f.tmpl, f.err
|
||||
}
|
||||
|
||||
type fakeRouter struct{ channels []string }
|
||||
type fakeRouter struct {
|
||||
channels []string
|
||||
title string
|
||||
content string
|
||||
}
|
||||
|
||||
func (f *fakeRouter) Route(context.Context, *model.Rule, string, string) []string {
|
||||
func (f *fakeRouter) Route(_ context.Context, _ *model.Rule, title, content string) []string {
|
||||
f.title = title
|
||||
f.content = content
|
||||
return f.channels
|
||||
}
|
||||
|
||||
@@ -111,6 +118,29 @@ func TestProcessTemplateCanSwitchOnEvent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessInjectsPushedAt(t *testing.T) {
|
||||
rt := &fakeRouter{channels: []string{"safew:1"}}
|
||||
svc := newSvc(
|
||||
&fakeMatcher{rule: &model.Rule{ID: 9, TemplateID: 1}},
|
||||
&fakeTemplates{tmpl: &model.Template{ID: 1, Content: `{{line "推送时间" .pushedAt}}`}},
|
||||
rt,
|
||||
)
|
||||
res, err := svc.Process(context.Background(), Request{
|
||||
Source: &model.Source{ID: 1, Name: "crypto-strategy"},
|
||||
Event: "trade.open",
|
||||
Data: map[string]interface{}{"symbol": "QNT"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !res.Matched {
|
||||
t.Fatalf("%+v", res)
|
||||
}
|
||||
if !strings.Contains(rt.content, "推送时间:") {
|
||||
t.Fatalf("content=%q", rt.content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessInvalidConditions(t *testing.T) {
|
||||
raw := json.RawMessage(`not-json`)
|
||||
svc := newSvc(&fakeMatcher{rule: &model.Rule{ID: 1, TemplateID: 1, Conditions: &raw}}, &fakeTemplates{}, &fakeRouter{})
|
||||
|
||||
Reference in New Issue
Block a user