70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package builder
|
|
|
|
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",
|
|
}
|
|
|
|
GetUser := NewGetUserBuilder(requestContext)
|
|
user, err := GetUser.SetUsername("MaxMustermannDer69ste").Execute()
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
|
|
if user.ID == userResponse.ID && user.Name == userResponse.Name && user.CreatedAt == user.CreatedAt {
|
|
return
|
|
}
|
|
|
|
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", user, userResponse)
|
|
|
|
}
|