Skip to content

Commit 6e5da01

Browse files
randomized the user creation
1 parent ad768d8 commit 6e5da01

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

spec/client_spec.rb

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@ def loop_times(times)
2626
@created_users = []
2727

2828
@fellowship_of_the_ring = [
29-
{ id: 'frodo-baggins', name: 'Frodo Baggins', race: 'Hobbit', age: 50 },
30-
{ id: 'sam-gamgee', name: 'Samwise Gamgee', race: 'Hobbit', age: 38 },
31-
{ id: 'gandalf', name: 'Gandalf the Grey', race: 'Istari' },
32-
{ id: 'legolas', name: 'Legolas', race: 'Elf', age: 500 }
29+
{ id: SecureRandom.uuid, name: 'Frodo Baggins', race: 'Hobbit', age: 50 },
30+
{ id: SecureRandom.uuid, name: 'Samwise Gamgee', race: 'Hobbit', age: 38 },
31+
{ id: SecureRandom.uuid, name: 'Gandalf the Grey', race: 'Istari' },
32+
{ id: SecureRandom.uuid, name: 'Legolas', race: 'Elf', age: 500 }
3333
]
34+
35+
@legolas = @fellowship_of_the_ring[3][:id]
36+
@gandalf = @fellowship_of_the_ring[2][:id]
37+
@frodo = @fellowship_of_the_ring[0][:id]
38+
@sam = @fellowship_of_the_ring[1][:id]
39+
3440
@client.upsert_users(@fellowship_of_the_ring)
3541

3642
# Create a new channel for chat max length for channel_id is 64 characters
3743
channel_id = "fellowship-of-the-ring-chat-#{SecureRandom.alphanumeric(20)}"
3844

3945
@channel = @client.channel('team', channel_id: channel_id,
4046
data: { members: @fellowship_of_the_ring.map { |fellow| fellow[:id] } })
41-
@channel.create('gandalf')
47+
@channel.create(@gandalf)
4248
end
4349

4450
before(:each) do
@@ -226,7 +232,7 @@ def loop_times(times)
226232
end
227233

228234
it 'exports a user' do
229-
response = @client.export_user('gandalf')
235+
response = @client.export_user(@gandalf)
230236
expect(response).to include 'user'
231237
expect(response['user']['name']).to eq('Gandalf the Grey')
232238
end
@@ -452,7 +458,7 @@ def loop_times(times)
452458
end
453459

454460
it 'queries channels' do
455-
response = @client.query_channels({ 'members' => { '$in' => ['legolas'] } }, sort: { 'id' => 1 })
461+
response = @client.query_channels({ 'members' => { '$in' => [@legolas] } }, sort: { 'id' => 1 })
456462
expect(response['channels'].length).to eq 1
457463
expect(response['channels'][0]['channel']['id']).to eq @channel.id
458464
expect(response['channels'][0]['members'].length).to eq 4
@@ -511,41 +517,41 @@ def loop_times(times)
511517
describe 'search' do
512518
it 'search for messages' do
513519
text = SecureRandom.uuid
514-
@channel.send_message({ text: text }, 'legolas')
515-
resp = @client.search({ members: { '$in' => ['legolas'] } }, text)
520+
@channel.send_message({ text: text }, @fellowship_of_the_ring[2][:id])
521+
resp = @client.search({ members: { '$in' => [@fellowship_of_the_ring[2][:id]] } }, text)
516522
p resp
517523
expect(resp['results'].length).to eq(1)
518524
end
519525

520526
it 'search for messages with filter conditions' do
521527
text = SecureRandom.uuid
522-
@channel.send_message({ text: text }, 'legolas')
523-
resp = @client.search({ members: { '$in' => ['legolas'] } }, { text: { '$q': text } })
528+
@channel.send_message({ text: text }, @legolas)
529+
resp = @client.search({ members: { '$in' => [@legolas] } }, { text: { '$q': text } })
524530
expect(resp['results'].length).to eq(1)
525531
end
526532

527533
it 'offset with sort should fail' do
528534
expect do
529-
@client.search({ members: { '$in' => ['legolas'] } }, SecureRandom.uuid, sort: { created_at: -1 }, offset: 2)
535+
@client.search({ members: { '$in' => [@legolas] } }, SecureRandom.uuid, sort: { created_at: -1 }, offset: 2)
530536
end.to raise_error(/cannot use offset with next or sort parameters/)
531537
end
532538

533539
it 'offset with next should fail' do
534540
expect do
535-
@client.search({ members: { '$in' => ['legolas'] } }, SecureRandom.uuid, offset: 2, next: SecureRandom.uuid)
541+
@client.search({ members: { '$in' => [@legolas] } }, SecureRandom.uuid, offset: 2, next: SecureRandom.uuid)
536542
end.to raise_error(/cannot use offset with next or sort parameters/)
537543
end
538544

539545
xit 'search for messages with sorting' do
540546
text = SecureRandom.uuid
541547
message_ids = ["0-#{text}", "1-#{text}"]
542-
@channel.send_message({ id: message_ids[0], text: text }, 'legolas')
543-
@channel.send_message({ id: message_ids[1], text: text }, 'legolas')
544-
page1 = @client.search({ members: { '$in' => ['legolas'] } }, text, sort: [{ created_at: -1 }], limit: 1)
548+
@channel.send_message({ id: message_ids[0], text: text }, @legolas)
549+
@channel.send_message({ id: message_ids[1], text: text }, @legolas)
550+
page1 = @client.search({ members: { '$in' => [@legolas] } }, text, sort: [{ created_at: -1 }], limit: 1)
545551
expect(page1['results'].length).to eq
546552
expect(page1['results'][0]['message']['id']).to eq(message_ids[1])
547553
expect(page1['next']).not_to be_empty
548-
page2 = @client.search({ members: { '$in' => ['legolas'] } }, text, limit: 1, next: page1['next'])
554+
page2 = @client.search({ members: { '$in' => [@legolas] } }, text, limit: 1, next: page1['next'])
549555
expect(page2['results'].length).to eq(1)
550556
expect(page2['results'][0]['message']['id']).to eq(message_ids[0])
551557
expect(page2['previous']).not_to be_empty
@@ -837,7 +843,7 @@ def loop_times(times)
837843

838844
it 'check push notification test are working' do
839845
message_id = SecureRandom.uuid
840-
@channel.send_message({ id: message_id, text: SecureRandom.uuid }, 'legolas')
846+
@channel.send_message({ id: message_id, text: SecureRandom.uuid }, @legolas)
841847
resp = @client.check_push({ message_id: message_id, skip_devices: true, user_id: @random_user[:id] })
842848
expect(resp['rendered_message']).not_to be_empty
843849
end
@@ -867,7 +873,7 @@ def loop_times(times)
867873

868874
it 'can translate a message' do
869875
message_id = SecureRandom.uuid
870-
@channel.send_message({ id: message_id, text: SecureRandom.uuid }, 'legolas')
876+
@channel.send_message({ id: message_id, text: SecureRandom.uuid }, @legolas)
871877
response = @client.translate_message(message_id, 'hu')
872878
expect(response['message']).not_to be_empty
873879
end
@@ -1129,10 +1135,6 @@ def loop_times(times)
11291135
@message_id = @message['message']['id']
11301136
end
11311137

1132-
after(:all) do
1133-
@channel.update_partial({ config_overrides: { user_message_reminders: false } })
1134-
end
1135-
11361138
describe 'create_reminder' do
11371139
it 'create reminder' do
11381140
remind_at = DateTime.now + 1

spec/moderation_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def loop_times(times)
3131
{ id: SecureRandom.uuid, name: 'Gandalf the Grey', race: 'Istari' },
3232
{ id: SecureRandom.uuid, name: 'Legolas', race: 'Elf', age: 500 }
3333
]
34+
@gandalf = @fellowship_of_the_ring[2]
35+
@frodo = @fellowship_of_the_ring[0]
36+
@sam = @fellowship_of_the_ring[1]
37+
@legolas = @fellowship_of_the_ring[3]
38+
3439
@client.upsert_users(@fellowship_of_the_ring)
3540

3641
# Create a new channel for moderation

0 commit comments

Comments
 (0)