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 4585 test - prevent negative step coords #16

Merged
merged 2 commits into from
Nov 27, 2024
Merged
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
16 changes: 16 additions & 0 deletions API-tests/workflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

type WorkflowStep struct {
WorkflowID int `json:"workflowID"`
StepID int `json:"stepID"`
StepTitle string `json:"stepTitle"`
StepBgColor string `json:"stepBgColor"`
StepFontColor string `json:"stepFontColor"`
JsSrc string `json:"jsSrc"`
PosX int `json:"posX"`
PosY int `json:"posY"`
IndicatorID_for_assigned_empUID int `json:"indicatorID_for_assigned_empUID"`
IndicatorID_for_assigned_groupID int `json:"indicatorID_for_assigned_groupID"`
RequiresDigitalSignature int `json:"requiresDigitalSignature"`
StepData string `json:"stepData"`
}
82 changes: 82 additions & 0 deletions API-tests/workflow_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"encoding/json"
"io"
"strconv"
"log"
"net/url"
"testing"

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

func getWorkflowStep(stepID string) WorkflowStep {
res, _ := client.Get(RootURL + "api/workflow/step/" + stepID)
b, _ := io.ReadAll(res.Body)

var m WorkflowStep
err := json.Unmarshal(b, &m)
if err != nil {
log.Printf("JSON parsing error, couldn't parse: %v", string(b))
log.Printf("JSON parsing error: %v", err.Error())
}
return m
}

func setStepCoordinates(workflowID string, stepID string, x string, y string) string {
postData := url.Values{}
postData.Set("CSRFToken", CsrfToken)
postData.Set("stepID", stepID)
postData.Set("x", x)
postData.Set("y", y)

res, _ := client.PostForm(RootURL + `api/workflow/`+ workflowID + `/editorPosition`, postData)
bodyBytes, _ := io.ReadAll(res.Body)

var c string
err := json.Unmarshal(bodyBytes, &c)
if err != nil {
log.Printf("JSON parsing error, couldn't parse: %v", string(bodyBytes))
}
return c
}

func TestWorkflow_Set_Step_Coordinates(t *testing.T) {
//negative coords use min val of 0
got := setStepCoordinates("1", "1", "-100", "-100")
want := "1"
if !cmp.Equal(got, want) {
t.Errorf("Error setting step position = %v, want = %v", got, want)
}

workflowStep := getWorkflowStep("1")
got = strconv.Itoa(workflowStep.PosX)
want = "0"
if !cmp.Equal(got, want) {
t.Errorf("Saved X position should have min possible value of 0 = %v, want = %v", got, want)
}
got = strconv.Itoa(workflowStep.PosY)
if !cmp.Equal(got, want) {
t.Errorf("Saved Y position should have min possible value of 0 = %v, want = %v", got, want)
}

//positive coords should save as given
got = setStepCoordinates("1", "1", "200", "500")
want = "1"
if !cmp.Equal(got, want) {
t.Errorf("Error setting step position = %v, want = %v", got, want)
}

workflowStep = getWorkflowStep("1")
got = strconv.Itoa(workflowStep.PosX)
want = "200"
if !cmp.Equal(got, want) {
t.Errorf("Saved X position did not match input = %v, want = %v", got, want)
}
got = strconv.Itoa(workflowStep.PosY)
want = "500"
if !cmp.Equal(got, want) {
t.Errorf("Saved Y position did not match input = %v, want = %v", got, want)
}
}
Loading