package builder
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
)
func TestGetUsers(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
userResponse := []model.User{
{
WikiPageVersionCount: 0,
ArtistVersionCount: 0,
PoolVersionCount: 0,
ForumPostCount: 0,
CommentCount: 69,
FlagCount: 0,
FavoriteCount: 1337,
PositiveFeedbackCount: 0,
NeutralFeedbackCount: 0,
NegativeFeedbackCount: 0,
UploadLimit: 0,
ID: 1,
CreatedAt: "2020-04-07T07:16:40.286+02:00",
Name: "MaxMustermannDer69ste",
Level: 0,
BaseUploadLimit: 0,
PostUploadCount: 0,
PostUpdateCount: 0,
NoteUpdateCount: 0,
IsBanned: false,
CanApprovePosts: false,
CanUploadFree: false,
LevelString: "Member",
AvatarID: 7,
},
CommentCount: 1337,
FavoriteCount: 69,
CreatedAt: "2020-04-08T07:16:40.286+02:00",
Name: "HollaDieWaldfee",
AvatarID: 16,
}
jsonResponser, err := httpmock.NewJsonResponder(200, userResponse)
if err != nil {
t.Error(err)
return
httpmock.RegisterResponder("GET", "https://e621.net/users.json", jsonResponser)
requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)",
Username: "memo",
APIKey: "123456",
getUsers := NewGetUsersBuilder(requestContext)
user, err := getUsers.Execute()
if len(user) == 2 && user[0].ID == userResponse[0].ID && user[1].Name == userResponse[1].Name {
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", user, userResponse)