forked from invopop/gobl.fatturapa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Our SOAP server needs to be able to parse different types of incoming requests. Here we prepare a structure that accepts the different types of messages that SDI might send us and we parse the message. We still need to decide how we want to pass in the handling of the message.
- Loading branch information
Showing
3 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package sdi_test | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"log" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
sdi "github.com/invopop/gobl.fatturapa/sdi" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseMessage(t *testing.T) { | ||
t.Run("parse MetadatiInvioFile", func(t *testing.T) { | ||
var buf bytes.Buffer | ||
log.SetOutput(&buf) | ||
defer func() { | ||
log.SetOutput(os.Stderr) | ||
}() | ||
|
||
message := `<?xml version='1.0' encoding='UTF-8'?>` + | ||
`<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:typ='http://www.fatturapa.gov.it/sdi/ws/trasmissione/v1.0/types'>` + | ||
`<soapenv:Header/>` + | ||
`<soapenv:Body>` + | ||
`<ns3:MetadatiInvioFile xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://www.fatturapa.gov.it/sdi/messaggi/v1.0" versione="1.0">` + | ||
`<IdentificativoSdI>29218239</IdentificativoSdI>` + | ||
`<NomeFile>ESB85905495_00010.xml</NomeFile>` + | ||
`<CodiceDestinatario>WSBKWM</CodiceDestinatario>` + | ||
`<Formato>FPA12</Formato>` + | ||
`<TentativiInvio>1</TentativiInvio>` + | ||
`<MessageId>176121330</MessageId>` + | ||
`</ns3:MetadatiInvioFile>` + | ||
`</soapenv:Body>` + | ||
`</soapenv:Envelope>` | ||
reader := strings.NewReader(message) | ||
|
||
sdi.ParseMessage(io.NopCloser(reader)) | ||
|
||
assert.Contains(t, buf.String(), "parsing MetadatiInvioFile") | ||
}) | ||
|
||
t.Run("parse NotificaMancataConsegna", func(t *testing.T) { | ||
var buf bytes.Buffer | ||
log.SetOutput(&buf) | ||
defer func() { | ||
log.SetOutput(os.Stderr) | ||
}() | ||
|
||
message := `<?xml version='1.0' encoding='UTF-8'?>` + | ||
`<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:typ='http://www.fatturapa.gov.it/sdi/ws/trasmissione/v1.0/types'>` + | ||
`<soapenv:Header/>` + | ||
`<soapenv:Body>` + | ||
`<ns3:NotificaMancataConsegna xmlns:ns3="http://www.fatturapa.gov.it/sdi/messaggi/v1.0" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" versione="1.0">` + | ||
`<IdentificativoSdI>29218239</IdentificativoSdI>` + | ||
`<NomeFile>ESB85905495_00010.xml</NomeFile>` + | ||
`<DataOraRicezione>2024-05-31T14:54:02.000+02:00</DataOraRicezione>` + | ||
`<Descrizione>Non è stato possibile recapitare la fattura/e al destinatario.Sono in corso le necessarie verifiche,al termine delle quali si procederà ad un nuovo tentativo di trasmissione. Si rimanda pertanto ad un momento successivo l'invio della ricevuta di consegna.</Descrizione>` + | ||
`<MessageId>176130653</MessageId>` + | ||
`<Note/>` + | ||
`</ns3:NotificaMancataConsegna>` + | ||
`</soapenv:Body>` + | ||
`</soapenv:Envelope>` | ||
reader := strings.NewReader(message) | ||
|
||
sdi.ParseMessage(io.NopCloser(reader)) | ||
|
||
assert.Contains(t, buf.String(), "parsing NotificaMancataConsegna") | ||
}) | ||
|
||
t.Run("parse AttestazioneTrasmissioneFattura", func(t *testing.T) { | ||
var buf bytes.Buffer | ||
log.SetOutput(&buf) | ||
defer func() { | ||
log.SetOutput(os.Stderr) | ||
}() | ||
|
||
message := `<?xml version='1.0' encoding='UTF-8'?>` + | ||
`<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:typ='http://www.fatturapa.gov.it/sdi/ws/trasmissione/v1.0/types'>` + | ||
`<soapenv:Header/>` + | ||
`<soapenv:Body>` + | ||
`<ns3:AttestazioneTrasmissioneFattura xmlns:ns3="http://www.fatturapa.gov.it/sdi/messaggi/v1.0" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" versione="1.0">` + | ||
`<IdentificativoSdI>29218239</IdentificativoSdI>` + | ||
`<NomeFile>ESB85905495_00010.xml</NomeFile>` + | ||
`<DataOraRicezione>2024-05-31T14:54:02.000+02:00</DataOraRicezione>` + | ||
`<Destinatario>` + | ||
`<Codice>WSBKWM</Codice>` + | ||
`<Descrizione>Amministrazione di test - Ufficio_test</Descrizione>` + | ||
`</Destinatario>` + | ||
`<MessageId>176197456</MessageId>` + | ||
`<Note>Fattura</Note>` + | ||
`<HashFileOriginale>bc0c40728a04f06d52412d946a939540583cbe0ea0edaa5c0ba8097fc0519d16</HashFileOriginale>` + | ||
`</ns3:AttestazioneTrasmissioneFattura>` + | ||
`</soapenv:Body>` + | ||
`</soapenv:Envelope>` | ||
reader := strings.NewReader(message) | ||
|
||
sdi.ParseMessage(io.NopCloser(reader)) | ||
|
||
assert.Contains(t, buf.String(), "parsing AttestazioneTrasmissioneFattura") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters