Skip to content

Commit

Permalink
add ticket controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangplus committed Aug 28, 2024
1 parent 3432c72 commit d1d15ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ gem "sanitize"
gem "awesome_print"
gem "resend"
gem "icalendar"
gem "hash_diff"

gem "aliyunsdkcore"
gem "imagekitio"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ GEM
forwardable (1.3.3)
globalid (1.2.1)
activesupport (>= 6.1)
hash_diff (1.1.1)
http-accept (1.7.0)
http-cookie (1.0.7)
domain_name (~> 0.5)
Expand Down Expand Up @@ -414,6 +415,7 @@ DEPENDENCIES
dotenv-rails
ed25519 (= 1.3.0)
eth
hash_diff
icalendar
imagekitio
importmap-rails
Expand Down
30 changes: 30 additions & 0 deletions test/controllers/api/ticket_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,35 @@ class Api::TicketControllerTest < ActionDispatch::IntegrationTest
params: { auth_token: auth_token, id: event.id, ticket_id: ticket.id, payment_method_id: nil }
assert_response :success
end

test "api#ticket/rsvp with crypto ticket" do
profile = Profile.find_by(handle: "cookie")
auth_token = profile.gen_auth_token
group = Group.find_by(handle: "guildx")

event = events(:with_ticket)
ticket = Ticket.find_by(event: event, title: 'crypto')
op_paymethod = PaymentMethod.find_by(item: ticket, chain: 'op')

post api_ticket_rsvp_url,
params: { auth_token: auth_token, id: event.id, ticket_id: ticket.id, payment_method_id: op_paymethod.id }
assert_response :success

ticket_item = TicketItem.find_by(event: event)
assert ticket_item.status == "pending"

ENV['NEXT_TOKEN'] = "VBNM"

post api_ticket_set_ticket_payment_status_url,
params: { next_token: ENV['NEXT_TOKEN'], chain: ticket_item.chain, product_id: event.id, item_id: ticket_item.order_number, amount: ticket_item.amount, txhash: "0x7890"}
assert_response :success

ticket_item.reload
assert ticket_item.txhash == "0x7890"
assert ticket_item.status == "succeeded"

# hash_diff = HashDiff::Comparison.new( ticket_item.as_json, ticket_item.reload.as_json )
# p hash_diff.diff
end
end

0 comments on commit d1d15ae

Please sign in to comment.