Allow editing/deleting of comments and threads

This commit is contained in:
James Allen
2017-01-24 15:44:32 +01:00
parent a997bf9c01
commit fa63eb6947
9 changed files with 184 additions and 4 deletions
@@ -0,0 +1,30 @@
{ObjectId} = require "../../../app/js/mongojs"
expect = require("chai").expect
ChatClient = require "./helpers/ChatClient"
describe "Deleting a message", ->
before ->
@project_id = ObjectId().toString()
@user_id = ObjectId().toString()
@thread_id = ObjectId().toString()
describe "in a thread", ->
before (done) ->
ChatClient.sendMessage @project_id, @thread_id, @user_id, "first message", (error, response, @message) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 201
ChatClient.sendMessage @project_id, @thread_id, @user_id, "deleted message", (error, response, @message) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 201
ChatClient.deleteMessage @project_id, @thread_id, @message.id, (error, response, body) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 204
done()
it "should then remove the message from the threads", (done) ->
ChatClient.getThreads @project_id, (error, response, threads) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 200
expect(threads[@thread_id].messages.length).to.equal 1
done()
@@ -0,0 +1,29 @@
{ObjectId} = require "../../../app/js/mongojs"
expect = require("chai").expect
crypto = require "crypto"
ChatClient = require "./helpers/ChatClient"
describe "Deleting a thread", ->
before ->
@project_id = ObjectId().toString()
@user_id = ObjectId().toString()
describe "with a thread that is deleted", ->
before (done) ->
@thread_id = ObjectId().toString()
@content = "deleted 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
ChatClient.deleteThread @project_id, @thread_id, (error, response, body) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 204
done()
it "should then not list the thread for the project", (done) ->
ChatClient.getThreads @project_id, (error, response, threads) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 200
expect(Object.keys(threads).length).to.equal 0
done()
@@ -0,0 +1,34 @@
{ObjectId} = require "../../../app/js/mongojs"
expect = require("chai").expect
ChatClient = require "./helpers/ChatClient"
describe "Editing a message", ->
before ->
@project_id = ObjectId().toString()
@user_id = ObjectId().toString()
@thread_id = ObjectId().toString()
describe "in a thread", ->
before (done) ->
@content = "thread message"
@new_content = "updated thread message"
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, @message) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 201
expect(@message.id).to.exist
expect(@message.content).to.equal @content
ChatClient.editMessage @project_id, @thread_id, @message.id, @new_content, (error, response, @new_message) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 201
expect(@new_message.edited_at).to.exist
expect(@new_message.content).to.equal @new_content
done()
it "should then list the updated message in the threads", (done) ->
ChatClient.getThreads @project_id, (error, response, threads) =>
expect(error).to.be.null
expect(response.statusCode).to.equal 200
expect(threads[@thread_id].messages.length).to.equal 1
expect(threads[@thread_id].messages[0].content).to.equal @new_content
done()
@@ -40,4 +40,21 @@ module.exports =
reopenThread: (project_id, thread_id, callback) ->
request.post {
url: "/project/#{project_id}/thread/#{thread_id}/reopen",
}, callback
}, callback
deleteThread: (project_id, thread_id, callback) ->
request.del {
url: "/project/#{project_id}/thread/#{thread_id}",
}, callback
editMessage: (project_id, thread_id, message_id, content, callback) ->
request.post {
url: "/project/#{project_id}/thread/#{thread_id}/messages/#{message_id}/edit"
json:
content: content
}, callback
deleteMessage: (project_id, thread_id, message_id, callback) ->
request.del {
url: "/project/#{project_id}/thread/#{thread_id}/messages/#{message_id}",
}, callback