diff --git a/__tests__/lib/voucherify_data.rb b/__tests__/lib/voucherify_data.rb index 90e640d8..fa4bcc69 100644 --- a/__tests__/lib/voucherify_data.rb +++ b/__tests__/lib/voucherify_data.rb @@ -15,6 +15,7 @@ def initialize @loyalty_card = nil @product_ids = [] @sku = nil + @validation_rule = nil end def set_discount_campaign(discount_campaign) @@ -37,6 +38,10 @@ def add_product_id(product_id) @product_ids.push(product_id) end + def set_validation_rule(validation_rule) + @validation_rule = validation_rule + end + def get_product_ids @product_ids end @@ -89,6 +94,10 @@ def get_loyalty_card @loyalty_card end + def get_validation_rule + @validation_rule + end + def set_loyalty_card(loyalty_card) @loyalty_card = loyalty_card end diff --git a/__tests__/spec/2_campaigns_spec.rb b/__tests__/spec/2_campaigns_spec.rb index 4cc5dd10..9658622d 100644 --- a/__tests__/spec/2_campaigns_spec.rb +++ b/__tests__/spec/2_campaigns_spec.rb @@ -14,7 +14,6 @@ $created_promotion_campaign = nil $created_loyalty_campaign = nil $created_validation_rule_applicable_to = nil - $created_campaign_with_validation_rule = nil it 'create a validation rule with applicable_to', :order => :first do validation_rule = create_validation_rule_applicable_to(@validation_rules_api_instance, @voucherify_data.get_product.id) @@ -22,6 +21,7 @@ expect(validation_rule).not_to be_nil $created_validation_rule_applicable_to = validation_rule + @voucherify_data.set_validation_rule(validation_rule) end it 'create a discount campaign with applicable_to validation rule', :order => :second do diff --git a/__tests__/spec/a1_validation_rules_spec.rb b/__tests__/spec/a1_validation_rules_spec.rb new file mode 100644 index 00000000..44e1ed5c --- /dev/null +++ b/__tests__/spec/a1_validation_rules_spec.rb @@ -0,0 +1,35 @@ +require_relative '../lib/config.rb' +require_relative '../lib/voucherify_data.rb' +require 'VoucherifySdk' + +RSpec.describe 'Validation Rules API', :order => :defined do + before(:each) do + @validation_rules_api_instance = Config.validation_rules_api_instance() + @voucherify_data = VoucherifyData.instance() + end + + it 'create validation rule', :order => :first do + voucher = @voucherify_data.get_voucher() + validation_rule = @voucherify_data.get_validation_rule() + + validationRulesAssignmentsCreateRequestBody = VoucherifySdk::ValidationRulesAssignmentsCreateRequestBody.new({ + related_object_type: "voucher", + related_object_id: voucher.code + }) + + created_validation_rule_assignment = @validation_rules_api_instance.create_validation_rule_assignment(validation_rule.id, { + validation_rules_assignments_create_request_body: validationRulesAssignmentsCreateRequestBody + }) + + puts(created_validation_rule_assignment) + + expect(created_validation_rule_assignment).not_to be_nil + expect(created_validation_rule_assignment.id).not_to be_nil + expect(created_validation_rule_assignment.created_at).not_to be_nil + expect(created_validation_rule_assignment.rule_id).to eq(validation_rule.id) + expect(created_validation_rule_assignment.related_object_id).to eq(voucher.id) + expect(created_validation_rule_assignment.related_object_type).to eq("voucher") + expect(created_validation_rule_assignment.object).to eq("validation_rules_assignment") + end + +end