require 'rails_helper'

RSpec.describe 'Wiki body search', type: :request do
  let!(:user) { create_member_user! }

  it 'searches wiki pages by body text' do
    pending '#336 で対応予定'

    Wiki::Commit.create_content!(
        tag_name: TagName.create!(name: 'wiki_body_search_hit'),
        body: 'unique body keyword for wiki search',
        created_by_user: user,
        message: 'init')

    Wiki::Commit.create_content!(
        tag_name: TagName.create!(name: 'wiki_body_search_miss'),
        body: 'ordinary body',
        created_by_user: user,
        message: 'init')

    get '/wiki/search', params: { body: 'unique body keyword' }

    expect(response).to have_http_status(:ok)
    expect(json.map { |page| page['title'] }).to include('wiki_body_search_hit')
    expect(json.map { |page| page['title'] }).not_to include('wiki_body_search_miss')
  end
end
