mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Update GET /inventory_columns, GET /inventory_columns/:id endpts
This commit is contained in:
parent
eaa8a627a8
commit
6625b4019e
|
@ -14,8 +14,9 @@ module Api
|
||||||
.includes(:repository_list_items)
|
.includes(:repository_list_items)
|
||||||
.page(params.dig(:page, :number))
|
.page(params.dig(:page, :number))
|
||||||
.per(params.dig(:page, :size))
|
.per(params.dig(:page, :size))
|
||||||
render jsonapi: columns, each_serializer: InventoryColumnSerializer,
|
render jsonapi: columns,
|
||||||
include: :inventory_list_items
|
each_serializer: InventoryColumnSerializer,
|
||||||
|
hide_list_items: true
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -27,7 +28,9 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render jsonapi: @inventory_column, serializer: InventoryColumnSerializer
|
render jsonapi: @inventory_column,
|
||||||
|
serializer: InventoryColumnSerializer,
|
||||||
|
include: :inventory_list_items
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
@ -7,7 +7,9 @@ module Api
|
||||||
attributes :name, :data_type
|
attributes :name, :data_type
|
||||||
has_many :repository_list_items, key: :inventory_list_items,
|
has_many :repository_list_items, key: :inventory_list_items,
|
||||||
serializer: InventoryListItemSerializer,
|
serializer: InventoryListItemSerializer,
|
||||||
class_name: 'RepositoryListItem'
|
class_name: 'RepositoryListItem',
|
||||||
|
if: -> { object.data_type == 'RepositoryListValue' &&
|
||||||
|
!instance_options[:hide_list_items] }
|
||||||
|
|
||||||
def data_type
|
def data_type
|
||||||
type_id = RepositoryColumn
|
type_id = RepositoryColumn
|
||||||
|
|
|
@ -41,16 +41,9 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do
|
||||||
ActiveModelSerializers::SerializableResource
|
ActiveModelSerializers::SerializableResource
|
||||||
.new(@valid_inventory.repository_columns.limit(10),
|
.new(@valid_inventory.repository_columns.limit(10),
|
||||||
each_serializer: Api::V1::InventoryColumnSerializer,
|
each_serializer: Api::V1::InventoryColumnSerializer,
|
||||||
include: :inventory_columns)
|
hide_list_items: true)
|
||||||
.as_json[:data]
|
.as_json[:data]
|
||||||
)
|
)
|
||||||
expect(hash_body[:included]).to match(
|
|
||||||
ActiveModelSerializers::SerializableResource
|
|
||||||
.new(@valid_inventory.repository_columns.limit(10),
|
|
||||||
each_serializer: Api::V1::InventoryColumnSerializer,
|
|
||||||
include: :inventory_list_items)
|
|
||||||
.as_json[:included]
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'When invalid request, user in not member of the team' do
|
it 'When invalid request, user in not member of the team' do
|
||||||
|
@ -87,6 +80,100 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'GET inventory_column, #show' do
|
||||||
|
it 'Valid text column response' do
|
||||||
|
text_column = @valid_inventory.repository_columns.first
|
||||||
|
hash_body = nil
|
||||||
|
get api_v1_team_inventory_column_path(
|
||||||
|
id: text_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(text_column,
|
||||||
|
serializer: Api::V1::InventoryColumnSerializer)
|
||||||
|
.as_json[:data]
|
||||||
|
)
|
||||||
|
expect(hash_body[:data]).not_to include('relationships')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'Valid list column response' do
|
||||||
|
list_column = @valid_inventory.repository_columns.second
|
||||||
|
hash_body = nil
|
||||||
|
get api_v1_team_inventory_column_path(
|
||||||
|
id: list_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(list_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_list_items)
|
||||||
|
.as_json[:included]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'Valid file column response' do
|
||||||
|
file_column = @valid_inventory.repository_columns.third
|
||||||
|
hash_body = nil
|
||||||
|
get api_v1_team_inventory_column_path(
|
||||||
|
id: file_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(file_column,
|
||||||
|
serializer: Api::V1::InventoryColumnSerializer)
|
||||||
|
.as_json[:data]
|
||||||
|
)
|
||||||
|
expect(hash_body[:data]).not_to include('relationships')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'Invalid request, non existing inventory column' do
|
||||||
|
get api_v1_team_inventory_column_path(
|
||||||
|
id: 1001,
|
||||||
|
team_id: @teams.first.id,
|
||||||
|
inventory_id: @teams.first.repositories.first.id
|
||||||
|
), headers: @valid_headers
|
||||||
|
expect(response).to have_http_status(404)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'When invalid request, incorrect repository' do
|
||||||
|
id = @teams.first.repositories.first.repository_columns.last.id
|
||||||
|
get api_v1_team_inventory_column_path(
|
||||||
|
id: id,
|
||||||
|
team_id: @teams.first.id,
|
||||||
|
inventory_id: @teams.second.repositories.first.id
|
||||||
|
), headers: @valid_headers
|
||||||
|
expect(response).to have_http_status(404)
|
||||||
|
expect(RepositoryColumn.where(id: id)).to exist
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'When invalid request, repository from another team' do
|
||||||
|
id = @teams.first.repositories.first.repository_columns.last.id
|
||||||
|
get api_v1_team_inventory_column_path(
|
||||||
|
id: id,
|
||||||
|
team_id: @teams.second.id,
|
||||||
|
inventory_id: @teams.first.repositories.first.id
|
||||||
|
), headers: @valid_headers
|
||||||
|
expect(response).to have_http_status(403)
|
||||||
|
expect(RepositoryColumn.where(id: id)).to exist
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'POST inventory_column, #create' do
|
describe 'POST inventory_column, #create' do
|
||||||
before :all do
|
before :all do
|
||||||
@valid_headers['Content-Type'] = 'application/json'
|
@valid_headers['Content-Type'] = 'application/json'
|
||||||
|
|
Loading…
Reference in a new issue