Skip to content

Commit

Permalink
Fix limit on Article attribute quantity_in_stock
Browse files Browse the repository at this point in the history
  • Loading branch information
ehannes committed Dec 10, 2024
1 parent ebeb124 commit 4fc72ba
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fortnox/api/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Article < Fortnox::API::Model::Base
attribute :purchase_price, Types::Sized::Float[0.0, 99_999_999_999_999.9]

# QuantityInStock Quantity in stock of the article
attribute :quantity_in_stock, Types::Sized::Float[0.0, 99_999_999_999_999.9]
attribute :quantity_in_stock, Types::Sized::Float[-100_000_000_000_000.0, 99_999_999_999_999.9]

# ReservedQuantity Reserved quantity of the article
attribute :reserved_quantity, Types::Nullable::Float.is(:read_only)
Expand Down
32 changes: 32 additions & 0 deletions spec/fortnox/api/repositories/article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,36 @@

# VCR: Expected mathes must be updated
include_examples '.search', :description, 'Test article', 3

describe 'limits' do
let(:article) do
VCR.use_cassette("#{vcr_dir}/#{cassette}") do
repository.save(described_class::MODEL.new(**attributes))
end
end

describe 'quantity_in_stock' do
let(:cassette) { 'limits/quantity_in_stock_min_value' }
let(:attributes) do
{
description: 'Test article',
quantity_in_stock: quantity_in_stock
}
end
let(:quantity_in_stock) { -99_999_999_999_999.9 }

it 'has a lower limit' do
expect(article.quantity_in_stock).to eq(-100_000_000_000_000.0)
end

context 'when positive' do
let(:cassette) { 'limits/quantity_in_stock_rounding_positive_value' }
let(:quantity_in_stock) { 1.123 }

it 'rounds to two decimals' do
expect(article.quantity_in_stock).to eq(1.12)
end
end
end
end
end
63 changes: 63 additions & 0 deletions spec/vcr_cassettes/articles/limits/quantity_in_stock_min_value.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fc72ba

Please sign in to comment.