-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsocial_api_test.go
111 lines (95 loc) · 4.02 KB
/
social_api_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//go:build e2e
// Progress:
// All tests are synced with 2023-2-20 version of the API. Not sure if the API will change in the future.
package main
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
// TestRelation tests the procedure of follow, list users.
func TestRelation(t *testing.T) {
e := newExpect(t)
userIdA, tokenA := getTestUserToken(testUserA, e)
userIdB, tokenB := getTestUserToken(testUserB, e)
relationResp := e.POST("/douyin/relation/action/").
WithQuery("token", tokenA).WithQuery("to_user_id", userIdB).WithQuery("action_type", 1).
WithFormField("token", tokenA).WithFormField("to_user_id", userIdB).WithFormField("action_type", 1).
Expect().
Status(http.StatusOK).
JSON().Object()
relationResp.Value("status_code").Number().Equal(0)
relationResp.Value("status_msg").String().NotEmpty()
followListResp := e.GET("/douyin/relation/follow/list/").
WithQuery("token", tokenA).WithQuery("user_id", userIdA).
WithFormField("token", tokenA).WithFormField("user_id", userIdA).
Expect().
Status(http.StatusOK).
JSON().Object()
followListResp.Value("status_code").Number().Equal(0)
followListResp.Value("user_list").Array().NotEmpty()
containTestUserB := false
for _, element := range followListResp.Value("user_list").Array().Iter() {
user := element.Object()
user.ContainsKey("id")
ValidateUser(user)
if int(user.Value("id").Number().Raw()) == userIdB {
containTestUserB = true
}
}
assert.True(t, containTestUserB, "Follow test user failed")
followerListResp := e.GET("/douyin/relation/follower/list/").
WithQuery("token", tokenB).WithQuery("user_id", userIdB).
WithFormField("token", tokenB).WithFormField("user_id", userIdB).
Expect().
Status(http.StatusOK).
JSON().Object()
followerListResp.Value("status_code").Number().Equal(0)
followerListResp.Value("user_list").Array().NotEmpty()
containTestUserA := false
for _, element := range followerListResp.Value("user_list").Array().Iter() {
user := element.Object()
user.ContainsKey("id")
ValidateUser(user)
if int(user.Value("id").Number().Raw()) == userIdA {
containTestUserA = true
}
}
assert.True(t, containTestUserA, "Follower test user failed")
}
// TestChat tests the procedure of sending and receiving messages.
func TestChat(t *testing.T) {
e := newExpect(t)
userIdA, tokenA := getTestUserToken(testUserA, e)
userIdB, tokenB := getTestUserToken(testUserB, e)
messageResp := e.POST("/douyin/message/action/").
WithQuery("token", tokenA).WithQuery("to_user_id", userIdB).WithQuery("action_type", 1).WithQuery("content", "Send to UserB").
WithFormField("token", tokenA).WithFormField("to_user_id", userIdB).WithFormField("action_type", 1).WithQuery("content", "Send to UserB").
Expect().
Status(http.StatusOK).
JSON().Object()
messageResp.Value("status_code").Number().Equal(0)
messageResp.Value("status_msg").String().NotEmpty()
chatResp := e.GET("/douyin/message/chat/").
WithQuery("token", tokenA).WithQuery("to_user_id", userIdB).
WithFormField("token", tokenA).WithFormField("to_user_id", userIdB).
Expect().
Status(http.StatusOK).
JSON().Object()
chatResp.Value("status_code").Number().Equal(0)
chatResp.Value("status_msg").String().NotEmpty()
chatResp.Value("message_list").Array().Length().Gt(0)
chatResp.Value("message_list").Array().First().Object().Value("content").String().Equal("Send to UserB")
chatResp.Value("message_list").Array().First().Object().Value("create_time").String().NotEmpty()
chatResp = e.GET("/douyin/message/chat/").
WithQuery("token", tokenB).WithQuery("to_user_id", userIdA).
WithFormField("token", tokenB).WithFormField("to_user_id", userIdA).
Expect().
Status(http.StatusOK).
JSON().Object()
chatResp.Value("status_code").Number().Equal(0)
chatResp.Value("status_msg").String().NotEmpty()
chatResp.Value("message_list").Array().Length().Gt(0)
chatResp.Value("message_list").Array().First().Object().Value("content").String().Equal("Send to UserB")
chatResp.Value("message_list").Array().First().Object().Value("create_time").String().NotEmpty()
}