Skip to content

Commit

Permalink
feat(api): add TestingGroup methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereCloud committed Jul 17, 2022
1 parent 9091654 commit 364b484
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 0 deletions.
48 changes: 48 additions & 0 deletions api/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import (
"github.com/SevereCloud/vksdk/v2/object"
)

// AppsAddUsersToTestingGroup method.
//
// https://vk.com/dev/apps.addUsersToTestingGroup
func (vk *VK) AppsAddUsersToTestingGroup(params Params) (response int, err error) {
err = vk.RequestUnmarshal("apps.addUsersToTestingGroup", &response, params)
return
}

// AppsDeleteAppRequests deletes all request notifications from the current app.
//
// https://vk.com/dev/apps.deleteAppRequests
Expand Down Expand Up @@ -140,10 +148,50 @@ func (vk *VK) AppsGetScore(params Params) (response string, err error) {
return
}

// AppsGetTestingGroupsResponse struct.
type AppsGetTestingGroupsResponse []object.AppsTestingGroup

// AppsGetTestingGroups method.
//
// https://vk.com/dev/apps.getTestingGroups
func (vk *VK) AppsGetTestingGroups(params Params) (response AppsGetTestingGroupsResponse, err error) {
err = vk.RequestUnmarshal("apps.getTestingGroups", &response, params)
return
}

// AppsRemoveTestingGroup method.
//
// https://vk.com/dev/apps.removeTestingGroup
func (vk *VK) AppsRemoveTestingGroup(params Params) (response int, err error) {
err = vk.RequestUnmarshal("apps.removeTestingGroup", &response, params)
return
}

// AppsRemoveUsersFromTestingGroups method.
//
// https://vk.com/dev/apps.removeUsersFromTestingGroups
func (vk *VK) AppsRemoveUsersFromTestingGroups(params Params) (response int, err error) {
err = vk.RequestUnmarshal("apps.removeUsersFromTestingGroups", &response, params)
return
}

// AppsSendRequest sends a request to another user in an app that uses VK authorization.
//
// https://vk.com/dev/apps.sendRequest
func (vk *VK) AppsSendRequest(params Params) (response int, err error) {
err = vk.RequestUnmarshal("apps.sendRequest", &response, params)
return
}

// AppsUpdateMetaForTestingGroupResponse struct.
type AppsUpdateMetaForTestingGroupResponse struct {
GroupID int `json:"group_id"`
}

// AppsUpdateMetaForTestingGroup method.
//
// https://vk.com/dev/apps.updateMetaForTestingGroup
func (vk *VK) AppsUpdateMetaForTestingGroup(params Params) (response AppsUpdateMetaForTestingGroupResponse, err error) {
err = vk.RequestUnmarshal("apps.updateMetaForTestingGroup", &response, params)
return
}
41 changes: 41 additions & 0 deletions api/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,44 @@ func TestVK_AppsGetScopes(t *testing.T) {

// TODO: TestVK_AppsGetScore
// TODO: TestVK_AppsSendRequest

func TestVK_AppsTestingGroups(t *testing.T) {
t.Parallel()

needServiceToken(t)

respUpdate, err := vkService.AppsUpdateMetaForTestingGroup(api.Params{
"webview": "https://example.com",
"name": "example",
"platforms": []string{"mobile"},
})
noErrorOrFail(t, err)

_, err = vkService.AppsAddUsersToTestingGroup(api.Params{
"user_ids": []int{1},
"group_id": respUpdate.GroupID,
})
noError(t, err)

resp, err := vkService.AppsGetTestingGroups(api.Params{
"group_id": respUpdate.GroupID,
})
noError(t, err)

if assert.NotEmpty(t, resp) {
assert.NotEmpty(t, resp[0].GroupID)
assert.NotEmpty(t, resp[0].Name)
assert.NotEmpty(t, resp[0].Webview)
}

_, err = vkService.AppsRemoveUsersFromTestingGroups(api.Params{
"user_ids": []int{1},
"group_id": respUpdate.GroupID,
})
noError(t, err)

_, err = vkService.AppsRemoveTestingGroup(api.Params{
"group_id": respUpdate.GroupID,
})
noError(t, err)
}
120 changes: 120 additions & 0 deletions api/params/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ import (
"github.com/SevereCloud/vksdk/v2/api"
)

// AppsAddUsersToTestingGroupBuilder builder.
//
// https://vk.com/dev/apps.addUsersToTestingGroup
type AppsAddUsersToTestingGroupBuilder struct {
api.Params
}

// NewAppsAddUsersToTestingGroupBuilder func.
func NewAppsAddUsersToTestingGroupBuilder() *AppsAddUsersToTestingGroupBuilder {
return &AppsAddUsersToTestingGroupBuilder{api.Params{}}
}

// UserIDs users ID.
func (b *AppsAddUsersToTestingGroupBuilder) UserIDs(v []int) *AppsAddUsersToTestingGroupBuilder {
b.Params["user_ids"] = v
return b
}

// GroupID group ID.
func (b *AppsAddUsersToTestingGroupBuilder) GroupID(v int) *AppsAddUsersToTestingGroupBuilder {
b.Params["group_id"] = v
return b
}

// AppsGetBuilder builder.
//
// Returns applications data.
Expand Down Expand Up @@ -353,6 +377,60 @@ func (b *AppsGetScoreBuilder) UserID(v int) *AppsGetScoreBuilder {
return b
}

// AppsGetTestingGroupsBuilder builder.
//
// https://vk.com/dev/apps.getTestingGroups
type AppsGetTestingGroupsBuilder struct {
api.Params
}

// NewAppsGetTestingGroupsBuilder func.
func NewAppsGetTestingGroupsBuilder() *AppsGetTestingGroupsBuilder {
return &AppsGetTestingGroupsBuilder{api.Params{}}
}

// GroupID group ID.
func (b *AppsGetTestingGroupsBuilder) GroupID(v int) *AppsGetTestingGroupsBuilder {
b.Params["group_id"] = v
return b
}

// AppsRemoveUsersFromTestingGroupsBuilder builder.
//
// https://vk.com/dev/apps.removeUsersFromTestingGroups
type AppsRemoveUsersFromTestingGroupsBuilder struct {
api.Params
}

// NewAppsRemoveUsersFromTestingGroupsBuilder func.
func NewAppsRemoveUsersFromTestingGroupsBuilder() *AppsRemoveUsersFromTestingGroupsBuilder {
return &AppsRemoveUsersFromTestingGroupsBuilder{api.Params{}}
}

// UserIDs users ID.
func (b *AppsRemoveUsersFromTestingGroupsBuilder) UserIDs(v []int) *AppsRemoveUsersFromTestingGroupsBuilder {
b.Params["user_ids"] = v
return b
}

// AppsRemoveTestingGroupBuilder builder.
//
// https://vk.com/dev/apps.removeTestingGroup
type AppsRemoveTestingGroupBuilder struct {
api.Params
}

// NewAppsRemoveTestingGroupBuilder func.
func NewAppsRemoveTestingGroupBuilder() *AppsRemoveTestingGroupBuilder {
return &AppsRemoveTestingGroupBuilder{api.Params{}}
}

// GroupID group ID.
func (b *AppsRemoveTestingGroupBuilder) GroupID(v int) *AppsRemoveTestingGroupBuilder {
b.Params["group_id"] = v
return b
}

// AppsSendRequestBuilder builder.
//
// Sends a request to another user in an app that uses VK authorization.
Expand Down Expand Up @@ -406,3 +484,45 @@ func (b *AppsSendRequestBuilder) Separate(v bool) *AppsSendRequestBuilder {
b.Params["separate"] = v
return b
}

// AppsUpdateMetaForTestingGroupBuilder builder.
//
// https://vk.com/dev/apps.UpdateMetaForTestingGroup
type AppsUpdateMetaForTestingGroupBuilder struct {
api.Params
}

// NewAppsUpdateMetaForTestingGroupBuilder func.
func NewAppsUpdateMetaForTestingGroupBuilder() *AppsUpdateMetaForTestingGroupBuilder {
return &AppsUpdateMetaForTestingGroupBuilder{api.Params{}}
}

// GroupID parameter.
func (b *AppsUpdateMetaForTestingGroupBuilder) GroupID(v int) *AppsUpdateMetaForTestingGroupBuilder {
b.Params["group_id"] = v
return b
}

// Webview parameter.
func (b *AppsUpdateMetaForTestingGroupBuilder) Webview(v string) *AppsUpdateMetaForTestingGroupBuilder {
b.Params["webview"] = v
return b
}

// Name parameter.
func (b *AppsUpdateMetaForTestingGroupBuilder) Name(v string) *AppsUpdateMetaForTestingGroupBuilder {
b.Params["name"] = v
return b
}

// Platforms parameter.
func (b *AppsUpdateMetaForTestingGroupBuilder) Platforms(v []string) *AppsUpdateMetaForTestingGroupBuilder {
b.Params["platforms"] = v
return b
}

// UserIDs users ID.
func (b *AppsUpdateMetaForTestingGroupBuilder) UserIDs(v []int) *AppsUpdateMetaForTestingGroupBuilder {
b.Params["user_ids"] = v
return b
}
60 changes: 60 additions & 0 deletions api/params/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import (
"github.com/stretchr/testify/assert"
)

func TestAppsAddUsersToTestingGroupBuilder(t *testing.T) {
t.Parallel()

b := params.NewAppsAddUsersToTestingGroupBuilder()

b.UserIDs([]int{1})
b.GroupID(1)

assert.Equal(t, b.Params["user_ids"], []int{1})
assert.Equal(t, b.Params["group_id"], 1)
}

func TestAppsGetBuilder(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -111,6 +123,36 @@ func TestAppsGetScoreBuilder(t *testing.T) {
assert.Equal(t, b.Params["user_id"], 1)
}

func TestAppsGetTestingGroupsBuilder(t *testing.T) {
t.Parallel()

b := params.NewAppsGetTestingGroupsBuilder()

b.GroupID(1)

assert.Equal(t, b.Params["group_id"], 1)
}

func TestAppsRemoveUsersFromTestingGroupsBuilder(t *testing.T) {
t.Parallel()

b := params.NewAppsRemoveUsersFromTestingGroupsBuilder()

b.UserIDs([]int{1})

assert.Equal(t, b.Params["user_ids"], []int{1})
}

func TestAppsRemoveTestingGroupBuilder(t *testing.T) {
t.Parallel()

b := params.NewAppsRemoveTestingGroupBuilder()

b.GroupID(1)

assert.Equal(t, b.Params["group_id"], 1)
}

func TestAppsSendRequestBuilder(t *testing.T) {
t.Parallel()

Expand All @@ -130,3 +172,21 @@ func TestAppsSendRequestBuilder(t *testing.T) {
assert.Equal(t, b.Params["key"], "text")
assert.Equal(t, b.Params["separate"], true)
}

func TestAppsUpdateMetaForTestingGroupBuilder(t *testing.T) {
t.Parallel()

b := params.NewAppsUpdateMetaForTestingGroupBuilder()

b.GroupID(1)
b.Webview("text")
b.Name("text")
b.Platforms([]string{"text"})
b.UserIDs([]int{1})

assert.Equal(t, b.Params["group_id"], 1)
assert.Equal(t, b.Params["webview"], "text")
assert.Equal(t, b.Params["name"], "text")
assert.Equal(t, b.Params["platforms"], []string{"text"})
assert.Equal(t, b.Params["user_ids"], []int{1})
}
9 changes: 9 additions & 0 deletions object/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,12 @@ type AppsScope struct {
Name string `json:"name"` // Scope name
Title string `json:"title"` // Scope title
}

// AppsTestingGroup testing group description.
type AppsTestingGroup struct {
GroupID int `json:"group_id"`
UserIDs []int `json:"user_ids"`
Name string `json:"name"`
Webview string `json:"webview"`
Platforms []string `json:"platforms"`
}

0 comments on commit 364b484

Please sign in to comment.