2023-10-19 13:30:36 +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:30:36 +00:00
|
|
|
|
"github.com/jarcoal/httpmock"
|
|
|
|
|
"net/http"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetNote(t *testing.T) {
|
|
|
|
|
httpmock.Activate()
|
|
|
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
|
|
|
|
|
|
noteResponse := model.Note{
|
|
|
|
|
ID: 385777,
|
|
|
|
|
CreatedAt: "2023-10-19T06:42:20.171-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T06:42:20.171-04:00",
|
|
|
|
|
CreatorID: 1472475,
|
|
|
|
|
X: 277,
|
|
|
|
|
Y: 841,
|
|
|
|
|
Width: 101,
|
|
|
|
|
Height: 176,
|
|
|
|
|
Version: 2,
|
|
|
|
|
IsActive: true,
|
|
|
|
|
PostID: 2624329,
|
|
|
|
|
Body: "Well, isn’t it just right to use them?",
|
|
|
|
|
CreatorName: "ponypussypounder",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsonResponser, err := httpmock.NewJsonResponder(200, noteResponse)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
httpmock.RegisterResponder("GET", "https://e621.net/notes/36957.json", jsonResponser)
|
|
|
|
|
|
|
|
|
|
requestContext := model.RequestContext{
|
2023-10-23 13:35:14 +00:00
|
|
|
|
Client: http.Client{},
|
2023-10-19 13:30:36 +00:00
|
|
|
|
Host: "https://e621.net",
|
|
|
|
|
UserAgent: "Go-e621-SDK (@username)",
|
|
|
|
|
Username: "memo",
|
|
|
|
|
APIKey: "123456",
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 13:35:14 +00:00
|
|
|
|
pool, err := GetNote(requestContext, "36957")
|
2023-10-19 13:30:36 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if pool.ID == noteResponse.ID && pool.Body == noteResponse.Body {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pool, noteResponse)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetNotes(t *testing.T) {
|
|
|
|
|
httpmock.Activate()
|
|
|
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
|
|
|
|
|
|
noteResponse := []model.Note{
|
|
|
|
|
{
|
|
|
|
|
ID: 385777,
|
|
|
|
|
CreatedAt: "2023-10-19T06:42:20.171-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T06:42:20.171-04:00",
|
|
|
|
|
CreatorID: 1472475,
|
|
|
|
|
X: 277,
|
|
|
|
|
Y: 841,
|
|
|
|
|
Width: 101,
|
|
|
|
|
Height: 176,
|
|
|
|
|
Version: 2,
|
|
|
|
|
IsActive: true,
|
|
|
|
|
PostID: 2624329,
|
|
|
|
|
Body: "Well, isn’t it just right to use them?",
|
|
|
|
|
CreatorName: "ponypussypounder",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ID: 56782,
|
|
|
|
|
CreatedAt: "2023-10-19T06:42:20.171-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T06:42:20.171-04:00",
|
|
|
|
|
CreatorID: 1472475,
|
|
|
|
|
X: 277,
|
|
|
|
|
Y: 841,
|
|
|
|
|
Width: 101,
|
|
|
|
|
Height: 176,
|
|
|
|
|
Version: 2,
|
|
|
|
|
IsActive: true,
|
|
|
|
|
PostID: 2624329,
|
|
|
|
|
Body: "Well, isn’t it just right to use them?",
|
|
|
|
|
CreatorName: "ponypussypounder",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ID: 43847234,
|
|
|
|
|
CreatedAt: "2023-10-19T06:42:20.171-04:00",
|
|
|
|
|
UpdatedAt: "2023-10-19T06:42:20.171-04:00",
|
|
|
|
|
CreatorID: 1472475,
|
|
|
|
|
X: 277,
|
|
|
|
|
Y: 841,
|
|
|
|
|
Width: 101,
|
|
|
|
|
Height: 176,
|
|
|
|
|
Version: 2,
|
|
|
|
|
IsActive: true,
|
|
|
|
|
PostID: 2624329,
|
|
|
|
|
Body: "Well, isn’t it just right to use them?",
|
|
|
|
|
CreatorName: "ponypussypounder",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsonResponser, err := httpmock.NewJsonResponder(200, noteResponse)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
httpmock.RegisterResponder("GET", "https://e621.net/notes.json", jsonResponser)
|
|
|
|
|
|
|
|
|
|
requestContext := model.RequestContext{
|
2023-10-23 13:35:14 +00:00
|
|
|
|
Client: http.Client{},
|
2023-10-19 13:30:36 +00:00
|
|
|
|
Host: "https://e621.net",
|
|
|
|
|
UserAgent: "Go-e621-SDK (@username)",
|
|
|
|
|
Username: "memo",
|
|
|
|
|
APIKey: "123456",
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 13:35:14 +00:00
|
|
|
|
pools, err := GetNotes(requestContext, map[string]string{})
|
2023-10-19 13:30:36 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(pools) == 3 && pools[0].ID == noteResponse[0].ID && pools[1].Body == noteResponse[1].Body && pools[2].UpdatedAt == noteResponse[2].UpdatedAt {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pools, noteResponse)
|
|
|
|
|
|
|
|
|
|
}
|