mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-29 15:53:31 +02:00
Solidify json unit tests
This commit is contained in:
parent
db985cb3d7
commit
f8c14ea36a
6 changed files with 107 additions and 20 deletions
|
@ -291,13 +291,13 @@ We use the [CSS Block Element Modifier (BEM)](https://getbem.com/naming/) naming
|
||||||
|
|
||||||
### Upgrading USWDS and other JavaScript packages
|
### Upgrading USWDS and other JavaScript packages
|
||||||
|
|
||||||
Version numbers can be manually controlled in `package.json`. Edit that, if desired.
|
1. Version numbers can be manually controlled in `package.json`. Edit that, if desired.
|
||||||
|
2. Now run `docker-compose run node npm update`.
|
||||||
Now run `docker-compose run node npm update`.
|
3. Then run `docker-compose up` to recompile and recopy the assets, or run `docker-compose updateUswds` if your docker is already up.
|
||||||
|
4. Make note of the dotgov changes in uswds-edited.js.
|
||||||
Then run `docker-compose up` to recompile and recopy the assets.
|
5. Copy over the newly compiled code from uswds.js into uswds-edited.js.
|
||||||
|
6. Put back the dotgov changes you made note of into uswds-edited.js.
|
||||||
Examine the results in the running application (remember to empty your cache!) and commit `package.json` and `package-lock.json` if all is well.
|
7. Examine the results in the running application (remember to empty your cache!) and commit `package.json` and `package-lock.json` if all is well.
|
||||||
|
|
||||||
## Finite State Machines
|
## Finite State Machines
|
||||||
|
|
||||||
|
|
|
@ -952,6 +952,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
data.domains.forEach(domain => {
|
data.domains.forEach(domain => {
|
||||||
const expirationDate = domain.expiration_date ? new Date(domain.expiration_date) : null;
|
const expirationDate = domain.expiration_date ? new Date(domain.expiration_date) : null;
|
||||||
const expirationDateSortValue = expirationDate ? expirationDate.getTime() : '';
|
const expirationDateSortValue = expirationDate ? expirationDate.getTime() : '';
|
||||||
|
const actionUrl = domain.action_url;
|
||||||
|
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
|
@ -975,7 +976,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
</svg>
|
</svg>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="/domain/${domain.id}">
|
<a href="${actionUrl}">
|
||||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24">
|
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24">
|
||||||
<use xlink:href="/public/img/sprite.svg#${domain.state === 'deleted' || domain.state === 'on hold' ? 'visibility' : 'settings'}"></use>
|
<use xlink:href="/public/img/sprite.svg#${domain.state === 'deleted' || domain.state === 'on hold' ? 'visibility' : 'settings'}"></use>
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -1132,8 +1133,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
data.domain_requests.forEach(request => {
|
data.domain_requests.forEach(request => {
|
||||||
const domainName = request.requested_domain ? request.requested_domain : `New domain request <span class="text-base font-body-xs">(${new Date(request.created_at).toLocaleString()} UTC)</span>`;
|
const domainName = request.requested_domain ? request.requested_domain : `New domain request <span class="text-base font-body-xs">(${new Date(request.created_at).toLocaleString()} UTC)</span>`;
|
||||||
const submissionDate = request.submission_date ? new Date(request.submission_date).toLocaleDateString() : `<span class="text-base">Not submitted</span>`;
|
const submissionDate = request.submission_date ? new Date(request.submission_date).toLocaleDateString() : `<span class="text-base">Not submitted</span>`;
|
||||||
const actionUrl = (request.status === 'Started' || request.status === 'Withdrawn') ? `/domain-request/${request.id}/edit` : `/domain-request/${request.id}`;
|
const actionUrl = request.action_url;
|
||||||
const actionLabel = (request.status === 'Started' || request.status === 'Withdrawn') ? 'Edit' : 'Manage';
|
const actionLabel = request.action_label;
|
||||||
const deleteButton = request.is_deletable ? `
|
const deleteButton = request.is_deletable ? `
|
||||||
<a
|
<a
|
||||||
role="button"
|
role="button"
|
||||||
|
|
|
@ -2,6 +2,7 @@ from registrar.models import UserDomainRole, Domain
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from .test_views import TestWithUser
|
from .test_views import TestWithUser
|
||||||
from django_webtest import WebTest # type: ignore
|
from django_webtest import WebTest # type: ignore
|
||||||
|
from django.utils.dateparse import parse_date
|
||||||
|
|
||||||
|
|
||||||
class GetDomainsJsonTest(TestWithUser, WebTest):
|
class GetDomainsJsonTest(TestWithUser, WebTest):
|
||||||
|
@ -19,13 +20,18 @@ class GetDomainsJsonTest(TestWithUser, WebTest):
|
||||||
UserDomainRole.objects.create(user=self.user, domain=self.domain2)
|
UserDomainRole.objects.create(user=self.user, domain=self.domain2)
|
||||||
UserDomainRole.objects.create(user=self.user, domain=self.domain3)
|
UserDomainRole.objects.create(user=self.user, domain=self.domain3)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
|
UserDomainRole.objects.all().delete()
|
||||||
|
UserDomainRole.objects.all().delete()
|
||||||
|
|
||||||
def test_get_domains_json_unauthenticated(self):
|
def test_get_domains_json_unauthenticated(self):
|
||||||
"""for an unauthenticated user, test that the user is redirected for auth"""
|
"""for an unauthenticated user, test that the user is redirected for auth"""
|
||||||
self.app.reset()
|
self.app.reset()
|
||||||
|
|
||||||
response = self.client.get(reverse("get_domains_json"))
|
response = self.client.get(reverse("get_domains_json"))
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
def test_get_domains_json_authenticated(self):
|
def test_get_domains_json_authenticated(self):
|
||||||
"""Test that an authenticated user gets the list of 3 domains."""
|
"""Test that an authenticated user gets the list of 3 domains."""
|
||||||
response = self.app.get(reverse("get_domains_json"))
|
response = self.app.get(reverse("get_domains_json"))
|
||||||
|
@ -38,12 +44,37 @@ class GetDomainsJsonTest(TestWithUser, WebTest):
|
||||||
self.assertFalse(data["has_previous"])
|
self.assertFalse(data["has_previous"])
|
||||||
self.assertEqual(data["num_pages"], 1)
|
self.assertEqual(data["num_pages"], 1)
|
||||||
|
|
||||||
# Check domains
|
# Check the number of domains
|
||||||
self.assertEqual(len(data["domains"]), 3)
|
self.assertEqual(len(data["domains"]), 3)
|
||||||
|
|
||||||
|
# Expected domains
|
||||||
|
expected_domains = [self.domain1, self.domain2, self.domain3]
|
||||||
|
|
||||||
|
# Extract fields from response
|
||||||
domain_ids = [domain["id"] for domain in data["domains"]]
|
domain_ids = [domain["id"] for domain in data["domains"]]
|
||||||
self.assertIn(self.domain1.id, domain_ids)
|
names = [domain["name"] for domain in data["domains"]]
|
||||||
self.assertIn(self.domain2.id, domain_ids)
|
expiration_dates = [domain["expiration_date"] for domain in data["domains"]]
|
||||||
self.assertIn(self.domain3.id, domain_ids)
|
states = [domain["state"] for domain in data["domains"]]
|
||||||
|
state_displays = [domain["state_display"] for domain in data["domains"]]
|
||||||
|
get_state_help_texts = [domain["get_state_help_text"] for domain in data["domains"]]
|
||||||
|
action_urls = [domain["action_url"] for domain in data["domains"]]
|
||||||
|
|
||||||
|
# Check fields for each domain
|
||||||
|
for i, expected_domain in enumerate(expected_domains):
|
||||||
|
self.assertEqual(expected_domain.id, domain_ids[i])
|
||||||
|
self.assertEqual(expected_domain.name, names[i])
|
||||||
|
self.assertEqual(expected_domain.expiration_date, expiration_dates[i])
|
||||||
|
self.assertEqual(expected_domain.state, states[i])
|
||||||
|
|
||||||
|
# Parsing the expiration date from string to date
|
||||||
|
parsed_expiration_date = parse_date(expiration_dates[i])
|
||||||
|
expected_domain.expiration_date = parsed_expiration_date
|
||||||
|
|
||||||
|
# Check state_display and get_state_help_text
|
||||||
|
self.assertEqual(expected_domain.state_display(), state_displays[i])
|
||||||
|
self.assertEqual(expected_domain.get_state_help_text(), get_state_help_texts[i])
|
||||||
|
|
||||||
|
self.assertEqual(f'/domain/{expected_domain.id}', action_urls[i])
|
||||||
|
|
||||||
def test_pagination(self):
|
def test_pagination(self):
|
||||||
"""Test that pagination is correct in the response"""
|
"""Test that pagination is correct in the response"""
|
||||||
|
|
|
@ -2,6 +2,8 @@ from registrar.models import DomainRequest
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from .test_views import TestWithUser
|
from .test_views import TestWithUser
|
||||||
from django_webtest import WebTest # type: ignore
|
from django_webtest import WebTest # type: ignore
|
||||||
|
from datetime import datetime
|
||||||
|
from django.utils.dateparse import parse_datetime
|
||||||
|
|
||||||
|
|
||||||
class DomainRequestViewTest(TestWithUser, WebTest):
|
class DomainRequestViewTest(TestWithUser, WebTest):
|
||||||
|
@ -88,6 +90,13 @@ class DomainRequestViewTest(TestWithUser, WebTest):
|
||||||
status=DomainRequest.DomainRequestStatus.REJECTED,
|
status=DomainRequest.DomainRequestStatus.REJECTED,
|
||||||
created_at="2024-11-01",
|
created_at="2024-11-01",
|
||||||
),
|
),
|
||||||
|
DomainRequest.objects.create(
|
||||||
|
creator=self.user,
|
||||||
|
requested_domain=None,
|
||||||
|
submission_date="2024-11-02",
|
||||||
|
status=DomainRequest.DomainRequestStatus.WITHDRAWN,
|
||||||
|
created_at="2024-11-02",
|
||||||
|
),
|
||||||
DomainRequest.objects.create(
|
DomainRequest.objects.create(
|
||||||
creator=self.user,
|
creator=self.user,
|
||||||
requested_domain=None,
|
requested_domain=None,
|
||||||
|
@ -97,8 +106,12 @@ class DomainRequestViewTest(TestWithUser, WebTest):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
|
DomainRequest.objects.all().delete()
|
||||||
|
|
||||||
def test_get_domain_requests_json_authenticated(self):
|
def test_get_domain_requests_json_authenticated(self):
|
||||||
"""test that domain requests are returned properly for an authenticated user"""
|
"""Test that domain requests are returned properly for an authenticated user."""
|
||||||
response = self.app.get(reverse("get_domain_requests_json"))
|
response = self.app.get(reverse("get_domain_requests_json"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
data = response.json
|
data = response.json
|
||||||
|
@ -109,10 +122,33 @@ class DomainRequestViewTest(TestWithUser, WebTest):
|
||||||
self.assertFalse(data["has_previous"])
|
self.assertFalse(data["has_previous"])
|
||||||
self.assertEqual(data["num_pages"], 2)
|
self.assertEqual(data["num_pages"], 2)
|
||||||
|
|
||||||
# Check domain requests
|
# Check the number of domain requests
|
||||||
self.assertEqual(len(data["domain_requests"]), 10)
|
self.assertEqual(len(data["domain_requests"]), 10)
|
||||||
for domain_request in data["domain_requests"]:
|
|
||||||
self.assertNotEqual(domain_request["status"], "Approved")
|
# Extract fields from response
|
||||||
|
requested_domains = [request["requested_domain"] for request in data["domain_requests"]]
|
||||||
|
submission_dates = [request["submission_date"] for request in data["domain_requests"]]
|
||||||
|
statuses = [request["status"] for request in data["domain_requests"]]
|
||||||
|
created_ats = [request["created_at"] for request in data["domain_requests"]]
|
||||||
|
ids = [request["id"] for request in data["domain_requests"]]
|
||||||
|
is_deletables = [request["is_deletable"] for request in data["domain_requests"]]
|
||||||
|
|
||||||
|
# Check fields for each domain request
|
||||||
|
for i in range(10):
|
||||||
|
self.assertNotEqual(data["domain_requests"][i]["status"], "Approved")
|
||||||
|
self.assertEqual(self.domain_requests[i].requested_domain.name if self.domain_requests[i].requested_domain else None, requested_domains[i])
|
||||||
|
self.assertEqual(self.domain_requests[i].submission_date, submission_dates[i])
|
||||||
|
self.assertEqual(self.domain_requests[i].get_status_display(), statuses[i])
|
||||||
|
self.assertEqual(parse_datetime(self.domain_requests[i].created_at.isoformat()), parse_datetime(created_ats[i]))
|
||||||
|
self.assertEqual(self.domain_requests[i].id, ids[i])
|
||||||
|
|
||||||
|
# Check is_deletable
|
||||||
|
is_deletable_expected = self.domain_requests[i].status in [
|
||||||
|
DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
DomainRequest.DomainRequestStatus.WITHDRAWN
|
||||||
|
]
|
||||||
|
self.assertEqual(is_deletable_expected, is_deletables[i])
|
||||||
|
|
||||||
|
|
||||||
def test_pagination(self):
|
def test_pagination(self):
|
||||||
"""Test that pagination works properly. There are 11 total non-approved requests and
|
"""Test that pagination works properly. There are 11 total non-approved requests and
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from registrar.models import DomainRequest
|
from registrar.models import DomainRequest
|
||||||
|
from django.utils.dateformat import format
|
||||||
|
from django.utils.dateparse import parse_datetime
|
||||||
|
|
||||||
|
|
||||||
def get_domain_requests_json(request):
|
def get_domain_requests_json(request):
|
||||||
|
@ -28,10 +30,26 @@ def get_domain_requests_json(request):
|
||||||
"requested_domain": domain_request.requested_domain.name if domain_request.requested_domain else None,
|
"requested_domain": domain_request.requested_domain.name if domain_request.requested_domain else None,
|
||||||
"submission_date": domain_request.submission_date,
|
"submission_date": domain_request.submission_date,
|
||||||
"status": domain_request.get_status_display(),
|
"status": domain_request.get_status_display(),
|
||||||
"created_at": domain_request.created_at,
|
"created_at": format(domain_request.created_at, 'c'), # Serialize to ISO 8601
|
||||||
"id": domain_request.id,
|
"id": domain_request.id,
|
||||||
"is_deletable": domain_request.status
|
"is_deletable": domain_request.status
|
||||||
in [DomainRequest.DomainRequestStatus.STARTED, DomainRequest.DomainRequestStatus.WITHDRAWN],
|
in [DomainRequest.DomainRequestStatus.STARTED, DomainRequest.DomainRequestStatus.WITHDRAWN],
|
||||||
|
"action_url": (
|
||||||
|
f"/domain-request/{domain_request.id}/edit"
|
||||||
|
if domain_request.status in [
|
||||||
|
DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
DomainRequest.DomainRequestStatus.WITHDRAWN
|
||||||
|
]
|
||||||
|
else f"/domain-request/{domain_request.id}"
|
||||||
|
),
|
||||||
|
"action_label": (
|
||||||
|
"Edit"
|
||||||
|
if domain_request.status in [
|
||||||
|
DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
DomainRequest.DomainRequestStatus.WITHDRAWN
|
||||||
|
]
|
||||||
|
else "Manage"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
for domain_request in page_obj
|
for domain_request in page_obj
|
||||||
]
|
]
|
||||||
|
|
|
@ -41,6 +41,7 @@ def get_domains_json(request):
|
||||||
"state": domain.state,
|
"state": domain.state,
|
||||||
"state_display": domain.state_display(),
|
"state_display": domain.state_display(),
|
||||||
"get_state_help_text": domain.get_state_help_text(),
|
"get_state_help_text": domain.get_state_help_text(),
|
||||||
|
"action_url": f"/domain/{domain.id}",
|
||||||
}
|
}
|
||||||
for domain in page_obj.object_list
|
for domain in page_obj.object_list
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue