Skip to content

Commit

Permalink
correct workflow request handler function and write unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtabBukhari committed Nov 19, 2024
1 parent 0638d6e commit 291424b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion handlers/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (wh *workflowHandler) HandleWorkflowRequest(w http.ResponseWriter, r *http.
return
}

request.Status = db.StatusNew
request.RequestID = processedRequestID
request.Status = db.StatusNew

if err := wh.db.CreateWorkflowRequest(&request); err != nil {
http.Error(w, "Failed to create workflow request", http.StatusInternalServerError)
Expand Down
16 changes: 7 additions & 9 deletions handlers/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package handlers
import (
"bytes"
"encoding/json"
"github.com/stakwork/sphinx-tribes/db"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"

"github.com/google/uuid"
"github.com/stakwork/sphinx-tribes/db"
"github.com/stretchr/testify/assert"
)

func TestHandleWorkflowRequest(t *testing.T) {
Expand All @@ -23,11 +21,10 @@ func TestHandleWorkflowRequest(t *testing.T) {
"test_key": "test_value",
}

request := db.WfRequest{
Source: "test_source",
Action: "test_action",
WorkflowID: "workflow_id",
ProjectID: uuid.New().String(),
request := &db.WfRequest{
Source: "test_source_1",
Action: "test_action_1",
WorkflowID: "test_workflow",
RequestData: requestData,
}

Expand All @@ -40,6 +37,7 @@ func TestHandleWorkflowRequest(t *testing.T) {
wh.HandleWorkflowRequest(w, req)

assert.Equal(t, http.StatusCreated, w.Code)

var respBody map[string]string
err := json.NewDecoder(w.Body).Decode(&respBody)
assert.NoError(t, err)
Expand Down

0 comments on commit 291424b

Please sign in to comment.