|
253 | 253 | end |
254 | 254 | end |
255 | 255 |
|
256 | | - it 'search for messages' do |
257 | | - text = SecureRandom.uuid |
258 | | - @channel.send_message({ text: text }, 'legolas') |
259 | | - resp = @client.search({ members: { '$in' => ['legolas'] } }, text) |
260 | | - expect(resp['results'].length).to eq(1) |
| 256 | + describe 'search' do |
| 257 | + it 'search for messages' do |
| 258 | + text = SecureRandom.uuid |
| 259 | + @channel.send_message({ text: text }, 'legolas') |
| 260 | + resp = @client.search({ members: { '$in' => ['legolas'] } }, text) |
| 261 | + expect(resp['results'].length).to eq(1) |
| 262 | + end |
| 263 | + it 'search for messages with filter conditions' do |
| 264 | + text = SecureRandom.uuid |
| 265 | + @channel.send_message({ text: text }, 'legolas') |
| 266 | + resp = @client.search({ members: { '$in' => ['legolas'] } }, { text: { '$q': text } }) |
| 267 | + expect(resp['results'].length).to eq(1) |
| 268 | + end |
| 269 | + it 'offset with sort should fail' do |
| 270 | + expect do |
| 271 | + @client.search({ members: { '$in' => ['legolas'] } }, SecureRandom.uuid, sort: [{ created_at: -1 }], offset: 2) |
| 272 | + end.to raise_error(/cannot use offset with next or sort parameters/) |
| 273 | + end |
| 274 | + it 'offset with next should fail' do |
| 275 | + expect do |
| 276 | + @client.search({ members: { '$in' => ['legolas'] } }, SecureRandom.uuid, offset: 2, next: SecureRandom.uuid) |
| 277 | + end.to raise_error(/cannot use offset with next or sort parameters/) |
| 278 | + end |
| 279 | + xit 'search for messages with sorting' do |
| 280 | + text = SecureRandom.uuid |
| 281 | + message_ids = ["0-#{text}", "1-#{text}"] |
| 282 | + @channel.send_message({ id: message_ids[0], text: text }, 'legolas') |
| 283 | + @channel.send_message({ id: message_ids[1], text: text }, 'legolas') |
| 284 | + page1 = @client.search({ members: { '$in' => ['legolas'] } }, text, sort: [{ created_at: -1 }], limit: 1) |
| 285 | + expect(page1['results'].length).to eq |
| 286 | + expect(page1['results'][0]['message']['id']).to eq(message_ids[1]) |
| 287 | + expect(page1['next']).not_to be_empty |
| 288 | + page2 = @client.search({ members: { '$in' => ['legolas'] } }, text, limit: 1, next: page1['next']) |
| 289 | + expect(page2['results'].length).to eq(1) |
| 290 | + expect(page2['results'][0]['message']['id']).to eq(message_ids[0]) |
| 291 | + expect(page2['previous']).not_to be_empty |
| 292 | + end |
261 | 293 | end |
262 | 294 |
|
263 | 295 | describe 'blocklist' do |
|
0 commit comments