Repository: cisagov/manage.get.gov

Issue:
[Bug]: Nameserver display isn't correct for new domain interface
### Current Behavior

The new domain interface that we are building has changed the return type of the `nameservers()` method. The domain overview page displays the name servers in a strange way because of the change in that method.

![Screenshot 2023-06-07 at 9 46 25 AM](https://github.com/cisagov/getgov/assets/443389/de3c4857-6355-4594-b79f-84f4944d4701)


### Expected Behavior

The list of nameservers should not include any parentheses or commas.

### Steps to Reproduce

1. Visit the approved domain overview page at /domain/<id>


### Environment (optional)

_No response_

### Additional Context (optional)

_No response_


Discussion:
Hi @neilmb, we (@erinysong and I) just wanted to confirm what end result we want displayed for this ticket:

Current: `('http://ns1.helloerin.com', [89.89.89.89])`

To confirm, do we want it to display like this with an IP addresses:
`'http://ns1.helloerin.com', [89.89.89.89]`

And like this without an IP address:
`'http://ns1.helloerin.com'`

Or if we are completely off, would you mind providing us with examples? Thank you!




A couple thoughts: you can't include the `http://` because these aren't websites that are accessed over HTTP, so just use the hostname `ns1.helloerin.com`. I think if there is no IP address with it (the list is empty) then we shouldn't have any indication of the second part of that return type, so just `ns1.helloerin.com` in that case. If there is are IP addresses with them, how about this `ns1.helloerin.gov (89.89.89.89)` or `ns1.helloerin.gov (89.89.89.89, 89.89.89.90)` if there's more than one. (FYI they only have IP addresses with them if the nameservers are in the .gov zone.)

And maybe more importantly, these are really design questions, so I suggest you pick something and go with it and then ask on #dotgov-disco channel to make sure that they see what you chose in your PR when they review it, and be ready to change it to their much better ideas than mine.

Resolving patch:
diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py
--- a/src/registrar/models/domain.py
+++ b/src/registrar/models/domain.py
@@ -256,7 +256,6 @@ def nameservers(self) -> list[tuple[str, list]]:
         hostList = []
         for host in hosts:
             hostList.append((host["name"], host["addrs"]))
-
         return hostList
 
     def _create_host(self, host, addrs):


Test patch:
diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py
--- a/src/registrar/tests/common.py
+++ b/src/registrar/tests/common.py
@@ -738,6 +738,7 @@ def dummyInfoContactResultData(
             "ns1.cats-are-superior3.com",
         ],
     )
+
     infoDomainNoHost = fakedEppObject(
         "my-nameserver.gov",
         cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
@@ -793,7 +794,20 @@ def dummyInfoContactResultData(
     infoDomainHasIP = fakedEppObject(
         "nameserverwithip.gov",
         cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
-        contacts=[],
+        contacts=[
+            common.DomainContact(
+                contact="securityContact",
+                type=PublicContact.ContactTypeChoices.SECURITY,
+            ),
+            common.DomainContact(
+                contact="technicalContact",
+                type=PublicContact.ContactTypeChoices.TECHNICAL,
+            ),
+            common.DomainContact(
+                contact="adminContact",
+                type=PublicContact.ContactTypeChoices.ADMINISTRATIVE,
+            ),
+        ],
         hosts=[
             "ns1.nameserverwithip.gov",
             "ns2.nameserverwithip.gov",
@@ -802,6 +816,29 @@ def dummyInfoContactResultData(
         addrs=["1.2.3.4", "2.3.4.5"],
     )
 
+    justNameserver = fakedEppObject(
+        "justnameserver.com",
+        cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
+        contacts=[
+            common.DomainContact(
+                contact="securityContact",
+                type=PublicContact.ContactTypeChoices.SECURITY,
+            ),
+            common.DomainContact(
+                contact="technicalContact",
+                type=PublicContact.ContactTypeChoices.TECHNICAL,
+            ),
+            common.DomainContact(
+                contact="adminContact",
+                type=PublicContact.ContactTypeChoices.ADMINISTRATIVE,
+            ),
+        ],
+        hosts=[
+            "ns1.justnameserver.com",
+            "ns2.justnameserver.com",
+        ],
+    )
+
     infoDomainCheckHostIPCombo = fakedEppObject(
         "nameserversubdomain.gov",
         cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
@@ -922,6 +959,7 @@ def mockInfoDomainCommands(self, _request, cleaned):
             "threenameserversDomain.gov": (self.infoDomainThreeHosts, None),
             "defaultsecurity.gov": (self.InfoDomainWithDefaultSecurityContact, None),
             "defaulttechnical.gov": (self.InfoDomainWithDefaultTechnicalContact, None),
+            "justnameserver.com": (self.justNameserver, None),
         }
 
         # Retrieve the corresponding values from the dictionary
diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py
--- a/src/registrar/tests/test_views.py
+++ b/src/registrar/tests/test_views.py
@@ -1095,6 +1095,13 @@ class TestWithDomainPermissions(TestWithUser):
     def setUp(self):
         super().setUp()
         self.domain, _ = Domain.objects.get_or_create(name="igorville.gov")
+        self.domain_with_ip, _ = Domain.objects.get_or_create(
+            name="nameserverwithip.gov"
+        )
+        self.domain_just_nameserver, _ = Domain.objects.get_or_create(
+            name="justnameserver.com"
+        )
+
         self.domain_dsdata, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
         self.domain_multdsdata, _ = Domain.objects.get_or_create(
             name="dnssec-multdsdata.gov"
@@ -1104,9 +1111,11 @@ def setUp(self):
         self.domain_dnssec_none, _ = Domain.objects.get_or_create(
             name="dnssec-none.gov"
         )
+
         self.domain_information, _ = DomainInformation.objects.get_or_create(
             creator=self.user, domain=self.domain
         )
+
         DomainInformation.objects.get_or_create(
             creator=self.user, domain=self.domain_dsdata
         )
@@ -1116,9 +1125,17 @@ def setUp(self):
         DomainInformation.objects.get_or_create(
             creator=self.user, domain=self.domain_dnssec_none
         )
+        DomainInformation.objects.get_or_create(
+            creator=self.user, domain=self.domain_with_ip
+        )
+        DomainInformation.objects.get_or_create(
+            creator=self.user, domain=self.domain_just_nameserver
+        )
+
         self.role, _ = UserDomainRole.objects.get_or_create(
             user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER
         )
+
         UserDomainRole.objects.get_or_create(
             user=self.user, domain=self.domain_dsdata, role=UserDomainRole.Roles.MANAGER
         )
@@ -1132,6 +1149,16 @@ def setUp(self):
             domain=self.domain_dnssec_none,
             role=UserDomainRole.Roles.MANAGER,
         )
+        UserDomainRole.objects.get_or_create(
+            user=self.user,
+            domain=self.domain_with_ip,
+            role=UserDomainRole.Roles.MANAGER,
+        )
+        UserDomainRole.objects.get_or_create(
+            user=self.user,
+            domain=self.domain_just_nameserver,
+            role=UserDomainRole.Roles.MANAGER,
+        )
 
     def tearDown(self):
         try:
@@ -1215,6 +1242,37 @@ def test_domain_overview_blocked_for_ineligible_user(self):
             response = self.client.get(reverse("domain", kwargs={"pk": self.domain.id}))
             self.assertEqual(response.status_code, 403)
 
+    def test_domain_see_just_nameserver(self):
+        home_page = self.app.get("/")
+        self.assertContains(home_page, "justnameserver.com")
+
+        # View nameserver on Domain Overview page
+        detail_page = self.app.get(
+            reverse("domain", kwargs={"pk": self.domain_just_nameserver.id})
+        )
+
+        self.assertContains(detail_page, "justnameserver.com")
+        self.assertContains(detail_page, "ns1.justnameserver.com")
+        self.assertContains(detail_page, "ns2.justnameserver.com")
+
+    def test_domain_see_nameserver_and_ip(self):
+        home_page = self.app.get("/")
+        self.assertContains(home_page, "nameserverwithip.gov")
+
+        # View nameserver on Domain Overview page
+        detail_page = self.app.get(
+            reverse("domain", kwargs={"pk": self.domain_with_ip.id})
+        )
+
+        self.assertContains(detail_page, "nameserverwithip.gov")
+
+        self.assertContains(detail_page, "ns1.nameserverwithip.gov")
+        self.assertContains(detail_page, "ns2.nameserverwithip.gov")
+        self.assertContains(detail_page, "ns3.nameserverwithip.gov")
+        # Splitting IP addresses bc there is odd whitespace and can't strip text
+        self.assertContains(detail_page, "(1.2.3.4,")
+        self.assertContains(detail_page, "2.3.4.5)")
+
 
 class TestDomainManagers(TestDomainOverview):
     def test_domain_managers(self):