diff --git a/tests/pacs_008_test.go b/tests/pacs_008_test.go new file mode 100644 index 0000000..7fb4287 --- /dev/null +++ b/tests/pacs_008_test.go @@ -0,0 +1,36 @@ +package tests + +import ( + "encoding/xml" + "strings" + "testing" + + "github.com/moov-io/base" + "github.com/moov-io/rtp20022/gen/messages" + + "github.com/stretchr/testify/require" +) + +func TestPacs008(t *testing.T) { + input := `000000010B1200000058T1B20231206000000010B1B00335081122910pacs.008.001.082023-12-06T23:08:38FZ5WNW1KttP2ZoEkvu5YliFKRxzuwxAPSTeAafm4HCA=kqN8hzwC0KmMKVVXbwOWWxdLBhn3gb0jA0a9wpQz85CcgPE0hR1zA5A7gv4WWvFooqnMLotzLQ/tzaGKjbbPm1Bf08XLc+BcWVzXjCfRSMNtpR+gMp50ODGlvNafrMHnsummGkFWF3+HGivCFpkLWSzau2+20DKsCxAQGGdhWCMfDqcYWfRVrkVWKVfz+YDUF7K7U7hXVM3DuWhJMcxmcIwGern/14KX+fIecMxsE2+a8R+sOPr5gYQ+TOwwFo/bwGCHTT5MLSgOpa+1+fLYnxY0QVYXihIGMYuy+JyW3JS+1FkzRU4X3oWayfe8FEVnkTTHZ0kTx/pFuOdLY5pZvg==CN=DigiCert Global G2 TLS RSA SHA256 2020 CA1,O=DigiCert Inc,C=US7733185569732290893228546868636904811CN=bc553361-9e6a-468f-9941-e7acb234513d.moov.io,O=Moov Financial Inc.,L=Cedar Falls,ST=Iowa,C=USM20231206000000010B1B003350811229102023-12-06T23:08:381526.332023-12-06CLRGTCH20231206200000057T1B123840081122910NOREF20231206200000057T1B123840081122910SDVAINTERMEDIARYCONSUMER526.33SLEV123456780987654320Moov, Inc65434577456456123456780987654320Jane Doe842 Other Ave89415Green StreamIAUS74625332505100907` + + t.Run("parse and validate, while expecting errors", func(t *testing.T) { + var m messages.Message + err := xml.NewDecoder(strings.NewReader(input)).Decode(&m) + require.NoError(t, err) + + err = m.Validate() + require.Error(t, err) + + el, ok := err.(base.ErrorList) + require.True(t, ok) + require.Len(t, el, 5) + + // Check each error + require.ErrorContains(t, el[0], "PostalAddress24TCH.StrtNm: fails validation with length 0 >= required minLength 1") + require.ErrorContains(t, el[1], "PostalAddress24TCH.PstCd: fails validation with length 0 >= required minLength 1") + require.ErrorContains(t, el[2], "PostalAddress24TCH.TwnNm: fails validation with length 0 >= required minLength 1") + require.ErrorContains(t, el[3], "PostalAddress24TCH.CtrySubDvsn: fails validation with length 0 >= required minLength 1") + require.ErrorContains(t, el[4], "PostalAddress24TCH.Ctry: fails validation with pattern [A-Z]{2,2}") + }) +}