Azure Durable Functions Integration Testing Exercise
This exercise focuses on fixing integration tests for an Azure Durable Functions application that processes invoices. The tests are currently failing due to incorrect assertions, and your task is to fix them.
Prerequisites
- Node.js (v14 or later)
- Azure Functions Core Tools
- Azurite (for local storage emulation)
- Jest (for testing)
Getting Started
- Clone the repository
- Install dependencies:
npm install
- Start Azurite:
azurite --silent
- Start the Azure Functions runtime:
npm start
- Run the tests:
npm test
Exercise Tasks
1. Fix Test Assertions
The integration tests are failing due to incorrect assertions. Your task is to fix them by understanding the actual behavior of the system. Here are the main issues to address:
Normal Invoice Test
- HTTP status code should be 202 (Accepted), not 200
- Success flag should be true for successful processing
- Only one blob should be created
- Blob name should contain ‘INV-NORMAL’
High-Value Invoice Test
- Runtime status should be ‘Completed’, not ‘Failed’
- Approval result should be defined and contain approval information
- Total amount should be 20000, not 10000
- Blob name should contain ‘INV-HIGH’
Rejected Vendor Test
- Runtime status should be ‘Completed’, not ‘Failed’
- Success flag should be false for rejected invoices
- Approval result should be defined
- Reason should be ‘Not approved’, not ‘Approved’
- No blobs should be created
Invalid Invoice Test
- Output should be defined
- Success flag should be false
- Error information should be present
- No blobs should be created
Missing CustomerId Test
- Runtime status should be ‘Completed’, not ‘Failed’
- Success flag should be true
- Invoice ID should be ‘INV-NORMAL’, not ‘INV-HIGH’
- One blob should be created
Malformed Request Test
- Runtime status should be ‘Completed’, not ‘Failed’
- Success flag should be true
- Invoice ID should be ‘INV-NORMAL’, not ‘INV-HIGH’
- One blob should be created
2. Add Missing Test Cases
Add the following test cases:
-
Concurrent Invoice Processing
- Test multiple simultaneous invoice requests
- Verify all invoices are processed correctly
- Check for any race conditions
-
Retry Behavior
- Test automatic retries for failed operations
- Verify retry limits and delays
- Check retry success scenarios
-
Timeout Handling
- Test long-running operations
- Verify timeout limits
- Check timeout recovery
Tips
- Use the Azure Functions Core Tools to debug your functions
- Check the Azurite logs for storage-related issues
- Use Jest’s
--verbose
flag for detailed test output - Consider using
jest --watch
for development
Resources
- Azure Durable Functions Documentation
- Azurite Documentation
- Jest Documentation
- Azure Functions Testing Best Practices
Expected Test Output
After fixing all assertions, running npm test
should show:
PASS src/functions/__tests__/InvoiceLogOrchestrator.integration.test.js
Invoice Processing Integration Tests
End-to-End Invoice Processing
✓ should process a normal invoice (customerId: 0) and generate PDF
✓ should process high-value invoice (customerId: 1) with approval and generate PDF
✓ should reject invoice from rejected vendor (customerId: 2)
✓ should handle invalid invoice data (customerId: 3)
✓ should handle missing customerId gracefully
✓ should handle malformed request body by defaulting to normal invoice
✓ should handle concurrent invoice processing
✓ should handle retry behavior
✓ should handle timeout scenarios
Test Suites: 1 passed, 1 total
Tests: 9 passed, 9 total