Skip to content

Commit

Permalink
test: board methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereCloud committed Jul 17, 2019
1 parent a7b1be3 commit bfb81aa
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 4 deletions.
8 changes: 4 additions & 4 deletions 5.92/api/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (vk *VK) BoardGetCommentsExtended(params map[string]string) (response Board
type BoardGetTopicsResponse struct {
Count int `json:"count"`
Items []object.BoardTopic `json:"items"`
DefaultOrder int `json:"default_order"`
DefaultOrder float64 `json:"default_order"` // BUG(VK): default_order int
CanAddTopics int `json:"can_add_topics"`
}

Expand All @@ -155,7 +155,7 @@ func (vk *VK) BoardGetTopics(params map[string]string) (response BoardGetTopicsR
type BoardGetTopicsExtendedResponse struct {
Count int `json:"count"`
Items []object.BoardTopic `json:"items"`
DefaultOrder int `json:"default_order"`
DefaultOrder float64 `json:"default_order"` // BUG(VK): default_order int
CanAddTopics int `json:"can_add_topics"`
Profiles []object.UsersUser `json:"profiles"`
Groups []object.GroupsGroup `json:"groups"`
Expand Down Expand Up @@ -195,12 +195,12 @@ func (vk *VK) BoardRestoreComment(params map[string]string) (response BoardResto
}

// BoardUnfixTopicRResponse struct
type BoardUnfixTopicRResponse int
type BoardUnfixTopicResponse int

// BoardUnfixTopicR unpins a pinned topic from the top of a community's discussion board.
//
// https://vk.com/dev/board.unfixTopic
func (vk *VK) BoardUnfixTopicR(params map[string]string) (response BoardUnfixTopicRResponse, vkErr Error) {
func (vk *VK) BoardUnfixTopic(params map[string]string) (response BoardUnfixTopicResponse, vkErr Error) {
vk.RequestUnmarshal("board.unfixTopic", params, &response, &vkErr)
return
}
150 changes: 150 additions & 0 deletions 5.92/api/board_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package api

import (
"strconv"
"testing"
)

func TestVK_BoardAddTopic(t *testing.T) {
if vkUser.AccessToken == "" {
t.Skip("USER_TOKEN empty")
}

topic, gotVkErr := vkUser.BoardAddTopic(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"title": "Test topic",
"text": "Test",
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardAddTopic() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardCloseTopic(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardCloseTopic() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardOpenTopic(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardOpenTopic() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardEditTopic(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
"title": "Test topic edited",
"text": "Test edited",
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardEditTopic() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardFixTopic(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardFixTopic() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardUnfixTopic(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardUnfixTopic() gotVkErr = %v, want %v", gotVkErr, 0)
}

comment, gotVkErr := vkUser.BoardCreateComment(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
"message": "topic comment",
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardCreateComment() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardEditComment(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
"comment_id": strconv.Itoa(int(comment)),
"message": "topic comment",
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardEditComment() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardDeleteComment(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
"comment_id": strconv.Itoa(int(comment)),
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardDeleteComment() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardRestoreComment(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
"comment_id": strconv.Itoa(int(comment)),
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardRestoreComment() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardDeleteTopic(map[string]string{
"group_id": strconv.Itoa(vkGroupID),
"topic_id": strconv.Itoa(int(topic)),
})
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardDeleteTopic() gotVkErr = %v, want %v", gotVkErr, 0)
}
}

func TestVK_BoardGetComments(t *testing.T) {
if vkUser.AccessToken == "" {
t.Skip("USER_TOKEN empty")
}

params := map[string]string{
"group_id": "1",
"topic_id": "21972169",
}

_, gotVkErr := vkUser.BoardGetComments(params)
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardGetComments() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardGetCommentsExtended(params)
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardGetCommentsExtended() gotVkErr = %v, want %v", gotVkErr, 0)
}
}

func TestVK_BoardGetTopics(t *testing.T) {
if vkUser.AccessToken == "" {
t.Skip("USER_TOKEN empty")
}

params := map[string]string{
"group_id": "1",
"topic_id": "21972169",
}

_, gotVkErr := vkUser.BoardGetTopics(params)
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardGetTopics() gotVkErr = %v, want %v", gotVkErr, 0)
}

_, gotVkErr = vkUser.BoardGetTopicsExtended(params)
if gotVkErr.Code != 0 {
t.Errorf("VK.BoardGetTopicsExtended() gotVkErr = %v, want %v", gotVkErr, 0)
}
}

0 comments on commit bfb81aa

Please sign in to comment.