Skip to content

Commit

Permalink
LEAF 4455 test - add tests for display of inactive accts, filled and …
Browse files Browse the repository at this point in the history
…empty metadata
  • Loading branch information
aerinkayne committed Dec 16, 2024
1 parent fa9e520 commit 62a24b6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 24 deletions.
2 changes: 1 addition & 1 deletion API-tests/database/portal_test_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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\": \"[email protected]\", \"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\": \"[email protected]\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'),
(12, 1694021465, 0, 'tester', 'TestFormQuery_InitiatorName', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"[email protected]\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'),
(13, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"[email protected]\", \"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\": \"[email protected]\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'),
(15, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"[email protected]\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'),
(16, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1, '{\"email\": \"[email protected]\", \"lastName\": \"Tester\", \"userName\": \"tester\", \"firstName\": \"Tester\", \"middleName\": \"\"}'),
Expand Down
11 changes: 9 additions & 2 deletions API-tests/employee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
76 changes: 55 additions & 21 deletions API-tests/formQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,51 +323,42 @@ func TestFormQuery_Records_UserMetadata__Has_Expected_Values(t *testing.T) {
Email: "Risá[email protected]",
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
wantMiddle := mock_orgchart_employee.MiddleName
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)
}
Expand All @@ -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)
}
}

0 comments on commit 62a24b6

Please sign in to comment.