This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/pkg/e621/builder/notes_test.go

50 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-07-11 11:10:30 +00:00
package builder
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 TestGetNotes(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
response, err := utils.LoadJsonTestData[[]model.Note]("../../../tests/notes.json")
if err != nil {
t.Error(err)
return
}
responser, err := httpmock.NewJsonResponder(200, response)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/notes.json", responser)
requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)",
Username: "memo",
APIKey: "123456",
}
getNotes := NewGetNotesBuilder(requestContext)
pools, err := getNotes.SetLimit(3).Execute()
if err != nil {
t.Error(err)
return
}
if pools[0].ID == response[0].ID && pools[1].Body == response[1].Body && pools[2].UpdatedAt == response[2].UpdatedAt {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pools, response)
}