Middle
POST /api/v1/transfers/internal Idempotency-Key: UUID (required) Authorization: Bearer <token> { "source_account_id": "83740e53-609c-[phone]f9e61f22401", "destination_account_id": "[phone]f5c-[phone]a", "amount": 1500.50, "currency": "USD", "description": "payment for rent", "save_as_template": true } { "status": "success", "transaction_id": "77e1c83b-7bb0-437b-9250-8c9339e0538b", "data": { "amount": 1500.00, "currency": "USD", "executed_at": "[phone]T23:15:00Z", "template_saved": true } } [Sequence diagram and database schema are provided for context]
sobes.tech AI
Answer from AI
To test this API endpoint, it is important to verify the following points:
- Idempotency: The
Idempotency-Keyheader is mandatory and should ensure that a repeated request with the same key does not create a duplicate transaction. - Authorization: Verify that access is denied without a correct token.
- Input validation: Check the correctness of UUID, amount, currency, and other fields.
- Template saving logic: If
save_as_templateis true, ensure that the template is actually saved. - Response correctness: The status, transaction ID, amount, currency, execution time, and template save flag should meet expectations.
An example of an automated test in pseudocode:
response = post('/api/v1/transfers/internal', headers={
'Idempotency-Key': 'uuid-1234',
'Authorization': 'Bearer valid_token'
}, json={
'source_account_id': 'valid-uuid-1',
'destination_account_id': 'valid-uuid-2',
'amount': 1500.50,
'currency': 'USD',
'description': 'payment for rent',
'save_as_template': True
})
assert response.status_code == 200
assert response.json()['status'] == 'success'
assert response.json()['data']['template_saved'] == True
# Repeating the request with the same Idempotency-Key
response_repeat = post(...)
assert response_repeat.json()['transaction_id'] == response.json()['transaction_id']
It is also important to check error handling, for example, when headers are missing or data is incorrect.