This document provides guidelines for testing the 1ClickImpact JavaScript SDK.
-
Install dependencies:
npm install
-
Create a
.envfile in the project root with your test API key:TEST_API_KEY=your_sandbox_api_key_hereImportant: Always use a sandbox API key for testing, never a production key.
npm testnpx jest __tests__/client.test.tsnpx jest -t "should plant trees"npm test -- --coverageAfter running tests with coverage, open coverage/lcov-report/index.html in your browser to view the detailed coverage report.
The test suite can run in two modes:
When you provide a TEST_API_KEY in your .env file, the tests will make real API calls to the sandbox environment. This is useful for end-to-end testing and ensures that the SDK correctly interacts with the 1ClickImpact API.
Note: Running integration tests will create real records in the sandbox environment and count towards your API usage limits.
If no TEST_API_KEY is provided, only the basic functionality tests will run. These don't make actual API calls but still test the SDK's core functionality.
The tests are organized by SDK functions:
- Initialization tests
- Environmental impact tests (plant trees, clean ocean, etc.)
- Data access tests (records, customers, impact statistics)
Each function has tests for:
- Basic functionality
- Parameter handling
- Error conditions
- Response parsing
When adding new functionality to the SDK, please ensure you add corresponding tests that cover:
- Happy path (expected usage)
- Edge cases
- Error handling
If you need to debug tests, you can add the --verbose flag:
npm test -- --verboseFor more detailed logging, uncomment the console.log statements in the makeRequest method of the client.