diff --git a/app/serializers/api/v1/repository_number_value_serializer.rb b/app/serializers/api/v1/repository_number_value_serializer.rb new file mode 100644 index 000000000..577f325b8 --- /dev/null +++ b/app/serializers/api/v1/repository_number_value_serializer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Api + module V1 + class RepositoryNumberValueSerializer < ActiveModel::Serializer + attribute :data + + include TimestampableModel + end + end +end diff --git a/app/serializers/api/v1/repository_stock_value_serializer.rb b/app/serializers/api/v1/repository_stock_value_serializer.rb new file mode 100644 index 000000000..dcc09dea3 --- /dev/null +++ b/app/serializers/api/v1/repository_stock_value_serializer.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Api + module V1 + class RepositoryStockValueSerializer < ActiveModel::Serializer + attribute :repository_stock_unit_item_id, key: :inventory_stock_unit_item_id + attributes :amount, :low_stock_threshold, :comment + + include TimestampableModel + end + end +end diff --git a/spec/factories/assets.rb b/spec/factories/assets.rb index 26faa3ef6..f2ef9de9e 100644 --- a/spec/factories/assets.rb +++ b/spec/factories/assets.rb @@ -2,6 +2,7 @@ FactoryBot.define do factory :asset do + team after(:create) do |asset| asset.file.attach(io: File.open(Rails.root.join('spec/fixtures/files/test.jpg')), filename: 'test.jpg') end diff --git a/spec/requests/api/v1/inventory_items_controller_spec.rb b/spec/requests/api/v1/inventory_items_controller_spec.rb index fe1c06087..e4e170b37 100644 --- a/spec/requests/api/v1/inventory_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_items_controller_spec.rb @@ -68,10 +68,10 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do inventory_id: @team1.repositories.first.id ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception - expect(hash_body[:data]).to match( + expect(hash_body[:data]).to match_array( JSON.parse( ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_rows.limit(10), + .new(@valid_inventory.repository_rows.order(:id).limit(10), each_serializer: Api::V1::InventoryItemSerializer, include: :inventory_cells) .to_json @@ -88,19 +88,19 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do include: 'inventory_cells' ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception - expect(hash_body[:data]).to match( + expect(hash_body[:data]).to match_array( JSON.parse( ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_rows.limit(10), + .new(@valid_inventory.repository_rows.order(:id).limit(10), each_serializer: Api::V1::InventoryItemSerializer, include: :inventory_cells) .to_json )['data'] ) - expect(hash_body[:included]).to match( + expect(hash_body[:included]).to match_array( JSON.parse( ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_rows.limit(10), + .new(@valid_inventory.repository_rows.order(:id).limit(10), each_serializer: Api::V1::InventoryItemSerializer, include: :inventory_cells) .to_json @@ -115,7 +115,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do inventory_id: @team1.repositories.first.id ), params: { page: { size: 100 } }, headers: @valid_headers expect { hash_body = json }.not_to raise_exception - expect(hash_body[:data]).to match( + expect(hash_body[:data]).to match_array( JSON.parse( ActiveModelSerializers::SerializableResource .new(@valid_inventory.repository_rows.limit(100),