diff --git a/proctord/jobs/execution/handler.go b/proctord/jobs/execution/handler.go index fe31343c..e9da2c4c 100644 --- a/proctord/jobs/execution/handler.go +++ b/proctord/jobs/execution/handler.go @@ -55,7 +55,9 @@ func (handler *executionHandler) Status() http.HandlerFunc { func (handler *executionHandler) Handle() http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { - jobsExecutionAuditLog := &postgres.JobsExecutionAuditLog{} + jobsExecutionAuditLog := &postgres.JobsExecutionAuditLog{ + JobExecutionStatus: "WAITING", + } defer func() { go handler.auditor.JobsExecutionAndStatus(jobsExecutionAuditLog) }() userEmail := req.Header.Get(utility.UserEmailHeaderKey) diff --git a/proctord/jobs/execution/handler_test.go b/proctord/jobs/execution/handler_test.go index 8a37283d..ff73bea6 100644 --- a/proctord/jobs/execution/handler_test.go +++ b/proctord/jobs/execution/handler_test.go @@ -168,6 +168,27 @@ func (suite *ExecutionHandlerTestSuite) TestJobStatusShouldReturn404IfJobStatusI assert.Equal(suite.T(), http.StatusNotFound, response.StatusCode) } +func (suite *ExecutionHandlerTestSuite) TestJobStatusShouldReturn200IfJobStatusIsWaiting() { + t := suite.T() + + jobName := "sample-job-name" + + url := fmt.Sprintf("%s/jobs/execute/%s/status", suite.TestServer.URL, jobName) + + suite.mockStore.On("GetJobExecutionStatus", jobName).Return("WAITING", nil).Once() + + req, _ := http.NewRequest("GET", url, nil) + + response, _ := suite.Client.Do(req) + suite.mockStore.AssertExpectations(t) + assert.Equal(suite.T(), http.StatusOK, response.StatusCode) + + buf := new(bytes.Buffer) + buf.ReadFrom(response.Body) + jobStatus := buf.String() + assert.Equal(suite.T(), utility.JobWaiting, jobStatus) +} + func (suite *ExecutionHandlerTestSuite) TestJobStatusShouldReturn500OnError() { t := suite.T()