package endpoints import ( "git.dragse.it/anthrove/e621-to-graph/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{ Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", Username: "memo", APIKey: "123456", } client := http.Client{} user, err := GetUser(client, requestContext, "MaxMustermannDer69ste") 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) } 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{ Host: "https://e621.net", UserAgent: "Go-e621-SDK (@username)", Username: "memo", APIKey: "123456", } client := http.Client{} user, err := GetUsers(client, 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) }