From 62a24b6c45513321dd020645e5dafd81a77625e3 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Mon, 16 Dec 2024 15:21:53 -0500 Subject: [PATCH] LEAF 4455 test - add tests for display of inactive accts, filled and empty metadata --- API-tests/database/portal_test_db.sql | 2 +- API-tests/employee_test.go | 11 +++- API-tests/formQuery_test.go | 76 +++++++++++++++++++-------- 3 files changed, 65 insertions(+), 24 deletions(-) diff --git a/API-tests/database/portal_test_db.sql b/API-tests/database/portal_test_db.sql index 4aec52c8..c18681be 100644 --- a/API-tests/database/portal_test_db.sql +++ b/API-tests/database/portal_test_db.sql @@ -6287,7 +6287,7 @@ INSERT INTO `records` (`recordID`, `date`, `serviceID`, `userID`, `title`, `prio (10, 1694021465, 0, 'tester', 'TestFormWorkflow_ApplyAction', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"tester.tester@fake-email.com\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'), (11, 1694021465, 0, 'tester', 'TestFormQuery_Employee_Format__Orgchart_Has_Expected_Values', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"tester.tester@fake-email.com\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'), (12, 1694021465, 0, 'tester', 'TestFormQuery_InitiatorName', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"tester.tester@fake-email.com\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'), -(13, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"tester.tester@fake-email.com\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'), +(13, 1694021465, 0, 'tester_disabled', 'TestFormQuery_Initiator_Disabled__Empty_Metadata', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"\", \"lastName\": \"\", \"userName\": \"\", \"firstName\": \"\", \"middleName\": \"\"}'), (14, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"tester.tester@fake-email.com\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'), (15, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"tester.tester@fake-email.com\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'), (16, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"tester.tester@fake-email.com\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'), diff --git a/API-tests/employee_test.go b/API-tests/employee_test.go index 011c15f0..d4718f96 100644 --- a/API-tests/employee_test.go +++ b/API-tests/employee_test.go @@ -59,7 +59,14 @@ func postEmployee(postUrl string, data Employee) (string, error) { return c, nil } -func disableEmployee(postUrl string) error { +func EnableLocalEmployee(empUID string) error { + postData := url.Values{} + postData.Set("CSRFToken", CsrfToken) + _, err := client.PostForm(RootOrgchartURL+`api/employee/` + empUID + `/activate`, postData) + return err +} + +func DisableEmployee(postUrl string) error { data := url.Values{} data.Set("CSRFToken", CsrfToken) @@ -271,7 +278,7 @@ func TestEmployee_CheckNationalEmployee(t *testing.T) { } // delete remote employee - err = disableEmployee(fmt.Sprintf("%sapi/employee/%s", NationalOrgchartURL, natEmployeeKey)) + err = DisableEmployee(fmt.Sprintf("%sapi/employee/%s", NationalOrgchartURL, natEmployeeKey)) if err != nil { t.Error(err) } diff --git a/API-tests/formQuery_test.go b/API-tests/formQuery_test.go index 29620bf9..b58c9823 100644 --- a/API-tests/formQuery_test.go +++ b/API-tests/formQuery_test.go @@ -323,28 +323,28 @@ func TestFormQuery_Records_UserMetadata__Has_Expected_Values(t *testing.T) { Email: "Risá.Keebler@fake-email.com", UserName: "vtrigzcristal", } - + //post new request under a username postData := url.Values{} postData.Set("CSRFToken", CsrfToken) postData.Set("initiator", "vtrigzcristal") _, _ = client.PostForm(RootURL+`api/form/12/initiator`, postData) + //confirm firstName, lastName and userMetadata have expected values q := `api/form/query/?q={"terms":[{"id":"categoryID","operator":"=","match":"form_5ea07","gate":"AND"},{"id":"deleted","operator":"=","match":0,"gate":"AND"}],"joins":["initiatorName"],"sort":{}}` xFilter := `&x-filterData=recordID,lastName,firstName,userMetadata` res, _ := getFormQuery(RootURL + q + xFilter) - recordID := 12 - formRecord := res[recordID] - initiatorOrgchart := formRecord.UserMetadata + formRecord := res[12] + initiatorMetadata := formRecord.UserMetadata - gotFirstName := res[recordID].FirstName - gotLastName := res[recordID].LastName + gotFirstName := formRecord.FirstName + gotLastName := formRecord.LastName - gotMetadataFirstName := initiatorOrgchart.FirstName - gotMetadataLastName := initiatorOrgchart.LastName - gotMetadataMiddle := initiatorOrgchart.MiddleName - gotMetadataEmail := initiatorOrgchart.Email - gotMetadataUserName := initiatorOrgchart.UserName + gotMetadataFirstName := initiatorMetadata.FirstName + gotMetadataLastName := initiatorMetadata.LastName + gotMetadataMiddle := initiatorMetadata.MiddleName + gotMetadataEmail := initiatorMetadata.Email + gotMetadataUserName := initiatorMetadata.UserName wantFirst := mock_orgchart_employee.FirstName wantLast := mock_orgchart_employee.LastName @@ -352,22 +352,13 @@ func TestFormQuery_Records_UserMetadata__Has_Expected_Values(t *testing.T) { wantEmail := mock_orgchart_employee.Email wantUserName := mock_orgchart_employee.UserName - //record firstName lastName fields. These are extracted from JSON userMetadata and should also match. - if !cmp.Equal(gotFirstName, wantFirst) { - t.Errorf("Record first name got = %v, want = %v", gotFirstName, wantFirst) - } - if !cmp.Equal(gotLastName, wantLast) { - t.Errorf("Record last name got = %v, want = %v", gotLastName, wantLast) - } - //record userMetadata firstName lastName properties + //record userMetadata properties if !cmp.Equal(gotMetadataFirstName, wantFirst) { t.Errorf("Record userMetadata first name got = %v, want = %v", gotMetadataFirstName, wantFirst) } if !cmp.Equal(gotMetadataLastName, wantLast) { t.Errorf("Record userMetadata last name got = %v, want = %v", gotMetadataLastName, wantLast) } - - //record userMetadata middleName email and userName properties if !cmp.Equal(gotMetadataMiddle, wantMiddle) { t.Errorf("Last name got = %v, want = %v", gotMetadataMiddle, wantMiddle) } @@ -377,4 +368,47 @@ func TestFormQuery_Records_UserMetadata__Has_Expected_Values(t *testing.T) { if !cmp.Equal(gotMetadataUserName, wantUserName) { t.Errorf("Last name got = %v, want = %v", gotMetadataUserName, wantUserName) } + + //record firstName lastName fields. These are extracted from JSON userMetadata and should also match. + if !cmp.Equal(gotFirstName, wantFirst) { + t.Errorf("Record first name got = %v, want = %v", gotFirstName, wantFirst) + } + if !cmp.Equal(gotLastName, wantLast) { + t.Errorf("Record last name got = %v, want = %v", gotLastName, wantLast) + } + + //disable the account locally and confirm first and last name are still available + err := DisableEmployee(RootOrgchartURL + "api/employee/11") + if err != nil { + t.Error(err) + } + res, _ = getFormQuery(RootURL + q + xFilter) + formRecord = res[12] + gotFirstName = formRecord.FirstName + gotLastName = formRecord.LastName + if !cmp.Equal(gotFirstName, wantFirst) { + t.Errorf("Record first name got = %v, want = %v", gotFirstName, wantFirst) + } + if !cmp.Equal(gotLastName, wantLast) { + t.Errorf("Record last name got = %v, want = %v", gotLastName, wantLast) + } + //re-enable account + err = EnableLocalEmployee("11") + if err != nil { + t.Error(err) + } + + //test firstName, lastName record fields for a record (#13)with empty metadata (accounts disabled prior to 12/6/2024) + formRecord = res[13] + gotFirstName = formRecord.FirstName + gotLastName = formRecord.LastName + + wantFirst = "(inactive user)" + wantLast = "tester_disabled" + if !cmp.Equal(gotFirstName, wantFirst) { + t.Errorf("Record first name got = %v, want = %v", gotFirstName, wantFirst) + } + if !cmp.Equal(gotLastName, wantLast) { + t.Errorf("Record last name got = %v, want = %v", gotLastName, wantLast) + } } \ No newline at end of file