fix(test): isolate staff workflow fixtures
This commit is contained in:
parent
615aee3d7a
commit
22e83a420b
|
|
@ -8,10 +8,12 @@ defmodule Mix.Tasks.Wnh.StagingFullE2e do
|
|||
alias WhoNeedHelp.Activities.{Activity, Participant}
|
||||
alias WhoNeedHelp.Activities.Message, as: ActivityMessage
|
||||
alias WhoNeedHelp.Catalog.{CategoryProposal, CategoryVote}
|
||||
alias WhoNeedHelp.ContentRemoval.Notice
|
||||
alias WhoNeedHelp.Help.{Assignment, HelpRequest}
|
||||
alias WhoNeedHelp.Messaging.Message
|
||||
alias WhoNeedHelp.Notifications.Notification
|
||||
alias WhoNeedHelp.Repo
|
||||
alias WhoNeedHelp.Support.SupportRequest
|
||||
alias WhoNeedHelp.Tracking.{Position, TrackingSession}
|
||||
|
||||
alias WhoNeedHelp.Trust.{
|
||||
|
|
@ -172,8 +174,17 @@ defmodule Mix.Tasks.Wnh.StagingFullE2e do
|
|||
|> select([report], report.id)
|
||||
|> Repo.all()
|
||||
|
||||
support_request_ids = ids(SupportRequest, :requester_id, user_ids)
|
||||
content_removal_notice_ids = ids(Notice, :requester_id, user_ids)
|
||||
|
||||
validate_reviewed_records!(user_ids, report_ids, proposal_ids)
|
||||
|
||||
validate_staff_reviewed_records!(
|
||||
user_ids,
|
||||
support_request_ids,
|
||||
content_removal_notice_ids
|
||||
)
|
||||
|
||||
abuse_signal_ids =
|
||||
AbuseSignal
|
||||
|> where(
|
||||
|
|
@ -191,7 +202,9 @@ defmodule Mix.Tasks.Wnh.StagingFullE2e do
|
|||
activity_participants: activity_participant_ids,
|
||||
proposals: proposal_ids,
|
||||
reports: report_ids,
|
||||
signals: abuse_signal_ids
|
||||
signals: abuse_signal_ids,
|
||||
support_requests: support_request_ids,
|
||||
content_removal_notices: content_removal_notice_ids
|
||||
})
|
||||
|
||||
job_ids = fixture_job_ids(user_ids, request_ids, notification_ids)
|
||||
|
|
@ -205,6 +218,8 @@ defmodule Mix.Tasks.Wnh.StagingFullE2e do
|
|||
AuditEvent
|
||||
|> where([event], event.actor_id in ^user_ids)
|
||||
|> delete_count(),
|
||||
support_requests: delete_ids(SupportRequest, support_request_ids),
|
||||
content_removal_notices: delete_ids(Notice, content_removal_notice_ids),
|
||||
reports: delete_ids(Report, report_ids),
|
||||
activity_messages: delete_ids(ActivityMessage, activity_message_ids),
|
||||
activity_participants: delete_ids(Participant, activity_participant_ids),
|
||||
|
|
@ -358,6 +373,32 @@ defmodule Mix.Tasks.Wnh.StagingFullE2e do
|
|||
end
|
||||
end
|
||||
|
||||
defp validate_staff_reviewed_records!(
|
||||
user_ids,
|
||||
support_request_ids,
|
||||
content_removal_notice_ids
|
||||
) do
|
||||
unexpected_support_request? =
|
||||
Repo.exists?(
|
||||
from request in SupportRequest,
|
||||
where:
|
||||
request.reviewed_by_id in ^user_ids and
|
||||
request.id not in ^support_request_ids
|
||||
)
|
||||
|
||||
unexpected_content_removal_notice? =
|
||||
Repo.exists?(
|
||||
from notice in Notice,
|
||||
where:
|
||||
notice.reviewed_by_id in ^user_ids and
|
||||
notice.id not in ^content_removal_notice_ids
|
||||
)
|
||||
|
||||
if unexpected_support_request? or unexpected_content_removal_notice? do
|
||||
Mix.raise("the run-scoped moderator changed a non-fixture support record")
|
||||
end
|
||||
end
|
||||
|
||||
defp validate_audits(targets) do
|
||||
allowed =
|
||||
[
|
||||
|
|
@ -368,7 +409,9 @@ defmodule Mix.Tasks.Wnh.StagingFullE2e do
|
|||
{"activity_participant", targets.activity_participants},
|
||||
{"category_proposal", targets.proposals},
|
||||
{"report", targets.reports},
|
||||
{"abuse_signal", targets.signals}
|
||||
{"abuse_signal", targets.signals},
|
||||
{"support_request", targets.support_requests},
|
||||
{"content_removal_notice", targets.content_removal_notices}
|
||||
]
|
||||
|> Enum.flat_map(fn {type, ids} -> Enum.map(ids, &{type, &1}) end)
|
||||
|> MapSet.new()
|
||||
|
|
|
|||
|
|
@ -114,6 +114,14 @@ UNION ALL SELECT 'category_proposals', count(*) FROM category_proposals
|
|||
UNION ALL SELECT 'category_votes', count(*) FROM category_votes
|
||||
UNION ALL SELECT 'blocks', count(*) FROM blocks
|
||||
UNION ALL SELECT 'social_identities', count(*) FROM social_identities
|
||||
UNION ALL SELECT 'support_requests', count(*) FROM support_requests
|
||||
UNION ALL SELECT 'support_messages', count(*) FROM support_messages
|
||||
UNION ALL SELECT 'support_status_events', count(*) FROM support_status_events
|
||||
UNION ALL SELECT 'content_removal_notices', count(*) FROM content_removal_notices
|
||||
UNION ALL SELECT 'notifications', count(*) FROM notifications
|
||||
UNION ALL SELECT 'notification_preferences', count(*) FROM notification_preferences
|
||||
UNION ALL SELECT 'nearby_subscriptions', count(*) FROM nearby_subscriptions
|
||||
UNION ALL SELECT 'push_devices', count(*) FROM push_devices
|
||||
UNION ALL SELECT 'rate_limit_buckets', count(*) FROM rate_limit_buckets
|
||||
ORDER BY table_name;
|
||||
COMMIT;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user