From 3c41547f491e08a1781682a539de2b6e4d8a38a7 Mon Sep 17 00:00:00 2001 From: Daniel M Brasil Date: Wed, 31 May 2023 10:32:37 -0300 Subject: [PATCH] Add test coverage for `Mastodon::CLI::Accounts#backup` (#25163) --- spec/lib/mastodon/cli/accounts_spec.rb | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spec/lib/mastodon/cli/accounts_spec.rb b/spec/lib/mastodon/cli/accounts_spec.rb index a7fcc281fd..8eee6f5381 100644 --- a/spec/lib/mastodon/cli/accounts_spec.rb +++ b/spec/lib/mastodon/cli/accounts_spec.rb @@ -624,4 +624,42 @@ describe Mastodon::CLI::Accounts do end end end + + describe '#backup' do + context 'when the given username is not found' do + let(:arguments) { ['non_existent_username'] } + + it 'exits with an error message indicating that there is no such account' do + expect { cli.invoke(:backup, arguments) }.to output( + a_string_including('No user with such username') + ).to_stdout + .and raise_error(SystemExit) + end + end + + context 'when the given username is found' do + let(:account) { Fabricate(:account) } + let(:user) { account.user } + let(:arguments) { [account.username] } + + it 'creates a new backup for the specified user' do + expect { cli.invoke(:backup, arguments) }.to change { user.backups.count }.by(1) + end + + it 'creates a backup job' do + allow(BackupWorker).to receive(:perform_async) + + cli.invoke(:backup, arguments) + latest_backup = user.backups.last + + expect(BackupWorker).to have_received(:perform_async).with(latest_backup.id).once + end + + it 'displays a successful message' do + expect { cli.invoke(:backup, arguments) }.to output( + a_string_including('OK') + ).to_stdout + end + end + end end