2023-05-24 19:55:40 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'mastodon/cli/feeds'
|
|
|
|
|
|
|
|
describe Mastodon::CLI::Feeds do
|
2023-12-08 00:49:14 +11:00
|
|
|
subject { cli.invoke(action, arguments, options) }
|
|
|
|
|
2023-06-11 02:37:36 +10:00
|
|
|
let(:cli) { described_class.new }
|
2023-12-08 00:49:14 +11:00
|
|
|
let(:arguments) { [] }
|
|
|
|
let(:options) { {} }
|
2023-06-11 02:37:36 +10:00
|
|
|
|
2023-12-01 23:00:34 +11:00
|
|
|
it_behaves_like 'CLI Command'
|
2023-06-11 02:37:36 +10:00
|
|
|
|
|
|
|
describe '#build' do
|
2023-12-08 00:49:14 +11:00
|
|
|
let(:action) { :build }
|
|
|
|
|
2023-06-11 02:37:36 +10:00
|
|
|
before { Fabricate(:account) }
|
|
|
|
|
|
|
|
context 'with --all option' do
|
|
|
|
let(:options) { { all: true } }
|
|
|
|
|
|
|
|
it 'regenerates feeds for all accounts' do
|
2023-12-08 00:49:14 +11:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Regenerated feeds')
|
2023-06-11 02:37:36 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a username' do
|
|
|
|
before { Fabricate(:account, username: 'alice') }
|
|
|
|
|
|
|
|
let(:arguments) { ['alice'] }
|
|
|
|
|
|
|
|
it 'regenerates feeds for the account' do
|
2023-12-08 00:49:14 +11:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('OK')
|
2023-06-11 02:37:36 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid username' do
|
|
|
|
let(:arguments) { ['invalid-username'] }
|
|
|
|
|
|
|
|
it 'displays an error and exits' do
|
2023-12-08 00:49:14 +11:00
|
|
|
expect { subject }
|
2024-01-26 19:53:44 +11:00
|
|
|
.to raise_error(Thor::Error, 'No such account')
|
2023-06-11 02:37:36 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#clear' do
|
2023-12-08 00:49:14 +11:00
|
|
|
let(:action) { :clear }
|
|
|
|
|
2023-06-11 02:37:36 +10:00
|
|
|
before do
|
|
|
|
allow(redis).to receive(:del).with(key_namespace)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'clears the redis `feed:*` namespace' do
|
2023-12-08 00:49:14 +11:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('OK')
|
2023-06-11 02:37:36 +10:00
|
|
|
|
|
|
|
expect(redis).to have_received(:del).with(key_namespace).once
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_namespace
|
|
|
|
redis.keys('feed:*')
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 19:55:40 +10:00
|
|
|
end
|