Add custom filter tests of kmyblue original params
This commit is contained in:
parent
5e687f4d93
commit
18583e5275
5 changed files with 129 additions and 5 deletions
|
@ -47,7 +47,16 @@ RSpec.describe 'Filters' do
|
|||
it_behaves_like 'unauthorized for invalid token'
|
||||
|
||||
context 'with valid params' do
|
||||
let(:params) { { title: 'magic', context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic', whole_word: true] } }
|
||||
let(:params) do
|
||||
{
|
||||
title: 'magic',
|
||||
context: %w(home),
|
||||
filter_action: 'hide',
|
||||
exclude_follows: true,
|
||||
exclude_localusers: true,
|
||||
keywords_attributes: [keyword: 'magic', whole_word: true],
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
subject
|
||||
|
@ -64,6 +73,8 @@ RSpec.describe 'Filters' do
|
|||
expect(json[:filter_action]).to eq 'hide'
|
||||
expect(json[:context]).to eq ['home']
|
||||
expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to eq [{ keyword: 'magic', whole_word: true }]
|
||||
expect(json[:exclude_follows]).to be true
|
||||
expect(json[:exclude_localusers]).to be true
|
||||
end
|
||||
|
||||
it 'creates a filter', :aggregate_failures do
|
||||
|
@ -74,13 +85,15 @@ RSpec.describe 'Filters' do
|
|||
expect(filter).to be_present
|
||||
expect(filter.keywords.pluck(:keyword)).to eq ['magic']
|
||||
expect(filter.context).to eq %w(home)
|
||||
expect(filter.exclude_follows).to be true
|
||||
expect(filter.exclude_localusers).to be true
|
||||
expect(filter.irreversible?).to be true
|
||||
expect(filter.expires_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the required title param is missing' do
|
||||
let(:params) { { context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
|
||||
let(:params) { { context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic'], exclude_follows: false, exclude_localusers: false } }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
subject
|
||||
|
@ -90,7 +103,7 @@ RSpec.describe 'Filters' do
|
|||
end
|
||||
|
||||
context 'when the required context param is missing' do
|
||||
let(:params) { { title: 'magic', filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
|
||||
let(:params) { { title: 'magic', filter_action: 'hide', keywords_attributes: [keyword: 'magic'], exclude_follows: false, exclude_localusers: false } }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
subject
|
||||
|
@ -99,8 +112,18 @@ RSpec.describe 'Filters' do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the required kmyblue original params are missing' do
|
||||
let(:params) { { title: 'magic', context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
|
||||
|
||||
it 'returns http success' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the given context value is invalid' do
|
||||
let(:params) { { title: 'magic', context: %w(shaolin), filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
|
||||
let(:params) { { title: 'magic', context: %w(shaolin), filter_action: 'hide', keywords_attributes: [keyword: 'magic'], exclude_follows: false, exclude_localusers: false } }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
subject
|
||||
|
@ -152,7 +175,7 @@ RSpec.describe 'Filters' do
|
|||
|
||||
context 'when updating filter parameters' do
|
||||
context 'with valid params' do
|
||||
let(:params) { { title: 'updated', context: %w(home public) } }
|
||||
let(:params) { { title: 'updated', context: %w(home public), exclude_follows: true, exclude_localusers: true } }
|
||||
|
||||
it 'updates the filter successfully', :aggregate_failures do
|
||||
subject
|
||||
|
@ -162,6 +185,8 @@ RSpec.describe 'Filters' do
|
|||
expect(response).to have_http_status(200)
|
||||
expect(filter.title).to eq 'updated'
|
||||
expect(filter.reload.context).to eq %w(home public)
|
||||
expect(filter.exclude_follows).to be true
|
||||
expect(filter.exclude_localusers).to be true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue