mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-09 06:35:37 +08:00
Add missing serializers for repository cell value on api and fix some tests [SCI-9613] (#6571)
This commit is contained in:
parent
0c605ab63a
commit
55308f6a81
4 changed files with 31 additions and 7 deletions
11
app/serializers/api/v1/repository_number_value_serializer.rb
Normal file
11
app/serializers/api/v1/repository_number_value_serializer.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class RepositoryNumberValueSerializer < ActiveModel::Serializer
|
||||
attribute :data
|
||||
|
||||
include TimestampableModel
|
||||
end
|
||||
end
|
||||
end
|
12
app/serializers/api/v1/repository_stock_value_serializer.rb
Normal file
12
app/serializers/api/v1/repository_stock_value_serializer.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Reference in a new issue