~cytrogen/masto-fe

3c41547f491e08a1781682a539de2b6e4d8a38a7 — Daniel M Brasil 2 years ago 8b1bfae
Add test coverage for `Mastodon::CLI::Accounts#backup` (#25163)

1 files changed, 38 insertions(+), 0 deletions(-)

M spec/lib/mastodon/cli/accounts_spec.rb
M spec/lib/mastodon/cli/accounts_spec.rb => spec/lib/mastodon/cli/accounts_spec.rb +38 -0
@@ 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