From bb04ea1fe9a11f1ccda08e94ff87b5aaee20ff0c Mon Sep 17 00:00:00 2001
From: Tore Brede <Tore.Brede@uib.no>
Date: Tue, 9 Nov 2021 16:34:42 +0100
Subject: [PATCH] Adding missing contact person field on form

---
 frontend/public/locales/en/common.json        |  3 +-
 frontend/public/locales/nb/common.json        |  3 +-
 frontend/public/locales/nn/common.json        |  3 +-
 .../src/routes/sponsor/register/formData.ts   |  1 +
 .../sponsor/register/stepPersonForm.tsx       |  6 ++++
 .../sponsor/register/stepRegistration.tsx     |  1 +
 gregui/tests/api/test_invite_guest.py         | 29 ++++++++++++-------
 7 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/frontend/public/locales/en/common.json b/frontend/public/locales/en/common.json
index 795e3894..248a52f4 100644
--- a/frontend/public/locales/en/common.json
+++ b/frontend/public/locales/en/common.json
@@ -24,7 +24,8 @@
     "mobilePhone": "Mobile phone",
     "passportNumber": "Passport number",
     "passportNationality": "Passport nationality",
-    "countryCallingCode": "Country code"
+    "countryCallingCode": "Country code",
+    "contactPersonUnit": "Contact at unit"
   },
   "sponsor": {
     "addRole": "Add role",
diff --git a/frontend/public/locales/nb/common.json b/frontend/public/locales/nb/common.json
index 2a1a32b4..4afc7b8e 100644
--- a/frontend/public/locales/nb/common.json
+++ b/frontend/public/locales/nb/common.json
@@ -24,7 +24,8 @@
     "mobilePhone": "Mobilnummer",
     "passportNumber": "Passnummer",
     "passportNationality": "Passnasjonalitet",
-    "countryCallingCode": "Landkode"
+    "countryCallingCode": "Landkode",
+    "contactPersonUnit": "Kontakt ved avdeling"
   },
   "sponsor": {
     "addRole": "Legg til rolle",
diff --git a/frontend/public/locales/nn/common.json b/frontend/public/locales/nn/common.json
index 30dde00a..256f5fce 100644
--- a/frontend/public/locales/nn/common.json
+++ b/frontend/public/locales/nn/common.json
@@ -25,7 +25,8 @@
     "mobilePhone": "Mobilnummer",
     "passportNumber": "Passnummer",
     "passportNationality": "Passnasjonalitet",
-    "countryCallingCode": "Landkode"
+    "countryCallingCode": "Landkode",
+    "contactPersonUnit": "Kontakt ved avdeling"
   },
   "sponsor": {
     "addRole": "Legg til role",
diff --git a/frontend/src/routes/sponsor/register/formData.ts b/frontend/src/routes/sponsor/register/formData.ts
index 5e518b30..8e96d7a6 100644
--- a/frontend/src/routes/sponsor/register/formData.ts
+++ b/frontend/src/routes/sponsor/register/formData.ts
@@ -4,6 +4,7 @@ export type RegisterFormData = {
   role_type?: string
   role_start?: Date
   role_end?: Date
+  contact_person_unit?: string
   comment?: string
   ou_id?: number
   email?: string
diff --git a/frontend/src/routes/sponsor/register/stepPersonForm.tsx b/frontend/src/routes/sponsor/register/stepPersonForm.tsx
index bbfd2431..b005b4ee 100644
--- a/frontend/src/routes/sponsor/register/stepPersonForm.tsx
+++ b/frontend/src/routes/sponsor/register/stepPersonForm.tsx
@@ -219,6 +219,12 @@ const StepPersonForm = forwardRef(
                 )}
               />
 
+              <TextField
+                id="contact_person"
+                label={t('input.contactPersonUnit')}
+                {...register(`contact_person_unit`)}
+              />
+
               <TextField
                 id="comment"
                 label={t('input.comment')}
diff --git a/frontend/src/routes/sponsor/register/stepRegistration.tsx b/frontend/src/routes/sponsor/register/stepRegistration.tsx
index 8e4bd716..36ba38bb 100644
--- a/frontend/src/routes/sponsor/register/stepRegistration.tsx
+++ b/frontend/src/routes/sponsor/register/stepRegistration.tsx
@@ -70,6 +70,7 @@ export default function StepRegistration() {
           formData.role_end === null
             ? null
             : format(formData.role_end as Date, 'yyyy-MM-dd'),
+        contact_person_unit: formData.contact_person_unit,
         comments: formData.comment,
         orgunit: formData.ou_id,
       },
diff --git a/gregui/tests/api/test_invite_guest.py b/gregui/tests/api/test_invite_guest.py
index 0f265b1e..4c819f99 100644
--- a/gregui/tests/api/test_invite_guest.py
+++ b/gregui/tests/api/test_invite_guest.py
@@ -10,28 +10,29 @@ from gregui.api.views.invitation import InvitationView
 
 @pytest.mark.django_db
 def test_invite_guest(client, user_sponsor, unit_foo, role_type_foo):
+    test_comment = "This is a test comment"
+    contact_person_unit = "This is a test contact person"
+    role_start_date = datetime.datetime.today() + datetime.timedelta(days=1)
+    role_end_date = datetime.datetime.today() + datetime.timedelta(days=10)
+
     data = {
         "first_name": "Foo",
         "last_name": "Bar",
         "email": "test@example.com",
         "role": {
-            "start_date": (
-                datetime.datetime.today() + datetime.timedelta(days=1)
-            ).strftime("%Y-%m-%d"),
-            "end_date": (
-                datetime.datetime.today() + datetime.timedelta(days=10)
-            ).strftime("%Y-%m-%d"),
+            "start_date": (role_start_date).strftime("%Y-%m-%d"),
+            "end_date": (role_end_date).strftime("%Y-%m-%d"),
             "orgunit": unit_foo.id,
             "type": role_type_foo.id,
+            "comments": test_comment,
+            "contact_person_unit": contact_person_unit,
         },
     }
     url = reverse("gregui-v1:invitation")
 
-    all_persons = Person.objects.all()
-    assert len(all_persons) == 0
+    assert len(Person.objects.all()) == 0
 
-    factory = APIRequestFactory()
-    request = factory.post(url, data, format="json")
+    request = APIRequestFactory().post(url, data, format="json")
     force_authenticate(request, user=user_sponsor)
 
     view = InvitationView.as_view()
@@ -50,6 +51,14 @@ def test_invite_guest(client, user_sponsor, unit_foo, role_type_foo):
         value="test@example.com",
     ).exists()
 
+    role = Role.objects.filter(person__id=person.id).get()
+    assert role.orgunit == unit_foo
+    assert role.type == role_type_foo
+    assert role.start_date == role_start_date.date()
+    assert role.end_date == role_end_date.date()
+    assert role.contact_person_unit == contact_person_unit
+    assert role.comments == test_comment
+
 
 @pytest.mark.django_db
 def test_invite_cancel(
-- 
GitLab