This project contains an automated test suite for the Wallet REST API challenge. It focuses on the transaction processing logic, specifically the POST /wallet/{walletId}/transaction endpoint.
- Data-Driven Testing (DDT): Tests are structured to iterate over JSON fixtures, allowing for easy scaling of test cases (multiple currencies, amounts, and scenarios) without code duplication.
- Environment-Driven Configuration: Uses
.envfor seamless switching between local mock and live environments. - Dynamic Data Discovery: Automatically handles authentication and discovers user information and wallet IDs at runtime—no hardcoded UUIDs.
- Local Mock Server: Includes a custom-built Node.js mock server that fully implements the API specification, including idempotency logic, for local verification.
- Modular Helpers: Logic for API communication and authentication is encapsulated in a dedicated
helpers/directory.
- JavaScript: Core language.
- Mocha: Test runner.
- Chai: Assertion library.
- Supertest: HTTP client for API testing.
- Dotenv: Environment variable management.
- Node.js (version 16 or higher recommended)
- npm (Node Package Manager)
- Clone or extract the project to your local machine.
- Install the dependencies:
npm install
- Create a
.envfile in the root directory (using.env.exampleas a template or as follows):BASE_URL=https://challenge.test.local/challenge/api/v1 SERVICE_ID=ChallengeService TEST_USER_NAME=testuser TEST_USER_PASSWORD=password123
If the live API is not reachable, you can use the built-in mock server:
- Start the mock server in a separate terminal:
npm run start-mock
- Update your
.envto point to the local server:BASE_URL=http://127.0.0.1:3000/challenge/api/v1
- Run the tests:
npm test
Ensure your .env contains the correct BASE_URL and credentials, then run:
npm test- Environment Variables: All sensitive data and endpoint URLs are managed via the
.envfile. - Dynamic User Discovery: The suite automatically retrieves the
userIdafter login to discover the associatedwalletId. - Authentication: The
/user/loginendpoint is functional and returns a valid JWT token. - Mocking: A local mock server (
test/mockServer.js) is provided for environments where the production domain cannot be resolved.
This mock server was created using the Gemini 3 Flash. All code and documentation have been vetted and verified for correctness against the provided specification.