Skip to content

Commit

Permalink
LEAF-4581 - extended character set test (#22)
Browse files Browse the repository at this point in the history
* LEAF-4851 - initial setup of test

* LEAF-4581 - testing of special characters on record title and data. Also includes test to show affects on other parts of the site that do not use mb4

---------

Co-authored-by: shane <[email protected]>
  • Loading branch information
shaneodd and shane authored Jan 16, 2025
1 parent 6758bfd commit 0d4aacb
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 34 deletions.
84 changes: 54 additions & 30 deletions API-tests/events_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"testing"
"github.com/google/go-cmp/cmp"
"encoding/json"
"io"
"net/url"
"testing"

"github.com/google/go-cmp/cmp"
)

func getEvent(url string) (WorkflowEventsResponse, error) {
Expand Down Expand Up @@ -84,20 +85,20 @@ func confirmEventsRecordValues(t *testing.T, expectedEvent WorkflowEvent, expect
/*
* Get emailTemplates records and search by eventDescription / email_templates label.
* Confirm that a record is found and has the expected property values based on the eventID.
*/
*/
func confirmEmailTemplatesRecordValues(t *testing.T, eventID string, eventDescription string) {
emailTemplatesResponse, err := getEmailTemplatesResponse(RootURL + `api/emailTemplates`)
if err != nil {
t.Error(err)
}
var newEmailTemplatesRecord EmailTemplatesRecord
for i := 0; i < len(emailTemplatesResponse); i++ {
emailTempRec := emailTemplatesResponse[i];
if(emailTempRec.DisplayName == eventDescription) {
emailTempRec := emailTemplatesResponse[i]
if emailTempRec.DisplayName == eventDescription {
newEmailTemplatesRecord = emailTempRec
}
}
if (newEmailTemplatesRecord.FileName == "") {
if newEmailTemplatesRecord.FileName == "" {
t.Errorf("Did not find expected email templates record")
} else {
got := newEmailTemplatesRecord.FileName
Expand Down Expand Up @@ -125,19 +126,19 @@ func confirmEmailTemplatesRecordValues(t *testing.T, eventID string, eventDescri

/*
* Event posts successfully and associated events and email_templates table records have expected values
*/
*/
func TestEvents_NewValidCustomEmailEvent(t *testing.T) {
eventName := "CustomEvent_event_valid"
optionsIn := map[string]string {
optionsIn := map[string]string{
"data[Notify Requestor]": "true",
"data[Notify Next]": "true",
"data[Notify Group]": "203",
"data[Notify Next]": "true",
"data[Notify Group]": "203",
}
expectedJSON := `{"NotifyRequestor":"true","NotifyNext":"true","NotifyGroup":"203"}`
ev_valid := WorkflowEvent{
EventID: eventName,
EventDescription: "test event description",
EventType: "Email",
EventID: eventName,
EventDescription: "test event description",
EventType: "Email",
}
res, err := postEvent(RootURL+`api/workflow/events`, ev_valid, optionsIn)
if err != nil {
Expand All @@ -156,14 +157,14 @@ func TestEvents_NewValidCustomEmailEvent(t *testing.T) {

func TestEvents_ReservedPrefixes_NotAllowed(t *testing.T) {
ev_leafsecure := WorkflowEvent{
EventID: "LeafSecure_prefix",
EventDescription: "prefix is reserved 1",
EventType: "Email",
EventID: "LeafSecure_prefix",
EventDescription: "prefix is reserved 1",
EventType: "Email",
}
ev_std_email := WorkflowEvent{
EventID: "std_email_prefix",
EventDescription: "prefix is reserved 2",
EventType: "Email",
EventID: "std_email_prefix",
EventDescription: "prefix is reserved 2",
EventType: "Email",
}

res, err := postEvent(RootURL+`api/workflow/events`, ev_leafsecure, map[string]string{})
Expand All @@ -189,9 +190,9 @@ func TestEvents_ReservedPrefixes_NotAllowed(t *testing.T) {

func TestEvents_DuplicateDescription_NotAllowed(t *testing.T) {
ev_desc_dup := WorkflowEvent{
EventID: "CustomEvent_event_desc_dup",
EventDescription: "test event description",
EventType: "Email",
EventID: "CustomEvent_event_desc_dup",
EventDescription: "test event description",
EventType: "Email",
}

res, err := postEvent(RootURL+`api/workflow/events`, ev_desc_dup, map[string]string{})
Expand All @@ -208,19 +209,19 @@ func TestEvents_DuplicateDescription_NotAllowed(t *testing.T) {
func TestEvents_EditValidCustomEmailEvent(t *testing.T) {
oldEventName := "CustomEvent_event_valid"
newEventName := "CustomEvent_event_valid_edited"
newOptionsIn := map[string]string {
newOptionsIn := map[string]string{
"data[Notify Requestor]": "false",
"data[Notify Next]": "false",
"data[Notify Group]": "101",
"newName": newEventName,
"data[Notify Next]": "false",
"data[Notify Group]": "101",
"newName": newEventName,
}
newExpectedJSON := `{"NotifyRequestor":"false","NotifyNext":"false","NotifyGroup":"101"}`
new_ev_valid := WorkflowEvent{
EventID: newEventName,
EventDescription: "test edited event description",
EventType: "Email",
EventID: newEventName,
EventDescription: "test edited event description",
EventType: "Email",
}
res, err := postEvent(RootURL+`api/workflow/editEvent/_` + oldEventName, new_ev_valid, newOptionsIn)
res, err := postEvent(RootURL+`api/workflow/editEvent/_`+oldEventName, new_ev_valid, newOptionsIn)
if err != nil {
t.Error(err)
}
Expand All @@ -234,3 +235,26 @@ func TestEvents_EditValidCustomEmailEvent(t *testing.T) {

confirmEmailTemplatesRecordValues(t, new_ev_valid.EventID, new_ev_valid.EventDescription)
}

/* This is to show off what will happen if you try and use a utf8 era character in latin1*/
func TestEvents_Special_Character(t *testing.T) {
this_is_a_only_a_simley_face_test := WorkflowEvent{
EventID: "this_is_a_only_a_simley_face_test",
EventDescription: "This is a simley face 😀 Text afterwards",
EventType: "Email",
}
theMorphedText := "This is a simley face ? Text afterwards"
_, err := postEvent(RootURL+`api/workflow/events`, this_is_a_only_a_simley_face_test, map[string]string{})
if err != nil {
t.Error(err)
}

event, err := getEvent(RootURL + `api/workflow/event/_` + this_is_a_only_a_simley_face_test.EventID)
if err != nil {
t.Error(err)
}

if event[0].EventDescription != theMorphedText {
t.Errorf(`Title %v Does not match %v.`, event[0].EventDescription, theMorphedText)
}
}
49 changes: 45 additions & 4 deletions API-tests/formQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"encoding/json"
"fmt"
"io"
"net/url"
"strings"
"strconv"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -248,9 +249,9 @@ func TestFormQuery_FindTwoSteps(t *testing.T) {
/* 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{
EmpUID: 201,
FirstName: "Ramon",
LastName: "Watsica",
EmpUID: 201,
FirstName: "Ramon",
LastName: "Watsica",
MiddleName: "Yundt",
Email: "[email protected]",
UserName: "vtrycxbethany",
Expand Down Expand Up @@ -524,3 +525,43 @@ func TestForm_VerifyInitiator(t *testing.T) {
t.Error("UserName not set")
}
}

/* Test special characters saved in the title of a record and contents of a record */
func TestFormQuery_Special_Characters(t *testing.T) {

theTestString := "This is an otter 🦦 this is a smiley 😀"
theTestTitleString := "TestForm_Special_Characters😀"

// Setup conditions
postData := url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("numform_5ea07", "1")
postData.Set("title", theTestTitleString)
postData.Set("3", theTestString)
postData.Set("8", "1")
postData.Set("9", "112")

// TODO: streamline this
pRes, _ := client.PostForm(RootURL+`api/form/new`, postData)
bodyBytes, _ := io.ReadAll(pRes.Body)
var response string
json.Unmarshal(bodyBytes, &response)
recordID, err := strconv.Atoi(string(response))

if err != nil {
t.Errorf("Could not create record for TestFormQuery_Special_Characters: " + err.Error())
}

res, _ := getFormQuery(RootURL + fmt.Sprintf(`api/form/query/?q={"terms":[{"id":"recordID","operator":"=","match":"%d","gate":"AND"},{"id":"deleted","operator":"=","match":0,"gate":"AND"}],"joins":[],"sort":{},"getData":["3"]}&x-filterData=recordID,title`, recordID))

if res[recordID].Title != theTestTitleString {
t.Errorf(`Title %v Does not match %v.`, res[recordID].Title, theTestTitleString)
}

for tKey, tVal := range res[recordID].S1 {

if tKey == "id3" && tVal != theTestString {
t.Errorf(`Text %v Does not match %v.`, tVal, theTestString)
}
}
}

0 comments on commit 0d4aacb

Please sign in to comment.