Add missing serializers for repository cell value on api and fix some tests [SCI-9613] (#6571)

This commit is contained in:
ajugo 2023-11-03 14:38:01 +01:00 committed by GitHub
parent 0c605ab63a
commit 55308f6a81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 7 deletions

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
module Api
module V1
class RepositoryNumberValueSerializer < ActiveModel::Serializer
attribute :data
include TimestampableModel
end
end
end

View file

@ -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

View file

@ -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

View file

@ -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),