feat: DB constraints for phone auth
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from django.db import IntegrityError
|
||||
from django.urls import reverse
|
||||
|
||||
from apps.accounts.models import OtpPurpose, PhoneOTP, User
|
||||
@@ -69,3 +70,24 @@ def test_otp_verify_rejects_auth_purpose_otp(client):
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_db_rejects_null_phone_number():
|
||||
# DB invariant: phone_number is mandatory.
|
||||
with pytest.raises(IntegrityError):
|
||||
User.objects.create(email="null-phone@example.com")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_db_rejects_non_e164_phone_number():
|
||||
# DB invariant: store normalized E.164 only.
|
||||
with pytest.raises(IntegrityError):
|
||||
User.objects.create_user(phone_number="0512345678")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_db_rejects_duplicate_phone_number():
|
||||
User.objects.create_user(phone_number="+966512345678")
|
||||
with pytest.raises(IntegrityError):
|
||||
User.objects.create_user(phone_number="+966512345678")
|
||||
|
||||
Reference in New Issue
Block a user