Sha256: c536ab6d3ac57e79a8849e95d4454a8e9397c892018f82f990d38958ead54563

Contents?: true

Size: 1.33 KB

Versions: 9

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true
require 'test_helper'

class DiscountCodeBatchTest < Test::Unit::TestCase
  def setup
    super
    fake('price_rules/102586120/batch/989355119', body: load_fixture('discount_code_batch'))
  end

  def test_get_batch
    batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })

    assert_equal(989355119, batch.id)
  end

  def test_get_batch_discount_codes
    fake(
      'price_rules/102586120/batch/989355119/discount_codes',
      method: :get,
      status: 200,
      body: load_fixture('discount_code_batch_discount_codes')
    )
    batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })
    discount_code_job = batch.discount_code_job

    assert_equal(3, discount_code_job.count)
    assert(discount_code_job[2].errors.present?)
  end

  def test_create_batch
    fake('price_rules/102586120/batch', method: :post, status: 201, body: load_fixture('discount_code_batch'))
    batch = ShopifyAPI::DiscountCodeBatch.new
    batch.prefix_options[:price_rule_id] = 102586120
    discount_codes = [{ "code": "SUMMER1" }, { "code": "SUMMER2" }, { "code": "SUMMER3" }]
    batch.discount_codes = discount_codes
    batch.save

    expected_body = { discount_codes: discount_codes }.to_json
    assert_equal(expected_body, WebMock.last_request.body)
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
shopify_api-9.5.2 test/discount_code_batch_test.rb
ruby_shopify_api-1.2.0 test/discount_code_batch_test.rb
ruby_shopify_api-1.1.0 test/discount_code_batch_test.rb
ruby_shopify_api-1.0.0 test/discount_code_batch_test.rb
shopify_api-9.5.1 test/discount_code_batch_test.rb
shopify_api-9.5 test/discount_code_batch_test.rb
shopify_api-9.4.1 test/discount_code_batch_test.rb
shopify_api-9.4.0 test/discount_code_batch_test.rb
shopify_api-9.3.0 test/discount_code_batch_test.rb