Skip to content

Commit

Permalink
Add report tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Jun 22, 2024
1 parent ae427e8 commit c51029b
Show file tree
Hide file tree
Showing 14 changed files with 494 additions and 415 deletions.
9 changes: 7 additions & 2 deletions frontend/src/api/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ export const apiGetReports = async (opts?: ReportQueryFilter, abortController?:
};

export const apiGetUserReports = async (abortController?: AbortController) => {
const resp = await apiCall<ReportWithAuthor[], ReportQueryFilter>(`/api/reports/user`, 'POST', {}, abortController);
const resp = await apiCall<ReportWithAuthor[], ReportQueryFilter>(
`/api/reports/user`,
'GET',
undefined,
abortController
);
return resp.map(transformTimeStampedDates);
};

Expand All @@ -133,7 +138,7 @@ export const apiGetReportMessages = async (report_id: number, abortController?:
);

export interface CreateReportMessage {
message: string;
body_md: string;
}

export const apiCreateReportMessage = async (report_id: number, message: string) =>
Expand Down
20 changes: 3 additions & 17 deletions internal/ban/ban_steam_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,12 @@ func (s banSteamUsecase) Ban(ctx context.Context, curUser domain.PersonInfo, ori
return ban, errors.Join(errBannedPerson, domain.ErrSaveBan)
}

s.discord.SendPayload(domain.ChannelBanLog, discord.BanSteamResponse(bannedPerson))

updateAppealState := func(reportId int64) error {
report, errReport := s.reports.GetReport(ctx, curUser, reportId)
if errReport != nil {
return errors.Join(errReport, domain.ErrGetBanReport)
}

report.ReportStatus = domain.ClosedWithAction
if errSaveReport := s.reports.SaveReport(ctx, &report.Report); errSaveReport != nil {
return errors.Join(errSaveReport, domain.ErrReportStateUpdate)
}

return nil
}
go s.discord.SendPayload(domain.ChannelBanLog, discord.BanSteamResponse(bannedPerson))

// Close the report if the ban was attached to one
if banSteam.ReportID > 0 {
if errRep := updateAppealState(banSteam.ReportID); errRep != nil {
return ban, errRep
if _, errSaveReport := s.reports.SetReportStatus(ctx, banSteam.ReportID, curUser, domain.ClosedWithAction); errSaveReport != nil {
return ban, errors.Join(errSaveReport, domain.ErrReportStateUpdate)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func serveCmd() *cobra.Command { //nolint:maintidx
notification.NewNotificationHandler(router, notificationUsecase, authUsecase)
patreon.NewPatreonHandler(router, patreonUsecase, authUsecase, configUsecase)
person.NewPersonHandler(router, configUsecase, personUsecase, authUsecase)
report.NewReportHandler(router, reportUsecase, configUsecase, discordUsecase, personUsecase, authUsecase, demoUsecase)
report.NewReportHandler(router, reportUsecase, authUsecase)
servers.NewServerHandler(router, serversUsecase, stateUsecase, authUsecase, personUsecase)
srcds.NewSRCDSHandler(router, srcdsUsecase, serversUsecase, personUsecase, assetUsecase,
reportUsecase, banUsecase, networkUsecase, banGroupUsecase, demoUsecase, authUsecase, banASNUsecase, banNetUsecase,
Expand Down
25 changes: 15 additions & 10 deletions internal/discord/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func DeleteReportMessage(existing domain.ReportMessage, user domain.PersonInfo,
return msgEmbed.AddAuthorPersonInfo(user, userURL).Embed().Truncate().MessageEmbed
}

func NewInGameReportResponse(report domain.Report, reportURL string, author domain.PersonInfo, authorURL string, _ string) *discordgo.MessageEmbed {
func NewInGameReportResponse(report domain.ReportWithAuthor, reportURL string, author domain.PersonInfo, authorURL string, _ string) *discordgo.MessageEmbed {
msgEmbed := NewEmbed("New User Report Created")
msgEmbed.
Embed().
Expand Down Expand Up @@ -1149,15 +1149,6 @@ func BanIPMessage() *discordgo.MessageEmbed {
MessageEmbed
}

func SetSteamMessage() *discordgo.MessageEmbed {
return NewEmbed().Embed().
SetTitle("Steam Account Linked").
SetDescription("Your steam and discord accounts are now linked").
SetColor(ColourSuccess).
Truncate().
MessageEmbed
}

func NotificationMessage(message string, link string) *discordgo.MessageEmbed {
msgEmbed := NewEmbed("Notification", message)
if link != "" {
Expand All @@ -1167,6 +1158,20 @@ func NotificationMessage(message string, link string) *discordgo.MessageEmbed {
return msgEmbed.Embed().Truncate().MessageEmbed
}

func ReportStatusChangeMessage(report domain.ReportWithAuthor, fromStatus domain.ReportStatus, link string) *discordgo.MessageEmbed {
msgEmbed := NewEmbed(
"Report status changed",
fmt.Sprintf("Changed from %s to %s", fromStatus.String(), report.ReportStatus.String()),
link)

msgEmbed.Embed().
AddField("report_id", strconv.FormatInt(report.ReportID, 10))
msgEmbed.AddAuthorPersonInfo(report.Author, link)
msgEmbed.AddTargetPerson(report.Subject)

return msgEmbed.Embed().Truncate().MessageEmbed
}

func VoteResultMessage(conf domain.Config, result domain.VoteResult, source domain.Person, target domain.Person) *discordgo.MessageEmbed {
avatarSource := domain.NewAvatarLinks(source.AvatarHash)
avatarTarget := domain.NewAvatarLinks(target.AvatarHash)
Expand Down
18 changes: 14 additions & 4 deletions internal/domain/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ type ReportUsecase interface {
GetReport(ctx context.Context, curUser PersonInfo, reportID int64) (ReportWithAuthor, error)
GetReportMessages(ctx context.Context, reportID int64) ([]ReportMessage, error)
GetReportMessageByID(ctx context.Context, reportMessageID int64) (ReportMessage, error)
DropReportMessage(ctx context.Context, message *ReportMessage) error
DropReportMessage(ctx context.Context, curUser PersonInfo, reportMessageID int64) error
DropReport(ctx context.Context, report *Report) error
SaveReport(ctx context.Context, report *Report) error
SaveReportMessage(ctx context.Context, message *ReportMessage) error
SaveReport(ctx context.Context, currentUser UserProfile, req RequestReportCreate) (ReportWithAuthor, error)
CreateReportMessage(ctx context.Context, reportID int64, curUser PersonInfo, req RequestMessageBodyMD) (ReportMessage, error)
EditReportMessage(ctx context.Context, reportMessageID int64, curUser PersonInfo, req RequestMessageBodyMD) (ReportMessage, error)
GetReportBySteamID(ctx context.Context, authorID steamid.SteamID, steamID steamid.SteamID) (Report, error)
SetReportStatus(ctx context.Context, reportID int64, user PersonInfo, status ReportStatus) (ReportWithAuthor, error)
}

type RequestMessageBodyMD struct {
BodyMD string `json:"body_md"`
}

type RequestReportStatusUpdate struct {
Status ReportStatus `json:"status"`
}

type CreateReportReq struct {
type RequestReportCreate struct {
SourceID steamid.SteamID `json:"source_id"`
TargetID steamid.SteamID `json:"target_id"`
Description string `json:"description"`
Expand Down
2 changes: 1 addition & 1 deletion internal/domain/srcds.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type SRCDSRepository interface { //nolint:interfacebloat

type SRCDSUsecase interface { //nolint:interfacebloat
GetBanState(ctx context.Context, steamID steamid.SteamID, ip netip.Addr) (PlayerBanState, string, error)
Report(ctx context.Context, currentUser UserProfile, req CreateReportReq) (*Report, error)
Report(ctx context.Context, currentUser UserProfile, req RequestReportCreate) (ReportWithAuthor, error)
GetAdminByID(ctx context.Context, adminID int) (SMAdmin, error)
AddAdmin(ctx context.Context, alias string, authType AuthType, identity string, flags string, immunity int, password string) (SMAdmin, error)
DelAdmin(ctx context.Context, adminID int) error
Expand Down
Loading

0 comments on commit c51029b

Please sign in to comment.