48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
|
|
package tests
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/yourorg/go-dw-platform/services/omnix-broadcast/domain"
|
||
|
|
"github.com/yourorg/go-dw-platform/services/omnix-broadcast/transformer"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestBuildDynamicMessage_Ordered(t *testing.T) {
|
||
|
|
tf := transformer.New()
|
||
|
|
|
||
|
|
variables := []*domain.TemplateVariable{
|
||
|
|
{VariableOrder: 1, VariableName: "Nama", VariableType: "string", FieldSource: "nasabah_nama", IsRequired: true},
|
||
|
|
{VariableOrder: 2, VariableName: "TotalTagihan", VariableType: "integer", FieldSource: "nominal_tagihan", IsRequired: true},
|
||
|
|
{VariableOrder: 3, VariableName: "TanggalJatuhTempo", VariableType: "date", FieldSource: "tanggal_tempo", IsRequired: true},
|
||
|
|
}
|
||
|
|
|
||
|
|
payload := map[string]any{
|
||
|
|
"nasabah_nama": "Budi Santoso",
|
||
|
|
"nominal_tagihan": 1500000.0,
|
||
|
|
"tanggal_tempo": "2026-06-30",
|
||
|
|
}
|
||
|
|
|
||
|
|
message, err := tf.BuildDynamicMessage(variables, payload)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("expected no error, got %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
want := "Budi Santoso#1500000#2026-06-30"
|
||
|
|
if message != want {
|
||
|
|
t.Fatalf("expected %q, got %q", want, message)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestBuildDynamicMessage_MissingRequiredField(t *testing.T) {
|
||
|
|
tf := transformer.New()
|
||
|
|
|
||
|
|
variables := []*domain.TemplateVariable{
|
||
|
|
{VariableOrder: 1, VariableName: "Nama", VariableType: "string", FieldSource: "nasabah_nama", IsRequired: true},
|
||
|
|
}
|
||
|
|
|
||
|
|
_, err := tf.BuildDynamicMessage(variables, map[string]any{})
|
||
|
|
if err == nil {
|
||
|
|
t.Fatal("expected error for missing required field, got nil")
|
||
|
|
}
|
||
|
|
}
|