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

Feat: workflow trigger new resources #623

Merged
merged 2 commits into from
Mar 13, 2023
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
2 changes: 2 additions & 0 deletions client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ type ApiClientInterface interface {
CustomFlowAssign(assignments []CustomFlowAssignment) error
CustomFlowUnassign(assignments []CustomFlowAssignment) error
CustomFlowGetAssignments(assignments []CustomFlowAssignment) ([]CustomFlowAssignment, error)
SubscribeWorkflowTrigger(environmentId string, payload WorkflowTriggerEnvironments) error
UnsubscribeWorkflowTrigger(environmentId string, payload WorkflowTriggerEnvironments) error
}

func NewApiClient(client http.HttpClientInterface, defaultOrganizationId string) ApiClientInterface {
Expand Down
28 changes: 28 additions & 0 deletions client/api_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion client/workflow_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ type WorkflowTriggerUpsertPayload struct {
DownstreamEnvironmentIds []string `json:"downstreamEnvironmentIds"`
}

type WorkflowTriggerEnvironments struct {
DownstreamEnvironmentIds []string `json:"downstreamEnvironmentIds"`
}

func (client *ApiClient) WorkflowTrigger(environmentId string) ([]WorkflowTrigger, error) {
var result []WorkflowTrigger
err := client.http.Get("environments/"+environmentId+"/downstream", nil, &result)
err := client.http.Get("/environments/"+environmentId+"/downstream", nil, &result)
if err != nil {
return []WorkflowTrigger{}, err
}
Expand All @@ -27,3 +31,11 @@ func (client *ApiClient) WorkflowTriggerUpsert(environmentId string, request Wor
}
return result, nil
}

func (client *ApiClient) SubscribeWorkflowTrigger(environmentId string, payload WorkflowTriggerEnvironments) error {
return client.http.Post("/environments/"+environmentId+"/downstream/subscribe", payload, nil)
}

func (client *ApiClient) UnsubscribeWorkflowTrigger(environmentId string, payload WorkflowTriggerEnvironments) error {
return client.http.Post("/environments/"+environmentId+"/downstream/unsubscribe", payload, nil)
}
38 changes: 37 additions & 1 deletion client/workflow_triggers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var _ = Describe("Workflow Triggers", func() {
Describe("WorkflowTrigger", func() {
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().
Get("environments/"+environmentId+"/downstream", nil, gomock.Any()).
Get("/environments/"+environmentId+"/downstream", nil, gomock.Any()).
Do(func(path string, request interface{}, response *[]WorkflowTrigger) {
*response = mockTrigger
})
Expand All @@ -52,4 +52,40 @@ var _ = Describe("Workflow Triggers", func() {
Expect(triggers).To(Equal(mockTrigger))
})
})

Describe("SubscribeWorkflowTrigger", func() {
var err error

subscribePayload := WorkflowTriggerEnvironments{
DownstreamEnvironmentIds: []string{"1", "2"},
}

BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Post("/environments/"+environmentId+"/downstream/subscribe", subscribePayload, nil)
httpCall.Times(1)
err = apiClient.SubscribeWorkflowTrigger(environmentId, subscribePayload)
})

It("Should not return an error", func() {
Expect(err).To(BeNil())
})
})

Describe("UnsubscribeWorkflowTrigger", func() {
var err error

unsubscribePayload := WorkflowTriggerEnvironments{
DownstreamEnvironmentIds: []string{"1", "2"},
}

BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().Post("/environments/"+environmentId+"/downstream/unsubscribe", unsubscribePayload, nil)
httpCall.Times(1)
err = apiClient.UnsubscribeWorkflowTrigger(environmentId, unsubscribePayload)
})

It("Should not return an error", func() {
Expect(err).To(BeNil())
})
})
})