Skip to content

Commit 364b484

Browse files
committed
feat(api): add TestingGroup methods
1 parent 9091654 commit 364b484

File tree

5 files changed

+278
-0
lines changed

5 files changed

+278
-0
lines changed

api/apps.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import (
44
"github.com/SevereCloud/vksdk/v2/object"
55
)
66

7+
// AppsAddUsersToTestingGroup method.
8+
//
9+
// https://vk.com/dev/apps.addUsersToTestingGroup
10+
func (vk *VK) AppsAddUsersToTestingGroup(params Params) (response int, err error) {
11+
err = vk.RequestUnmarshal("apps.addUsersToTestingGroup", &response, params)
12+
return
13+
}
14+
715
// AppsDeleteAppRequests deletes all request notifications from the current app.
816
//
917
// https://vk.com/dev/apps.deleteAppRequests
@@ -140,10 +148,50 @@ func (vk *VK) AppsGetScore(params Params) (response string, err error) {
140148
return
141149
}
142150

151+
// AppsGetTestingGroupsResponse struct.
152+
type AppsGetTestingGroupsResponse []object.AppsTestingGroup
153+
154+
// AppsGetTestingGroups method.
155+
//
156+
// https://vk.com/dev/apps.getTestingGroups
157+
func (vk *VK) AppsGetTestingGroups(params Params) (response AppsGetTestingGroupsResponse, err error) {
158+
err = vk.RequestUnmarshal("apps.getTestingGroups", &response, params)
159+
return
160+
}
161+
162+
// AppsRemoveTestingGroup method.
163+
//
164+
// https://vk.com/dev/apps.removeTestingGroup
165+
func (vk *VK) AppsRemoveTestingGroup(params Params) (response int, err error) {
166+
err = vk.RequestUnmarshal("apps.removeTestingGroup", &response, params)
167+
return
168+
}
169+
170+
// AppsRemoveUsersFromTestingGroups method.
171+
//
172+
// https://vk.com/dev/apps.removeUsersFromTestingGroups
173+
func (vk *VK) AppsRemoveUsersFromTestingGroups(params Params) (response int, err error) {
174+
err = vk.RequestUnmarshal("apps.removeUsersFromTestingGroups", &response, params)
175+
return
176+
}
177+
143178
// AppsSendRequest sends a request to another user in an app that uses VK authorization.
144179
//
145180
// https://vk.com/dev/apps.sendRequest
146181
func (vk *VK) AppsSendRequest(params Params) (response int, err error) {
147182
err = vk.RequestUnmarshal("apps.sendRequest", &response, params)
148183
return
149184
}
185+
186+
// AppsUpdateMetaForTestingGroupResponse struct.
187+
type AppsUpdateMetaForTestingGroupResponse struct {
188+
GroupID int `json:"group_id"`
189+
}
190+
191+
// AppsUpdateMetaForTestingGroup method.
192+
//
193+
// https://vk.com/dev/apps.updateMetaForTestingGroup
194+
func (vk *VK) AppsUpdateMetaForTestingGroup(params Params) (response AppsUpdateMetaForTestingGroupResponse, err error) {
195+
err = vk.RequestUnmarshal("apps.updateMetaForTestingGroup", &response, params)
196+
return
197+
}

api/apps_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,44 @@ func TestVK_AppsGetScopes(t *testing.T) {
9393

9494
// TODO: TestVK_AppsGetScore
9595
// TODO: TestVK_AppsSendRequest
96+
97+
func TestVK_AppsTestingGroups(t *testing.T) {
98+
t.Parallel()
99+
100+
needServiceToken(t)
101+
102+
respUpdate, err := vkService.AppsUpdateMetaForTestingGroup(api.Params{
103+
"webview": "https://example.com",
104+
"name": "example",
105+
"platforms": []string{"mobile"},
106+
})
107+
noErrorOrFail(t, err)
108+
109+
_, err = vkService.AppsAddUsersToTestingGroup(api.Params{
110+
"user_ids": []int{1},
111+
"group_id": respUpdate.GroupID,
112+
})
113+
noError(t, err)
114+
115+
resp, err := vkService.AppsGetTestingGroups(api.Params{
116+
"group_id": respUpdate.GroupID,
117+
})
118+
noError(t, err)
119+
120+
if assert.NotEmpty(t, resp) {
121+
assert.NotEmpty(t, resp[0].GroupID)
122+
assert.NotEmpty(t, resp[0].Name)
123+
assert.NotEmpty(t, resp[0].Webview)
124+
}
125+
126+
_, err = vkService.AppsRemoveUsersFromTestingGroups(api.Params{
127+
"user_ids": []int{1},
128+
"group_id": respUpdate.GroupID,
129+
})
130+
noError(t, err)
131+
132+
_, err = vkService.AppsRemoveTestingGroup(api.Params{
133+
"group_id": respUpdate.GroupID,
134+
})
135+
noError(t, err)
136+
}

api/params/apps.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ import (
44
"github.com/SevereCloud/vksdk/v2/api"
55
)
66

7+
// AppsAddUsersToTestingGroupBuilder builder.
8+
//
9+
// https://vk.com/dev/apps.addUsersToTestingGroup
10+
type AppsAddUsersToTestingGroupBuilder struct {
11+
api.Params
12+
}
13+
14+
// NewAppsAddUsersToTestingGroupBuilder func.
15+
func NewAppsAddUsersToTestingGroupBuilder() *AppsAddUsersToTestingGroupBuilder {
16+
return &AppsAddUsersToTestingGroupBuilder{api.Params{}}
17+
}
18+
19+
// UserIDs users ID.
20+
func (b *AppsAddUsersToTestingGroupBuilder) UserIDs(v []int) *AppsAddUsersToTestingGroupBuilder {
21+
b.Params["user_ids"] = v
22+
return b
23+
}
24+
25+
// GroupID group ID.
26+
func (b *AppsAddUsersToTestingGroupBuilder) GroupID(v int) *AppsAddUsersToTestingGroupBuilder {
27+
b.Params["group_id"] = v
28+
return b
29+
}
30+
731
// AppsGetBuilder builder.
832
//
933
// Returns applications data.
@@ -353,6 +377,60 @@ func (b *AppsGetScoreBuilder) UserID(v int) *AppsGetScoreBuilder {
353377
return b
354378
}
355379

380+
// AppsGetTestingGroupsBuilder builder.
381+
//
382+
// https://vk.com/dev/apps.getTestingGroups
383+
type AppsGetTestingGroupsBuilder struct {
384+
api.Params
385+
}
386+
387+
// NewAppsGetTestingGroupsBuilder func.
388+
func NewAppsGetTestingGroupsBuilder() *AppsGetTestingGroupsBuilder {
389+
return &AppsGetTestingGroupsBuilder{api.Params{}}
390+
}
391+
392+
// GroupID group ID.
393+
func (b *AppsGetTestingGroupsBuilder) GroupID(v int) *AppsGetTestingGroupsBuilder {
394+
b.Params["group_id"] = v
395+
return b
396+
}
397+
398+
// AppsRemoveUsersFromTestingGroupsBuilder builder.
399+
//
400+
// https://vk.com/dev/apps.removeUsersFromTestingGroups
401+
type AppsRemoveUsersFromTestingGroupsBuilder struct {
402+
api.Params
403+
}
404+
405+
// NewAppsRemoveUsersFromTestingGroupsBuilder func.
406+
func NewAppsRemoveUsersFromTestingGroupsBuilder() *AppsRemoveUsersFromTestingGroupsBuilder {
407+
return &AppsRemoveUsersFromTestingGroupsBuilder{api.Params{}}
408+
}
409+
410+
// UserIDs users ID.
411+
func (b *AppsRemoveUsersFromTestingGroupsBuilder) UserIDs(v []int) *AppsRemoveUsersFromTestingGroupsBuilder {
412+
b.Params["user_ids"] = v
413+
return b
414+
}
415+
416+
// AppsRemoveTestingGroupBuilder builder.
417+
//
418+
// https://vk.com/dev/apps.removeTestingGroup
419+
type AppsRemoveTestingGroupBuilder struct {
420+
api.Params
421+
}
422+
423+
// NewAppsRemoveTestingGroupBuilder func.
424+
func NewAppsRemoveTestingGroupBuilder() *AppsRemoveTestingGroupBuilder {
425+
return &AppsRemoveTestingGroupBuilder{api.Params{}}
426+
}
427+
428+
// GroupID group ID.
429+
func (b *AppsRemoveTestingGroupBuilder) GroupID(v int) *AppsRemoveTestingGroupBuilder {
430+
b.Params["group_id"] = v
431+
return b
432+
}
433+
356434
// AppsSendRequestBuilder builder.
357435
//
358436
// Sends a request to another user in an app that uses VK authorization.
@@ -406,3 +484,45 @@ func (b *AppsSendRequestBuilder) Separate(v bool) *AppsSendRequestBuilder {
406484
b.Params["separate"] = v
407485
return b
408486
}
487+
488+
// AppsUpdateMetaForTestingGroupBuilder builder.
489+
//
490+
// https://vk.com/dev/apps.UpdateMetaForTestingGroup
491+
type AppsUpdateMetaForTestingGroupBuilder struct {
492+
api.Params
493+
}
494+
495+
// NewAppsUpdateMetaForTestingGroupBuilder func.
496+
func NewAppsUpdateMetaForTestingGroupBuilder() *AppsUpdateMetaForTestingGroupBuilder {
497+
return &AppsUpdateMetaForTestingGroupBuilder{api.Params{}}
498+
}
499+
500+
// GroupID parameter.
501+
func (b *AppsUpdateMetaForTestingGroupBuilder) GroupID(v int) *AppsUpdateMetaForTestingGroupBuilder {
502+
b.Params["group_id"] = v
503+
return b
504+
}
505+
506+
// Webview parameter.
507+
func (b *AppsUpdateMetaForTestingGroupBuilder) Webview(v string) *AppsUpdateMetaForTestingGroupBuilder {
508+
b.Params["webview"] = v
509+
return b
510+
}
511+
512+
// Name parameter.
513+
func (b *AppsUpdateMetaForTestingGroupBuilder) Name(v string) *AppsUpdateMetaForTestingGroupBuilder {
514+
b.Params["name"] = v
515+
return b
516+
}
517+
518+
// Platforms parameter.
519+
func (b *AppsUpdateMetaForTestingGroupBuilder) Platforms(v []string) *AppsUpdateMetaForTestingGroupBuilder {
520+
b.Params["platforms"] = v
521+
return b
522+
}
523+
524+
// UserIDs users ID.
525+
func (b *AppsUpdateMetaForTestingGroupBuilder) UserIDs(v []int) *AppsUpdateMetaForTestingGroupBuilder {
526+
b.Params["user_ids"] = v
527+
return b
528+
}

api/params/apps_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ import (
77
"github.com/stretchr/testify/assert"
88
)
99

10+
func TestAppsAddUsersToTestingGroupBuilder(t *testing.T) {
11+
t.Parallel()
12+
13+
b := params.NewAppsAddUsersToTestingGroupBuilder()
14+
15+
b.UserIDs([]int{1})
16+
b.GroupID(1)
17+
18+
assert.Equal(t, b.Params["user_ids"], []int{1})
19+
assert.Equal(t, b.Params["group_id"], 1)
20+
}
21+
1022
func TestAppsGetBuilder(t *testing.T) {
1123
t.Parallel()
1224

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

126+
func TestAppsGetTestingGroupsBuilder(t *testing.T) {
127+
t.Parallel()
128+
129+
b := params.NewAppsGetTestingGroupsBuilder()
130+
131+
b.GroupID(1)
132+
133+
assert.Equal(t, b.Params["group_id"], 1)
134+
}
135+
136+
func TestAppsRemoveUsersFromTestingGroupsBuilder(t *testing.T) {
137+
t.Parallel()
138+
139+
b := params.NewAppsRemoveUsersFromTestingGroupsBuilder()
140+
141+
b.UserIDs([]int{1})
142+
143+
assert.Equal(t, b.Params["user_ids"], []int{1})
144+
}
145+
146+
func TestAppsRemoveTestingGroupBuilder(t *testing.T) {
147+
t.Parallel()
148+
149+
b := params.NewAppsRemoveTestingGroupBuilder()
150+
151+
b.GroupID(1)
152+
153+
assert.Equal(t, b.Params["group_id"], 1)
154+
}
155+
114156
func TestAppsSendRequestBuilder(t *testing.T) {
115157
t.Parallel()
116158

@@ -130,3 +172,21 @@ func TestAppsSendRequestBuilder(t *testing.T) {
130172
assert.Equal(t, b.Params["key"], "text")
131173
assert.Equal(t, b.Params["separate"], true)
132174
}
175+
176+
func TestAppsUpdateMetaForTestingGroupBuilder(t *testing.T) {
177+
t.Parallel()
178+
179+
b := params.NewAppsUpdateMetaForTestingGroupBuilder()
180+
181+
b.GroupID(1)
182+
b.Webview("text")
183+
b.Name("text")
184+
b.Platforms([]string{"text"})
185+
b.UserIDs([]int{1})
186+
187+
assert.Equal(t, b.Params["group_id"], 1)
188+
assert.Equal(t, b.Params["webview"], "text")
189+
assert.Equal(t, b.Params["name"], "text")
190+
assert.Equal(t, b.Params["platforms"], []string{"text"})
191+
assert.Equal(t, b.Params["user_ids"], []int{1})
192+
}

object/apps.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,12 @@ type AppsScope struct {
100100
Name string `json:"name"` // Scope name
101101
Title string `json:"title"` // Scope title
102102
}
103+
104+
// AppsTestingGroup testing group description.
105+
type AppsTestingGroup struct {
106+
GroupID int `json:"group_id"`
107+
UserIDs []int `json:"user_ids"`
108+
Name string `json:"name"`
109+
Webview string `json:"webview"`
110+
Platforms []string `json:"platforms"`
111+
}

0 commit comments

Comments
 (0)