Skip to content

Commit

Permalink
add revrec to addons and items
Browse files Browse the repository at this point in the history
  • Loading branch information
wsethbrown committed Feb 21, 2024
1 parent e76fe7f commit 1d942d4
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/recurly/add_on.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Item < Resource
created_at
updated_at
deleted_at
)
) + RevRec::PRODUCT_ATTRIBUTES

def changed_attributes
attrs = super
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/items/create-201.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Location: https://api.recurly.com/v2/items/plastic_gloves
<description>Sleek Plastic</description>
<external_sku>awesome-plastic-gloves</external_sku>
<accounting_code>1569273944</accounting_code>
<liability_gl_account_id>uf0jwj5zhclg</liability_gl_account_id>
<revenue_gl_account_id>uf0jwincednb'</revenue_gl_account_id>
<performance_obligation_id>1</performance_obligation_id>
<revenue_schedule_type>never</revenue_schedule_type>
<tax_exempt type="boolean">true</tax_exempt>
<tax_code nil="nil"/>
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/items/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ Content-Type: application/xml; charset=utf-8
<created_at type="datetime">2019-09-23T21:25:45Z</created_at>
<updated_at type="datetime">2019-09-23T21:25:45Z</updated_at>
<deleted_at nil="nil"/>
<liability_gl_account_id>uf0jwj5zhclg</liability_gl_account_id>
<revenue_gl_account_id>uf0jwincednb</revenue_gl_account_id>
<performance_obligation_id>1</performance_obligation_id>
</item>
3 changes: 3 additions & 0 deletions spec/fixtures/plans/add_ons/index-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Content-Type: application/xml; charset=utf-8
<default_quantity type="integer">1</default_quantity>
<display_quantity_on_hosted_page type="boolean">false</display_quantity_on_hosted_page>
<revenue_schedule_type>evenly</revenue_schedule_type>
<liability_gl_account_id>udexyr9hjgkc</liability_gl_account_id>
<revenue_gl_account_id>uelq7rzkydlu</revenue_gl_account_id>
<performance_obligation_id>6</performance_obligation_id>
<unit_amount_in_cents>
<USD type="integer">5</USD>
</unit_amount_in_cents>
Expand Down
22 changes: 22 additions & 0 deletions spec/fixtures/plans/add_ons/show-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<add_on href="https://api.recurly.com/v2/plans/gold/add_ons/marketing_email">
<plan href="https://api.recurly.com/v2/plans/gold"/>
<add_on_code>marketing_email</add_on_code>
<name>Marketing Email</name>
<default_quantity type="integer">1</default_quantity>
<display_quantity_on_hosted_page type="boolean">false</display_quantity_on_hosted_page>
<revenue_schedule_type>evenly</revenue_schedule_type>
<liability_gl_account_id>udexyr9hjgkc</liability_gl_account_id>
<revenue_gl_account_id>uelq7rzkydlu</revenue_gl_account_id>
<performance_obligation_id>6</performance_obligation_id>
<unit_amount_in_cents>
<USD type="integer">5</USD>
</unit_amount_in_cents>
<accounting_code>marketing-email</accounting_code>
<avalara_service_type type="integer">600</avalara_service_type>
<avalara_transaction_type type="integer">3</avalara_transaction_type>
<created_at type="datetime">2016-04-19T20:26:03Z</created_at>
</add_on>
84 changes: 84 additions & 0 deletions spec/recurly/add_on_spec.rb
Original file line number Diff line number Diff line change
@@ -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 <<XML.chomp
<add_on>\
<add_on_code>pink_sweaters</add_on_code>\
<add_on_type>usage</add_on_type>\
<liability_gl_account_id>uf0jwj5zhclg</liability_gl_account_id>\
<name>Pink Sweaters</name>\
<optional>false</optional>\
<performance_obligation_id>1</performance_obligation_id>\
<revenue_gl_account_id>uf0jwincednb</revenue_gl_account_id>\
<revenue_schedule_type>evenly</revenue_schedule_type>\
<unit_amount_in_cents>\
<USD>200</USD>\
</unit_amount_in_cents>\
<usage_type>price</usage_type>\
</add_on>
XML
end

before do
stub_api_request(
:get, 'plans/gold', 'plans/show-200'
Expand All @@ -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
Expand Down Expand Up @@ -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 => "<add_on><add_on_code>pink_sweaters</add_on_code><add_on_type>usage</add_on_type><liability_gl_account_id>uf0jwj5zhclg</liability_gl_account_id><name>Pink Sweaters</name><optional>false</optional><performance_obligation_id>1</performance_obligation_id><revenue_gl_account_id>uf0jwincednb</revenue_gl_account_id><revenue_schedule_type>evenly</revenue_schedule_type><unit_amount_in_cents><USD>200</USD></unit_amount_in_cents><usage_type>price</usage_type></add_on>",
: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 => "<add_on><liability_gl_account_id>a8hkyaw9nm</liability_gl_account_id><name>Updated Emails</name><revenue_gl_account_id>aksdfu48</revenue_gl_account_id></add_on>",
: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
44 changes: 40 additions & 4 deletions spec/recurly/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,7 +26,10 @@
<description>Some Pink Sweaters</description>\
<external_sku>ABC-123</external_sku>\
<item_code>pink_sweaters</item_code>\
<liability_gl_account_id>uf0jwj5zhclg</liability_gl_account_id>\
<name>Pink Sweaters</name>\
<performance_obligation_id>1</performance_obligation_id>\
<revenue_gl_account_id>uf0jwincednb</revenue_gl_account_id>\
<revenue_schedule_type>evenly</revenue_schedule_type>\
</item>
XML
Expand All @@ -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
Expand All @@ -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 => "<item><name>Sleek Plastic Gloves</name></item>",
with(:body => "<item><liability_gl_account_id>a8hkyaw9nm</liability_gl_account_id><name>Sleek Plastic Gloves</name><performance_obligation_id>6</performance_obligation_id><revenue_gl_account_id>aksdfu48</revenue_gl_account_id></item>",
: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

Expand Down

0 comments on commit 1d942d4

Please sign in to comment.