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/endpoints/user_test.go
SoXX 3e80192bef test: fix tests conversions
Signed-off-by: SoXX <soxx@fenpa.ws>
2023-10-24 15:25:38 +02:00

158 lines
4.0 KiB
Go

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