__tests__/lib/campaigns.rb in voucherify-5.0.0 vs __tests__/lib/campaigns.rb in voucherify-6.0.0

- old
+ new

@@ -5,11 +5,11 @@ def create_validation_rule_applicable_to(validation_rules_api_instance, product_id) begin created_validation_rule = validation_rules_api_instance.create_validation_rules({ validation_rules_create_request_body: VoucherifySdk::ValidationRulesCreateRequestBody.new({ name: generate_random_string(), - applicable_to: VoucherifySdk::ValidationRuleBaseApplicableTo.new({ + applicable_to: VoucherifySdk::ValidationRulesCreateRequestBodyApplicableTo.new({ included: [VoucherifySdk::ApplicableTo.new({ object: "product", id: product_id })] }), @@ -48,24 +48,25 @@ end def create_discount_campaign(campaigns_api_instance, validation_rule_id) begin campaign = campaigns_api_instance.create_campaign({ - campaigns_create_request_body: VoucherifySdk::CampaignsCreateDiscountCouponsCampaign.new({ + campaigns_create_request_body: VoucherifySdk::CampaignsCreateRequestBody.new({ campaign_type: "DISCOUNT_COUPONS", name: generate_random_string(), type: "AUTO_UPDATE", - voucher: VoucherifySdk::DiscountCouponsCampaignVoucher.new({ - discount: VoucherifySdk::DiscountAmount.new({ - type: "AMOUNT", + voucher: VoucherifySdk::CampaignsCreateRequestBodyVoucher.new({ + type: 'DISCOUNT_VOUCHER', + discount: VoucherifySdk::Discount.new({ + type: 'AMOUNT', amount_off: 1000 }) }), validation_rules: [validation_rule_id] }) }) - + return campaign rescue VoucherifySdk::ApiError => e return nil end end @@ -109,10 +110,11 @@ points: 1000, } } } }) + return campaign end end def delete_campaign(campaigns_api_instance, campaign_id) begin @@ -122,7 +124,25 @@ rescue VoucherifySdk::ApiError => e return nil end end - +def add_vouchers_to_campaign(campaigns_api_instance, campaign_id, voucher_count) + begin + vouchers = [] + + voucher_count.times do + voucher = campaigns_api_instance.add_vouchers_to_campaign( + campaign_id, + { + vouchers_count: 1 + } + ) + vouchers << voucher.code + end + + return vouchers + rescue VoucherifySdk::ApiError => e + return nil + end + end