Skip to content

Commit

Permalink
feat: add md api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtawast committed Aug 30, 2023
1 parent 4ade307 commit 0d4c9f6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/benefit/terms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TermsAdmin(admin.ModelAdmin):
list_display = ("id", "terms_type", "effective_from")

class Media:
css = {"all": ("css/markdownx.css",)}
css = {"all": ("css/markdown.css",)}


class ApprovedApplicantConsentInline(admin.ModelAdmin):
Expand Down
12 changes: 9 additions & 3 deletions backend/benefit/terms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ class Terms(UUIDModel, TimeStampedModel):
default=TermsType.APPLICANT_TERMS,
)

terms_md_fi = models.TextField(verbose_name=_("Finnish terms (md)"), blank=True)
terms_md_en = models.TextField(verbose_name=_("English terms (md)"), blank=True)
terms_md_sv = models.TextField(verbose_name=_("Swedish terms (md)"), blank=True)
terms_md_fi = models.TextField(
verbose_name=_("Finnish terms (md)"), blank=True, default=""
)
terms_md_en = models.TextField(
verbose_name=_("English terms (md)"), blank=True, default=""
)
terms_md_sv = models.TextField(
verbose_name=_("Swedish terms (md)"), blank=True, default=""
)

"""
If effective_from is set to null, that means the terms are not to be displayed to the applicant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@
list-style: disc;
font-size: 1em;
}

label[for*="id_terms_md_"] {
float: none;
}
9 changes: 9 additions & 0 deletions backend/benefit/terms/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ class Meta:
model = ApplicantConsent


markdown_content = """# Heading 1
Lorem ipsum dolor sit amet"""


class TermsFactory(factory.django.DjangoModelFactory):
terms_pdf_fi = "terms_fi.pdf"
terms_pdf_en = "terms_en.pdf"
terms_pdf_sv = "terms_sv.pdf"

terms_md_fi = markdown_content
terms_md_en = markdown_content
terms_md_sv = markdown_content

applicant_consent_1 = factory.RelatedFactory(
ApplicantConsentFactory,
factory_related_name="terms",
Expand Down
54 changes: 53 additions & 1 deletion backend/benefit/terms/tests/test_terms_of_service_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_current_user_url():
return "/v1/users/me/"


def test_terms_of_service_in_effect(
def test_terms_of_service_in_effect_pdf(
api_client, mock_get_organisation_roles_and_create_company
):
"""
Expand Down Expand Up @@ -60,6 +60,58 @@ def test_terms_of_service_in_effect(
assert response.status_code == 200


def test_terms_of_service_in_effect_md(
api_client, mock_get_organisation_roles_and_create_company
):
"""
Test that the API returns the correct Terms and ApplicantConsents in the terms_of_service_in_effect field.
"""
current_terms = TermsFactory(
effective_from=date.today(), terms_type=TermsType.TERMS_OF_SERVICE
)

markdown_content = """# Heading 1
Lorem ipsum dolor sit amet"""

# Create some extra terms that should not be returned
# ... old terms
TermsFactory(
effective_from=date.today() - timedelta(days=1),
terms_type=TermsType.TERMS_OF_SERVICE,
)
# ... future terms
TermsFactory(
effective_from=date.today() + timedelta(days=1),
terms_type=TermsType.TERMS_OF_SERVICE,
)
# ... wrong type of terms
TermsFactory(effective_from=date.today(), terms_type=TermsType.APPLICANT_TERMS)
response = api_client.get(get_current_user_url())

assert (
get_company_from_request(response.wsgi_request)
== mock_get_organisation_roles_and_create_company
)
assert response.data["terms_of_service_in_effect"]["id"] == str(current_terms.pk)
assert (
response.data["terms_of_service_in_effect"]["terms_md_fi"] == markdown_content
)
assert (
response.data["terms_of_service_in_effect"]["terms_md_en"] == markdown_content
)
assert (
response.data["terms_of_service_in_effect"]["terms_md_sv"] == markdown_content
)

assert {
obj["id"]
for obj in response.data["terms_of_service_in_effect"]["applicant_consents"]
} == {str(obj.pk) for obj in current_terms.applicant_consents.all()}

assert response.status_code == 200


@pytest.mark.parametrize("previously_approved", [False, True])
def test_approve_terms_success(
api_client,
Expand Down

0 comments on commit 0d4c9f6

Please sign in to comment.