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/favorite_test.go

144 lines
3.8 KiB
Go
Raw Normal View History

package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
)
func TestGetFavorites(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
postResponse := model.PostResponse{
Post: model.Post{},
Posts: []model.Post{
{
ID: 658415636580,
CreatedAt: "2023-10-15T03:58:27.272-04:00",
UpdatedAt: "2023-10-19T02:47:33.597-04:00",
File: model.File{
Width: 759,
Height: 980,
EXT: "jpg",
Size: 640942,
Md5: "36e229e910638c7aebe65a500f16f3ee",
URL: "https://static1.e621.net/data/36/e2/36e229e910638c7aebe65a500f16f3ee.jpg",
},
Preview: model.Preview{},
Sample: model.Sample{},
Score: model.Score{},
Tags: model.Tags{},
LockedTags: nil,
ChangeSeq: 0,
Flags: model.Flags{},
Rating: "",
FavCount: 0,
Sources: nil,
Pools: nil,
Relationships: model.Relationships{},
ApproverID: nil,
UploaderID: 0,
Description: "",
CommentCount: 0,
IsFavorited: false,
HasNotes: false,
Duration: nil,
},
{
ID: 698418695,
CreatedAt: "2023-10-15T03:58:27.272-04:00",
UpdatedAt: "2023-10-19T02:47:33.597-04:00",
File: model.File{
Width: 759,
Height: 980,
EXT: "jpg",
Size: 640942,
Md5: "36e229e910638c7aebe65a500f16f3ee",
URL: "https://static1.e621.net/data/36/e2/36e229e910638c7aebe65a500f16f3ee.jpg",
},
Preview: model.Preview{},
Sample: model.Sample{},
Score: model.Score{},
Tags: model.Tags{},
LockedTags: nil,
ChangeSeq: 0,
Flags: model.Flags{},
Rating: "",
FavCount: 0,
Sources: nil,
Pools: nil,
Relationships: model.Relationships{},
ApproverID: nil,
UploaderID: 0,
Description: "",
CommentCount: 0,
IsFavorited: false,
HasNotes: false,
Duration: nil,
},
{
ID: 48976516894,
CreatedAt: "2023-10-15T03:58:27.272-04:00",
UpdatedAt: "2023-10-19T02:47:33.597-04:00",
File: model.File{
Width: 759,
Height: 980,
EXT: "jpg",
Size: 640942,
Md5: "36e229e910638c7aebe65a500f16f3ee",
URL: "https://static1.e621.net/data/36/e2/36e229e910638c7aebe65a500f16f3ee.jpg",
},
Preview: model.Preview{},
Sample: model.Sample{},
Score: model.Score{},
Tags: model.Tags{},
LockedTags: nil,
ChangeSeq: 0,
Flags: model.Flags{},
Rating: "",
FavCount: 0,
Sources: nil,
Pools: nil,
Relationships: model.Relationships{},
ApproverID: nil,
UploaderID: 0,
Description: "",
CommentCount: 0,
IsFavorited: false,
HasNotes: false,
Duration: nil,
},
},
}
jsonResponser, err := httpmock.NewJsonResponder(200, postResponse)
if err != nil {
t.Error(err)
return
}
httpmock.RegisterResponder("GET", "https://e621.net/favorites.json", jsonResponser)
requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)",
Username: "memo",
APIKey: "123456",
}
getFavorites := NewGetFavoritesBuilder(requestContext)
posts, err := getFavorites.SetLimit(3).Execute()
if err != nil {
t.Error(err)
return
}
if len(posts) == 3 && posts[0].ID == postResponse.Posts[0].ID && posts[1].File.Md5 == postResponse.Posts[1].File.Md5 && posts[2].File.EXT == postResponse.Posts[2].File.EXT {
return
}
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", posts, postResponse)
}