-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: minor fixes, doc updates and hello 2024
- Loading branch information
Showing
7 changed files
with
127 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package lark | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPostEventMessage(t *testing.T) { | ||
message := EventMessage{ | ||
Timestamp: "", | ||
Token: "", | ||
EventType: "event_callback", | ||
Event: EventBody{ | ||
Type: "message", | ||
ChatType: "private", | ||
MsgType: "text", | ||
OpenID: testUserOpenID, | ||
Text: "private event", | ||
Title: "", | ||
OpenMessageID: "", | ||
ImageKey: "", | ||
ImageURL: "", | ||
}, | ||
} | ||
w := performRequest(func(w http.ResponseWriter, r *http.Request) { | ||
var m EventMessage | ||
json.NewDecoder(r.Body).Decode(&m) | ||
w.Write([]byte(m.Event.Text)) | ||
}, "POST", "/", message) | ||
assert.Equal(t, "private event", string(w.Body.Bytes())) | ||
|
||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
m, _ := json.Marshal(message) | ||
w.Write([]byte(m)) | ||
})) | ||
defer ts.Close() | ||
resp, err := PostEvent(http.DefaultClient, ts.URL, message) | ||
if assert.NoError(t, err) { | ||
var event EventMessage | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if assert.NoError(t, err) { | ||
defer resp.Body.Close() | ||
_ = json.Unmarshal(body, &event) | ||
assert.Equal(t, "event_callback", event.EventType) | ||
assert.Equal(t, "message", event.Event.Type) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters