2020-01-16 04:27:57 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-04-27 00:25:47 +00:00
|
|
|
"fmt"
|
2020-01-16 04:27:57 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2020-04-27 00:25:47 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/diamondburned/arikawa/discord"
|
2020-01-16 04:27:57 +00:00
|
|
|
)
|
|
|
|
|
2020-04-27 00:25:47 +00:00
|
|
|
type testConfig struct {
|
|
|
|
BotToken string
|
|
|
|
ChannelID discord.Snowflake
|
|
|
|
}
|
|
|
|
|
|
|
|
func mustConfig(t *testing.T) testConfig {
|
2020-01-16 04:27:57 +00:00
|
|
|
var token = os.Getenv("BOT_TOKEN")
|
|
|
|
if token == "" {
|
|
|
|
t.Fatal("Missing $BOT_TOKEN")
|
|
|
|
}
|
|
|
|
|
2020-04-27 00:25:47 +00:00
|
|
|
var cid = os.Getenv("CHANNEL_ID")
|
|
|
|
if cid == "" {
|
|
|
|
t.Fatal("Missing $CHANNEL_ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := discord.ParseSnowflake(cid)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Invalid $CHANNEL_ID:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return testConfig{
|
|
|
|
BotToken: token,
|
|
|
|
ChannelID: id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIntegration(t *testing.T) {
|
|
|
|
cfg := mustConfig(t)
|
|
|
|
|
|
|
|
client := NewClient("Bot " + cfg.BotToken)
|
2020-01-16 04:27:57 +00:00
|
|
|
|
|
|
|
// Simple GET request
|
|
|
|
u, err := client.Me()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Can't get self:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("API user:", u.Username)
|
|
|
|
|
|
|
|
// POST with URL param and paginator
|
|
|
|
_, err = client.Guilds(100)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Can't get guilds:", err)
|
|
|
|
}
|
|
|
|
}
|
2020-04-27 00:25:47 +00:00
|
|
|
|
|
|
|
var emojisToSend = [...]string{
|
|
|
|
"🥺",
|
|
|
|
"❤",
|
|
|
|
"😂",
|
|
|
|
"🥰",
|
|
|
|
"😊",
|
|
|
|
"🔥",
|
|
|
|
"✔",
|
|
|
|
"👍",
|
|
|
|
"😍",
|
|
|
|
"🐻",
|
|
|
|
"🤯",
|
|
|
|
"🔣",
|
|
|
|
"🍔",
|
|
|
|
"🎌",
|
|
|
|
"🇯🇵",
|
|
|
|
"🎥",
|
|
|
|
"🇺🇸",
|
|
|
|
"🌎",
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReactions(t *testing.T) {
|
|
|
|
cfg := mustConfig(t)
|
|
|
|
|
|
|
|
client := NewClient("Bot " + cfg.BotToken)
|
|
|
|
|
2020-05-13 00:09:32 +00:00
|
|
|
msg := fmt.Sprintf("This is a message sent at %v.", time.Now())
|
2020-04-27 00:25:47 +00:00
|
|
|
|
|
|
|
// Send a new message.
|
|
|
|
m, err := client.SendMessage(cfg.ChannelID, msg, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Failed to send message:", err)
|
|
|
|
}
|
|
|
|
|
2020-05-13 00:09:32 +00:00
|
|
|
now := time.Now()
|
|
|
|
|
2020-04-27 00:25:47 +00:00
|
|
|
for _, emojiString := range emojisToSend {
|
|
|
|
if err := client.React(cfg.ChannelID, m.ID, emojiString); err != nil {
|
|
|
|
t.Fatal("Failed to send emoji "+emojiString+":", err)
|
|
|
|
}
|
|
|
|
}
|
2020-05-13 00:09:32 +00:00
|
|
|
|
|
|
|
msg += " Total time taken to send all reactions: " + time.Now().Sub(now)
|
|
|
|
|
2020-05-13 00:29:22 +00:00
|
|
|
m, err = client.EditMessage(cfg.ChannelID, m.ID, msg, nil, false)
|
2020-05-13 00:09:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Failed to edit message:", err)
|
|
|
|
}
|
2020-04-27 00:25:47 +00:00
|
|
|
}
|