Sha256: f576db81fc5621ab652132101bce42ebe5e5c7c6a29e9af2590d2e48c2bc8ae7

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

require 'test_helper'

class Alipay::Wap::NotifyTest < Minitest::Test
  def setup
    @notify_id = 'notify_id_test'

    @notify_params = {
      service: 'alipay.wap.trade.create.direct',
      v: '1.0',
      sec_id: 'MD5',
      notify_data: "<notify><notify_id>#{@notify_id}</notify_id><other_key>other_value</other_key></notify>"
    }

    query = [ :service, :v, :sec_id, :notify_data ].map {|key| "#{key}=#{@notify_params[key]}"}.join('&')
    @sign_params = @notify_params.merge(sign: Digest::MD5.hexdigest("#{query}#{Alipay.key}"))
  end

  def test_unsign_notify
    stub_request(
      :get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}"
    ).to_return(body: "true")
    assert !Alipay::Wap::Notify.verify?(@notify_params)
  end

  def test_verify_notify_when_true
    stub_request(
      :get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}"
    ).to_return(body: "true")
    assert Alipay::Wap::Notify.verify?(@sign_params)
  end

  def test_verify_notify_when_false
    stub_request(
      :get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}"
    ).to_return(body: "false")
    assert !Alipay::Wap::Notify.verify?(@sign_params)
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
yl_alipay-0.15.3 test/alipay/wap/notify_test.rb
yl_alipay-0.15.2 test/alipay/wap/notify_test.rb
alipay-0.14.0 test/alipay/wap/notify_test.rb