Merge pull request #2679 from urbanrotnik/ur-sci-4741-api-endopints-update

Filter out non active repositories and rows [SCI-4741]
This commit is contained in:
Alex Kriuchykhin 2020-06-24 12:51:13 +02:00 committed by GitHub
commit e1b862a332
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 1 deletions

View file

@ -11,6 +11,7 @@ module Api
def index
inventories = @team.repositories
.active
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: inventories, each_serializer: InventorySerializer

View file

@ -13,6 +13,7 @@ module Api
def index
items =
@inventory.repository_rows
.active
.preload(repository_cells: :repository_column)
.preload(repository_cells: @inventory.cell_preload_includes)
.page(params.dig(:page, :number))

View file

@ -46,6 +46,21 @@ RSpec.describe 'Api::V1::InventoriesController', type: :request do
expect { hash_body = json }.not_to raise_exception
expect(hash_body['errors'][0]).to include('status': 403)
end
context 'when have some archived inventories' do
before do
create(:repository, :archived, name: Faker::Name.unique.name, created_by: @user, team: @teams.first)
end
it 'will ignore them' do
hash_body = nil
get api_v1_team_inventories_path(team_id: @teams.first.id), headers: @valid_headers
expect { hash_body = json }.not_to raise_exception
expect(hash_body['data'].count).to be_eql 2
end
end
end
describe 'GET inventory, #show' do

View file

@ -50,7 +50,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
attributes: {
name: Faker::Name.unique.name
} },
included: [
included: [
{ type: 'inventory_cells',
attributes: {
column_id: text_column.id,
@ -150,6 +150,25 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do
expect { hash_body = json }.not_to raise_exception
expect(hash_body['errors'][0]).to include('status': 404)
end
context 'when have some archived rows' do
before do
create(:repository_row, :archived,
name: Faker::Name.unique.name, created_by: @user, repository: @teams.first.repositories.first)
end
it 'will ignore them' do
hash_body = nil
get api_v1_team_inventory_items_path(
team_id: @teams.first.id,
inventory_id: @teams.first.repositories.first.id
), params: { page: { size: 200 } }, headers: @valid_headers
expect { hash_body = json }.not_to raise_exception
expect(hash_body['data'].count).to be_eql 100
end
end
end
describe 'DELETE inventory_items, #destroy' do