<commit_before>require 'rails_helper'

describe API::V1::Admin::CollectionsController, type: :controller do
  it_behaves_like(:destructible, :collection, as: :editor)
  it_behaves_like(:creatable, Collection, as: :editor) do
    let(:query) {
      Hash[
        title: FFaker::LoremCN.words(2).join,
        description: FFaker::LoremCN.words(2).join
      ]
    }
  end

  it_behaves_like(:updatable, :collection, as: :admin) do
    let(:query) {
      Hash[
        title: '1',
        description: '2',
        banner: '3',
        banner_mobile: '4'
      ]
    }
  end

  describe 'add_members' do
    it 'add members correctly' do
      n = 3
      c = create(:collection)
      posts = create_list(:post, n)

      expect {
        post :add_members,
             params: {
               collection_id: c.id,
               post_ids: posts.pluck(:id),
               **as(:editor),
               format: :json
             }
      }.to change { c.posts.count }.by(n)
      expect(c.reload.posts.pluck(:id)).to include(*posts.pluck(:id))
    end
  end

  describe 'reset_members' do
    it 'reset members correctly' do
      n = 4
      c = create(:collection, :with_posts)
      posts = create_list(:post, n)<commit_msg>fix tests<commit_after>require 'rails_helper'

describe API::V1::Admin::CollectionsController, type: :controller do
  it_behaves_like(:destructible, :collection, as: :editor)
  it_behaves_like(:creatable, Collection, as: :editor) do
    let(:query) {
      Hash[
        title: FFaker::LoremCN.words(2).join,
        description: FFaker::LoremCN.words(2).join
      ]
    }
  end

  it_behaves_like(:updatable, :collection, as: :admin) do
    let(:query) {
      Hash[
        title: '1',
        description: '2'
      ]
    }
  end

  describe 'add_members' do
    it 'add members correctly' do
      n = 3
      c = create(:collection)
      posts = create_list(:post, n)

      expect {
        post :add_members,
             params: {
               collection_id: c.id,
               post_ids: posts.pluck(:id),
               **as(:editor),
               format: :json
             }
      }.to change { c.posts.count }.by(n)
      expect(c.reload.posts.pluck(:id)).to include(*posts.pluck(:id))
    end
  end

  describe 'reset_members' do
    it 'reset members correctly' do
      n = 4
      c = create(:collection, :with_posts)
      posts = create_list(:post, n)
{'fraction_non_alphanumeric': 0.12879102617366014, 'fraction_numerical': 0.006647278770253427, 'mean_word_length': 2.1767810026385224, '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': '6959124', 'n_tokens_mistral': 802, 'n_tokens_neox': 770, 'n_words': 174}