mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-15 18:56:59 +00:00
Fix type, add attempt at test
Fix type comparison and add an attempt at a test for the new method
This commit is contained in:
parent
fc8c3d4608
commit
74bddee30b
2 changed files with 36 additions and 1 deletions
|
@ -145,7 +145,7 @@ func RemoveResolvedReports(ctx context.Context, timeout time.Duration) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if report.ShadowCopyID.valid && report.ShadowCopyID.Int64 != 0 {
|
||||
if report.ShadowCopyID.Valid && report.ShadowCopyID.Int64 != 0 {
|
||||
_, err := db.GetEngine(ctx).ID(report.ShadowCopyID).Delete(&moderation.AbuseReportShadowCopy{})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
35
services/moderation/reporting_test.go
Normal file
35
services/moderation/reporting_test.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package moderation
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"forgejo.org/models/db"
|
||||
report_model "forgejo.org/models/moderation"
|
||||
"forgejo.org/models/unittest"
|
||||
"forgejo.org/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
|
||||
func TestRemoveResolvedReportsTypeHandled(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
// Add a resolved report
|
||||
resolvedReport := &report_model.AbuseReport{
|
||||
Status: report_model.ReportStatusTypeHandled,
|
||||
ReporterID: 1, ContentType: report_model.ReportedContentTypeRepository,
|
||||
ContentID: 2, Category: report_model.AbuseCategoryTypeOther,
|
||||
CreatedUnix: timeutil.TimeStampNow(),
|
||||
}
|
||||
_, err := db.GetEngine(db.DefaultContext).NoAutoTime().Insert(resolvedReport)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = RemoveResolvedReports(db.DefaultContext, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Resolved reports older than a minute should be deleted.
|
||||
unittest.AssertExistsIf(t, false, resolvedReport)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue