✨(mail) add status on domain create or retrieve API
to display status on frontend
This commit is contained in:
@@ -25,6 +25,7 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
|||||||
"id",
|
"id",
|
||||||
"name",
|
"name",
|
||||||
"slug",
|
"slug",
|
||||||
|
"status",
|
||||||
"abilities",
|
"abilities",
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
@@ -32,6 +33,7 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
|||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
"id",
|
"id",
|
||||||
"slug",
|
"slug",
|
||||||
|
"status",
|
||||||
"abilities",
|
"abilities",
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
|
|||||||
@@ -52,12 +52,10 @@ def test_api_mail_domains__create_authenticated():
|
|||||||
Authenticated users should be able to create mail domains
|
Authenticated users should be able to create mail domains
|
||||||
and should automatically be added as owner of the newly created domain.
|
and should automatically be added as owner of the newly created domain.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user = core_factories.UserFactory()
|
user = core_factories.UserFactory()
|
||||||
|
|
||||||
client = APIClient()
|
client = APIClient()
|
||||||
client.force_login(user)
|
client.force_login(user)
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/api/v1.0/mail-domains/",
|
"/api/v1.0/mail-domains/",
|
||||||
{
|
{
|
||||||
@@ -65,10 +63,21 @@ def test_api_mail_domains__create_authenticated():
|
|||||||
},
|
},
|
||||||
format="json",
|
format="json",
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == status.HTTP_201_CREATED
|
assert response.status_code == status.HTTP_201_CREATED
|
||||||
# a new domain pending is created and the authenticated user is the owner
|
|
||||||
domain = models.MailDomain.objects.get()
|
domain = models.MailDomain.objects.get()
|
||||||
|
|
||||||
|
# response is as expected
|
||||||
|
assert response.json() == {
|
||||||
|
"id": str(domain.id),
|
||||||
|
"name": domain.name,
|
||||||
|
"slug": domain.slug,
|
||||||
|
"status": enums.MailDomainStatusChoices.PENDING,
|
||||||
|
"created_at": domain.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": domain.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"abilities": domain.get_abilities(user),
|
||||||
|
}
|
||||||
|
|
||||||
|
# a new domain with status "pending" is created and authenticated user is the owner
|
||||||
assert domain.status == enums.MailDomainStatusChoices.PENDING
|
assert domain.status == enums.MailDomainStatusChoices.PENDING
|
||||||
assert domain.name == "mydomain.com"
|
assert domain.name == "mydomain.com"
|
||||||
assert domain.accesses.filter(role="owner", user=user).exists()
|
assert domain.accesses.filter(role="owner", user=user).exists()
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ def test_api_mail_domains__retrieve_authenticated_related():
|
|||||||
"id": str(domain.id),
|
"id": str(domain.id),
|
||||||
"name": domain.name,
|
"name": domain.name,
|
||||||
"slug": domain.slug,
|
"slug": domain.slug,
|
||||||
|
"status": domain.status,
|
||||||
"created_at": domain.created_at.isoformat().replace("+00:00", "Z"),
|
"created_at": domain.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
"updated_at": domain.updated_at.isoformat().replace("+00:00", "Z"),
|
"updated_at": domain.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
"abilities": domain.get_abilities(user),
|
"abilities": domain.get_abilities(user),
|
||||||
|
|||||||
Reference in New Issue
Block a user