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
|
package slack
import (
"encoding/json"
"net/http"
"testing"
)
func TestListEventAuthorizations(t *testing.T) {
http.HandleFunc("/apps.event.authorizations.list", testListEventAuthorizationsHandler)
once.Do(startServer)
api := New("", OptionAppLevelToken("test-token"), OptionAPIURL("http://"+serverAddr+"/"))
authorizations, err := api.ListEventAuthorizations("1-message-T012345678-DR12345678")
if err != nil {
t.Errorf("Failed, but should have succeeded")
} else if len(authorizations) != 1 {
t.Errorf("Didn't get 1 authorization")
} else if authorizations[0].UserID != "U123456789" {
t.Errorf("User ID is wrong")
}
}
func testListEventAuthorizationsHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
response, _ := json.Marshal(listEventAuthorizationsResponse{
SlackResponse: SlackResponse{Ok: true},
Authorizations: []EventAuthorization{
{
UserID: "U123456789",
TeamID: "T012345678",
},
},
})
w.Write(response)
}
func TestUninstallApp(t *testing.T) {
http.HandleFunc("/apps.uninstall", testUninstallAppHandler)
once.Do(startServer)
api := New("test-token", OptionAPIURL("http://"+serverAddr+"/"))
err := api.UninstallApp("", "")
if err != nil {
t.Errorf("Failed, but should have succeeded")
}
}
func testUninstallAppHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
response, _ := json.Marshal(SlackResponse{Ok: true})
w.Write(response)
}
|