Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEAF-4581 - extended character set test #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
53 changes: 47 additions & 6 deletions API-tests/formQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

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

Expand Down Expand Up @@ -208,15 +210,14 @@ 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{
FirstName: "Ramon",
LastName: "Watsica",
FirstName: "Ramon",
LastName: "Watsica",
MiddleName: "Yundt",
Email: "[email protected]",
UserName: "vtrycxbethany",
Email: "[email protected]",
UserName: "vtrycxbethany",
}

postData := url.Values{}
Expand All @@ -243,7 +244,7 @@ func TestFormQuery_Employee_Format__Orgchart_Has_Expected_Values(t *testing.T) {
recData := formRes[11].S1

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

var org_emp FormQuery_Orgchart_Employee
Expand Down Expand Up @@ -278,3 +279,43 @@ func TestFormQuery_Employee_Format__Orgchart_Has_Expected_Values(t *testing.T) {
t.Errorf("userName got = %v, want = %v", got, want)
}
}

/* 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)
}
}
}
Loading