Fix sales API proxy endpoints and tests
This commit is contained in:
@@ -150,6 +150,27 @@ def test_gateway_forwards_delete_requests(monkeypatch):
|
||||
assert DummyAsyncClient.last_request['url'].endswith('/queues/que_delete_me')
|
||||
|
||||
|
||||
def test_gateway_prefixes_sales_public_api_paths(monkeypatch):
|
||||
monkeypatch.setattr(gateway_module.httpx, 'AsyncClient', DummyAsyncClient)
|
||||
client = TestClient(gateway_module.app)
|
||||
|
||||
response = client.get('/proxy/sales/pipelines?limit=25')
|
||||
|
||||
assert response.status_code == 200
|
||||
assert DummyAsyncClient.last_request['url'].endswith('/api/v1/pipelines')
|
||||
assert DummyAsyncClient.last_request['params'] == {'limit': '25'}
|
||||
|
||||
|
||||
def test_gateway_does_not_prefix_sales_internal_paths(monkeypatch):
|
||||
monkeypatch.setattr(gateway_module.httpx, 'AsyncClient', DummyAsyncClient)
|
||||
client = TestClient(gateway_module.app)
|
||||
|
||||
response = client.post('/proxy/sales/internal/sales-sync/telegram', json={'chat_id': '123'})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert DummyAsyncClient.last_request['url'].endswith('/internal/sales-sync/telegram')
|
||||
|
||||
|
||||
def test_gateway_preserves_binary_audio_response(monkeypatch):
|
||||
async def request(self, method, url, params=None, content=None, headers=None): # noqa: ANN001, ANN201
|
||||
return DummyResponse(
|
||||
@@ -171,3 +192,20 @@ def test_gateway_preserves_binary_audio_response(monkeypatch):
|
||||
assert response.content == b'RIFFdemo'
|
||||
assert response.headers['content-type'].startswith('audio/wav')
|
||||
assert 'demo-call.wav' in response.headers['content-disposition']
|
||||
|
||||
|
||||
def test_gateway_returns_bad_gateway_when_upstream_unavailable(monkeypatch):
|
||||
async def request(self, method, url, params=None, content=None, headers=None): # noqa: ANN001, ANN201
|
||||
raise gateway_module.httpx.ConnectError("All connection attempts failed")
|
||||
|
||||
monkeypatch.setattr(DummyAsyncClient, 'request', request)
|
||||
monkeypatch.setattr(gateway_module.httpx, 'AsyncClient', DummyAsyncClient)
|
||||
client = TestClient(gateway_module.app)
|
||||
|
||||
response = client.get('/proxy/sales/pipelines')
|
||||
|
||||
assert response.status_code == 502
|
||||
assert response.json() == {
|
||||
'detail': 'Upstream service unavailable',
|
||||
'service': 'sales',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user