|
@@ -5,12 +5,11 @@ ChatClient = require "./helpers/ChatClient"
|
|
|
|
|
|
|
|
describe "Sending a message", ->
|
|
describe "Sending a message", ->
|
|
|
before ->
|
|
before ->
|
|
|
- @project_id = ObjectId().toString()
|
|
|
|
|
- @user_id = ObjectId().toString()
|
|
|
|
|
- @thread_id = ObjectId().toString()
|
|
|
|
|
|
|
|
|
|
describe "globally", ->
|
|
describe "globally", ->
|
|
|
before (done) ->
|
|
before (done) ->
|
|
|
|
|
+ @project_id = ObjectId().toString()
|
|
|
|
|
+ @user_id = ObjectId().toString()
|
|
|
@content = "global message"
|
|
@content = "global message"
|
|
|
ChatClient.sendGlobalMessage @project_id, @user_id, @content, (error, response, body) =>
|
|
ChatClient.sendGlobalMessage @project_id, @user_id, @content, (error, response, body) =>
|
|
|
expect(error).to.be.null
|
|
expect(error).to.be.null
|
|
@@ -30,6 +29,9 @@ describe "Sending a message", ->
|
|
|
|
|
|
|
|
describe "to a thread", ->
|
|
describe "to a thread", ->
|
|
|
before (done) ->
|
|
before (done) ->
|
|
|
|
|
+ @project_id = ObjectId().toString()
|
|
|
|
|
+ @user_id = ObjectId().toString()
|
|
|
|
|
+ @thread_id = ObjectId().toString()
|
|
|
@content = "thread message"
|
|
@content = "thread message"
|
|
|
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) =>
|
|
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) =>
|
|
|
expect(error).to.be.null
|
|
expect(error).to.be.null
|
|
@@ -46,39 +48,52 @@ describe "Sending a message", ->
|
|
|
expect(threads[@thread_id].messages.length).to.equal 1
|
|
expect(threads[@thread_id].messages.length).to.equal 1
|
|
|
expect(threads[@thread_id].messages[0].content).to.equal @content
|
|
expect(threads[@thread_id].messages[0].content).to.equal @content
|
|
|
done()
|
|
done()
|
|
|
-
|
|
|
|
|
- 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"
|
|
|
|
|
|
|
+
|
|
|
|
|
+ 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
|
|
|
done()
|
|
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()
|
|
|
|
|
|
|
+ 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()
|