ALKINT Integration Test Scripts

PowerShell scripts for testing the ALKINT Integration BC extension by inserting sample data into staging tables via the BC API.

Prerequisites

  1. BC Extension Published: The ALKINT extension must be published to your BC environment
  2. Entra App Registration: Create an app registration in Azure for OAuth authentication (recommended)
  3. API Permissions: Grant the app Dynamics 365 Business Central > API.ReadWrite.All permission
  4. PowerShell 5.1+ or PowerShell 7+

Setup

  1. Configure Authentication in config.ps1:

    Option A: OAuth 2.0 (Recommended)

    $global:BCConfig = @{
        TenantId     = "your-tenant-id"
        Environment  = "Sandbox-10-03"
        ClientId     = "your-app-client-id"
        ClientSecret = "your-app-client-secret"
        # ...
    }

    Option B: Basic Auth (Testing Only)

    $global:BCConfig = @{
        UseBasicAuth  = $true
        Username      = "your-bc-username"
        WebServiceKey = "your-web-service-access-key"
        # ...
    }
  2. Get Web Service Access Key (for Basic Auth):

    • In BC, go to your User Card
    • Click "Change Web Service Access Key"
    • Copy the generated key

Usage

Run All Tests (Interactive Menu)

.\Run-AllTests.ps1

Insert Specific Data

# Load auth module
. .\auth.ps1

# Set company
Set-BCCompany -CompanyName "Phillips Companies"

# Insert Item staging data
. .\Insert-ItemStaging.ps1
Insert-SampleItemData

# Insert Customer staging data
. .\Insert-CustomerStaging.ps1
Insert-SampleCustomerData

# Insert COD staging data (Cash + Credit Card transactions)
. .\Insert-CODStaging.ps1
Insert-SampleCODData

# Insert Sales Document staging data (Invoice + Credit Memo)
. .\Insert-SalesDocStaging.ps1
Insert-SampleSalesDocData

Create Individual Records

# Create a single item
New-ItemStagingRecord -ExternalID "MY-ITEM-001" -ItemNo "1000" -Description "Test Product" -UnitPrice 50.00

# Create a single customer
New-CustomerStagingRecord -ExternalID "MY-CUST-001" -CustomerNo "20000" -Name "Test Customer" -State "TX" -CreditLimit 10000

# Create a COD transaction
$header = New-CODHeaderStagingRecord -ExternalID "MY-COD-001" -PostingDate (Get-Date) -TotalAmount 100.00 -PaymentMethodCode "CASH"

New-CODLineStagingRecord -HeaderExternalID "MY-COD-001" -LineNo 10000 -ItemNo "1000" -Quantity 2 -UnitPrice 50.00 -CODHeaderEntryNo $header.entryNo

Query Staging Records

# Get all item staging records
Get-ItemStagingRecords

# Filter by status
Get-ItemStagingRecords -Filter "status eq 'New'"

# Get COD headers
Get-CODHeaderStagingRecords -Filter "paymentMethodCode eq 'CASH'"

File Structure

File Description
config.ps1BC connection and authentication settings
auth.ps1OAuth/Basic auth helpers and API functions
Insert-ItemStaging.ps1Item staging table operations
Insert-CustomerStaging.ps1Customer staging table operations
Insert-CODStaging.ps1COD Header/Line staging operations
Insert-SalesDocStaging.ps1Sales Doc Header/Line staging operations
Validate-FailureScenarios.ps1Stages failure scenarios and validates expected error behavior after processing
Run-AllTests.ps1Interactive menu to run all tests

Failure Validation Tests

Run end-to-end failure-focused checks:

.\Validate-FailureScenarios.ps1

What it validates:

Notes:

API Endpoints

The scripts use these BC API endpoints:

Full URL format:

https://api.businesscentral.dynamics.com/v2.0/{tenantId}/{environment}/api/vel/alkint/v1.0/companies({companyId})/{entityName}

Troubleshooting

401 Unauthorized

404 Not Found

400 Bad Request

COD Processing Logic

When COD records are processed by the Job Queue:

Payment Method BC Customer
CASH26999
CC / CREDITCARD26997

The ProcessCOD procedure creates Sales Invoices with:

Indexed view. Interactive page: open here