Skip to content

Commit

Permalink
Merge branch 'main' into feat-terragrunt-binary-#979
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber authored Nov 20, 2024
2 parents 6abd865 + c43e444 commit 37c8525
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
31 changes: 24 additions & 7 deletions client/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ type Team struct {
Users []User `json:"users"`
}

type PaginatedTeamsResponse struct {
Teams []Team `json:"teams"`
NextPageKey string `json:"nextPageKey"`
}

func (client *ApiClient) TeamCreate(payload TeamCreatePayload) (Team, error) {
if payload.Name == "" {
return Team{}, errors.New("must specify team name on creation")
Expand Down Expand Up @@ -84,20 +89,32 @@ func (client *ApiClient) GetTeams(params map[string]string) ([]Team, error) {
return nil, err
}

var result []Team
var teams []Team

err = client.http.Get("/teams/organizations/"+organizationId, params, &result)
if err != nil {
return nil, err
for {
var res PaginatedTeamsResponse

if err := client.http.Get("/teams/organizations/"+organizationId, params, &res); err != nil {
return nil, err
}

teams = append(teams, res.Teams...)

nextPageKey := res.NextPageKey
if nextPageKey == "" {
break
}

params["offset"] = nextPageKey
}

return result, err
return teams, nil
}

func (client *ApiClient) Teams() ([]Team, error) {
return client.GetTeams(nil)
return client.GetTeams(map[string]string{"limit": "100"})
}

func (client *ApiClient) TeamsByName(name string) ([]Team, error) {
return client.GetTeams(map[string]string{"name": name})
return client.GetTeams(map[string]string{"name": name, "limit": "100"})
}
30 changes: 26 additions & 4 deletions client/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ var _ = Describe("Teams Client", func() {
Name: "team-name",
}

mockTeam2 := Team{
Id: "team-id2",
Name: "team-name2",
}

Describe("Get Single Team", func() {
var returnedTeam Team

Expand All @@ -40,13 +45,29 @@ var _ = Describe("Teams Client", func() {
Describe("Get All Teams", func() {
var returnedTeams []Team
mockTeams := []Team{mockTeam}
mockTeams2 := []Team{mockTeam2}

BeforeEach(func() {
mockOrganizationIdCall()
httpCall = mockHttpClient.EXPECT().
Get("/teams/organizations/"+organizationId, nil, gomock.Any()).
Do(func(path string, request interface{}, response *[]Team) {
*response = mockTeams
Get("/teams/organizations/"+organizationId, map[string]string{
"limit": "100",
}, gomock.Any()).
Do(func(path string, request interface{}, response *PaginatedTeamsResponse) {
*response = PaginatedTeamsResponse{
Teams: mockTeams,
NextPageKey: "next_page_key",
}
})
httpCall2 = mockHttpClient.EXPECT().
Get("/teams/organizations/"+organizationId, map[string]string{
"offset": "next_page_key",
"limit": "100",
}, gomock.Any()).
Do(func(path string, request interface{}, response *PaginatedTeamsResponse) {
*response = PaginatedTeamsResponse{
Teams: mockTeams2,
}
})
returnedTeams, _ = apiClient.Teams()
})
Expand All @@ -57,10 +78,11 @@ var _ = Describe("Teams Client", func() {

It("Should send GET request", func() {
httpCall.Times(1)
httpCall2.Times(1)
})

It("Should return teams", func() {
Expect(returnedTeams).To(Equal(mockTeams))
Expect(returnedTeams).To(Equal(append(mockTeams, mockTeams2...)))
})
})

Expand Down

0 comments on commit 37c8525

Please sign in to comment.