Skip to content

Commit

Permalink
new pull
Browse files Browse the repository at this point in the history
  • Loading branch information
nk2136 committed Oct 24, 2024
2 parents 468e21d + d1ef779 commit 54dc7bb
Show file tree
Hide file tree
Showing 16 changed files with 682 additions and 125 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 @@ -6280,7 +6280,7 @@ INSERT INTO `records` (`recordID`, `date`, `serviceID`, `userID`, `title`, `prio
(8, 1694021464, 0, 'tester', 'TestFormWorkflow_ApplyAction', 0, 'Approved', 1694021485, 0, 0, 1),
(9, 1694021464, 0, 'tester', 'TestFormQuery_GroupClickedApprove', 0, 'Approved', 1694021485, 0, 0, 1),
(10, 1694021465, 0, 'tester', 'TestFormWorkflow_ApplyAction', 0, 'Submitted', 1694021485, 0, 0, 1),
(11, 1694021465, 0, 'tester', 'Employee Metadata Posts Correctly', 0, 'Submitted', 1694021485, 0, 0, 1),
(11, 1694021465, 0, 'tester', 'TestFormQuery_Employee_Format__Orgchart_Has_Expected_Values', 0, 'Submitted', 1694021485, 0, 0, 1),
(12, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1),
(13, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1),
(14, 1694021465, 0, 'tester', 'Available for test case', 0, 'Submitted', 1694021485, 0, 0, 1),
Expand Down
118 changes: 118 additions & 0 deletions API-tests/employee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"net/url"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -91,6 +92,123 @@ func disableEmployee(postUrl string) error {

}

func TestEmployee_AvoidPhantomIncrements(t *testing.T) {
// as the test name suggests this test is to prevent the auto increment in
// the employees table from incrementing without an actual insert. This
// test will reveal when a condition exists where an insert causes the
// increment to increase but a unique key forces the ON DUPLICATE UPDATE
// to update an existing row.

// This test needs to run before TestEmployee_CheckNationalEmployee as they
// both run the refreshOrgchartEmployees.php. This test expects there to be
// a difference between National and Local orgcharts and that may not be true
// once the refreshOrgchartEmployees.php runs.

// add new employee getting the empUID
m := Employee{
FirstName: "testing",
LastName: "users",
UserName: "testingusers",
}

n := Employee{
FirstName: "testing",
LastName: "users",
UserName: "TESTINGUSERS",
}

employeeId, err := postEmployee(NationalOrgchartURL+`api/employee/new`, m)

if err != nil {
t.Error(err)
}

if employeeId == "" {
t.Error("no user id returned")
}

var empUID1 string

empUID1, err = postEmployee(RootOrgchartURL+`api/employee/new`, n)

if err != nil {
t.Error(err)
}

if empUID1 == "" {
t.Error("no user id returned")
}

// ensure userNames are spelled the same but with different cases in
// national and local
var localEmployeeKey string
var natEmployeeKey string

natEmpoyeeRes, err := getEmployee(NationalOrgchartURL + `api/employee/search?q=username:testingusers`)

if err != nil {
t.Error(err)
}

for key := range natEmpoyeeRes {
natEmployeeKey = key
break
}

localEmployeeRes, _ := getEmployee(RootOrgchartURL + `api/employee/search?q=username:testingusers`)
for key := range localEmployeeRes {
localEmployeeKey = key
break
}

local := localEmployeeRes[localEmployeeKey].UserName
nat := natEmpoyeeRes[natEmployeeKey].UserName

if (!(nat != local && strings.ToLower(nat) == strings.ToLower(local))) {
t.Errorf("userNames should match except case - local = %v, national = %v", local, nat)
}

// run refresh Orgchart
err = updateEmployees(RootOrgchartURL + `scripts/refreshOrgchartEmployees.php`)

if err != nil {
t.Error(err)
}

var empUID2 string

// add new user getting empUID
o := Employee{
FirstName: "testing",
LastName: "users",
UserName: "testingusers2",
}

empUID2, err = postEmployee(RootOrgchartURL+`api/employee/new`, o)

if err != nil {
t.Error(err)
}

if empUID2 == "" {
t.Error("no user id returned")
}

var id1 int
var id2 int

id1, err1 := strconv.Atoi(empUID1)
id2, err2 := strconv.Atoi(empUID2)

if err1 != nil || err2 != nil {
t.Error("empUID is not a number")
}

if id2 != (id1 + 1) {
t.Error("unexpected auto increment value")
}
}

func TestEmployee_CheckNationalEmployee(t *testing.T) {

// make sure the users are in place before we start.
Expand Down
8 changes: 8 additions & 0 deletions API-tests/formQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ type FormQueryResponse map[int]FormQueryRecord

type FormQueryData map[string]any

type FormQuery_Orgchart_Employee struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
MiddleName string `json:"middleName"`
Email string `json:"email"`
UserName string `json:"userName"`
}

type FormQueryRecord struct {
RecordID int `json:"recordID"`
ServiceID int `json:"serviceID"`
Expand Down
43 changes: 15 additions & 28 deletions API-tests/formQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,17 @@ func TestFormQuery_FindTwoSteps(t *testing.T) {
}
}

/*
* Reading of metadata values will be added in a future deployment
* The orgchart value is still from the orgchart lookup, not the metadata field
// "strconv"
// "github.com/google/go-cmp/cmp"
func TestFormQuery_Employee_Metadata(t *testing.T) {
//values that should be assigned to S1 ind orchart value when form data are read
mock_orgchart_employee := Orgchart_employee_metadata{

/* post a new employee to an orgchart format question and then confirm expected values on orgchart property */
func TestFormQuery_Employee_Format__Orgchart_Has_Expected_Values(t *testing.T) {
mock_orgchart_employee := FormQuery_Orgchart_Employee{
FirstName: "Ramon",
LastName: "Watsica",
MiddleName: "Yundt",
Email: "[email protected]",
UserName: "VTRYCXBETHANY",
UserName: "vtrycxbethany",
}

//post and confirm post success
postData := url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("8", "201")
Expand All @@ -242,52 +236,45 @@ func TestFormQuery_Employee_Metadata(t *testing.T) {
}

formRes, _ := getFormQuery(RootURL + `api/form/query/?q={"terms":[{"id":"categoryID","operator":"=","match":"form_5ea07","gate":"AND"},{"id":"deleted","operator":"=","match":0,"gate":"AND"}],"joins":[],"sort":{},"getData":["8"],"limit":10000,"limitOffset":0}&x-filterData=recordID,title`)
if _, exists := formRes[11]; !exists {
t.Errorf("Record 11 should be readable")
}

recData := formRes[11].S1

metadataInterface := recData["id8_orgchart"]
orgchart := metadataInterface.(map[string]interface {})
dataInterface := recData["id8_orgchart"]
orgchart := dataInterface.(map[string]interface {})
b, _ := json.Marshal(orgchart)

var org_emp_md Orgchart_employee_metadata
err = json.Unmarshal(b, &org_emp_md)
var org_emp FormQuery_Orgchart_Employee
err = json.Unmarshal(b, &org_emp)
if err != nil {
t.Error("Error on orgchart_employee_metadata unmarshal")
t.Error("Error on FormQuery_Orgchart_Employee unmarshal")
}

got = org_emp_md.FirstName
got = org_emp.FirstName
want = mock_orgchart_employee.FirstName
if !cmp.Equal(got, want) {
t.Errorf("firstName got = %v, want = %v", got, want)
}
got = org_emp_md.LastName
got = org_emp.LastName
want = mock_orgchart_employee.LastName
if !cmp.Equal(got, want) {
t.Errorf("lastName got = %v, want = %v", got, want)
}
got = org_emp_md.MiddleName
got = org_emp.MiddleName
want = mock_orgchart_employee.MiddleName
if !cmp.Equal(got, want) {
t.Errorf("middleName got = %v, want = %v", got, want)
}
got = org_emp_md.Email
got = org_emp.Email
want = mock_orgchart_employee.Email
if !cmp.Equal(got, want) {
t.Errorf("email got = %v, want = %v", got, want)
}
got = org_emp_md.UserName
got = org_emp.UserName
want = mock_orgchart_employee.UserName
if !cmp.Equal(got, want) {
t.Errorf("userName got = %v, want = %v", got, want)
}
got = strconv.Itoa(org_emp_md.EmpUID)
want = "201"
if !cmp.Equal(got, want) {
t.Errorf("userName got = %v, want = %v", got, want)
}
}
*/
2 changes: 1 addition & 1 deletion API-tests/formStack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestFormStack_NewFormProperties(t *testing.T) {
}

got = strconv.Itoa(category.Visible)
want = "1"
want = "-1"
if !cmp.Equal(got, want) {
t.Errorf("Visible = %v, want = %v", got, want)
}
Expand Down
24 changes: 24 additions & 0 deletions API-tests/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

type PortalGroupResponse []PortalGroup
type NexusGroupResponse []NexusGroup
type ShortGroupResponse []ShortGroup

type PortalGroup struct {
GroupID int `json:"groupID"`
ParentGroupID int `json:"parentGroupID"`
Name string `json:"name"`
GroupDescription string `json:"groupDescription"`
Members []Member `json:"members"`
}

type NexusGroup struct {
GroupID int `json:"groupID"`
ParentID int `json:"parentID"`
GroupTitle string `json:"groupTitle"`
}

type ShortGroup struct {
GroupID int `json:"groupID"`
Name string `json:"name"`
}
Loading

0 comments on commit 54dc7bb

Please sign in to comment.