These tests validate the NFE.io SDK against the real API (development or production environment).
- Real API calls: These tests make actual HTTP requests to NFE.io API
- API key required: You must provide valid credentials
- Costs may apply: Depending on your NFE.io plan, API calls might incur costs
- Cleanup: Tests attempt to cleanup resources, but failures might leave data
- Development/Test: Create account at NFE.io and use a test API key
- Production: Use your production API key (
⚠️ not recommended for testing)
Note: NFE.io API uses the same endpoint (https://api.nfe.io/v1) for both environments. The difference is determined by the API key you use, not the URL.
# Required: API key (test/development key recommended)
export NFE_API_KEY="your-development-api-key"
# Optional: Test environment (default: development)
export NFE_TEST_ENVIRONMENT="development" # or "production"
# Optional: Enable integration tests in CI
export RUN_INTEGRATION_TESTS="true"
# Optional: Debug logging
export DEBUG_INTEGRATION_TESTS="true"Windows (PowerShell):
$env:NFE_API_KEY="your-development-api-key"
$env:NFE_TEST_ENVIRONMENT="development"
$env:RUN_INTEGRATION_TESTS="true"# Run all integration tests
npm run test:integration
# Run specific integration test file
npm test tests/integration/companies.integration.test.ts
# Run with debug logging
DEBUG_INTEGRATION_TESTS=true npm test tests/integration/
# Run with coverage
npm run test:integration -- --coverage- Environment configuration
- Test data helpers
- Cleanup utilities
- Client factory
- CRUD operations for Companies
- Certificate upload (skipped - requires PFX file)
- Validation error handling
- Duplicate detection
Tests: 8 tests (1 skipped)
- Complete invoice workflow
- Synchronous (201) and asynchronous (202) creation
- Polling until completion
- PDF/XML downloads
- Email sending
- Invoice cancellation
- Validation and error handling
Tests: 13 tests
Duration: ~5-10 minutes (includes polling waits)
- Authentication errors (401)
- Not found errors (404)
- Validation errors (400/422)
- Network timeouts
- Retry logic verification
- Rate limiting behavior
- Concurrent requests
- Error detail preservation
Tests: 10 tests
✅ Create company
✅ Retrieve company by ID
✅ List companies
✅ Update company
✅ Delete company
✅ 404 handling
✅ Validation errors
✅ Duplicate CNPJ detection
⏭️ Certificate upload (skipped)
✅ Synchronous invoice creation (201)
✅ Asynchronous invoice creation (202)
✅ Polling until completion
✅ createAndWait() helper
✅ Retrieve invoice
✅ List invoices
✅ Cancel invoice
✅ Send invoice email
✅ Download PDF
✅ Download XML
✅ Validation errors
✅ 404 handling
✅ Polling timeout
✅ 401 Authentication error
✅ 404 Not found error
✅ 400/422 Validation error
✅ Network timeout
✅ Retry logic
✅ Rate limiting (if enforced)
✅ Malformed response handling
✅ Error detail preservation
✅ Concurrent requests
✅ Empty response lists
Integration tests are automatically skipped when:
- No API key is configured (
NFE_API_KEYnot set) - Running in CI without explicit opt-in (
RUN_INTEGRATION_TESTSnot set)
You'll see: "Skipping integration tests - no API key configured"
Individual tests can be skipped with .skip():
it.skip('test that requires special setup', async () => {
// ...
});Tests automatically cleanup created resources:
- Companies are deleted after tests
- Invoices are cancelled after tests
- Errors during cleanup are logged but don't fail tests
Manual cleanup (if tests crash):
# List companies
curl -X GET https://api.nfe.io/v1/companies \
-H "Authorization: Bearer YOUR_API_KEY"
# Delete company
curl -X DELETE https://api.nfe.io/v1/companies/{id} \
-H "Authorization: Bearer YOUR_API_KEY"- Default test timeout: 30 seconds
- Invoice polling tests: 90 seconds (waits for processing)
- Configurable via
INTEGRATION_TEST_CONFIG.timeoutinsetup.ts
DEBUG_INTEGRATION_TESTS=true npm test tests/integration/npm test tests/integration/companies.integration.test.ts -- -t "should create a company"- Tests log important events when
DEBUG_INTEGRATION_TESTS=true - Check
logTestInfo()outputs in console
- Create new test file:
tests/integration/your-resource.integration.test.ts - Import setup utilities:
import {
createIntegrationClient,
skipIfNoApiKey,
cleanupTestCompany,
logTestInfo,
INTEGRATION_TEST_CONFIG,
} from './setup.js';- Use
skipIfNoApiKey()to skip when no credentials:
it.skipIf(skipIfNoApiKey())('your test', async () => {
const client = createIntegrationClient();
// ... test code
}, { timeout: INTEGRATION_TEST_CONFIG.timeout });- Always cleanup resources:
afterEach(async () => {
await cleanupTestCompany(client, companyId);
});All tests should pass when:
- Valid development/test API key is configured
- NFE.io API is operational
- Network connection is stable
Passing rate: 100% (excluding skipped tests)
Common failures:
- ❌ "Skipping integration tests - no API key configured" → Set
NFE_API_KEY - ❌ "Authentication error" → Check API key validity
- ❌ "Timeout waiting for invoice" → API might be slow, increase timeout
- ❌ "Network error" → Check internet connection
name: Integration Tests
on:
schedule:
- cron: '0 0 * * *' # Daily
workflow_dispatch: # Manual trigger
jobs:
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
- run: npm ci
- name: Run integration tests
env:
NFE_API_KEY: ${{ secrets.NFE_DEV_API_KEY }}
NFE_TEST_ENVIRONMENT: development
RUN_INTEGRATION_TESTS: true
run: npm run test:integrationSecrets to configure:
NFE_DEV_API_KEY: Your development/test API key
- Integration tests take 5-10 minutes due to invoice processing waits
- Tests use development environment by default with test API keys to avoid production costs
- Some tests (like certificate upload) are skipped as they require external files
- Rate limiting tests might not trigger limits in development
- All tests are isolated and don't depend on each other
→ API key not configured, tests are being skipped
→ Increase timeout in test or check API status
→ Check API key validity and environment configuration
→ Check internet connection and API status
→ Run manual cleanup commands listed above
Ready to test? Set your API key and run:
export NFE_API_KEY="your-key"
npm run test:integration