|
| 1 | +package slack |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func toolingTokensRotate(rw http.ResponseWriter, r *http.Request) { |
| 11 | + rw.Header().Set("Content-Type", "application/json") |
| 12 | + response := []byte(`{ |
| 13 | + "ok": true, |
| 14 | + "token": "xoxe.xoxp-...", |
| 15 | + "refresh_token": "xoxe-...", |
| 16 | + "team_id": "...", |
| 17 | + "user_id": "...", |
| 18 | + "iat": 1633095660, |
| 19 | + "exp": 1633138860 |
| 20 | +}`) |
| 21 | + rw.Write(response) |
| 22 | +} |
| 23 | + |
| 24 | +func TestToolingTokensRotate(t *testing.T) { |
| 25 | + http.HandleFunc("/tooling.tokens.rotate", toolingTokensRotate) |
| 26 | + |
| 27 | + once.Do(startServer) |
| 28 | + api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/")) |
| 29 | + |
| 30 | + token, err := api.ToolingTokensRotate("xoxe.xoxp-...") |
| 31 | + if err != nil { |
| 32 | + t.Errorf("Unexpected error: %s", err) |
| 33 | + return |
| 34 | + } |
| 35 | + |
| 36 | + assert.Equal(t, true, token.Ok) |
| 37 | + assert.Equal(t, "", token.Error) |
| 38 | + |
| 39 | + assert.Equal(t, "xoxe.xoxp-...", token.Token) |
| 40 | + assert.Equal(t, "xoxe-...", token.RefreshToken) |
| 41 | + assert.Equal(t, "...", token.TeamID) |
| 42 | + assert.Equal(t, "...", token.UserID) |
| 43 | + assert.Equal(t, int64(1633095660), token.Iat) |
| 44 | + assert.Equal(t, int64(1633138860), token.Exp) |
| 45 | +} |
0 commit comments