Skip to content

Commit

Permalink
Add SetClient() on Card, Board, and List.
Browse files Browse the repository at this point in the history
  • Loading branch information
adlio committed Mar 28, 2021
1 parent 1a3ee4c commit 62c161d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions board.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ type BackgroundImage struct {
URL string `json:"url"`
}

// SetClient can be used to override this Board's internal connection to the
// Trello API. Normally, this is set automatically after calls to GetBoard()
// from the Client. This method exists for special cases where
// functions which need a Client need to be called on Board structs which
// weren't created from a Client in the first place.
func (b *Board) SetClient(newClient *Client) {
b.client = newClient
}

// CreatedAt returns a board's created-at attribute as time.Time.
func (b *Board) CreatedAt() time.Time {
t, _ := IDToTime(b.ID)
Expand Down
9 changes: 9 additions & 0 deletions board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,12 @@ func TestBoardAddMember(t *testing.T) {
t.Errorf("Status membership incorrect, got %v", response.Memberships[1].Unconfirmed)
}
}

func TestBoardSetClient(t *testing.T) {
board := testBoard(t)
client := testClient()
board.SetClient(client)
if board.client == nil {
t.Error("Expected non-nil board.client")
}
}
9 changes: 9 additions & 0 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ type Card struct {
customFieldMap *map[string]interface{}
}

// SetClient can be used to override this Card's internal connection to the
// Trello API. Normally, this is set automatically after calls to GetCard()
// from the Client or a List. This method exists for special cases where
// functions which need a Client need to be called on Card structs which
// weren't created from a Client in the first place.
func (c *Card) SetClient(newClient *Client) {
c.client = newClient
}

// CreatedAt returns the receiver card's created-at attribute as time.Time.
func (c *Card) CreatedAt() time.Time {
t, _ := IDToTime(c.ID)
Expand Down
9 changes: 9 additions & 0 deletions card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ func TestAddURLAttachmentToCard(t *testing.T) {
}
}

func TestCardSetClient(t *testing.T) {
card := Card{}
client := testClient()
card.SetClient(client)
if card.client == nil {
t.Error("Expected non-nil card.client")
}
}

// Utility function to get a simple response from Client.GetCard()
//
func testCard(t *testing.T) *Card {
Expand Down
9 changes: 9 additions & 0 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ type List struct {
Cards []*Card `json:"cards,omitempty"`
}

// SetClient can be used to override this List's internal connection to the
// Trello API. Normally, this is set automatically after calls to GetList()
// from the Client. This method exists for special cases where
// functions which need a Client need to be called on List structs which
// weren't created from a Client in the first place.
func (l *List) SetClient(newClient *Client) {
l.client = newClient
}

// CreatedAt returns the time.Time from the list's id.
func (l *List) CreatedAt() time.Time {
t, _ := IDToTime(l.ID)
Expand Down
9 changes: 9 additions & 0 deletions list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,12 @@ func TestUpdateList(t *testing.T) {
t.Errorf("Expected the returned list to pick up a position. Instead got '%v'.", list.Pos)
}
}

func TestListSetClient(t *testing.T) {
list := List{}
client := testClient()
list.SetClient(client)
if list.client == nil {
t.Error("Expected non-nil list.client")
}
}

0 comments on commit 62c161d

Please sign in to comment.