|
- $ErrorActionPreference = 'Stop'
- $projectRoot = Split-Path -Parent $PSScriptRoot
- $workPath = Join-Path $projectRoot ('temp\contact-flow-' + [guid]::NewGuid().ToString('N'))
- New-Item -ItemType Directory -Path $workPath -Force | Out-Null
- $databasePath = Join-Path $workPath 'test.mdb'
- $configPath = Join-Path $workPath 'test.ini'
- $csvPath = Join-Path $workPath 'contacts.csv'
- $pickupPath = Join-Path $workPath 'pickup'
- $scriptHost = Join-Path $env:SystemRoot 'SysWOW64\cscript.exe'
- $powerShellX86 = Join-Path $env:SystemRoot 'SysWOW64\WindowsPowerShell\v1.0\powershell.exe'
-
- try {
- $example = Get-Content -LiteralPath (Join-Path $projectRoot 'config.example.ini') -Raw
- $example.Replace('DB_PATH=data/MassMailer.mdb', ('DB_PATH=' + $databasePath)).Replace(
- 'SMTP_TEST_TO=', 'SMTP_TEST_TO=test@example.invalid') |
- Set-Content -LiteralPath $configPath -Encoding UTF8
- @'
- email,business_name,source_reference,acquired_at
- one@example.invalid,"Example, Inc.",https://example.invalid/one,2026-10-20
- two@example.invalid,Two,,
- ONE@example.invalid,Duplicate,https://example.invalid/one,
- blocked@example.invalid,Blocked,https://example.invalid/blocked,
- '@ | Set-Content -LiteralPath $csvPath -Encoding UTF8
-
- & $scriptHost //nologo (Join-Path $PSScriptRoot 'init-db.vbs') $configPath
- if ($LASTEXITCODE -ne 0) { throw 'MDB initialization failed' }
- & $scriptHost //nologo (Join-Path $PSScriptRoot 'launch.vbs') check $configPath
- if ($LASTEXITCODE -ne 0) { throw 'Startup preflight failed' }
- & $powerShellX86 -NoProfile -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot 'test-secret-store.ps1') -ConfigPath $configPath
- if ($LASTEXITCODE -ne 0) { throw 'Protected password test failed' }
- New-Item -ItemType Directory -Path $pickupPath | Out-Null
- & $powerShellX86 -NoProfile -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot 'test-smtp-message.ps1') -ConfigPath $configPath -PickupDirectory $pickupPath
- if ($LASTEXITCODE -ne 0) { throw 'Pickup MIME test failed' }
- $messages = @(Get-ChildItem -LiteralPath $pickupPath -Filter '*.eml' -File)
- if ($messages.Count -ne 1) { throw 'Pickup MIME test did not create one message' }
- $mime = Get-Content -LiteralPath $messages[0].FullName -Raw
- if ($mime -notmatch 'multipart/related' -or $mime -notmatch 'Content-ID:\s*<massmailer-test-image>') {
- throw 'Pickup MIME is missing a related inline image'
- }
- Write-Output 'HTML and inline-image MIME pickup test passed'
- & $scriptHost //nologo //E:JScript (Join-Path $PSScriptRoot 'test-contact-flow.js') $databasePath $csvPath
- if ($LASTEXITCODE -ne 0) { throw 'Contact flow test failed' }
- }
- finally {
- if (Test-Path -LiteralPath $pickupPath) {
- Get-ChildItem -LiteralPath $pickupPath -File | ForEach-Object { Remove-Item -LiteralPath $_.FullName -Force }
- Remove-Item -LiteralPath $pickupPath -Force
- }
- foreach ($fileName in @('test.ini', 'contacts.csv', 'test.mdb', 'test.ldb')) {
- $filePath = Join-Path $workPath $fileName
- if (Test-Path -LiteralPath $filePath) { Remove-Item -LiteralPath $filePath -Force }
- }
- if (Test-Path -LiteralPath $workPath) { Remove-Item -LiteralPath $workPath -Force }
- }
|