refactor: tests use premade json files to test against.
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
babbf48192
commit
34b7b9346f
@ -11,114 +11,18 @@ 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)
|
||||
response, err := loadJsonTestData[model.PostResponse]("../../../tests/posts.json")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
httpmock.RegisterResponder("GET", "https://e621.net/favorites.json", jsonResponser)
|
||||
|
||||
responder, err := httpmock.NewJsonResponder(200, response)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
httpmock.RegisterResponder("GET", "https://e621.net/favorites.json", responder)
|
||||
|
||||
requestContext := model.RequestContext{
|
||||
Client: http.Client{},
|
||||
@ -134,10 +38,10 @@ func TestGetFavorites(t *testing.T) {
|
||||
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 {
|
||||
if posts[0].ID == response.Posts[0].ID && posts[1].File.Md5 == response.Posts[1].File.Md5 && posts[2].File.EXT == response.Posts[2].File.EXT {
|
||||
return
|
||||
}
|
||||
|
||||
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", posts, postResponse)
|
||||
t.Errorf("Respons did not match mock data:\nOriginal: %v\nMock: %v", posts, response)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user