Skip to content

Commit

Permalink
Merge pull request #93 from justinfarrelldev/master
Browse files Browse the repository at this point in the history
Added GetBoardsInOrganization to Organizations.go
  • Loading branch information
adlio committed Jun 20, 2022
2 parents 02f26cf + 7cbdf0f commit 905f038
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
12 changes: 12 additions & 0 deletions organization.go
Expand Up @@ -35,6 +35,18 @@ func (c *Client) GetOrganization(orgID string, extraArgs ...Arguments) (organiza
return
}

// GetBoardsInOrganization takes an organization id and Arguments and either GET returns
// a slice of boards within that organization, or an error.
func (c *Client) GetBoardsInOrganization(orgID string, extraArgs ...Arguments) (boards []*Board, err error) {
args := flattenArguments(extraArgs)
path := fmt.Sprintf("organizations/%s/boards", orgID)
err = c.Get(path, args, &boards)
if err != nil {
return nil, err
}
return
}

// SetClient can be used to override this Organization's internal connection
// to the Trello API. Normally, this is set automatically after API calls.
func (o *Organization) SetClient(newClient *Client) {
Expand Down
18 changes: 18 additions & 0 deletions organization_test.go
Expand Up @@ -16,6 +16,24 @@ func TestGetOrganization(t *testing.T) {
}
}

func TestGetBoardsInOrganization(t *testing.T) {
organization := testOrganization(t)
if organization.DisplayName != "Culture Foundry" {
t.Errorf("Expected name 'Culture Foundry'. Got '%s'.", organization.DisplayName)
}

client := testClient()
client.BaseURL = mockResponse("organizations", "571ab6ad9dc91c597d6e9f90", "boards", "boards.json").URL

boards, err := client.GetBoardsInOrganization(organization.ID)
if err != nil {
t.Fatalf("Expected boards in organization to be returned. Got error: %v", err)
}
if boards == nil {
t.Fatalf("Expected boards slice to contain boards in the test organization with ID %s. Slice was nil.", organization.ID)
}
}

func TestOrganizationSetClient(t *testing.T) {
o := Organization{}
client := testClient()
Expand Down
148 changes: 148 additions & 0 deletions testdata/organizations/571ab6ad9dc91c597d6e9f90/boards/boards.json
@@ -0,0 +1,148 @@
[
{
"id": "4eea4ffc91e31d1746000046",
"closed": false,
"dateLastActivity": null,
"dateLastView": null,
"desc": "This board is used in the API examples",
"descData": null,
"idOrganization": "4efe2c2f2e1efe7a4c0002c9",
"invitations": [],
"invited": false,
"labelNames": {
"green": "",
"yellow": "",
"orange": "",
"red": "",
"purple": "",
"blue": "",
"sky": "",
"lime": "",
"pink": "",
"black": ""
},
"memberships": [
{
"id": "4eea4ffc91e31d174600004d",
"idMember": "4ee7deffe582acdec80000ac",
"memberType": "admin",
"unconfirmed": false
},
{
"id": "4eea507991e31d17460000fc",
"idMember": "4ee7df1be582acdec80000ae",
"memberType": "normal",
"unconfirmed": false
},
{
"id": "4eea50bc91e31d174600016d",
"idMember": "4ee7df74e582acdec80000b6",
"memberType": "normal",
"unconfirmed": false
}
],
"name": "Example Board",
"pinned": false,
"powerUps": [],
"prefs": {
"permissionLevel": "public",
"voting": "members",
"comments": "members",
"invitations": "members",
"selfJoin": true,
"cardCovers": true,
"calendarFeedEnabled": false,
"background": "blue",
"backgroundColor": "#0079BF",
"backgroundImage": null,
"backgroundImageScaled": null,
"backgroundTile": false,
"backgroundBrightness": "unknown",
"canBePublic": true,
"canBeOrg": true,
"canBePrivate": true,
"canInvite": true
},
"shortLink": "OXiBYZoj",
"shortUrl": "https://trello.com/b/OXiBYZoj",
"starred": null,
"subscribed": null,
"url": "https://trello.com/b/OXiBYZoj/example-board"
},
{
"id": "4ee7e707e582acdec800051a",
"closed": false,
"dateLastActivity": null,
"dateLastView": null,
"desc": "A board that everyone can see",
"descData": null,
"idOrganization": "",
"invitations": [],
"invited": false,
"labelNames": {
"green": "",
"yellow": "",
"orange": "",
"red": "",
"purple": "",
"blue": "",
"sky": "",
"lime": "",
"pink": "",
"black": ""
},
"lists": [
{
"name": "Some list",
"id": "4een4ffc91r31q174fsldk46"
}
],
"memberships": [
{
"id": "4ee7e707e582acdec8000521",
"idMember": "4ee7df3ce582acdec80000b2",
"memberType": "admin",
"unconfirmed": false
},
{
"id": "4ee7e72fe582acdec8000573",
"idMember": "4ee7df1be582acdec80000ae",
"memberType": "normal",
"unconfirmed": false
},
{
"id": "514c5f9cb569140000000016",
"idMember": "514c5f9cb569140000000014",
"memberType": "normal",
"unconfirmed": false
}
],
"name": "Public Board",
"pinned": false,
"powerUps": [],
"prefs": {
"permissionLevel": "public",
"voting": "public",
"comments": "public",
"invitations": "members",
"selfJoin": true,
"cardCovers": true,
"calendarFeedEnabled": false,
"background": "blue",
"backgroundColor": "#0079BF",
"backgroundImage": null,
"backgroundImageScaled": null,
"backgroundTile": false,
"backgroundBrightness": "unknown",
"canBePublic": true,
"canBeOrg": true,
"canBePrivate": true,
"canInvite": true
},
"shortLink": "IwLRbh3F",
"shortUrl": "https://trello.com/b/IwLRbh3F",
"starred": null,
"subscribed": null,
"url": "https://trello.com/b/IwLRbh3F/public-board"
}
]

0 comments on commit 905f038

Please sign in to comment.