Skip to content

Commit

Permalink
fix: ensure calling verify_completion with dry_run don't apply events
Browse files Browse the repository at this point in the history
  • Loading branch information
juliano-quatrin-nunes committed Feb 17, 2025
1 parent 9759683 commit e96dbb2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class BadgeCreated < Infra::Event
class BadgeUnlocked < Infra::Event
attribute :badge_id, Infra::Types::UUID
attribute :user_id, Infra::Types::UUID
attribute :notify, Infra::Types::Bool
end

class BadgeEarned < Infra::Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ def verify_completion?(user_id:, dry_run: false)
strategy = Gamification::SpecialBadgeStrategyFactory.for(@badge_type, badge_data: @badge_data, user_id: user_id, unlocked_by: @unlocked_by)
can_complete = strategy.verify_completion?

apply BadgeUnlocked.new(data: {
badge_id: @id,
user_id: user_id,
notify: !dry_run
}) if can_complete
if can_complete
apply BadgeUnlocked.new(data: {
badge_id: @id,
user_id: user_id,
}) unless dry_run

@unlocked_by << user_id if dry_run
end

can_complete
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call(event)
content: "New <a href='/achievements?badgeId=#{badge_id}'>badge</a> unlocked!",
notification_type: "badge_unlocked"
)
) if event.data[:notify]
)
end
end
end

0 comments on commit e96dbb2

Please sign in to comment.