Skip to content

Commit

Permalink
feat(tests): add PowerShell tests for factura_electronica.vbs and re…
Browse files Browse the repository at this point in the history
…mito_electronico_carico.vbs

- Add test_factura_electronica.ps1 to test AFIP electronic invoicing
- Add test_remito_electronico_carnico.ps1 to test meat shipping vouchers
- Update test_pyqr.ps1 to remove commented code

Signed-off-by: SONIABHISHEK121 <[email protected]>
  • Loading branch information
ABHISHEKSONI121 committed Aug 7, 2024
1 parent 9662e78 commit c395eab
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 31 deletions.
108 changes: 108 additions & 0 deletions tests/powershell/test_factura_electronica.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Test script for factura_electronica.vbs COM objects

$env:PYTHONPATH += ";$PWD;$PWD\env\lib\site-packages"
$WSAA = New-Object -ComObject WSAA
$WSFEv1 = New-Object -ComObject WSFEv1

function Write-Log {
param([string]$message)
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $message"
}

function Get-XmlValue {
param (
[string]$xml,
[string]$nodeName
)
if ($xml -match "<$nodeName>(.*?)</$nodeName>") {
return $Matches[1]
}
return $null
}

Describe "Factura Electronica Tests" {
BeforeAll {
$certFile = Join-Path $PSScriptRoot "..\..\reingart.crt"
$keyFile = Join-Path $PSScriptRoot "..\..\reingart.key"

Write-Log "Clearing cache..."
Remove-Item -Path "$env:TEMP\TA*.xml" -ErrorAction SilentlyContinue

$wsdl = "https://wsaahomo.afip.gov.ar/ws/services/LoginCms"
$service = "wsfe"

Write-Log "Attempting authentication..."
$authResult = $WSAA.Autenticar($service, $certFile, $keyFile, $wsdl)
Write-Log "Authentication result: $authResult"

if (-not $authResult) {
throw "Authentication failed: $($WSAA.Excepcion)"
}
Write-Log "Authentication successful"

$token = Get-XmlValue -xml $authResult -nodeName "token"
$sign = Get-XmlValue -xml $authResult -nodeName "sign"

Write-Log "Setting up WSFEv1..."
$WSFEv1.Cuit = "20267565393"
$WSFEv1.Token = $token
$WSFEv1.Sign = $sign
$wsdl = "https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL"
$ok = $WSFEv1.Conectar("", $wsdl)
Write-Log "WSFEv1 connection result: $ok"
if (-not $ok) {
throw "WSFEv1 connection failed: $($WSFEv1.Excepcion)"
}
Write-Log "WSFEv1 setup complete"
}

Context "WSAA Tests" {
It "Has valid Token and Sign" {
Write-Log "Token: $token"
Write-Log "Sign: $sign"
$token | Should -Not -BeNullOrEmpty
$sign | Should -Not -BeNullOrEmpty
}
}

Context "WSFEv1 Tests" {
It "Can connect to web service" {
$WSFEv1.Excepcion | Should -BeNullOrEmpty
}

It "Can get last authorized voucher" {
$tipo_cbte = 1
$punto_vta = 4002
$ult = $WSFEv1.CompUltimoAutorizado($tipo_cbte, $punto_vta)
Write-Log "Last authorized voucher: $ult"
$ult | Should -Not -BeNullOrEmpty
}

It "Can create invoice" {
$result = $WSFEv1.CrearFactura(1, 80, "33693450239", 1, 4002, ($ult + 1), ($ult + 1), "124.00", "2.00", "100.00", "21.00", "1.00", "0.00", (Get-Date).ToString("yyyyMMdd"), "", "", "", "PES", "1.000")
Write-Log "Create invoice result: $result"
Write-Log "WSFEv1 Exception: $($WSFEv1.Excepcion)"
Write-Log "WSFEv1 ErrMsg: $($WSFEv1.ErrMsg)"
$result | Should -Be $true
$WSFEv1.Excepcion | Should -BeNullOrEmpty
}

It "Can add associated vouchers" {
$result = $WSFEv1.AgregarCmpAsoc(1, 4002, $ult)
Write-Log "Add associated vouchers result: $result"
$result | Should -Be $true
}

It "Can add taxes" {
$result = $WSFEv1.AgregarTributo(99, "Impuesto Municipal Matanza", "100.00", "1.00", "1.00")
Write-Log "Add taxes result: $result"
$result | Should -Be $true
}

It "Can add VAT" {
$result = $WSFEv1.AgregarIva(5, "100.00", "21.00")
Write-Log "Add VAT result: $result"
$result | Should -Be $true
}
}
}
31 changes: 0 additions & 31 deletions tests/powershell/test_pyqr.ps1
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
# # Test script for PyQR COM object

# # Create PyQR COM object
# $PyQR = New-Object -ComObject PyQR

# Describe "PyQR Tests" {
# It "Can create a file" {
# $archivo = $PyQR.CrearArchivo()
# $archivo | Should -Not -BeNullOrEmpty
# }

# It "Can generate QR image" {
# $ver = 1
# $fecha = "2020-10-13"
# $cuit = 30000000007
# $pto_vta = 10
# $tipo_cmp = 1
# $nro_cmp = 94
# $importe = 12100
# $moneda = "DOL"
# $ctz = 65
# $tipo_doc_rec = 80
# $nro_doc_rec = 20000000001
# $tipo_cod_aut = "E"
# $cod_aut = 70417054367476

# $url = $PyQR.GenerarImagen($ver, $fecha, $cuit, $pto_vta, $tipo_cmp, $nro_cmp,
# $importe, $moneda, $ctz, $tipo_doc_rec, $nro_doc_rec,
# $tipo_cod_aut, $cod_aut)
# $url | Should -Not -BeNullOrEmpty
# Test-Path $url | Should -Be $true
# }
# }

$PyQR = New-Object -ComObject PyQR

Describe "PyQR Tests" {
Expand Down
86 changes: 86 additions & 0 deletions tests/powershell/test_remito_electronico_carnico.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Test Script for Remito Electronico Carnico VBS COM object

$vbsPath = Join-Path $PSScriptRoot "..\..\ejemplos\remito_electronico_carnico.vbs"

function Invoke-VBScript {
param (
[Parameter(Mandatory=$true)]
[string]$ScriptPath
)

$env:PYTHONPATH = "C:\Users\ADMIN\desktop\pyafipws;$env:PYTHONPATH"
$result = cscript //nologo $ScriptPath 2>&1
$exitCode = $LASTEXITCODE

return @{
StdOut = $result -join "`n"
ExitCode = $exitCode
}
}

Describe "Remito Electronico Carnico VBS Script Tests" {
BeforeAll {
$script:testVbsPath = $vbsPath
}

It "Should run without errors" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.ExitCode | Should -Be 0
}

It "Should authenticate successfully" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Match "Aut"
}

It "Should create WSRemCarne object" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Match "WSRemCarne"
}

It "Should connect to the webservice" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Not -Match "Error al conectar"
}

It "Should consult last authorized voucher" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Match "comprobante"
}

It "Should create a remito" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Match "Remito"
}

It "Should add a trip" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Not -Match "Error al agregar viaje"
}

It "Should add a vehicle" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Not -Match "Error al agregar vehiculo"
}

It "Should add merchandise" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Not -Match "Error al agregar mercaderia"
}

It "Should generate remito" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Match "Autorizacion"
}

It "Should not have any critical errors" {
$result = Invoke-VBScript -ScriptPath $script:testVbsPath
$result.StdOut | Should -Not -Match "Error crítico:"
}

AfterAll {
if (Test-Path "qr.png") {
Remove-Item "qr.png"
}
}
}

0 comments on commit c395eab

Please sign in to comment.