<commit_before>require 'pavlov_helper'
require_relative '../../../../app/interactors/interactors/topics/unfavourite'

describe Interactors::Topics::Unfavourite do
  include PavlovSupport

  describe '#authorized?' do
    before do
      described_class.any_instance.stub(validate: true)
    end

    it 'throws when no current_user' do
      expect { described_class.new(mock, mock).call }.
        to raise_error Pavlov::AccessDenied,'Unauthorized'
    end

    it 'throws when cannot edit favourites' do
      user = stub
      current_user = stub
      ability = stub
      ability.stub(:can?).with(:edit_favourites, user).and_return(false)
      pavlov_options = { current_user: current_user, ability: ability }

      Pavlov.stub(:old_query).
        with(:user_by_username, 'username', pavlov_options).
        and_return(user)

      expect { described_class.new 'username', 'slug_title', pavlov_options }.
        to raise_error Pavlov::AccessDenied, 'Unauthorized'
    end
  end

  describe '#call' do
    it 'calls a command to unfavourite topic' do
      user = mock(graph_user_id: mock)
      user_name = 'username'
      slug_title = 'slug-title'
<commit_msg>No need for .call<commit_after>require 'pavlov_helper'
require_relative '../../../../app/interactors/interactors/topics/unfavourite'

describe Interactors::Topics::Unfavourite do
  include PavlovSupport

  describe '#authorized?' do
    before do
      described_class.any_instance.stub(validate: true)
    end

    it 'throws when no current_user' do
      expect { described_class.new(mock, mock) }
        .to raise_error Pavlov::AccessDenied,'Unauthorized'
    end

    it 'throws when cannot edit favourites' do
      user = stub
      current_user = stub
      ability = stub
      ability.stub(:can?).with(:edit_favourites, user).and_return(false)
      pavlov_options = { current_user: current_user, ability: ability }

      Pavlov.stub(:old_query).
        with(:user_by_username, 'username', pavlov_options).
        and_return(user)

      expect { described_class.new 'username', 'slug_title', pavlov_options }.
        to raise_error Pavlov::AccessDenied, 'Unauthorized'
    end
  end

  describe '#call' do
    it 'calls a command to unfavourite topic' do
      user = mock(graph_user_id: mock)
      user_name = 'username'
      slug_title = 'slug-title'

{'fraction_non_alphanumeric': 0.10328638497652583, 'fraction_numerical': 0.0, 'mean_word_length': 3.246376811594203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5107039', 'n_tokens_mistral': 738, 'n_tokens_neox': 719, 'n_words': 173}