slash roleypoly yay
This commit is contained in:
parent
02f5075d3b
commit
607d7e121c
22 changed files with 394 additions and 66 deletions
|
@ -13,6 +13,23 @@ import (
|
|||
|
||||
type DiscordClientMock struct {
|
||||
mock.Mock
|
||||
|
||||
BotToken string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
}
|
||||
|
||||
func NewDiscordClientMock() *DiscordClientMock {
|
||||
dcm := &DiscordClientMock{
|
||||
BotToken: "bot-token",
|
||||
ClientID: "client-id",
|
||||
ClientSecret: "client-secret",
|
||||
}
|
||||
|
||||
dcm.On("BotAuth", mock.AnythingOfType("*http.Request"))
|
||||
dcm.On("GetClientID").Return(dcm.ClientID)
|
||||
|
||||
return dcm
|
||||
}
|
||||
|
||||
func (c *DiscordClientMock) Do(req *http.Request) (*http.Response, error) {
|
||||
|
@ -40,3 +57,7 @@ func (c *DiscordClientMock) MockResponse(method, path string, statusCode int, da
|
|||
return req.Method == method && pathMatcher.MatchString(req.URL.Path)
|
||||
})).Return(r, nil)
|
||||
}
|
||||
|
||||
func (c *DiscordClientMock) GetClientID() string {
|
||||
return c.Called().String(0)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ const DiscordBaseUrl = "https://discord.com/api/v10"
|
|||
type IDiscordClient interface {
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
BotAuth(req *http.Request)
|
||||
GetClientID() string
|
||||
}
|
||||
|
||||
type DiscordClient struct {
|
||||
|
@ -64,3 +65,7 @@ func OutputResponse(resp *http.Response, dst any) error {
|
|||
// TODO: more checks?
|
||||
return json.NewDecoder(resp.Body).Decode(dst)
|
||||
}
|
||||
|
||||
func (d *DiscordClient) GetClientID() string {
|
||||
return d.ClientID
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"git.sapphic.engineer/roleypoly/v4/discord"
|
||||
"git.sapphic.engineer/roleypoly/v4/discord/clientmock"
|
||||
"git.sapphic.engineer/roleypoly/v4/types/fixtures"
|
||||
"git.sapphic.engineer/roleypoly/v4/utils"
|
||||
)
|
||||
|
@ -17,7 +18,7 @@ var (
|
|||
)
|
||||
|
||||
func TestGetMember(t *testing.T) {
|
||||
dc := defaultMocks(t)
|
||||
dc := clientmock.NewDiscordClientMock()
|
||||
g := discord.Guild{
|
||||
Client: dc,
|
||||
DiscordGuild: fixtures.Guild,
|
||||
|
|
|
@ -6,11 +6,6 @@ import (
|
|||
"git.sapphic.engineer/roleypoly/v4/utils"
|
||||
)
|
||||
|
||||
type IGuildService interface {
|
||||
Client() IDiscordClient
|
||||
GetGuild(guildID string) (IGuild, error)
|
||||
}
|
||||
|
||||
type GuildService struct {
|
||||
client IDiscordClient
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"git.sapphic.engineer/roleypoly/v4/discord"
|
||||
"git.sapphic.engineer/roleypoly/v4/discord/clientmock"
|
||||
"git.sapphic.engineer/roleypoly/v4/types/fixtures"
|
||||
"git.sapphic.engineer/roleypoly/v4/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -16,7 +17,7 @@ var (
|
|||
)
|
||||
|
||||
func TestGetGuild(t *testing.T) {
|
||||
dc := defaultMocks(t)
|
||||
dc := clientmock.NewDiscordClientMock()
|
||||
gs := discord.NewGuildService(dc)
|
||||
|
||||
dc.MockResponse("GET", utils.J("guilds", fixtures.Guild.ID), 200, fixtureGuild)
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package discord_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.sapphic.engineer/roleypoly/v4/discord/clientmock"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
func defaultMocks(t *testing.T) *clientmock.DiscordClientMock {
|
||||
dc := &clientmock.DiscordClientMock{}
|
||||
|
||||
dc.On("BotAuth", mock.AnythingOfType("*http.Request"))
|
||||
|
||||
return dc
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue