From d1627b99eafebbd3a8dfe17529c524600cd00291 Mon Sep 17 00:00:00 2001
From: pka065 <pka065@it6100016.klientdrift.uib.no>
Date: Tue, 11 Oct 2022 13:41:28 +0200
Subject: [PATCH] Add test for the new API endpoint

---
 greg/api/urls.py              |  2 +-
 greg/tests/api/test_person.py | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/greg/api/urls.py b/greg/api/urls.py
index 9e028ba2..a9a36fd6 100644
--- a/greg/api/urls.py
+++ b/greg/api/urls.py
@@ -78,6 +78,6 @@ urlpatterns += [
     re_path(
         "person-search/",
         PersonSearchSet.as_view({"get": "list"}),
-        name="person-search",
+        name="person_search-list",
     ),
 ]
diff --git a/greg/tests/api/test_person.py b/greg/tests/api/test_person.py
index dc411637..95be3fe6 100644
--- a/greg/tests/api/test_person.py
+++ b/greg/tests/api/test_person.py
@@ -276,6 +276,21 @@ def test_identity_add_duplicate_fails(client, person_foo, person_bar):
     assert response.json() == {"non_field_errors": ["Identity already exists"]}
 
 
+@pytest.mark.django_db
+def test_person_search_list(client, person_foo):
+    response = client.get(
+        reverse("v1:person_search-list") + "?q=Foo"
+    )
+    data = response.json()
+    assert len(data) == 1
+
+    person = response.json()[0]
+    birth_date = person_foo.date_of_birth
+    assert person["first"] == person_foo.first_name
+    assert person["last"] == person_foo.last_name
+    assert person["date_of_birth"] == birth_date.strftime("%Y-%m-%d")
+
+
 @pytest.mark.django_db
 def test_add_invalid_type(client, person):
     data = {
-- 
GitLab