Sha256: 8732f01925167ddf2cfdaf3e472af32170019e3a0b47e6b1222645ee9dbdb297

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 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

4 entries across 4 versions & 1 rubygems

Version Path
shopify_api-9.2.0 test/discount_code_batch_test.rb
shopify_api-9.1.0 test/discount_code_batch_test.rb
shopify_api-9.0.4 test/discount_code_batch_test.rb
shopify_api-9.0.3 test/discount_code_batch_test.rb