sunat-engine-nest 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -235,6 +235,59 @@ return this.engine.sendInvoice(payload, {
|
|
|
235
235
|
| Comunicación de Baja (RA) | `sendVoided()` | Baja de comprobantes — SOAP asíncrono |
|
|
236
236
|
| Consulta de ticket | `getTicketStatus()` | Estado de procesos asíncronos |
|
|
237
237
|
|
|
238
|
+
## Testing / Modo simulado
|
|
239
|
+
|
|
240
|
+
SUNAT beta rechaza `sendSummary` (RC/RA) con el RUC genérico de prueba `20000000001` — ese RUC solo funciona de forma confiable para `sendBill` (facturas y boletas). Para probar el flujo completo sin depender del entorno beta, el módulo incluye un **cliente SOAP simulado** que devuelve respuestas válidas sin realizar ninguna llamada HTTP.
|
|
241
|
+
|
|
242
|
+
### Opción 1 — `useFake: true` en el módulo (recomendado)
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
// app.module.ts (para tests)
|
|
246
|
+
SunatEngineModule.forRoot({
|
|
247
|
+
useFake: true, // ← activa FakeSunatSoapClient automáticamente
|
|
248
|
+
sunat: {
|
|
249
|
+
ruc: '20000000001',
|
|
250
|
+
solUser: 'MODDATOS',
|
|
251
|
+
solPass: 'moddatos',
|
|
252
|
+
certPem: 'BASE64_DEL_P12',
|
|
253
|
+
},
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
// También con forRootAsync:
|
|
257
|
+
SunatEngineModule.forRootAsync({
|
|
258
|
+
imports: [ConfigModule],
|
|
259
|
+
inject: [ConfigService],
|
|
260
|
+
useFactory: (config: ConfigService) => ({
|
|
261
|
+
useFake: config.get('NODE_ENV') === 'test',
|
|
262
|
+
sunat: { ruc: config.get('SUNAT_RUC'), ... },
|
|
263
|
+
}),
|
|
264
|
+
})
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Opción 2 — `overrideProvider` en NestJS Testing
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { Test } from '@nestjs/testing';
|
|
271
|
+
import { SunatSoapClient, FakeSunatSoapClient } from 'sunat-engine-nest';
|
|
272
|
+
|
|
273
|
+
const moduleRef = await Test.createTestingModule({
|
|
274
|
+
imports: [SunatEngineModule.forRoot({ sunat: { ... } })],
|
|
275
|
+
})
|
|
276
|
+
.overrideProvider(SunatSoapClient)
|
|
277
|
+
.useClass(FakeSunatSoapClient)
|
|
278
|
+
.compile();
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Comportamiento del cliente simulado
|
|
282
|
+
|
|
283
|
+
| Método | Respuesta simulada |
|
|
284
|
+
|--------|-------------------|
|
|
285
|
+
| `sendBill` | CDR ZIP con `ResponseCode=0` (ACEPTADA) |
|
|
286
|
+
| `sendSummary` | Ticket numérico incremental (`1000000001`, `1000000002`, ...) |
|
|
287
|
+
| `getStatus` | CDR ZIP con `ResponseCode=0` (ACEPTADA) |
|
|
288
|
+
|
|
289
|
+
No se realiza ninguna llamada HTTP — el XML se genera y firma normalmente, solo el envío a SUNAT es simulado.
|
|
290
|
+
|
|
238
291
|
## Generación de PDF
|
|
239
292
|
|
|
240
293
|
```typescript
|
package/package.json
CHANGED