2016-12-14 12:38:14 -05:00
|
|
|
{ObjectId} = require "../../../app/js/mongojs"
|
|
|
|
expect = require("chai").expect
|
|
|
|
async = require "async"
|
|
|
|
crypto = require "crypto"
|
|
|
|
|
|
|
|
ChatClient = require "./helpers/ChatClient"
|
2018-01-29 07:01:26 -05:00
|
|
|
ChatApp = require "./helpers/ChatApp"
|
2016-12-14 12:38:14 -05:00
|
|
|
|
|
|
|
describe "Getting messages", ->
|
2018-01-29 07:01:26 -05:00
|
|
|
before (done) ->
|
2016-12-14 12:38:14 -05:00
|
|
|
@user_id1 = ObjectId().toString()
|
|
|
|
@user_id2 = ObjectId().toString()
|
|
|
|
@content1 = "foo bar"
|
|
|
|
@content2 = "hello world"
|
2018-01-29 07:01:26 -05:00
|
|
|
ChatApp.ensureRunning done
|
2016-12-14 12:38:14 -05:00
|
|
|
|
2016-12-16 11:52:50 -05:00
|
|
|
describe "globally", ->
|
2016-12-14 12:38:14 -05:00
|
|
|
before (done) ->
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
async.series [
|
2016-12-16 11:52:50 -05:00
|
|
|
(cb) => ChatClient.sendGlobalMessage @project_id, @user_id1, @content1, cb
|
|
|
|
(cb) => ChatClient.sendGlobalMessage @project_id, @user_id2, @content2, cb
|
2016-12-14 12:38:14 -05:00
|
|
|
], done
|
|
|
|
|
|
|
|
it "should contain the messages and populated users when getting the messages", (done) ->
|
2016-12-16 11:52:50 -05:00
|
|
|
ChatClient.getGlobalMessages @project_id, (error, response, messages) =>
|
2016-12-14 12:38:14 -05:00
|
|
|
expect(messages.length).to.equal 2
|
|
|
|
messages.reverse()
|
|
|
|
expect(messages[0].content).to.equal @content1
|
2017-01-06 08:14:47 -05:00
|
|
|
expect(messages[0].user_id).to.equal @user_id1
|
2016-12-14 12:38:14 -05:00
|
|
|
expect(messages[1].content).to.equal @content2
|
2017-01-06 08:14:47 -05:00
|
|
|
expect(messages[1].user_id).to.equal @user_id2
|
2016-12-14 12:38:14 -05:00
|
|
|
done()
|
|
|
|
|
2016-12-16 11:52:50 -05:00
|
|
|
describe "from all the threads", ->
|
|
|
|
before (done) ->
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@thread_id1 = ObjectId().toString()
|
|
|
|
@thread_id2 = ObjectId().toString()
|
|
|
|
async.series [
|
|
|
|
(cb) => ChatClient.sendMessage @project_id, @thread_id1, @user_id1, "one", cb
|
|
|
|
(cb) => ChatClient.sendMessage @project_id, @thread_id2, @user_id2, "two", cb
|
|
|
|
(cb) => ChatClient.sendMessage @project_id, @thread_id1, @user_id1, "three", cb
|
|
|
|
(cb) => ChatClient.sendMessage @project_id, @thread_id2, @user_id2, "four", cb
|
|
|
|
], done
|
|
|
|
|
|
|
|
it "should contain a dictionary of threads with messages with populated users", (done) ->
|
|
|
|
ChatClient.getThreads @project_id, (error, response, threads) =>
|
|
|
|
expect(Object.keys(threads).length).to.equal 2
|
|
|
|
thread1 = threads[@thread_id1]
|
2017-01-04 08:51:08 -05:00
|
|
|
expect(thread1.messages.length).to.equal 2
|
2016-12-16 11:52:50 -05:00
|
|
|
thread2 = threads[@thread_id2]
|
2017-01-04 08:51:08 -05:00
|
|
|
expect(thread2.messages.length).to.equal 2
|
2016-12-16 11:52:50 -05:00
|
|
|
|
2017-01-04 08:51:08 -05:00
|
|
|
expect(thread1.messages[0].content).to.equal "one"
|
2017-01-06 08:14:47 -05:00
|
|
|
expect(thread1.messages[0].user_id).to.equal @user_id1
|
2017-01-04 08:51:08 -05:00
|
|
|
expect(thread1.messages[1].content).to.equal "three"
|
2017-01-06 08:14:47 -05:00
|
|
|
expect(thread1.messages[1].user_id).to.equal @user_id1
|
2016-12-16 11:52:50 -05:00
|
|
|
|
2017-01-04 08:51:08 -05:00
|
|
|
expect(thread2.messages[0].content).to.equal "two"
|
2017-01-06 08:14:47 -05:00
|
|
|
expect(thread2.messages[0].user_id).to.equal @user_id2
|
2017-01-04 08:51:08 -05:00
|
|
|
expect(thread2.messages[1].content).to.equal "four"
|
2017-01-06 08:14:47 -05:00
|
|
|
expect(thread2.messages[1].user_id).to.equal @user_id2
|
2016-12-16 11:52:50 -05:00
|
|
|
done()
|