mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Update GET /inventory_columns, GET /inventory_columns/:id endpts
This commit is contained in:
parent
eaa8a627a8
commit
6625b4019e
3 changed files with 104 additions and 12 deletions
|
@ -14,8 +14,9 @@ module Api
|
|||
.includes(:repository_list_items)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: columns, each_serializer: InventoryColumnSerializer,
|
||||
include: :inventory_list_items
|
||||
render jsonapi: columns,
|
||||
each_serializer: InventoryColumnSerializer,
|
||||
hide_list_items: true
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -27,7 +28,9 @@ module Api
|
|||
end
|
||||
|
||||
def show
|
||||
render jsonapi: @inventory_column, serializer: InventoryColumnSerializer
|
||||
render jsonapi: @inventory_column,
|
||||
serializer: InventoryColumnSerializer,
|
||||
include: :inventory_list_items
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
@ -7,7 +7,9 @@ module Api
|
|||
attributes :name, :data_type
|
||||
has_many :repository_list_items, key: :inventory_list_items,
|
||||
serializer: InventoryListItemSerializer,
|
||||
class_name: 'RepositoryListItem'
|
||||
class_name: 'RepositoryListItem',
|
||||
if: -> { object.data_type == 'RepositoryListValue' &&
|
||||
!instance_options[:hide_list_items] }
|
||||
|
||||
def data_type
|
||||
type_id = RepositoryColumn
|
||||
|
|
|
@ -41,16 +41,9 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do
|
|||
ActiveModelSerializers::SerializableResource
|
||||
.new(@valid_inventory.repository_columns.limit(10),
|
||||
each_serializer: Api::V1::InventoryColumnSerializer,
|
||||
include: :inventory_columns)
|
||||
hide_list_items: true)
|
||||
.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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
before :all do
|
||||
@valid_headers['Content-Type'] = 'application/json'
|
||||
|
|
Loading…
Reference in a new issue