2023-10-19 13:19:40 +00:00
|
|
|
|
package endpoints
|
|
|
|
|
|
|
|
|
|
import (
|
2023-10-24 13:10:39 +00:00
|
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
2023-10-19 13:19:40 +00:00
|
|
|
|
"github.com/jarcoal/httpmock"
|
|
|
|
|
"net/http"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetPool(t *testing.T) {
|
|
|
|
|
httpmock.Activate()
|
|
|
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
|
|
|
|
|
|
poolResponse := model.Pool{
|
|
|
|
|
ID: 36957,
|
|
|
|
|
Name: "MLP:His_Nocturnal_Excellency",
|
|
|
|
|
CreatedAt: "2023-10-13T19:24:00.576-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
|
|
|
|
|
CreatorID: 16883,
|
|
|
|
|
Description: "Two (un)lucky royal guards who saw something they didn’t have to~",
|
|
|
|
|
IsActive: true,
|
|
|
|
|
Category: "series",
|
|
|
|
|
PostIDS: nil,
|
|
|
|
|
CreatorName: "2DUK",
|
|
|
|
|
PostCount: 11,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsonResponser, err := httpmock.NewJsonResponder(200, poolResponse)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
httpmock.RegisterResponder("GET", "https://e621.net/pools/36957.json", jsonResponser)
|
|
|
|
|
|
|
|
|
|
requestContext := model.RequestContext{
|
2023-10-23 11:19:59 +00:00
|
|
|
|
Client: http.Client{},
|
2023-10-19 13:19:40 +00:00
|
|
|
|
Host: "https://e621.net",
|
|
|
|
|
UserAgent: "Go-e621-SDK (@username)",
|
|
|
|
|
Username: "memo",
|
|
|
|
|
APIKey: "123456",
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 11:19:59 +00:00
|
|
|
|
pool, err := GetPool(requestContext, "36957")
|
2023-10-19 13:19:40 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if pool.ID == poolResponse.ID && pool.Name == poolResponse.Name {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pool, poolResponse)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetPools(t *testing.T) {
|
|
|
|
|
httpmock.Activate()
|
|
|
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
|
|
|
|
|
|
poolResponse := []model.Pool{
|
|
|
|
|
{
|
|
|
|
|
ID: 36957,
|
|
|
|
|
Name: "MLP:His_Nocturnal_Excellency",
|
|
|
|
|
CreatedAt: "2023-10-13T19:24:00.576-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
|
|
|
|
|
CreatorID: 16883,
|
|
|
|
|
Description: "Two (un)lucky royal guards who saw something they didn’t have to~",
|
|
|
|
|
IsActive: true,
|
|
|
|
|
Category: "series",
|
|
|
|
|
PostIDS: nil,
|
|
|
|
|
CreatorName: "2DUK",
|
|
|
|
|
PostCount: 11,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ID: 5772,
|
|
|
|
|
Name: "MLP:His_Nocturnal_Excellency",
|
|
|
|
|
CreatedAt: "2023-10-13T19:24:00.576-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
|
|
|
|
|
CreatorID: 16883,
|
|
|
|
|
Description: "Two (un)lucky royal guards who saw something they didn’t have to~",
|
|
|
|
|
IsActive: true,
|
|
|
|
|
Category: "series",
|
|
|
|
|
PostIDS: nil,
|
|
|
|
|
CreatorName: "2DUK",
|
|
|
|
|
PostCount: 11,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ID: 453687,
|
|
|
|
|
Name: "MLP:His_Nocturnal_Excellency",
|
|
|
|
|
CreatedAt: "2023-10-13T19:24:00.576-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
|
|
|
|
|
CreatorID: 16883,
|
|
|
|
|
Description: "Two (un)lucky royal guards who saw something they didn’t have to~",
|
|
|
|
|
IsActive: true,
|
|
|
|
|
Category: "series",
|
|
|
|
|
PostIDS: nil,
|
|
|
|
|
CreatorName: "2DUK",
|
|
|
|
|
PostCount: 11,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ID: 3456876,
|
|
|
|
|
Name: "MLP:His_Nocturnal_Excellency",
|
|
|
|
|
CreatedAt: "2023-10-13T19:24:00.576-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T07:46:00.267-04:00",
|
|
|
|
|
CreatorID: 16883,
|
|
|
|
|
Description: "Two (un)lucky royal guards who saw something they didn’t have to~",
|
|
|
|
|
IsActive: true,
|
|
|
|
|
Category: "series",
|
|
|
|
|
PostIDS: nil,
|
|
|
|
|
CreatorName: "2DUK",
|
|
|
|
|
PostCount: 11,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsonResponser, err := httpmock.NewJsonResponder(200, poolResponse)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
httpmock.RegisterResponder("GET", "https://e621.net/pools.json", jsonResponser)
|
|
|
|
|
|
|
|
|
|
requestContext := model.RequestContext{
|
2023-10-23 11:19:59 +00:00
|
|
|
|
Client: http.Client{},
|
2023-10-19 13:19:40 +00:00
|
|
|
|
Host: "https://e621.net",
|
|
|
|
|
UserAgent: "Go-e621-SDK (@username)",
|
|
|
|
|
Username: "memo",
|
|
|
|
|
APIKey: "123456",
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 11:19:59 +00:00
|
|
|
|
pools, err := GetPools(requestContext, map[string]string{})
|
2023-10-19 13:19:40 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(pools) == 4 && pools[0].ID == poolResponse[0].ID && pools[1].Name == poolResponse[1].Name && pools[2].UpdatedAt == poolResponse[2].UpdatedAt {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pools, poolResponse)
|
|
|
|
|
|
|
|
|
|
}
|