2018-12-20 14:14:08 -05:00
|
|
|
/* eslint-disable
|
|
|
|
handle-callback-err,
|
|
|
|
max-len,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2018-12-20 14:14:05 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-08-19 08:00:01 -04:00
|
|
|
const { ObjectId } = require('../../../app/js/mongodb')
|
2018-12-20 14:14:11 -05:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const async = require('async')
|
|
|
|
const crypto = require('crypto')
|
2016-12-14 12:38:14 -05:00
|
|
|
|
2018-12-20 14:14:11 -05:00
|
|
|
const ChatClient = require('./helpers/ChatClient')
|
|
|
|
const ChatApp = require('./helpers/ChatApp')
|
2016-12-14 12:38:14 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('Getting messages', function () {
|
|
|
|
before(function (done) {
|
2018-12-20 14:14:11 -05:00
|
|
|
this.user_id1 = ObjectId().toString()
|
|
|
|
this.user_id2 = ObjectId().toString()
|
|
|
|
this.content1 = 'foo bar'
|
|
|
|
this.content2 = 'hello world'
|
|
|
|
return ChatApp.ensureRunning(done)
|
|
|
|
})
|
2016-12-14 12:38:14 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('globally', function () {
|
|
|
|
before(function (done) {
|
2018-12-20 14:14:11 -05:00
|
|
|
this.project_id = ObjectId().toString()
|
|
|
|
return async.series(
|
|
|
|
[
|
2021-07-13 07:04:48 -04:00
|
|
|
cb =>
|
2018-12-20 14:14:11 -05:00
|
|
|
ChatClient.sendGlobalMessage(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id1,
|
|
|
|
this.content1,
|
|
|
|
cb
|
|
|
|
),
|
2021-07-13 07:04:48 -04:00
|
|
|
cb =>
|
2018-12-20 14:14:11 -05:00
|
|
|
ChatClient.sendGlobalMessage(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id2,
|
|
|
|
this.content2,
|
|
|
|
cb
|
2021-07-13 07:04:48 -04:00
|
|
|
),
|
2018-12-20 14:14:11 -05:00
|
|
|
],
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
2016-12-14 12:38:14 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should contain the messages and populated users when getting the messages', function (done) {
|
2018-12-20 14:14:11 -05:00
|
|
|
return ChatClient.getGlobalMessages(
|
|
|
|
this.project_id,
|
|
|
|
(error, response, messages) => {
|
|
|
|
expect(messages.length).to.equal(2)
|
|
|
|
messages.reverse()
|
|
|
|
expect(messages[0].content).to.equal(this.content1)
|
|
|
|
expect(messages[0].user_id).to.equal(this.user_id1)
|
|
|
|
expect(messages[1].content).to.equal(this.content2)
|
|
|
|
expect(messages[1].user_id).to.equal(this.user_id2)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2016-12-16 11:52:50 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('from all the threads', function () {
|
|
|
|
before(function (done) {
|
2018-12-20 14:14:11 -05:00
|
|
|
this.project_id = ObjectId().toString()
|
|
|
|
this.thread_id1 = ObjectId().toString()
|
|
|
|
this.thread_id2 = ObjectId().toString()
|
|
|
|
return async.series(
|
|
|
|
[
|
2021-07-13 07:04:48 -04:00
|
|
|
cb =>
|
2018-12-20 14:14:11 -05:00
|
|
|
ChatClient.sendMessage(
|
|
|
|
this.project_id,
|
|
|
|
this.thread_id1,
|
|
|
|
this.user_id1,
|
|
|
|
'one',
|
|
|
|
cb
|
|
|
|
),
|
2021-07-13 07:04:48 -04:00
|
|
|
cb =>
|
2018-12-20 14:14:11 -05:00
|
|
|
ChatClient.sendMessage(
|
|
|
|
this.project_id,
|
|
|
|
this.thread_id2,
|
|
|
|
this.user_id2,
|
|
|
|
'two',
|
|
|
|
cb
|
|
|
|
),
|
2021-07-13 07:04:48 -04:00
|
|
|
cb =>
|
2018-12-20 14:14:11 -05:00
|
|
|
ChatClient.sendMessage(
|
|
|
|
this.project_id,
|
|
|
|
this.thread_id1,
|
|
|
|
this.user_id1,
|
|
|
|
'three',
|
|
|
|
cb
|
|
|
|
),
|
2021-07-13 07:04:48 -04:00
|
|
|
cb =>
|
2018-12-20 14:14:11 -05:00
|
|
|
ChatClient.sendMessage(
|
|
|
|
this.project_id,
|
|
|
|
this.thread_id2,
|
|
|
|
this.user_id2,
|
|
|
|
'four',
|
|
|
|
cb
|
2021-07-13 07:04:48 -04:00
|
|
|
),
|
2018-12-20 14:14:11 -05:00
|
|
|
],
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should contain a dictionary of threads with messages with populated users', function (done) {
|
2018-12-20 14:14:11 -05:00
|
|
|
return ChatClient.getThreads(
|
|
|
|
this.project_id,
|
|
|
|
(error, response, threads) => {
|
|
|
|
expect(Object.keys(threads).length).to.equal(2)
|
|
|
|
const thread1 = threads[this.thread_id1]
|
|
|
|
expect(thread1.messages.length).to.equal(2)
|
|
|
|
const thread2 = threads[this.thread_id2]
|
|
|
|
expect(thread2.messages.length).to.equal(2)
|
|
|
|
|
|
|
|
expect(thread1.messages[0].content).to.equal('one')
|
|
|
|
expect(thread1.messages[0].user_id).to.equal(this.user_id1)
|
|
|
|
expect(thread1.messages[1].content).to.equal('three')
|
|
|
|
expect(thread1.messages[1].user_id).to.equal(this.user_id1)
|
|
|
|
|
|
|
|
expect(thread2.messages[0].content).to.equal('two')
|
|
|
|
expect(thread2.messages[0].user_id).to.equal(this.user_id2)
|
|
|
|
expect(thread2.messages[1].content).to.equal('four')
|
|
|
|
expect(thread2.messages[1].user_id).to.equal(this.user_id2)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|