feat: Limit the number of custom filters per user (#7101)

This commit is contained in:
Tejaswini Chile
2023-05-22 18:03:15 +05:30
committed by GitHub
parent 68dedc37ba
commit d481b9fbcf
5 changed files with 31 additions and 1 deletions

View File

@@ -66,6 +66,8 @@ RSpec.describe 'Custom Filters API', type: :request do
context 'when it is an authenticated user' do
let(:user) { create(:user, account: account) }
let(:new_account) { create(:account) }
let(:new_user) { create(:user, account: new_account) }
it 'creates the filter' do
expect do
@@ -77,6 +79,23 @@ RSpec.describe 'Custom Filters API', type: :request do
json_response = response.parsed_body
expect(json_response['name']).to eq 'vip-customers'
end
it 'gives the error for 51st record' do
CustomFilter::MAX_FILTER_PER_USER.times do
create(:custom_filter, user: user, account: account)
end
expect do
post "/api/v1/accounts/#{account.id}/custom_filters", headers: user.create_new_auth_token,
params: payload
end.not_to change(CustomFilter, :count)
expect(response).to have_http_status(:unprocessable_entity)
json_response = response.parsed_body
expect(json_response['message']).to include(
'Account Limit reached. The maximum number of allowed custom filters for a user per account is 50.'
)
end
end
end