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

Function getTestUserToken

test/common.go:24–49  ·  view source on GitHub ↗
(user string, e *httpexpect.Expect)

Source from the content-addressed store, hash-verified

22}
23
24func getTestUserToken(user string, e *httpexpect.Expect) (int, string) {
25 registerResp := e.POST("/douyin/user/register/").
26 WithQuery("username", user).WithQuery("password", user).
27 WithFormField("username", user).WithFormField("password", user).
28 Expect().
29 Status(http.StatusOK).
30 JSON().Object()
31
32 userId := 0
33 token := registerResp.Value("token").String().Raw()
34 if len(token) == 0 {
35 loginResp := e.POST("/douyin/user/login/").
36 WithQuery("username", user).WithQuery("password", user).
37 WithFormField("username", user).WithFormField("password", user).
38 Expect().
39 Status(http.StatusOK).
40 JSON().Object()
41 loginToken := loginResp.Value("token").String()
42 loginToken.Length().Gt(0)
43 token = loginToken.Raw()
44 userId = int(loginResp.Value("user_id").Number().Raw())
45 } else {
46 userId = int(registerResp.Value("user_id").Number().Raw())
47 }
48 return userId, token
49}

Callers 5

TestRelationFunction · 0.85
TestChatFunction · 0.85
TestFavoriteFunction · 0.85
TestCommentFunction · 0.85
TestPublishFunction · 0.85

Calls

no outgoing calls

Tested by 5

TestRelationFunction · 0.68
TestChatFunction · 0.68
TestFavoriteFunction · 0.68
TestCommentFunction · 0.68
TestPublishFunction · 0.68