Sha256: 0cf3d38cfabc8a2a1d02ebf28513af0d3123055b0779967f77af197535f67d9c

Contents?: true

Size: 1.96 KB

Versions: 17

Compression:

Stored size: 1.96 KB

Contents

require 'test_helper'

class DiscountCodeTest < Test::Unit::TestCase
  def setup
    super
    fake 'price_rules/102586120/discount_codes/1002091923', body: load_fixture('discount_code')

    @discount_code = ShopifyAPI::DiscountCode.find(1002091923, params: {price_rule_id: 102586120})
  end

  def test_get_discount_code
    fake 'price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_code')
    discount_code = ShopifyAPI::DiscountCode.find 1002091923, params: { price_rule_id: 102586120 }

    assert_equal 1002091923, discount_code.id
  end

  def test_get_all_discount_codes
    fake 'price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_codes')
    discount_codes = ShopifyAPI::DiscountCode.all params: { price_rule_id: 102586120 }

    assert_equal 1, discount_codes.length
    assert_equal 1002091923, discount_codes.first.id
  end

  def test_create_discount_code
    fake 'price_rules/102586120/discount_codes', method: :post, status: 201, body: load_fixture('discount_code')
    discount_code = ShopifyAPI::DiscountCode.new
    discount_code.prefix_options[:price_rule_id] = 102586120
    discount_code.code = "SUMMERSALE10"
    discount_code.save

    assert_equal '{"discount_code":{"code":"SUMMERSALE10"}}', FakeWeb.last_request.body
  end

  def test_update_discount_code
    discount_code_response = ActiveSupport::JSON.decode(load_fixture('discount_code'))
    discount_code_response['discount_code']['code'] = "WINTERSALE50"
    @discount_code.code = "WINTERSALE50"

    fake 'price_rules/102586120/discount_codes/1002091923', method: :put, status: 200, body: ActiveSupport::JSON.encode(discount_code_response)

    @discount_code.save
    
    assert_equal discount_code_response['discount_code']['code'], @discount_code.code
  end

  def test_delete_discount_code
    fake 'price_rules/102586120/discount_codes/1002091923', method: :delete, body: 'destroyed'

    assert @discount_code.destroy
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shopify_api-7.0.2 test/discount_code_test.rb
shopify_api-7.0.1 test/discount_code_test.rb
shopify_api-7.0.0 test/discount_code_test.rb
shopify_api-6.0.0 test/discount_code_test.rb
shopify_api-5.2.4 test/discount_code_test.rb
shopify_api-5.2.3 test/discount_code_test.rb
shopify_api-5.2.2 test/discount_code_test.rb
shopify_api-5.2.1 test/discount_code_test.rb
shopify_api-5.2.0 test/discount_code_test.rb
shopify_api-5.1.0 test/discount_code_test.rb
shopify_api-5.0.0 test/discount_code_test.rb
shopify_api-4.13.0 test/discount_code_test.rb
shopify_api-4.12.0 test/discount_code_test.rb
shopify_api-4.11.0 test/discount_code_test.rb
shopify_api-4.10.0 test/discount_code_test.rb
shopify_api-4.9.1 test/discount_code_test.rb
shopify_api-4.9.0 test/discount_code_test.rb