@@ -4,6 +4,7 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
44 use Oban.Testing , repo: Algora.Repo
55
66 import Algora.Factory
7+ import Ecto.Changeset
78 import Ecto.Query
89 import ExUnit.CaptureLog
910 import Money.Sigil
@@ -830,6 +831,46 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
830831 assert Repo . aggregate ( Transaction , :count ) == 0
831832 end
832833
834+ test "does not autopay when autopay is disabled" , ctx do
835+ issue_number = :rand . uniform ( 1000 )
836+ pr_number = :rand . uniform ( 1000 )
837+
838+ customer = insert! ( :customer , user: ctx [ :org ] )
839+ _payment_method = insert! ( :payment_method , customer: customer )
840+
841+ process_scenario! ( ctx , [
842+ % {
843+ event_action: "issue_comment.created" ,
844+ user_type: :admin ,
845+ body: "/bounty $100" ,
846+ params: % { "issue" => % { "number" => issue_number } }
847+ } ,
848+ % {
849+ event_action: "pull_request.opened" ,
850+ user_type: :unauthorized ,
851+ body: "/claim #{ issue_number } " ,
852+ params: % { "pull_request" => % { "number" => pr_number } }
853+ }
854+ ] )
855+
856+ Bounty |> Repo . one! ( ) |> change ( % { autopay_disabled: true } ) |> Repo . update! ( )
857+
858+ process_scenario! ( ctx , [
859+ % {
860+ event_action: "pull_request.closed" ,
861+ user_type: :unauthorized ,
862+ body: "/claim #{ issue_number } " ,
863+ params: % { "pull_request" => % { "number" => pr_number , "merged_at" => DateTime . to_iso8601 ( DateTime . utc_now ( ) ) } }
864+ }
865+ ] )
866+
867+ bounty = Repo . one! ( Bounty )
868+ claim = Repo . one! ( Claim )
869+ assert claim . target_id == bounty . ticket_id
870+ assert claim . status == :approved
871+ assert Repo . aggregate ( Transaction , :count ) == 0
872+ end
873+
833874 test "handles autopay when claim is changed to a different bounty and PR is merged" , ctx do
834875 issue_number1 = :rand . uniform ( 1000 )
835876 issue_number2 = issue_number1 + :rand . uniform ( 1000 )
0 commit comments