MCPcopy Create free account
hub / github.com/RaymondCode/simple-demo / TestComment

Function TestComment

test/interact_api_test.go:44–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42}
43
44func TestComment(t *testing.T) {
45 e := newExpect(t)
46
47 feedResp := e.GET("/douyin/feed/").Expect().Status(http.StatusOK).JSON().Object()
48 feedResp.Value("status_code").Number().Equal(0)
49 feedResp.Value("video_list").Array().Length().Gt(0)
50 firstVideo := feedResp.Value("video_list").Array().First().Object()
51 videoId := firstVideo.Value("id").Number().Raw()
52
53 _, token := getTestUserToken(testUserA, e)
54
55 addCommentResp := e.POST("/douyin/comment/action/").
56 WithQuery("token", token).WithQuery("video_id", videoId).WithQuery("action_type", 1).WithQuery("comment_text", "测试评论").
57 WithFormField("token", token).WithFormField("video_id", videoId).WithFormField("action_type", 1).WithFormField("comment_text", "测试评论").
58 Expect().
59 Status(http.StatusOK).
60 JSON().Object()
61 addCommentResp.Value("status_code").Number().Equal(0)
62 addCommentResp.Value("comment").Object().Value("id").Number().Gt(0)
63 commentId := int(addCommentResp.Value("comment").Object().Value("id").Number().Raw())
64
65 commentListResp := e.GET("/douyin/comment/list/").
66 WithQuery("token", token).WithQuery("video_id", videoId).
67 WithFormField("token", token).WithFormField("video_id", videoId).
68 Expect().
69 Status(http.StatusOK).
70 JSON().Object()
71 commentListResp.Value("status_code").Number().Equal(0)
72 containTestComment := false
73 for _, element := range commentListResp.Value("comment_list").Array().Iter() {
74 comment := element.Object()
75 comment.ContainsKey("id")
76 comment.ContainsKey("user")
77 comment.Value("content").String().NotEmpty()
78 comment.Value("create_date").String().NotEmpty()
79 if int(comment.Value("id").Number().Raw()) == commentId {
80 containTestComment = true
81 }
82 }
83
84 assert.True(t, containTestComment, "Can't find test comment in list")
85
86 delCommentResp := e.POST("/douyin/comment/action/").
87 WithQuery("token", token).WithQuery("video_id", videoId).WithQuery("action_type", 2).WithQuery("comment_id", commentId).
88 WithFormField("token", token).WithFormField("video_id", videoId).WithFormField("action_type", 2).WithFormField("comment_id", commentId).
89 Expect().
90 Status(http.StatusOK).
91 JSON().Object()
92 delCommentResp.Value("status_code").Number().Equal(0)
93}

Callers

nothing calls this directly

Calls 2

newExpectFunction · 0.85
getTestUserTokenFunction · 0.85

Tested by

no test coverage detected