From 1d942d4bc6c481811b941cd8758f7829cb974991 Mon Sep 17 00:00:00 2001 From: Seth Brown Date: Wed, 21 Feb 2024 11:41:29 -0500 Subject: [PATCH] add revrec to addons and items --- lib/recurly/add_on.rb | 2 +- lib/recurly/item.rb | 2 +- spec/fixtures/items/create-201.xml | 3 + spec/fixtures/items/show-200.xml | 3 + spec/fixtures/plans/add_ons/index-200.xml | 3 + spec/fixtures/plans/add_ons/show-200.xml | 22 ++++++ spec/recurly/add_on_spec.rb | 84 +++++++++++++++++++++++ spec/recurly/item_spec.rb | 44 ++++++++++-- 8 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 spec/fixtures/plans/add_ons/show-200.xml diff --git a/lib/recurly/add_on.rb b/lib/recurly/add_on.rb index ab9d9e92b..822cb77db 100644 --- a/lib/recurly/add_on.rb +++ b/lib/recurly/add_on.rb @@ -31,7 +31,7 @@ class AddOn < Resource external_sku avalara_service_type avalara_transaction_type - ) + ) + RevRec::PRODUCT_ATTRIBUTES alias to_param add_on_code alias quantity default_quantity diff --git a/lib/recurly/item.rb b/lib/recurly/item.rb index e9d37216c..db567e654 100644 --- a/lib/recurly/item.rb +++ b/lib/recurly/item.rb @@ -16,7 +16,7 @@ class Item < Resource created_at updated_at deleted_at - ) + ) + RevRec::PRODUCT_ATTRIBUTES def changed_attributes attrs = super diff --git a/spec/fixtures/items/create-201.xml b/spec/fixtures/items/create-201.xml index 27671d40d..010ec19d4 100644 --- a/spec/fixtures/items/create-201.xml +++ b/spec/fixtures/items/create-201.xml @@ -9,6 +9,9 @@ Location: https://api.recurly.com/v2/items/plastic_gloves Sleek Plastic awesome-plastic-gloves 1569273944 + uf0jwj5zhclg + uf0jwincednb' + 1 never true diff --git a/spec/fixtures/items/show-200.xml b/spec/fixtures/items/show-200.xml index a2b0e965a..4372147fd 100644 --- a/spec/fixtures/items/show-200.xml +++ b/spec/fixtures/items/show-200.xml @@ -21,4 +21,7 @@ Content-Type: application/xml; charset=utf-8 2019-09-23T21:25:45Z 2019-09-23T21:25:45Z + uf0jwj5zhclg + uf0jwincednb + 1 diff --git a/spec/fixtures/plans/add_ons/index-200.xml b/spec/fixtures/plans/add_ons/index-200.xml index 07414ec63..a2f0697e2 100644 --- a/spec/fixtures/plans/add_ons/index-200.xml +++ b/spec/fixtures/plans/add_ons/index-200.xml @@ -10,6 +10,9 @@ Content-Type: application/xml; charset=utf-8 1 false evenly + udexyr9hjgkc + uelq7rzkydlu + 6 5 diff --git a/spec/fixtures/plans/add_ons/show-200.xml b/spec/fixtures/plans/add_ons/show-200.xml new file mode 100644 index 000000000..22516d67e --- /dev/null +++ b/spec/fixtures/plans/add_ons/show-200.xml @@ -0,0 +1,22 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + marketing_email + Marketing Email + 1 + false + evenly + udexyr9hjgkc + uelq7rzkydlu + 6 + + 5 + + marketing-email + 600 + 3 + 2016-04-19T20:26:03Z + \ No newline at end of file diff --git a/spec/recurly/add_on_spec.rb b/spec/recurly/add_on_spec.rb index ccc034e25..03901846d 100644 --- a/spec/recurly/add_on_spec.rb +++ b/spec/recurly/add_on_spec.rb @@ -1,6 +1,40 @@ require 'spec_helper' describe AddOn do + let(:add_on) do + AddOn.new( + add_on_code: 'pink_sweaters', + name: 'Pink Sweaters', + revenue_schedule_type: 'evenly', + unit_amount_in_cents: 200, + add_on_type: 'usage', + optional: false, + usage_type: 'price', + liability_gl_account_id: 'uf0jwj5zhclg', + revenue_gl_account_id: 'uf0jwincednb', + performance_obligation_id: '1', + ) + end + + it 'must serialize' do + add_on.to_xml.must_equal <\ +pink_sweaters\ +usage\ +uf0jwj5zhclg\ +Pink Sweaters\ +false\ +1\ +uf0jwincednb\ +evenly\ +\ +200\ +\ +price\ + +XML + end + before do stub_api_request( :get, 'plans/gold', 'plans/show-200' @@ -26,6 +60,9 @@ stub_api_request( :get, 'plans/percentageplan/add_ons', 'plans/add_ons/index-200-tiered-percentage' ) + stub_api_request( + :get, 'plans/gold/add_ons/marketing_email', 'plans/add_ons/show-200' + ) end describe ".find" do @@ -85,5 +122,52 @@ add_on.percentage_tiers.first.tiers.count.must_equal 2 add_on.percentage_tiers.first.tiers.first.must_be_instance_of PercentageTier end + + it "returns RevRec attributes" do + plan = Plan.find 'gold' + add_ons = plan.add_ons + + add_on = add_ons.first + add_on.must_be_instance_of AddOn + add_on.liability_gl_account_id.must_equal "udexyr9hjgkc" + add_on.revenue_gl_account_id.must_equal "uelq7rzkydlu" + add_on.performance_obligation_id.must_equal "6" + end + end + + describe "create" do + it "must create a new add-on" do + stub_request(:post, "https://api.recurly.com/v2/plans/gold/add_ons"). + with(:body => "pink_sweatersusageuf0jwj5zhclgPink Sweatersfalse1uf0jwincednbevenly200price", + :headers => Recurly::API.headers).to_return(:status => 200, :body => "", :headers => {}) + + plan = Plan.find 'gold' + add_on = plan.add_ons.create( + add_on_code: 'pink_sweaters', + name: 'Pink Sweaters', + revenue_schedule_type: 'evenly', + unit_amount_in_cents: 200, + add_on_type: 'usage', + optional: false, + usage_type: 'price', + liability_gl_account_id: 'uf0jwj5zhclg', + revenue_gl_account_id: 'uf0jwincednb', + performance_obligation_id: '1' + ) + add_on.must_be_instance_of AddOn + add_on.name.must_equal 'Pink Sweaters' + end + end + + describe "update" do + it "sends changed attributes to the server" do + plan = Plan.find 'gold' + add_on = plan.add_ons.find 'marketing_email' + stub_request(:put, "https://api.recurly.com/v2/plans/gold/add_ons/marketing_email"). + with(:body => "a8hkyaw9nmUpdated Emailsaksdfu48", + :headers => Recurly::API.headers).to_return(:status => 200, :body => "", :headers => {}) + add_on.update_attributes({ name: 'Updated Emails', revenue_gl_account_id: 'aksdfu48', + liability_gl_account_id: 'a8hkyaw9nm', performance_obligation_id: '6'}) + end end end diff --git a/spec/recurly/item_spec.rb b/spec/recurly/item_spec.rb index 7cfa5a2b1..02a1dd837 100644 --- a/spec/recurly/item_spec.rb +++ b/spec/recurly/item_spec.rb @@ -10,7 +10,10 @@ accounting_code: '1234', revenue_schedule_type: 'evenly', avalara_transaction_type: 600, - avalara_service_type: 3 + avalara_service_type: 3, + liability_gl_account_id: 'uf0jwj5zhclg', + revenue_gl_account_id: 'uf0jwincednb', + performance_obligation_id: '1' ) end @@ -23,7 +26,10 @@ Some Pink Sweaters\ ABC-123\ pink_sweaters\ +uf0jwj5zhclg\ Pink Sweaters\ +1\ +uf0jwincednb\ evenly\ XML @@ -32,13 +38,42 @@ describe "methods" do let(:item) { Item.find 'plastic_gloves' } + describe "create" do + it "must create a new item" do + stub_api_request :post, 'items', 'items/create-201' + item = Item.create( + item_code: 'pink_sweaters', + name: 'Pink Sweaters', + description: 'Some Pink Sweaters', + external_sku: 'ABC-123', + accounting_code: '1234', + revenue_schedule_type: 'evenly', + avalara_transaction_type: 600, + avalara_service_type: 3, + liability_gl_account_id: 'uf0jwj5zhclg', + revenue_gl_account_id: 'uf0jwincednb', + performance_obligation_id: '1' + ) + item.must_be_instance_of Item + item.description.must_equal 'Sleek Plastic' + end + end + describe ".find" do - it "must return an item when available" do + before do stub_api_request :get, 'items/plastic_gloves', 'items/show-200' + end + it "must return an item when available" do item.must_be_instance_of Item item.description.must_equal 'Sleek Plastic' end + + it "must return RevRec details when available" do + item.liability_gl_account_id.must_equal('uf0jwj5zhclg') + item.revenue_gl_account_id.must_equal('uf0jwincednb') + item.performance_obligation_id.must_equal('1') + end end describe "#save" do @@ -57,9 +92,10 @@ it "sends changed attributes to the server" do stub_api_request :get, 'items/plastic_gloves', 'items/show-200' stub_request(:put, "https://api.recurly.com/v2/items/plastic_gloves"). - with(:body => "Sleek Plastic Gloves", + with(:body => "a8hkyaw9nmSleek Plastic Gloves6aksdfu48", :headers => Recurly::API.headers).to_return(:status => 200, :body => "", :headers => {}) - item.update_attributes({ name: 'Sleek Plastic Gloves' }) + item.update_attributes({ name: 'Sleek Plastic Gloves', revenue_gl_account_id: 'aksdfu48', + liability_gl_account_id: 'a8hkyaw9nm', performance_obligation_id: '6'}) end end