Skip to content

Commit b474de6

Browse files
committed
Update tests
1 parent 3e54a01 commit b474de6

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

tests/integration/api_org_avatar_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestAPIUpdateOrgAvatar(t *testing.T) {
2323

2424
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteOrganization)
2525

26+
// Test what happens if you use a valid image
2627
avatar, err := os.ReadFile("tests/integration/avatar.png")
2728
assert.NoError(t, err)
2829
if err != nil {
@@ -36,12 +37,27 @@ func TestAPIUpdateOrgAvatar(t *testing.T) {
3637
req := NewRequestWithJSON(t, "POST", "/api/v1/orgs/user3/avatar?token="+token, &opts)
3738
MakeRequest(t, req, http.StatusNoContent)
3839

40+
// Test what happens if you don't have a valid Base64 string
3941
opts = api.UpdateUserAvatarOption{
4042
Image: "Invalid",
4143
}
4244

4345
req = NewRequestWithJSON(t, "POST", "/api/v1/orgs/user3/avatar?token="+token, &opts)
4446
MakeRequest(t, req, http.StatusBadRequest)
47+
48+
// Test what happens if you use a file that is not an image
49+
text, err := os.ReadFile("tests/integration/README.md")
50+
assert.NoError(t, err)
51+
if err != nil {
52+
assert.FailNow(t, "Unable to open README.md")
53+
}
54+
55+
opts = api.UpdateUserAvatarOption{
56+
Image: base64.StdEncoding.EncodeToString(text),
57+
}
58+
59+
req = NewRequestWithJSON(t, "POST", "/api/v1/orgs/user3/avatar?token="+token, &opts)
60+
MakeRequest(t, req, http.StatusInternalServerError)
4561
}
4662

4763
func TestAPIDeleteOrgAvatar(t *testing.T) {

tests/integration/api_repo_avatar_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) {
2727
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
2828
token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository)
2929

30+
// Test what happens if you use a valid image
3031
avatar, err := os.ReadFile("tests/integration/avatar.png")
3132
assert.NoError(t, err)
3233
if err != nil {
@@ -40,12 +41,27 @@ func TestAPIUpdateRepoAvatar(t *testing.T) {
4041
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/avatar?token=%s", repo.OwnerName, repo.Name, token), &opts)
4142
MakeRequest(t, req, http.StatusNoContent)
4243

44+
// Test what happens if you donÄt have a valid Base64 string
4345
opts = api.UpdateRepoAvatarOption{
4446
Image: "Invalid",
4547
}
4648

4749
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/avatar?token=%s", repo.OwnerName, repo.Name, token), &opts)
4850
MakeRequest(t, req, http.StatusBadRequest)
51+
52+
// Test what happens if you use a file that is not an image
53+
text, err := os.ReadFile("tests/integration/README.md")
54+
assert.NoError(t, err)
55+
if err != nil {
56+
assert.FailNow(t, "Unable to open README.md")
57+
}
58+
59+
opts = api.UpdateRepoAvatarOption{
60+
Image: base64.StdEncoding.EncodeToString(text),
61+
}
62+
63+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/avatar?token=%s", repo.OwnerName, repo.Name, token), &opts)
64+
MakeRequest(t, req, http.StatusInternalServerError)
4965
}
5066

5167
func TestAPIDeleteRepoAvatar(t *testing.T) {

tests/integration/api_user_avatar_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ func TestAPIUpdateUserAvatar(t *testing.T) {
2323
session := loginUser(t, normalUsername)
2424
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser)
2525

26+
// Test what happens if you use a valid image
2627
avatar, err := os.ReadFile("tests/integration/avatar.png")
2728
assert.NoError(t, err)
2829
if err != nil {
2930
assert.FailNow(t, "Unable to open avatar.png")
3031
}
3132

33+
// Test what happens if you don't have a valid Base64 string
3234
opts := api.UpdateUserAvatarOption{
3335
Image: base64.StdEncoding.EncodeToString(avatar),
3436
}
@@ -42,6 +44,20 @@ func TestAPIUpdateUserAvatar(t *testing.T) {
4244

4345
req = NewRequestWithJSON(t, "POST", "/api/v1/user/avatar?token="+token, &opts)
4446
MakeRequest(t, req, http.StatusBadRequest)
47+
48+
// Test what happens if you use a file that is not an image
49+
text, err := os.ReadFile("tests/integration/README.md")
50+
assert.NoError(t, err)
51+
if err != nil {
52+
assert.FailNow(t, "Unable to open README.md")
53+
}
54+
55+
opts = api.UpdateUserAvatarOption{
56+
Image: base64.StdEncoding.EncodeToString(text),
57+
}
58+
59+
req = NewRequestWithJSON(t, "POST", "/api/v1/user/avatar?token="+token, &opts)
60+
MakeRequest(t, req, http.StatusInternalServerError)
4561
}
4662

4763
func TestAPIDeleteUserAvatar(t *testing.T) {

0 commit comments

Comments
 (0)