Skip to content

Commit 7dcb698

Browse files
Add tests for FormaPago (#23)
1 parent 4fc70df commit 7dcb698

File tree

10 files changed

+1017
-8
lines changed

10 files changed

+1017
-8
lines changed

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/creditnote/formapago/CreditNoteFormaPagoTest.java

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public CreditNoteFormaPagoTest() throws Exception {
3838
}
3939

4040
@Test
41-
public void testCreditNoteSinFormaPago() throws Exception {
41+
public void testCreditNoteSinFormaPago_afectaFactura() throws Exception {
4242
// Given
4343
CreditNoteInputModel input = CreditNoteInputModel.Builder.aCreditNoteInputModel()
4444
.withSerie("FC01")
@@ -77,12 +77,56 @@ public void testCreditNoteSinFormaPago() throws Exception {
7777

7878
// Then
7979
assertOutputHasNoConstraintViolations(validator, output);
80-
assertSnapshot(xml, "xml/creditnote/formapago/sinFormaPago.xml");
80+
assertSnapshot(xml, "xml/creditnote/formapago/sinFormaPago_afectaFactura.xml");
8181
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
8282
}
8383

8484
@Test
85-
public void testCreditNoteConFormaPago() throws Exception {
85+
public void testCreditNoteSinFormaPago_afectaBoleta() throws Exception {
86+
// Given
87+
CreditNoteInputModel input = CreditNoteInputModel.Builder.aCreditNoteInputModel()
88+
.withSerie("BC01")
89+
.withNumero(1)
90+
.withSerieNumeroComprobanteAfectado("B001-1")
91+
.withDescripcionSustento("mi sustento")
92+
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel()
93+
.withRuc("12345678912")
94+
.withRazonSocial("Softgreen S.A.C.")
95+
.build()
96+
)
97+
.withCliente(ClienteInputModel.Builder.aClienteInputModel()
98+
.withNombre("Carlos Feria")
99+
.withNumeroDocumentoIdentidad("12345678")
100+
.withTipoDocumentoIdentidad(Catalog6.DNI.toString())
101+
.build()
102+
)
103+
.withDetalle(Arrays.asList(
104+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
105+
.withDescripcion("Item1")
106+
.withCantidad(new BigDecimal(10))
107+
.withPrecioUnitario(new BigDecimal(100))
108+
.build(),
109+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
110+
.withDescripcion("Item2")
111+
.withCantidad(new BigDecimal(10))
112+
.withPrecioUnitario(new BigDecimal(100))
113+
.build())
114+
)
115+
.build();
116+
117+
// When
118+
DocumentWrapper<CreditNoteOutputModel> result = DocumentManager.createXML(input, config, systemClock);
119+
CreditNoteOutputModel output = result.getOutput();
120+
String xml = result.getXml();
121+
122+
// Then
123+
assertOutputHasNoConstraintViolations(validator, output);
124+
assertSnapshot(xml, "xml/creditnote/formapago/sinFormaPago_afectaBoleta.xml");
125+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
126+
}
127+
128+
@Test
129+
public void testCreditNoteConFormaPago_afectaFactura() throws Exception {
86130
Calendar calendar = Calendar.getInstance();
87131
calendar.set(2019, Calendar.JANUARY, 6, 0, 0, 0);
88132
calendar.setTimeZone(timeZone);
@@ -144,7 +188,74 @@ public void testCreditNoteConFormaPago() throws Exception {
144188

145189
// Then
146190
assertOutputHasNoConstraintViolations(validator, output);
147-
assertSnapshot(xml, "xml/creditnote/formapago/conFormaPago.xml");
191+
assertSnapshot(xml, "xml/creditnote/formapago/conFormaPago_afectaFactura.xml");
192+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
193+
}
194+
195+
@Test
196+
public void testCreditNoteConFormaPago_afectaBoleta() throws Exception {
197+
Calendar calendar = Calendar.getInstance();
198+
calendar.set(2019, Calendar.JANUARY, 6, 0, 0, 0);
199+
calendar.setTimeZone(timeZone);
200+
201+
long fechaEmision = calendar.getTimeInMillis();
202+
203+
calendar.add(Calendar.DAY_OF_MONTH, 1);
204+
long fechaCuota1 = calendar.getTimeInMillis();
205+
206+
calendar.add(Calendar.DAY_OF_MONTH, 1);
207+
long fechaCuota2 = calendar.getTimeInMillis();
208+
209+
// Given
210+
CreditNoteInputModel input = CreditNoteInputModel.Builder.aCreditNoteInputModel()
211+
.withSerie("BC01")
212+
.withNumero(1)
213+
.withFechaEmision(fechaEmision)
214+
.withSerieNumeroComprobanteAfectado("B001-1")
215+
.withDescripcionSustento("mi sustento")
216+
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel()
217+
.withRuc("12345678912")
218+
.withRazonSocial("Softgreen S.A.C.")
219+
.build()
220+
)
221+
.withCliente(ClienteInputModel.Builder.aClienteInputModel()
222+
.withNombre("Carlos Feria")
223+
.withNumeroDocumentoIdentidad("12345678")
224+
.withTipoDocumentoIdentidad(Catalog6.DNI.toString())
225+
.build()
226+
)
227+
.withDetalle(Arrays.asList(
228+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
229+
.withDescripcion("Item1")
230+
.withCantidad(new BigDecimal(10))
231+
.withPrecioUnitario(new BigDecimal(100))
232+
.build(),
233+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
234+
.withDescripcion("Item2")
235+
.withCantidad(new BigDecimal(10))
236+
.withPrecioUnitario(new BigDecimal(100))
237+
.build())
238+
)
239+
.withCuotasDePago(Arrays.asList(
240+
CuotaDePagoInputModel.Builder.aFormaPagoCuotaInputModel()
241+
.withMonto(new BigDecimal(2000))
242+
.withFechaPago(fechaCuota1)
243+
.build(),
244+
CuotaDePagoInputModel.Builder.aFormaPagoCuotaInputModel()
245+
.withMonto(new BigDecimal(360))
246+
.withFechaPago(fechaCuota2)
247+
.build()
248+
))
249+
.build();
250+
251+
// When
252+
DocumentWrapper<CreditNoteOutputModel> result = DocumentManager.createXML(input, config, systemClock);
253+
CreditNoteOutputModel output = result.getOutput();
254+
String xml = result.getXml();
255+
256+
// Then
257+
assertOutputHasNoConstraintViolations(validator, output);
258+
assertSnapshot(xml, "xml/creditnote/formapago/conFormaPago_afectaBoleta.xml");
148259
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
149260
}
150261
}

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/invoice/formapago/InvoiceFormaPagoTest.java

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public InvoiceFormaPagoTest() throws Exception {
3636
}
3737

3838
@Test
39-
void testInvoiceWithFormaPagoContadoPorDefecto() throws Exception {
39+
void testFacturaWithFormaPagoContadoPorDefecto() throws Exception {
4040
// Given
4141
InvoiceInputModel input = InvoiceInputModel.Builder.anInvoiceInputModel()
4242
.withSerie("F001")
@@ -66,7 +66,47 @@ void testInvoiceWithFormaPagoContadoPorDefecto() throws Exception {
6666
)
6767
.build();
6868

69+
// When
70+
DocumentWrapper<InvoiceOutputModel> result = DocumentManager.createXML(input, config, systemClock);
71+
InvoiceOutputModel output = result.getOutput();
72+
String xml = result.getXml();
6973

74+
// Then
75+
assertOutputHasNoConstraintViolations(validator, output);
76+
assertSnapshot(xml, "xml/invoice/formapago/sinFormaPagoFactura.xml");
77+
assertSendSunat(xml, "3030 - El XML no contiene el tag o no existe información del código de local anexo del emisor - INFO: 3030 (nodo: \"/\" valor: \"\")");
78+
}
79+
80+
@Test
81+
void testBoletaFacturaWithFormaPagoContadoPorDefecto() throws Exception {
82+
// Given
83+
InvoiceInputModel input = InvoiceInputModel.Builder.anInvoiceInputModel()
84+
.withSerie("B001")
85+
.withNumero(1)
86+
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel()
87+
.withRuc("12345678912")
88+
.withRazonSocial("Softgreen S.A.C.")
89+
.build()
90+
)
91+
.withCliente(ClienteInputModel.Builder.aClienteInputModel()
92+
.withNombre("Carlos Feria")
93+
.withNumeroDocumentoIdentidad("12345678")
94+
.withTipoDocumentoIdentidad(Catalog6.DNI.toString())
95+
.build()
96+
)
97+
.withDetalle(Arrays.asList(
98+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
99+
.withDescripcion("Item1")
100+
.withCantidad(new BigDecimal(10))
101+
.withPrecioUnitario(new BigDecimal(100))
102+
.build(),
103+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
104+
.withDescripcion("Item2")
105+
.withCantidad(new BigDecimal(10))
106+
.withPrecioUnitario(new BigDecimal(100))
107+
.build())
108+
)
109+
.build();
70110

71111
// When
72112
DocumentWrapper<InvoiceOutputModel> result = DocumentManager.createXML(input, config, systemClock);
@@ -75,12 +115,12 @@ void testInvoiceWithFormaPagoContadoPorDefecto() throws Exception {
75115

76116
// Then
77117
assertOutputHasNoConstraintViolations(validator, output);
78-
assertSnapshot(xml, "xml/invoice/formapago/default.xml");
118+
assertSnapshot(xml, "xml/invoice/formapago/sinFormaPagoBoleta.xml");
79119
assertSendSunat(xml, "3030 - El XML no contiene el tag o no existe información del código de local anexo del emisor - INFO: 3030 (nodo: \"/\" valor: \"\")");
80120
}
81121

82122
@Test
83-
void testInvoiceWithFormaPagoCredito() throws Exception {
123+
void testFacturaWithFormaPagoCredito() throws Exception {
84124
Calendar calendar = Calendar.getInstance();
85125
calendar.set(2019, Calendar.JANUARY, 6, 0, 0, 0);
86126
calendar.setTimeZone(timeZone);
@@ -142,7 +182,74 @@ void testInvoiceWithFormaPagoCredito() throws Exception {
142182

143183
// Then
144184
assertOutputHasNoConstraintViolations(validator, output);
145-
assertSnapshot(xml, "xml/invoice/formapago/alCredito.xml");
185+
assertSnapshot(xml, "xml/invoice/formapago/conFormaPagoFactura.xml");
186+
assertSendSunat(xml, "3030 - El XML no contiene el tag o no existe información del código de local anexo del emisor - INFO: 3030 (nodo: \"/\" valor: \"\")");
187+
}
188+
189+
@Test
190+
void testBoletaWithFormaPagoCredito() throws Exception {
191+
Calendar calendar = Calendar.getInstance();
192+
calendar.set(2019, Calendar.JANUARY, 6, 0, 0, 0);
193+
calendar.setTimeZone(timeZone);
194+
195+
long fechaEmision = calendar.getTimeInMillis();
196+
197+
calendar.add(Calendar.DAY_OF_MONTH, 1);
198+
long fechaCuota1 = calendar.getTimeInMillis();
199+
200+
calendar.add(Calendar.DAY_OF_MONTH, 1);
201+
long fechaCuota2 = calendar.getTimeInMillis();
202+
203+
// Given
204+
InvoiceInputModel input = InvoiceInputModel.Builder.anInvoiceInputModel()
205+
.withSerie("B001")
206+
.withNumero(1)
207+
.withFechaEmision(fechaEmision)
208+
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel()
209+
.withRuc("12345678912")
210+
.withRazonSocial("Softgreen S.A.C.")
211+
.build()
212+
)
213+
.withCliente(ClienteInputModel.Builder.aClienteInputModel()
214+
.withNombre("Carlos Feria")
215+
.withNumeroDocumentoIdentidad("12345678")
216+
.withTipoDocumentoIdentidad(Catalog6.DNI.toString())
217+
.build()
218+
)
219+
.withDetalle(Arrays.asList(
220+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
221+
.withDescripcion("Item1")
222+
.withCantidad(new BigDecimal(10))
223+
.withPrecioUnitario(new BigDecimal(100))
224+
.build(),
225+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
226+
.withDescripcion("Item2")
227+
.withCantidad(new BigDecimal(10))
228+
.withPrecioUnitario(new BigDecimal(100))
229+
.build())
230+
)
231+
.withCuotasDePago(Arrays.asList(
232+
CuotaDePagoInputModel.Builder.aFormaPagoCuotaInputModel()
233+
.withMonto(new BigDecimal(2000))
234+
.withFechaPago(fechaCuota1)
235+
.build(),
236+
CuotaDePagoInputModel.Builder.aFormaPagoCuotaInputModel()
237+
.withMonto(new BigDecimal(360))
238+
.withFechaPago(fechaCuota2)
239+
.build()
240+
))
241+
.build();
242+
243+
244+
245+
// When
246+
DocumentWrapper<InvoiceOutputModel> result = DocumentManager.createXML(input, config, systemClock);
247+
InvoiceOutputModel output = result.getOutput();
248+
String xml = result.getXml();
249+
250+
// Then
251+
assertOutputHasNoConstraintViolations(validator, output);
252+
assertSnapshot(xml, "xml/invoice/formapago/conFormaPagoBoleta.xml");
146253
assertSendSunat(xml, "3030 - El XML no contiene el tag o no existe información del código de local anexo del emisor - INFO: 3030 (nodo: \"/\" valor: \"\")");
147254
}
148255
}

0 commit comments

Comments
 (0)