mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Fix the inventory_columns_controller#create action
Based on unit tests, fix the create inventory columns endpoint to work as intended. Also add another unit test case.
This commit is contained in:
parent
436876ad76
commit
0b68a670c2
2 changed files with 23 additions and 4 deletions
|
@ -6,7 +6,7 @@ module Api
|
|||
before_action :load_team
|
||||
before_action :load_inventory
|
||||
before_action :load_inventory_column, only: %i(show update destroy)
|
||||
before_action :check_manage_permissions, only: %i(create update destroy)
|
||||
before_action :check_manage_permissions, only: %i(update destroy)
|
||||
|
||||
def index
|
||||
columns = @inventory.repository_columns
|
||||
|
@ -19,7 +19,7 @@ module Api
|
|||
|
||||
def create
|
||||
inventory_column =
|
||||
@inventory.inventory_columns.create!(inventory_column_params)
|
||||
@inventory.repository_columns.create!(inventory_column_params)
|
||||
render jsonapi: inventory_column,
|
||||
serializer: InventoryColumnSerializer,
|
||||
status: :created
|
||||
|
@ -72,7 +72,9 @@ module Api
|
|||
'Wrong object type within parameters'
|
||||
end
|
||||
params.require(:data).require(:attributes)
|
||||
params.permit(data: { attributes: %i(name) })[:data]
|
||||
params
|
||||
.permit(data: { attributes: %i(name data_type) })[:data]
|
||||
.merge(created_by: @current_user)
|
||||
end
|
||||
|
||||
def update_inventory_column_params
|
||||
|
|
|
@ -93,7 +93,9 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do
|
|||
@request_body = { data:
|
||||
{ type: 'inventory_columns',
|
||||
attributes: {
|
||||
name: Faker::Name.unique.name
|
||||
name: Faker::Name.unique.name,
|
||||
data_type:
|
||||
RepositoryColumn.data_types.values.first
|
||||
} } }
|
||||
end
|
||||
|
||||
|
@ -196,5 +198,20 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do
|
|||
expect { hash_body = json }.to_not raise_exception
|
||||
expect(hash_body).to match({})
|
||||
end
|
||||
|
||||
it 'When invalid request, missing attributes values' do
|
||||
hash_body = nil
|
||||
[:name, :data_type].each do |attr|
|
||||
invalid_request_body = @request_body.deep_dup
|
||||
invalid_request_body[:data][:attributes].delete(attr)
|
||||
post api_v1_team_inventory_columns_path(
|
||||
team_id: @teams.first.id,
|
||||
inventory_id: @teams.first.repositories.first.id
|
||||
), params: invalid_request_body.to_json, headers: @valid_headers
|
||||
expect(response).to have_http_status(400)
|
||||
expect { hash_body = json }.to_not raise_exception
|
||||
expect(hash_body).to match({})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue