2016-12-14 12:38:14 -05:00
|
|
|
{ObjectId} = require "../../../app/js/mongojs"
|
|
|
|
expect = require("chai").expect
|
|
|
|
|
|
|
|
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 "Sending a message", ->
|
2018-01-29 07:01:26 -05:00
|
|
|
before (done) ->
|
|
|
|
ChatApp.ensureRunning done
|
2016-12-16 11:52:50 -05:00
|
|
|
|
|
|
|
describe "globally", ->
|
|
|
|
before (done) ->
|
2017-02-24 10:20:06 -05:00
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@user_id = ObjectId().toString()
|
2016-12-16 11:52:50 -05:00
|
|
|
@content = "global message"
|
|
|
|
ChatClient.sendGlobalMessage @project_id, @user_id, @content, (error, response, body) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 201
|
|
|
|
expect(body.content).to.equal @content
|
2017-01-06 08:14:47 -05:00
|
|
|
expect(body.user_id).to.equal @user_id
|
|
|
|
expect(body.room_id).to.equal @project_id
|
2016-12-16 11:52:50 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it "should then list the message in the project messages", (done) ->
|
|
|
|
ChatClient.getGlobalMessages @project_id, (error, response, messages) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
|
expect(messages.length).to.equal 1
|
|
|
|
expect(messages[0].content).to.equal @content
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "to a thread", ->
|
|
|
|
before (done) ->
|
2017-02-24 10:20:06 -05:00
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@user_id = ObjectId().toString()
|
|
|
|
@thread_id = ObjectId().toString()
|
2016-12-16 11:52:50 -05:00
|
|
|
@content = "thread message"
|
|
|
|
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 201
|
|
|
|
expect(body.content).to.equal @content
|
2017-01-06 08:14:47 -05:00
|
|
|
expect(body.user_id).to.equal @user_id
|
|
|
|
expect(body.room_id).to.equal @project_id
|
2016-12-16 11:52:50 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it "should then list the message in the threads", (done) ->
|
|
|
|
ChatClient.getThreads @project_id, (error, response, threads) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 200
|
2017-01-04 08:51:08 -05:00
|
|
|
expect(threads[@thread_id].messages.length).to.equal 1
|
|
|
|
expect(threads[@thread_id].messages[0].content).to.equal @content
|
2016-12-16 11:52:50 -05:00
|
|
|
done()
|
2017-02-24 10:20:06 -05:00
|
|
|
|
|
|
|
it "should not appear in the global messages", (done) ->
|
|
|
|
ChatClient.getGlobalMessages @project_id, (error, response, messages) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
|
expect(messages.length).to.equal 0
|
2017-02-14 05:43:50 -05:00
|
|
|
done()
|
|
|
|
|
2017-02-24 10:20:06 -05:00
|
|
|
describe "failure cases", ->
|
|
|
|
before () ->
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@user_id = ObjectId().toString()
|
|
|
|
@thread_id = ObjectId().toString()
|
|
|
|
|
|
|
|
describe "with a malformed user_id", ->
|
|
|
|
it "should return a graceful error", (done) ->
|
|
|
|
ChatClient.sendMessage @project_id, @thread_id, "malformed-user", "content", (error, response, body) =>
|
|
|
|
expect(response.statusCode).to.equal 400
|
|
|
|
expect(body).to.equal "Invalid user_id"
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "with a malformed project_id", ->
|
|
|
|
it "should return a graceful error", (done) ->
|
|
|
|
ChatClient.sendMessage "malformed-project", @thread_id, @user_id, "content", (error, response, body) =>
|
|
|
|
expect(response.statusCode).to.equal 400
|
|
|
|
expect(body).to.equal "Invalid project_id"
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "with a malformed thread_id", ->
|
|
|
|
it "should return a graceful error", (done) ->
|
|
|
|
ChatClient.sendMessage @project_id, "malformed-thread-id", @user_id, "content", (error, response, body) =>
|
|
|
|
expect(response.statusCode).to.equal 400
|
|
|
|
expect(body).to.equal "Invalid thread_id"
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "with no content", ->
|
|
|
|
it "should return a graceful error", (done) ->
|
|
|
|
ChatClient.sendMessage @project_id, @thread_id, @user_id, null, (error, response, body) =>
|
|
|
|
expect(response.statusCode).to.equal 400
|
|
|
|
expect(body).to.equal "No content provided"
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "with very long content", ->
|
|
|
|
it "should return a graceful error", (done) ->
|
|
|
|
content = new Buffer(10240).toString("hex")
|
|
|
|
ChatClient.sendMessage @project_id, @thread_id, @user_id, content, (error, response, body) =>
|
|
|
|
expect(response.statusCode).to.equal 400
|
|
|
|
expect(body).to.equal "Content too long (> 10240 bytes)"
|
|
|
|
done()
|