package endpoints import ( "git.anthrove.art/anthrove/e621-sdk-go/pkg/e621/model" "git.anthrove.art/anthrove/e621-sdk-go/pkg/e621/utils" "github.com/jarcoal/httpmock" "net/http" "testing" ) func TestGetNote(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() response, err := utils.LoadJsonTestData[model.Note]("../../../tests/note.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/notes/1337.json", responder) requestContext := model.RequestContext{ Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", Username: "memo", APIKey: "123456", } pool, err := GetNote(requestContext, "1337") if err != nil { t.Error(err) return } if pool.ID == response.ID && pool.Body == response.Body { return } t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", pool, response) } 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 } responder, err := httpmock.NewJsonResponder(200, response) if err != nil { t.Error(err) return } httpmock.RegisterResponder("GET", "https://e621.net/notes.json", responder) requestContext := model.RequestContext{ Client: http.Client{}, Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", Username: "memo", APIKey: "123456", } pools, err := GetNotes(requestContext, map[string]string{}) 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) }