discount_code_batch_test.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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(
  14. 'price_rules/102586120/batch/989355119/discount_codes',
  15. method: :get,
  16. status: 200,
  17. body: load_fixture('discount_code_batch_discount_codes')
  18. )
  19. batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })
  20. discount_code_job = batch.discount_code_job
  21. assert_equal(3, discount_code_job.count)
  22. assert(discount_code_job[2].errors.present?)
  23. end
  24. def test_create_batch
  25. fake('price_rules/102586120/batch', method: :post, status: 201, body: load_fixture('discount_code_batch'))
  26. batch = ShopifyAPI::DiscountCodeBatch.new
  27. batch.prefix_options[:price_rule_id] = 102586120
  28. discount_codes = [{ "code": "SUMMER1" }, { "code": "SUMMER2" }, { "code": "SUMMER3" }]
  29. batch.discount_codes = discount_codes
  30. batch.save
  31. expected_body = { discount_codes: discount_codes }.to_json
  32. assert_equal(expected_body, WebMock.last_request.body)
  33. end
  34. end