mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-11 22:56:41 +08:00
close SCI-2702; unit tests for create inventory
This commit is contained in:
parent
2ff8500758
commit
43a3c1c06b
1 changed files with 93 additions and 0 deletions
|
|
@ -92,4 +92,97 @@ RSpec.describe "Api::V1::InventoriesController", type: :request do
|
||||||
expect(hash_body).to match({})
|
expect(hash_body).to match({})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'POST inventory, #create' do
|
||||||
|
before :all do
|
||||||
|
@valid_headers['Content-Type'] = 'application/json'
|
||||||
|
@request_body = { data:
|
||||||
|
{ type: 'inventories',
|
||||||
|
attributes: {
|
||||||
|
name: Faker::Name.unique.name
|
||||||
|
} } }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'Response with correct inventory' do
|
||||||
|
hash_body = nil
|
||||||
|
post api_v1_team_inventories_path(
|
||||||
|
team_id: @teams.first.id
|
||||||
|
), params: @request_body.to_json, headers: @valid_headers
|
||||||
|
expect(response).to have_http_status 201
|
||||||
|
expect { hash_body = json }.not_to raise_exception
|
||||||
|
expect(hash_body[:data]).to match(
|
||||||
|
ActiveModelSerializers::SerializableResource
|
||||||
|
.new(RepositoryColumn.last,
|
||||||
|
serializer: Api::V1::InventoryColumnSerializer,
|
||||||
|
include: :inventory_cells)
|
||||||
|
.as_json[:data]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'When invalid request, user in not member of the team' do
|
||||||
|
hash_body = nil
|
||||||
|
post api_v1_team_inventories_path(
|
||||||
|
team_id: @teams.second.id
|
||||||
|
), params: @request_body.to_json, headers: @valid_headers
|
||||||
|
expect(response).to have_http_status 403
|
||||||
|
expect { hash_body = json }.not_to raise_exception
|
||||||
|
expect(hash_body).to match({})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'When invalid request, non-existent team' do
|
||||||
|
hash_body = nil
|
||||||
|
post api_v1_team_inventories_path(
|
||||||
|
team_id: 123
|
||||||
|
), params: @request_body.to_json, headers: @valid_headers
|
||||||
|
expect(response).to have_http_status 404
|
||||||
|
expect { hash_body = json }.not_to raise_exception
|
||||||
|
expect(hash_body).to match({})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'When invalid request, incorrect type' do
|
||||||
|
invalid_request_body = @request_body.deep_dup
|
||||||
|
invalid_request_body[:data][:type] = 'repository_rows'
|
||||||
|
hash_body = nil
|
||||||
|
post api_v1_team_inventories_path(
|
||||||
|
team_id: @teams.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
|
||||||
|
|
||||||
|
it 'When invalid request, missing data param' do
|
||||||
|
hash_body = nil
|
||||||
|
post api_v1_team_inventories_path(
|
||||||
|
team_id: @teams.first.id
|
||||||
|
), params: {}, headers: @valid_headers
|
||||||
|
expect(response).to have_http_status(400)
|
||||||
|
expect { hash_body = json }.to_not raise_exception
|
||||||
|
expect(hash_body).to match({})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'When invalid request, missing attributes param' do
|
||||||
|
invalid_request_body = @request_body.deep_dup
|
||||||
|
invalid_request_body[:data].delete(:attributes)
|
||||||
|
hash_body = nil
|
||||||
|
post api_v1_team_inventories_path(
|
||||||
|
team_id: @teams.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
|
||||||
|
|
||||||
|
it 'When invalid request, missing type param' do
|
||||||
|
invalid_request_body = @request_body.deep_dup
|
||||||
|
invalid_request_body[:data].delete(:type)
|
||||||
|
hash_body = nil
|
||||||
|
post api_v1_team_inventories_path(
|
||||||
|
team_id: @teams.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…
Add table
Reference in a new issue