Skip to content

Commit

Permalink
Added tests for validation_rule_assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaliszuk committed May 8, 2024
1 parent 670f445 commit 8dd636b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __tests__/lib/voucherify_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize
@loyalty_card = nil
@product_ids = []
@sku = nil
@validation_rule = nil
end

def set_discount_campaign(discount_campaign)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion __tests__/spec/2_campaigns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
$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)

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
Expand Down
35 changes: 35 additions & 0 deletions __tests__/spec/a1_validation_rules_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8dd636b

Please sign in to comment.