diff --git a/services/chat/test/acceptance/coffee/DeletingAMessageTests.js b/services/chat/test/acceptance/coffee/DeletingAMessageTests.js index 7d6ca8b00b..0969d522cf 100644 --- a/services/chat/test/acceptance/coffee/DeletingAMessageTests.js +++ b/services/chat/test/acceptance/coffee/DeletingAMessageTests.js @@ -1,32 +1,48 @@ -{ObjectId} = require "../../../app/js/mongojs" -expect = require("chai").expect +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const {ObjectId} = require("../../../app/js/mongojs"); +const { expect } = require("chai"); -ChatClient = require "./helpers/ChatClient" -ChatApp = require "./helpers/ChatApp" +const ChatClient = require("./helpers/ChatClient"); +const ChatApp = require("./helpers/ChatApp"); -describe "Deleting a message", -> - before (done) -> - @project_id = ObjectId().toString() - @user_id = ObjectId().toString() - @thread_id = ObjectId().toString() - ChatApp.ensureRunning done +describe("Deleting a message", function() { + before(function(done) { + this.project_id = ObjectId().toString(); + this.user_id = ObjectId().toString(); + this.thread_id = ObjectId().toString(); + return ChatApp.ensureRunning(done); + }); - 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() + return describe("in a thread", function() { + before(function(done) { + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, "first message", (error, response, message) => { + this.message = message; + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, "deleted message", (error, response, message1) => { + this.message = message1; + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + return ChatClient.deleteMessage(this.project_id, this.thread_id, this.message.id, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(204); + return 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() \ No newline at end of file + return it("should then remove the message from the threads", function(done) { + return ChatClient.getThreads(this.project_id, (error, response, threads) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(200); + expect(threads[this.thread_id].messages.length).to.equal(1); + return done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/services/chat/test/acceptance/coffee/DeletingAThreadTests.js b/services/chat/test/acceptance/coffee/DeletingAThreadTests.js index a803e730c7..843134bbd8 100644 --- a/services/chat/test/acceptance/coffee/DeletingAThreadTests.js +++ b/services/chat/test/acceptance/coffee/DeletingAThreadTests.js @@ -1,31 +1,44 @@ -{ObjectId} = require "../../../app/js/mongojs" -expect = require("chai").expect -crypto = require "crypto" +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const {ObjectId} = require("../../../app/js/mongojs"); +const { expect } = require("chai"); +const crypto = require("crypto"); -ChatClient = require "./helpers/ChatClient" -ChatApp = require "./helpers/ChatApp" +const ChatClient = require("./helpers/ChatClient"); +const ChatApp = require("./helpers/ChatApp"); -describe "Deleting a thread", -> - before (done) -> - @project_id = ObjectId().toString() - @user_id = ObjectId().toString() - ChatApp.ensureRunning done +describe("Deleting a thread", function() { + before(function(done) { + this.project_id = ObjectId().toString(); + this.user_id = ObjectId().toString(); + return ChatApp.ensureRunning(done); + }); - 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() + return describe("with a thread that is deleted", function() { + before(function(done) { + this.thread_id = ObjectId().toString(); + this.content = "deleted thread message"; + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + return ChatClient.deleteThread(this.project_id, this.thread_id, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(204); + return 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() + return it("should then not list the thread for the project", function(done) { + return ChatClient.getThreads(this.project_id, (error, response, threads) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(200); + expect(Object.keys(threads).length).to.equal(0); + return done(); + }); + }); + }); +}); diff --git a/services/chat/test/acceptance/coffee/EditingAMessageTests.js b/services/chat/test/acceptance/coffee/EditingAMessageTests.js index f507e4b205..03bbbeab0a 100644 --- a/services/chat/test/acceptance/coffee/EditingAMessageTests.js +++ b/services/chat/test/acceptance/coffee/EditingAMessageTests.js @@ -1,34 +1,49 @@ -{ObjectId} = require "../../../app/js/mongojs" -expect = require("chai").expect +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const {ObjectId} = require("../../../app/js/mongojs"); +const { expect } = require("chai"); -ChatClient = require "./helpers/ChatClient" -ChatApp = require "./helpers/ChatApp" +const ChatClient = require("./helpers/ChatClient"); +const ChatApp = require("./helpers/ChatApp"); -describe "Editing a message", -> - before (done) -> - @project_id = ObjectId().toString() - @user_id = ObjectId().toString() - @thread_id = ObjectId().toString() - ChatApp.ensureRunning done +describe("Editing a message", function() { + before(function(done) { + this.project_id = ObjectId().toString(); + this.user_id = ObjectId().toString(); + this.thread_id = ObjectId().toString(); + return ChatApp.ensureRunning(done); + }); - 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 204 - done() + return describe("in a thread", function() { + before(function(done) { + this.content = "thread message"; + this.new_content = "updated thread message"; + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, message) => { + this.message = message; + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + expect(this.message.id).to.exist; + expect(this.message.content).to.equal(this.content); + return ChatClient.editMessage(this.project_id, this.thread_id, this.message.id, this.new_content, (error, response, new_message) => { + this.new_message = new_message; + expect(error).to.be.null; + expect(response.statusCode).to.equal(204); + return 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() \ No newline at end of file + return it("should then list the updated message in the threads", function(done) { + return ChatClient.getThreads(this.project_id, (error, response, threads) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(200); + expect(threads[this.thread_id].messages.length).to.equal(1); + expect(threads[this.thread_id].messages[0].content).to.equal(this.new_content); + return done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/services/chat/test/acceptance/coffee/GettingMessagesTests.js b/services/chat/test/acceptance/coffee/GettingMessagesTests.js index b0c872e5cd..a2d3c81df6 100644 --- a/services/chat/test/acceptance/coffee/GettingMessagesTests.js +++ b/services/chat/test/acceptance/coffee/GettingMessagesTests.js @@ -1,64 +1,79 @@ -{ObjectId} = require "../../../app/js/mongojs" -expect = require("chai").expect -async = require "async" -crypto = require "crypto" +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const {ObjectId} = require("../../../app/js/mongojs"); +const { expect } = require("chai"); +const async = require("async"); +const crypto = require("crypto"); -ChatClient = require "./helpers/ChatClient" -ChatApp = require "./helpers/ChatApp" +const ChatClient = require("./helpers/ChatClient"); +const ChatApp = require("./helpers/ChatApp"); -describe "Getting messages", -> - before (done) -> - @user_id1 = ObjectId().toString() - @user_id2 = ObjectId().toString() - @content1 = "foo bar" - @content2 = "hello world" - ChatApp.ensureRunning done +describe("Getting messages", function() { + before(function(done) { + this.user_id1 = ObjectId().toString(); + this.user_id2 = ObjectId().toString(); + this.content1 = "foo bar"; + this.content2 = "hello world"; + return ChatApp.ensureRunning(done); + }); - describe "globally", -> - before (done) -> - @project_id = ObjectId().toString() - async.series [ - (cb) => ChatClient.sendGlobalMessage @project_id, @user_id1, @content1, cb - (cb) => ChatClient.sendGlobalMessage @project_id, @user_id2, @content2, cb - ], done + describe("globally", function() { + before(function(done) { + this.project_id = ObjectId().toString(); + return async.series([ + cb => ChatClient.sendGlobalMessage(this.project_id, this.user_id1, this.content1, cb), + cb => ChatClient.sendGlobalMessage(this.project_id, this.user_id2, this.content2, cb) + ], done); + }); - it "should contain the messages and populated users when getting the messages", (done) -> - ChatClient.getGlobalMessages @project_id, (error, response, messages) => - expect(messages.length).to.equal 2 - messages.reverse() - expect(messages[0].content).to.equal @content1 - expect(messages[0].user_id).to.equal @user_id1 - expect(messages[1].content).to.equal @content2 - expect(messages[1].user_id).to.equal @user_id2 - done() + return it("should contain the messages and populated users when getting the messages", function(done) { + 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(); + }); + }); + }); - 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 + return describe("from all the threads", function() { + before(function(done) { + this.project_id = ObjectId().toString(); + this.thread_id1 = ObjectId().toString(); + this.thread_id2 = ObjectId().toString(); + return async.series([ + cb => ChatClient.sendMessage(this.project_id, this.thread_id1, this.user_id1, "one", cb), + cb => ChatClient.sendMessage(this.project_id, this.thread_id2, this.user_id2, "two", cb), + cb => ChatClient.sendMessage(this.project_id, this.thread_id1, this.user_id1, "three", cb), + cb => ChatClient.sendMessage(this.project_id, this.thread_id2, this.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] - expect(thread1.messages.length).to.equal 2 - thread2 = threads[@thread_id2] - expect(thread2.messages.length).to.equal 2 + return it("should contain a dictionary of threads with messages with populated users", function(done) { + 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 @user_id1 - expect(thread1.messages[1].content).to.equal "three" - expect(thread1.messages[1].user_id).to.equal @user_id1 + 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 @user_id2 - expect(thread2.messages[1].content).to.equal "four" - expect(thread2.messages[1].user_id).to.equal @user_id2 - done() + 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(); + }); + }); + }); +}); diff --git a/services/chat/test/acceptance/coffee/ResolvingAThreadTests.js b/services/chat/test/acceptance/coffee/ResolvingAThreadTests.js index d162f881f6..bad9b5feef 100644 --- a/services/chat/test/acceptance/coffee/ResolvingAThreadTests.js +++ b/services/chat/test/acceptance/coffee/ResolvingAThreadTests.js @@ -1,72 +1,97 @@ -{ObjectId} = require "../../../app/js/mongojs" -expect = require("chai").expect -crypto = require "crypto" +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const {ObjectId} = require("../../../app/js/mongojs"); +const { expect } = require("chai"); +const crypto = require("crypto"); -ChatClient = require "./helpers/ChatClient" -ChatApp = require "./helpers/ChatApp" +const ChatClient = require("./helpers/ChatClient"); +const ChatApp = require("./helpers/ChatApp"); -describe "Resolving a thread", -> - before (done) -> - @project_id = ObjectId().toString() - @user_id = ObjectId().toString() - ChatApp.ensureRunning done +describe("Resolving a thread", function() { + before(function(done) { + this.project_id = ObjectId().toString(); + this.user_id = ObjectId().toString(); + return ChatApp.ensureRunning(done); + }); - describe "with a resolved thread", -> - before (done) -> - @thread_id = ObjectId().toString() - @content = "resolved 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.resolveThread @project_id, @thread_id, @user_id, (error, response, body) => - expect(error).to.be.null - expect(response.statusCode).to.equal 204 - done() + describe("with a resolved thread", function() { + before(function(done) { + this.thread_id = ObjectId().toString(); + this.content = "resolved message"; + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + return ChatClient.resolveThread(this.project_id, this.thread_id, this.user_id, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(204); + return done(); + }); + }); + }); - it "should then list the thread as resolved", (done) -> - ChatClient.getThreads @project_id, (error, response, threads) => - expect(error).to.be.null - expect(response.statusCode).to.equal 200 - expect(threads[@thread_id].resolved).to.equal true - expect(threads[@thread_id].resolved_by_user_id).to.equal @user_id - resolved_at = new Date(threads[@thread_id].resolved_at) - expect(new Date() - resolved_at).to.be.below 1000 - done() + return it("should then list the thread as resolved", function(done) { + return ChatClient.getThreads(this.project_id, (error, response, threads) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(200); + expect(threads[this.thread_id].resolved).to.equal(true); + expect(threads[this.thread_id].resolved_by_user_id).to.equal(this.user_id); + const resolved_at = new Date(threads[this.thread_id].resolved_at); + expect(new Date() - resolved_at).to.be.below(1000); + return done(); + }); + }); + }); - describe "when a thread is not resolved", -> - before (done) -> - @thread_id = ObjectId().toString() - @content = "open message" - ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) => - expect(error).to.be.null - expect(response.statusCode).to.equal 201 - done() + describe("when a thread is not resolved", function() { + before(function(done) { + this.thread_id = ObjectId().toString(); + this.content = "open message"; + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + return done(); + }); + }); - it "should not list the thread as resolved", (done) -> - ChatClient.getThreads @project_id, (error, response, threads) => - expect(error).to.be.null - expect(response.statusCode).to.equal 200 - expect(threads[@thread_id].resolved).to.be.undefined - done() + return it("should not list the thread as resolved", function(done) { + return ChatClient.getThreads(this.project_id, (error, response, threads) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(200); + expect(threads[this.thread_id].resolved).to.be.undefined; + return done(); + }); + }); + }); - describe "when a thread is resolved then reopened", -> - before (done) -> - @thread_id = ObjectId().toString() - @content = "resolved 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.resolveThread @project_id, @thread_id, @user_id, (error, response, body) => - expect(error).to.be.null - expect(response.statusCode).to.equal 204 - ChatClient.reopenThread @project_id, @thread_id, (error, response, body) => - expect(error).to.be.null - expect(response.statusCode).to.equal 204 - done() + return describe("when a thread is resolved then reopened", function() { + before(function(done) { + this.thread_id = ObjectId().toString(); + this.content = "resolved message"; + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + return ChatClient.resolveThread(this.project_id, this.thread_id, this.user_id, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(204); + return ChatClient.reopenThread(this.project_id, this.thread_id, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(204); + return done(); + }); + }); + }); + }); - it "should not list the thread as resolved", (done) -> - ChatClient.getThreads @project_id, (error, response, threads) => - expect(error).to.be.null - expect(response.statusCode).to.equal 200 - expect(threads[@thread_id].resolved).to.be.undefined - done() + return it("should not list the thread as resolved", function(done) { + return ChatClient.getThreads(this.project_id, (error, response, threads) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(200); + expect(threads[this.thread_id].resolved).to.be.undefined; + return done(); + }); + }); + }); +}); diff --git a/services/chat/test/acceptance/coffee/SendingAMessageTests.js b/services/chat/test/acceptance/coffee/SendingAMessageTests.js index 64a2d5dbe5..d1459efe9b 100644 --- a/services/chat/test/acceptance/coffee/SendingAMessageTests.js +++ b/services/chat/test/acceptance/coffee/SendingAMessageTests.js @@ -1,101 +1,135 @@ -{ObjectId} = require "../../../app/js/mongojs" -expect = require("chai").expect +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const {ObjectId} = require("../../../app/js/mongojs"); +const { expect } = require("chai"); -ChatClient = require "./helpers/ChatClient" -ChatApp = require "./helpers/ChatApp" +const ChatClient = require("./helpers/ChatClient"); +const ChatApp = require("./helpers/ChatApp"); -describe "Sending a message", -> - before (done) -> - ChatApp.ensureRunning done +describe("Sending a message", function() { + before(done => ChatApp.ensureRunning(done)); - describe "globally", -> - before (done) -> - @project_id = ObjectId().toString() - @user_id = ObjectId().toString() - @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 - expect(body.user_id).to.equal @user_id - expect(body.room_id).to.equal @project_id - done() + describe("globally", function() { + before(function(done) { + this.project_id = ObjectId().toString(); + this.user_id = ObjectId().toString(); + this.content = "global message"; + return ChatClient.sendGlobalMessage(this.project_id, this.user_id, this.content, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + expect(body.content).to.equal(this.content); + expect(body.user_id).to.equal(this.user_id); + expect(body.room_id).to.equal(this.project_id); + return 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() + return it("should then list the message in the project messages", function(done) { + return ChatClient.getGlobalMessages(this.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(this.content); + return done(); + }); + }); + }); - describe "to a thread", -> - before (done) -> - @project_id = ObjectId().toString() - @user_id = ObjectId().toString() - @thread_id = ObjectId().toString() - @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 - expect(body.user_id).to.equal @user_id - expect(body.room_id).to.equal @project_id - done() + describe("to a thread", function() { + before(function(done) { + this.project_id = ObjectId().toString(); + this.user_id = ObjectId().toString(); + this.thread_id = ObjectId().toString(); + this.content = "thread message"; + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(201); + expect(body.content).to.equal(this.content); + expect(body.user_id).to.equal(this.user_id); + expect(body.room_id).to.equal(this.project_id); + return 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 - expect(threads[@thread_id].messages.length).to.equal 1 - expect(threads[@thread_id].messages[0].content).to.equal @content - done() + it("should then list the message in the threads", function(done) { + return ChatClient.getThreads(this.project_id, (error, response, threads) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(200); + expect(threads[this.thread_id].messages.length).to.equal(1); + expect(threads[this.thread_id].messages[0].content).to.equal(this.content); + return done(); + }); + }); - 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() + return it("should not appear in the global messages", function(done) { + return ChatClient.getGlobalMessages(this.project_id, (error, response, messages) => { + expect(error).to.be.null; + expect(response.statusCode).to.equal(200); + expect(messages.length).to.equal(0); + return done(); + }); + }); + }); - describe "failure cases", -> - before () -> - @project_id = ObjectId().toString() - @user_id = ObjectId().toString() - @thread_id = ObjectId().toString() + return describe("failure cases", function() { + before(function() { + this.project_id = ObjectId().toString(); + this.user_id = ObjectId().toString(); + return this.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 user_id", () => + it("should return a graceful error", function(done) { + return ChatClient.sendMessage(this.project_id, this.thread_id, "malformed-user", "content", (error, response, body) => { + expect(response.statusCode).to.equal(400); + expect(body).to.equal("Invalid user_id"); + return 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 project_id", () => + it("should return a graceful error", function(done) { + return ChatClient.sendMessage("malformed-project", this.thread_id, this.user_id, "content", (error, response, body) => { + expect(response.statusCode).to.equal(400); + expect(body).to.equal("Invalid project_id"); + return 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 a malformed thread_id", () => + it("should return a graceful error", function(done) { + return ChatClient.sendMessage(this.project_id, "malformed-thread-id", this.user_id, "content", (error, response, body) => { + expect(response.statusCode).to.equal(400); + expect(body).to.equal("Invalid thread_id"); + return 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 no content", () => + it("should return a graceful error", function(done) { + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, null, (error, response, body) => { + expect(response.statusCode).to.equal(400); + expect(body).to.equal("No content provided"); + return 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() \ No newline at end of file + return describe("with very long content", () => + it("should return a graceful error", function(done) { + const content = new Buffer(10240).toString("hex"); + return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, content, (error, response, body) => { + expect(response.statusCode).to.equal(400); + expect(body).to.equal("Content too long (> 10240 bytes)"); + return done(); + }); + }) + ); + }); +}); \ No newline at end of file diff --git a/services/chat/test/acceptance/coffee/helpers/ChatApp.js b/services/chat/test/acceptance/coffee/helpers/ChatApp.js index 8973541003..916901b08c 100644 --- a/services/chat/test/acceptance/coffee/helpers/ChatApp.js +++ b/services/chat/test/acceptance/coffee/helpers/ChatApp.js @@ -1,20 +1,38 @@ -app = require('../../../../app') -require("logger-sharelatex").logger.level("error") +/* + * decaffeinate suggestions: + * DS101: Remove unnecessary use of Array.from + * DS102: Remove unnecessary code created because of implicit returns + * DS205: Consider reworking code to avoid use of IIFEs + * DS207: Consider shorter variations of null checks + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const app = require('../../../../app'); +require("logger-sharelatex").logger.level("error"); -module.exports = - running: false - initing: false - callbacks: [] - ensureRunning: (callback = (error) ->) -> - if @running - return callback() - else if @initing - @callbacks.push callback - else - @initing = true - @callbacks.push callback - app.listen 3010, "localhost", (error) => - throw error if error? - @running = true - for callback in @callbacks - callback() \ No newline at end of file +module.exports = { + running: false, + initing: false, + callbacks: [], + ensureRunning(callback) { + if (callback == null) { callback = function(error) {}; } + if (this.running) { + return callback(); + } else if (this.initing) { + return this.callbacks.push(callback); + } else { + this.initing = true; + this.callbacks.push(callback); + return app.listen(3010, "localhost", error => { + if (error != null) { throw error; } + this.running = true; + return (() => { + const result = []; + for (callback of Array.from(this.callbacks)) { + result.push(callback()); + } + return result; + })(); + }); + } + } +}; \ No newline at end of file diff --git a/services/chat/test/acceptance/coffee/helpers/ChatClient.js b/services/chat/test/acceptance/coffee/helpers/ChatClient.js index 902d743d21..34c8d4cf5b 100644 --- a/services/chat/test/acceptance/coffee/helpers/ChatClient.js +++ b/services/chat/test/acceptance/coffee/helpers/ChatClient.js @@ -1,60 +1,78 @@ -request = require("request").defaults({baseUrl: "http://localhost:3010"}) +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +const request = require("request").defaults({baseUrl: "http://localhost:3010"}); -module.exports = - sendGlobalMessage: (project_id, user_id, content, callback) -> - request.post { - url: "/project/#{project_id}/messages" - json: - user_id: user_id - content: content - }, callback - - getGlobalMessages: (project_id, callback) -> - request.get { - url: "/project/#{project_id}/messages", - json: true - }, callback - - sendMessage: (project_id, thread_id, user_id, content, callback) -> - request.post { - url: "/project/#{project_id}/thread/#{thread_id}/messages" - json: - user_id: user_id - content: content - }, callback - - getThreads: (project_id, callback) -> - request.get { - url: "/project/#{project_id}/threads", - json: true - }, callback - - resolveThread: (project_id, thread_id, user_id, callback) -> - request.post { - url: "/project/#{project_id}/thread/#{thread_id}/resolve", +module.exports = { + sendGlobalMessage(project_id, user_id, content, callback) { + return request.post({ + url: `/project/${project_id}/messages`, json: { - user_id: user_id + user_id, + content } - }, callback + }, callback); + }, + + getGlobalMessages(project_id, callback) { + return request.get({ + url: `/project/${project_id}/messages`, + json: true + }, callback); + }, - reopenThread: (project_id, thread_id, callback) -> - request.post { - url: "/project/#{project_id}/thread/#{thread_id}/reopen", - }, callback + sendMessage(project_id, thread_id, user_id, content, callback) { + return request.post({ + url: `/project/${project_id}/thread/${thread_id}/messages`, + json: { + user_id, + content + } + }, callback); + }, + + getThreads(project_id, callback) { + return request.get({ + url: `/project/${project_id}/threads`, + json: true + }, callback); + }, + + resolveThread(project_id, thread_id, user_id, callback) { + return request.post({ + url: `/project/${project_id}/thread/${thread_id}/resolve`, + json: { + user_id + } + }, callback); + }, - deleteThread: (project_id, thread_id, callback) -> - request.del { - url: "/project/#{project_id}/thread/#{thread_id}", - }, callback + reopenThread(project_id, thread_id, callback) { + return request.post({ + url: `/project/${project_id}/thread/${thread_id}/reopen`, + }, 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 + deleteThread(project_id, thread_id, callback) { + return request.del({ + url: `/project/${project_id}/thread/${thread_id}`, + }, callback); + }, - deleteMessage: (project_id, thread_id, message_id, callback) -> - request.del { - url: "/project/#{project_id}/thread/#{thread_id}/messages/#{message_id}", - }, callback + editMessage(project_id, thread_id, message_id, content, callback) { + return request.post({ + url: `/project/${project_id}/thread/${thread_id}/messages/${message_id}/edit`, + json: { + content + } + }, callback); + }, + + deleteMessage(project_id, thread_id, message_id, callback) { + return request.del({ + url: `/project/${project_id}/thread/${thread_id}/messages/${message_id}`, + }, callback); + } +};