Commit d517169d by Clinton Blackburn

Updated Query spec

-Using factories to generate data
- Using single quotes
parent a7aed5a1
require 'spec_helper' require 'spec_helper'
require 'faker'
describe "app" do
before (:each) { set_api_key_header } describe 'app' do
before(:each) { set_api_key_header }
let(:body) { Faker::Lorem.word }
let(:author) { create_test_user(1) } describe 'GET /api/v1/search/threads' do
describe "thread search" do
describe "GET /api/v1/search/threads" do
it "returns thread with query match" do
commentable = Commentable.new("question_1")
random_string = (0...8).map{ ('a'..'z').to_a[rand(26)] }.join shared_examples_for 'a search endpoint' do
subject do
thread = CommentThread.new(title: "Test title", body: random_string, course_id: "1", commentable_id: commentable.id) refresh_es_index
thread.thread_type = :discussion get '/api/v1/search/threads', text: body
thread.author = author end
thread.save!
sleep 3 let(:matched_thread) { parse(subject.body)['collection'].select { |t| t['id'] == thread.id.to_s }.first }
get "/api/v1/search/threads", text: random_string it { should be_ok }
last_response.should be_ok
threads = parse(last_response.body)['collection']
check_thread_result_json(nil, thread, threads.select{|t| t["id"] == thread.id.to_s}.first)
end
it 'returns thread with query match' do
expect(matched_thread).to_not be_nil
check_thread_result_json(nil, thread, matched_thread)
end end
end end
describe "comment search" do context 'when searching on thread content' do
describe "GET /api/v1/search/threads" do let!(:thread) { create(:comment_thread, body: body) }
it "returns thread with comment query match" do
commentable = Commentable.new("question_1")
random_string = (0...8).map{ ('a'..'z').to_a[rand(26)] }.join
thread = CommentThread.new(title: "Test title", body: "elephant otter", course_id: "1", commentable_id: commentable.id)
thread.thread_type = :discussion
thread.author = author
thread.save!
sleep 3 it_behaves_like 'a search endpoint'
end
comment = Comment.new(body: random_string, course_id: "1")
comment.commentable_id = commentable.id
comment.author = author
comment.comment_thread = thread
comment.save!
sleep 1
get "/api/v1/search/threads", text: random_string context 'when searching on comment content' do
last_response.should be_ok let!(:thread) do
threads = parse(last_response.body)['collection'] comment = create(:comment, body: body)
check_thread_result_json(nil, thread, threads.select{|t| t["id"] == thread.id.to_s}.first) thread = comment.comment_thread
end end
it_behaves_like 'a search endpoint'
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment