| 1 | package slack |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestListEventAuthorizations(t *testing.T) { |
| 10 | http.HandleFunc("/apps.event.authorizations.list", testListEventAuthorizationsHandler) |
| 11 | once.Do(startServer) |
| 12 | |
| 13 | api := New("", OptionAppLevelToken("test-token"), OptionAPIURL("http://"+serverAddr+"/")) |
| 14 | |
| 15 | authorizations, err := api.ListEventAuthorizations("1-message-T012345678-DR12345678") |
| 16 | |
| 17 | if err != nil { |
| 18 | t.Errorf("Failed, but should have succeeded") |
| 19 | } else if len(authorizations) != 1 { |
| 20 | t.Errorf("Didn't get 1 authorization") |
| 21 | } else if authorizations[0].UserID != "U123456789" { |
| 22 | t.Errorf("User ID is wrong") |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | func testListEventAuthorizationsHandler(w http.ResponseWriter, r *http.Request) { |
| 27 | w.Header().Set("Content-Type", "application/json") |
| 28 | response, _ := json.Marshal(listEventAuthorizationsResponse{ |
| 29 | SlackResponse: SlackResponse{Ok: true}, |
| 30 | Authorizations: []EventAuthorization{ |
| 31 | { |
| 32 | UserID: "U123456789", |
| 33 | TeamID: "T012345678", |
| 34 | }, |
| 35 | }, |
| 36 | }) |
| 37 | w.Write(response) |
| 38 | } |
| 39 | |
| 40 | func TestUninstallApp(t *testing.T) { |
| 41 | http.HandleFunc("/apps.uninstall", testUninstallAppHandler) |
| 42 | once.Do(startServer) |
| 43 | |
| 44 | api := New("test-token", OptionAPIURL("http://"+serverAddr+"/")) |
| 45 | |
| 46 | err := api.UninstallApp("", "") |
| 47 | |
| 48 | if err != nil { |
| 49 | t.Errorf("Failed, but should have succeeded") |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | func testUninstallAppHandler(w http.ResponseWriter, r *http.Request) { |
| 54 | w.Header().Set("Content-Type", "application/json") |
| 55 | response, _ := json.Marshal(SlackResponse{Ok: true}) |
| 56 | w.Write(response) |
| 57 | } |