discount_code_batch_test.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. class DiscountCodeBatchTest < Test::Unit::TestCase
  4. def setup
  5. super
  6. fake 'price_rules/102586120/batch/989355119', body: load_fixture('discount_code_batch')
  7. end
  8. def test_get_batch
  9. batch = ShopifyAPI::DiscountCodeBatch.find 989355119, params: { price_rule_id: 102586120 }
  10. assert_equal 989355119, batch.id
  11. end
  12. def test_get_batch_discount_codes
  13. fake 'price_rules/102586120/batch/989355119/discount_codes',
  14. method: :get,
  15. status: 200,
  16. body: load_fixture('discount_code_batch_discount_codes')
  17. batch = ShopifyAPI::DiscountCodeBatch.find 989355119, params: { price_rule_id: 102586120 }
  18. discount_code_job = batch.discount_code_job
  19. assert_equal 3, discount_code_job.count
  20. assert discount_code_job[2].errors.present?
  21. end
  22. def test_create_batch
  23. fake 'price_rules/102586120/batch', method: :post, status: 201, body: load_fixture('discount_code_batch')
  24. batch = ShopifyAPI::DiscountCodeBatch.new
  25. batch.prefix_options[:price_rule_id] = 102586120
  26. discount_codes = [{ "code": "SUMMER1" }, { "code": "SUMMER2" }, { "code": "SUMMER3" }]
  27. batch.discount_codes = discount_codes
  28. batch.save
  29. expected_body = { discount_codes: discount_codes }.to_json
  30. assert_equal expected_body, WebMock.last_request.body
  31. end
  32. end