Skip to content

Commit 2fbf49e

Browse files
committed
Refactor test
1 parent 127e93e commit 2fbf49e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

spec/client_spec.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -962,28 +962,33 @@ def loop_times(times)
962962
end
963963

964964
describe '#query_threads' do
965-
before(:each) do
965+
before(:all) do
966+
# Create a dedicated random user for this block
967+
@thread_test_user = { id: SecureRandom.uuid }
968+
@client.upsert_users([@thread_test_user])
969+
966970
# Create a channel and send a message to create a thread
967971
@thread_channel = @client.channel('messaging', channel_id: SecureRandom.uuid, data: { test: true })
968-
@thread_channel.create(@random_user[:id])
972+
@thread_channel.create(@thread_test_user[:id])
969973

970974
# Send a message to create a thread
971-
@thread_message = @thread_channel.send_message({ text: 'Thread parent message' }, @random_user[:id])
975+
@thread_message = @thread_channel.send_message({ text: 'Thread parent message' }, @thread_test_user[:id])
972976

973977
# Send a reply to create a thread
974-
@thread_channel.send_message({ text: 'Thread reply', parent_id: @thread_message['message']['id'] }, @random_user[:id])
978+
@thread_channel.send_message({ text: 'Thread reply', parent_id: @thread_message['message']['id'] }, @thread_test_user[:id])
975979
end
976980

977-
after(:each) do
981+
after(:all) do
978982
@thread_channel.delete
983+
@client.delete_user(@thread_test_user[:id])
979984
end
980985

981986
it 'queries threads with filter' do
982987
filter = {
983-
'created_by_user_id' => { '$eq' => @random_user[:id] }
988+
'created_by_user_id' => { '$eq' => @thread_test_user[:id] }
984989
}
985990

986-
response = @client.query_threads(filter, user_id: @random_user[:id])
991+
response = @client.query_threads(filter, user_id: @thread_test_user[:id])
987992

988993
expect(response).to include 'threads'
989994
expect(response['threads'].length).to be >= 1
@@ -994,22 +999,22 @@ def loop_times(times)
994999
'created_at' => -1
9951000
}
9961001

997-
response = @client.query_threads({}, sort: sort, user_id: @random_user[:id])
1002+
response = @client.query_threads({}, sort: sort, user_id: @thread_test_user[:id])
9981003

9991004
expect(response).to include 'threads'
10001005
expect(response['threads'].length).to be >= 1
10011006
end
10021007

10031008
it 'queries threads with both filter and sort' do
10041009
filter = {
1005-
'created_by_user_id' => { '$eq' => @random_user[:id] }
1010+
'created_by_user_id' => { '$eq' => @thread_test_user[:id] }
10061011
}
10071012

10081013
sort = {
10091014
'created_at' => -1
10101015
}
10111016

1012-
response = @client.query_threads(filter, sort: sort, user_id: @random_user[:id])
1017+
response = @client.query_threads(filter, sort: sort, user_id: @thread_test_user[:id])
10131018

10141019
expect(response).to include 'threads'
10151020
expect(response['threads'].length).to be >= 1

0 commit comments

Comments
 (0)