diff --git a/server/api/pipeline.go b/server/api/pipeline.go index 400eaf357..07fefea62 100644 --- a/server/api/pipeline.go +++ b/server/api/pipeline.go @@ -132,7 +132,7 @@ func GetPipelines(c *gin.Context) { if events := c.Query("event"); events != "" { eventList := strings.Split(events, ",") wel := make(model.WebhookEventList, 0, len(eventList)) - for _, event := range events { + for _, event := range eventList { we := model.WebhookEvent(event) if err := we.Validate(); err != nil { _ = c.AbortWithError(http.StatusBadRequest, err) diff --git a/server/api/pipeline_test.go b/server/api/pipeline_test.go index 80e2e7965..dd7043cd5 100644 --- a/server/api/pipeline_test.go +++ b/server/api/pipeline_test.go @@ -96,6 +96,24 @@ func TestGetPipelines(t *testing.T) { assert.Equal(t, http.StatusOK, c.Writer.Status()) }) + + t.Run("should filter pipelines by events", func(t *testing.T) { + pipelines := []*model.Pipeline{fakePipeline} + mockStore := store_mocks.NewStore(t) + mockStore.On("GetPipelineList", mock.Anything, mock.Anything, mock.Anything).Return(pipelines, nil) + + w := httptest.NewRecorder() + c, _ := gin.CreateTestContext(w) + c.Set("store", mockStore) + c.Request, _ = http.NewRequest(http.MethodGet, "/?event=push,pull_request", nil) + + GetPipelines(c) + + mockStore.AssertCalled(t, "GetPipelineList", mock.Anything, mock.Anything, &model.PipelineFilter{ + Events: model.WebhookEventList{model.EventPush, model.EventPull}, + }) + assert.Equal(t, http.StatusOK, c.Writer.Status()) + }) } func TestDeletePipeline(t *testing.T) {