2024-07-11 11:10:30 +00:00
|
|
|
package endpoints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
|
|
|
|
"github.com/jarcoal/httpmock"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetPool(t *testing.T) {
|
|
|
|
httpmock.Activate()
|
|
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
|
|
|
|
response, err := utils.LoadJsonTestData[model.Pool]("../../../tests/pool.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
responder, err := httpmock.NewJsonResponder(200, response)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
httpmock.RegisterResponder("GET", "https://e621.net/pools/36957.json", responder)
|
|
|
|
|
|
|
|
requestContext := model.RequestContext{
|
|
|
|
Client: http.Client{},
|
|
|
|
Host: "https://e621.net",
|
|
|
|
UserAgent: "Go-e621-SDK (@username)",
|
|
|
|
Username: "memo",
|
|
|
|
APIKey: "123456",
|
|
|
|
}
|
|
|
|
|
|
|
|
pool, err := GetPool(requestContext, "36957")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if pool.ID == response.ID && pool.Name == response.Name {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pool, response)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetPools(t *testing.T) {
|
|
|
|
httpmock.Activate()
|
|
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
|
|
|
|
response, err := utils.LoadJsonTestData[[]model.Pool]("../../../tests/pools.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
responder, err := httpmock.NewJsonResponder(200, response)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
httpmock.RegisterResponder("GET", "https://e621.net/pools.json", responder)
|
|
|
|
|
|
|
|
requestContext := model.RequestContext{
|
|
|
|
Client: http.Client{},
|
|
|
|
Host: "https://e621.net",
|
|
|
|
UserAgent: "Go-e621-SDK (@username)",
|
|
|
|
Username: "memo",
|
|
|
|
APIKey: "123456",
|
|
|
|
}
|
|
|
|
|
|
|
|
pools, err := GetPools(requestContext, map[string]string{})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if pools[0].ID == response[0].ID && pools[1].Name == response[1].Name && pools[2].UpdatedAt == response[2].UpdatedAt {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pools, response)
|
|
|
|
|
|
|
|
}
|