feat(sms): add selectable provider strategy
This commit is contained in:
@@ -3,6 +3,7 @@ import pytest
|
||||
|
||||
from gapido_auth.domain.errors import ExternalServiceError
|
||||
from gapido_auth.infrastructure.kavenegar_client import KavenegarSmsClient
|
||||
from gapido_auth.infrastructure.sms_ir_client import SmsIrSmsClient
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -28,3 +29,29 @@ async def test_kavenegar_api_error() -> None:
|
||||
with pytest.raises(ExternalServiceError):
|
||||
await client.send_otp("989120000000", "123456", "login-otp")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sms_ir_success() -> None:
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
assert request.url == "https://api.sms.ir/v1/send/verify"
|
||||
assert request.headers["x-api-key"] == "sms-ir-key"
|
||||
payload = request.read()
|
||||
assert b'"mobile":"989120000000"' in payload
|
||||
assert b'"templateId":570574' in payload
|
||||
assert b'"name":"OTP"' in payload
|
||||
assert b'"value":"123456"' in payload
|
||||
return httpx.Response(200, json={"status": "1"})
|
||||
|
||||
client = SmsIrSmsClient("sms-ir-key", transport=httpx.MockTransport(handler))
|
||||
await client.send_otp("989120000000", "123456", "570574")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sms_ir_api_error() -> None:
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
return httpx.Response(200, json={"status": "0"})
|
||||
|
||||
client = SmsIrSmsClient("sms-ir-key", transport=httpx.MockTransport(handler))
|
||||
|
||||
with pytest.raises(ExternalServiceError):
|
||||
await client.send_otp("989120000000", "123456", "570574")
|
||||
|
||||
Reference in New Issue
Block a user