mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Update InventoryColumns API for new Status Type
This commit is contained in:
parent
7ab12baef9
commit
1e8261ac2a
5 changed files with 42 additions and 2 deletions
|
@ -14,6 +14,7 @@ module Api
|
|||
def index
|
||||
columns = @inventory.repository_columns
|
||||
.includes(:repository_list_items)
|
||||
.includes(:repository_status_items)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: columns,
|
||||
|
|
|
@ -27,6 +27,7 @@ class RepositoryColumn < ApplicationRecord
|
|||
|
||||
scope :list_type, -> { where(data_type: 'RepositoryListValue') }
|
||||
scope :asset_type, -> { where(data_type: 'RepositoryAssetValue') }
|
||||
scope :status_type, -> { where(data_type: 'RepositoryStatusValue') }
|
||||
|
||||
def self.name_like(query)
|
||||
where('repository_columns.name ILIKE ?', "%#{query}%")
|
||||
|
|
|
@ -13,6 +13,14 @@ module Api
|
|||
object.data_type == 'RepositoryListValue' &&
|
||||
!instance_options[:hide_list_items]
|
||||
end)
|
||||
has_many :repository_status_items,
|
||||
key: :repository_status_items,
|
||||
serializer: InventoryStatusItemSerializer,
|
||||
class_name: 'RepositoryStatusItem',
|
||||
if: (lambda do
|
||||
object.data_type == 'RepositoryStatusValue' &&
|
||||
!instance_options[:hide_list_items]
|
||||
end)
|
||||
|
||||
def data_type
|
||||
Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS[object.data_type]
|
||||
|
|
|
@ -72,7 +72,8 @@ class Extends
|
|||
API_REPOSITORY_DATA_TYPE_MAPPINGS = { 'RepositoryTextValue' => 'text',
|
||||
'RepositoryDateValue' => 'date',
|
||||
'RepositoryListValue' => 'list',
|
||||
'RepositoryAssetValue' => 'file' }
|
||||
'RepositoryAssetValue' => 'file',
|
||||
'RepositoryStatusValue' => 'status' }
|
||||
|
||||
OMNIAUTH_PROVIDERS = [:linkedin]
|
||||
|
||||
|
|
|
@ -22,6 +22,10 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do
|
|||
repository: @valid_inventory, data_type: :RepositoryListValue)
|
||||
create(:repository_list_item, repository: @valid_inventory,
|
||||
repository_column: list_column, data: Faker::Name.unique.name)
|
||||
status_column = create(:repository_column, name: Faker::Name.unique.name,
|
||||
repository: @valid_inventory, data_type: :RepositoryStatusValue)
|
||||
create(:repository_status_item, repository: @valid_inventory,
|
||||
repository_column: status_column, status: Faker::Name.unique.name, icon: 'icon')
|
||||
create(:repository_column, name: Faker::Name.unique.name,
|
||||
repository: @valid_inventory, data_type: :RepositoryAssetValue)
|
||||
|
||||
|
@ -124,8 +128,33 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do
|
|||
)
|
||||
end
|
||||
|
||||
it 'Valid status column response' do
|
||||
status_column = @valid_inventory.repository_columns.status_type.first
|
||||
hash_body = nil
|
||||
get api_v1_team_inventory_column_path(
|
||||
id: status_column.id,
|
||||
team_id: @teams.first.id,
|
||||
inventory_id: @valid_inventory.id
|
||||
), headers: @valid_headers
|
||||
expect { hash_body = json }.not_to raise_exception
|
||||
expect(hash_body[:data]).to match(
|
||||
ActiveModelSerializers::SerializableResource
|
||||
.new(status_column,
|
||||
serializer: Api::V1::InventoryColumnSerializer)
|
||||
.as_json[:data]
|
||||
)
|
||||
expect(hash_body[:data]).to include('relationships')
|
||||
expect(hash_body[:included]).to match(
|
||||
ActiveModelSerializers::SerializableResource
|
||||
.new(@valid_inventory.repository_columns.limit(10),
|
||||
each_serializer: Api::V1::InventoryColumnSerializer,
|
||||
include: :inventory_status_items)
|
||||
.as_json[:included]
|
||||
)
|
||||
end
|
||||
|
||||
it 'Valid file column response' do
|
||||
file_column = @valid_inventory.repository_columns.third
|
||||
file_column = @valid_inventory.repository_columns.asset_type.first
|
||||
hash_body = nil
|
||||
get api_v1_team_inventory_column_path(
|
||||
id: file_column.id,
|
||||
|
|
Loading…
Reference in a new issue