mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-03-26 06:33:04 -04:00
Closes #10078 and includes another small improvement (for comments and issues/PRs the title from report/s details page already included the poster name; now it will clickable, opening the poster profile page). Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10194 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: floss4good <floss4good@disroot.org> Co-committed-by: floss4good <floss4good@disroot.org>
70 lines
2.4 KiB
Go
70 lines
2.4 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package issues_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"forgejo.org/models/issues"
|
|
"forgejo.org/models/moderation"
|
|
"forgejo.org/modules/timeutil"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
const (
|
|
tsCreated timeutil.TimeStamp = timeutil.TimeStamp(1753093500) // 2025-07-21 10:25:00 UTC
|
|
tsUpdated timeutil.TimeStamp = timeutil.TimeStamp(1753093525) // 2025-07-21 10:25:25 UTC
|
|
)
|
|
|
|
func testShadowCopyField(t *testing.T, scField moderation.ShadowCopyField, key, value string) {
|
|
assert.Equal(t, key, scField.Key)
|
|
assert.Equal(t, value, scField.Value)
|
|
}
|
|
|
|
func TestIssueDataGetFieldsMap(t *testing.T) {
|
|
id := issues.IssueData{
|
|
RepoID: 2001,
|
|
Index: 2,
|
|
PosterID: 1002,
|
|
Title: "Professional marketing services",
|
|
Content: "Visit my website at promote-your-business.biz for a list of available services.",
|
|
ContentVersion: 0,
|
|
CreatedUnix: tsCreated,
|
|
UpdatedUnix: tsUpdated,
|
|
}
|
|
scFields := id.GetFieldsMap()
|
|
|
|
if assert.Len(t, scFields, 8) {
|
|
testShadowCopyField(t, scFields[0], "RepoID", "2001")
|
|
testShadowCopyField(t, scFields[1], "Index", "2")
|
|
testShadowCopyField(t, scFields[2], "Poster", "1002")
|
|
testShadowCopyField(t, scFields[3], "Title", "Professional marketing services")
|
|
testShadowCopyField(t, scFields[4], "Content", "Visit my website at promote-your-business.biz for a list of available services.")
|
|
testShadowCopyField(t, scFields[5], "ContentVersion", "0")
|
|
testShadowCopyField(t, scFields[6], "CreatedUnix", tsCreated.AsLocalTime().String())
|
|
testShadowCopyField(t, scFields[7], "UpdatedUnix", tsUpdated.AsLocalTime().String())
|
|
}
|
|
}
|
|
|
|
func TestCommentDataGetFieldsMap(t *testing.T) {
|
|
cd := issues.CommentData{
|
|
PosterID: 1002,
|
|
IssueID: 3001,
|
|
Content: "Check out [alexsmith/website](/alexsmith/website)",
|
|
ContentVersion: 0,
|
|
CreatedUnix: tsCreated,
|
|
UpdatedUnix: tsUpdated,
|
|
}
|
|
scFields := cd.GetFieldsMap()
|
|
|
|
if assert.Len(t, scFields, 6) {
|
|
testShadowCopyField(t, scFields[0], "Poster", "1002")
|
|
testShadowCopyField(t, scFields[1], "IssueID", "3001")
|
|
testShadowCopyField(t, scFields[2], "Content", "Check out [alexsmith/website](/alexsmith/website)")
|
|
testShadowCopyField(t, scFields[3], "ContentVersion", "0")
|
|
testShadowCopyField(t, scFields[4], "CreatedUnix", tsCreated.AsLocalTime().String())
|
|
testShadowCopyField(t, scFields[5], "UpdatedUnix", tsUpdated.AsLocalTime().String())
|
|
}
|
|
}
|