forked from forgejo/forgejo
GitLab migration: Sanitize response for reaction list (#25054)
This commit is contained in:
parent
b6d8d695da
commit
af3deb0b30
2 changed files with 67 additions and 15 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
base "code.gitea.io/gitea/modules/migration"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -469,3 +470,49 @@ func TestGitlabGetReviews(t *testing.T) {
|
|||
assertReviewsEqual(t, []*base.Review{&review}, rvs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAwardsToReactions(t *testing.T) {
|
||||
downloader := &GitlabDownloader{}
|
||||
// yes gitlab can have duplicated reactions (https://gitlab.com/jaywink/socialhome/-/issues/24)
|
||||
testResponse := `
|
||||
[
|
||||
{
|
||||
"name": "thumbsup",
|
||||
"user": {
|
||||
"id": 1241334,
|
||||
"username": "lafriks"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "thumbsup",
|
||||
"user": {
|
||||
"id": 1241334,
|
||||
"username": "lafriks"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "thumbsup",
|
||||
"user": {
|
||||
"id": 4575606,
|
||||
"username": "real6543"
|
||||
}
|
||||
}
|
||||
]
|
||||
`
|
||||
var awards []*gitlab.AwardEmoji
|
||||
assert.NoError(t, json.Unmarshal([]byte(testResponse), &awards))
|
||||
|
||||
reactions := downloader.awardsToReactions(awards)
|
||||
assert.EqualValues(t, []*base.Reaction{
|
||||
{
|
||||
UserName: "lafriks",
|
||||
UserID: 1241334,
|
||||
Content: "thumbsup",
|
||||
},
|
||||
{
|
||||
UserName: "real6543",
|
||||
UserID: 4575606,
|
||||
Content: "thumbsup",
|
||||
},
|
||||
}, reactions)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue