diff --git a/services/chat/test/acceptance/js/DeletingAMessageTests.js b/services/chat/test/acceptance/js/DeletingAMessageTests.js index 1af37a990a..9f13530cd4 100644 --- a/services/chat/test/acceptance/js/DeletingAMessageTests.js +++ b/services/chat/test/acceptance/js/DeletingAMessageTests.js @@ -8,46 +8,66 @@ * 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 { ObjectId } = require('../../../app/js/mongojs') +const { expect } = require('chai') -const ChatClient = require("./helpers/ChatClient"); -const ChatApp = require("./helpers/ChatApp"); +const ChatClient = require('./helpers/ChatClient') +const ChatApp = require('./helpers/ChatApp') -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('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) + }) - 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(); - }); - }); - }); - }); - - 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 + 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() + } + ) + } + ) + } + ) + }) + + 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() + } + ) + }) + }) +}) diff --git a/services/chat/test/acceptance/js/DeletingAThreadTests.js b/services/chat/test/acceptance/js/DeletingAThreadTests.js index 98fd62bc76..527e808568 100644 --- a/services/chat/test/acceptance/js/DeletingAThreadTests.js +++ b/services/chat/test/acceptance/js/DeletingAThreadTests.js @@ -9,42 +9,55 @@ * 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"); +const { ObjectId } = require('../../../app/js/mongojs') +const { expect } = require('chai') +const crypto = require('crypto') -const ChatClient = require("./helpers/ChatClient"); -const ChatApp = require("./helpers/ChatApp"); +const ChatClient = require('./helpers/ChatClient') +const ChatApp = require('./helpers/ChatApp') -describe("Deleting a thread", function() { - before(function(done) { - this.project_id = ObjectId().toString(); - this.user_id = ObjectId().toString(); - return 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) + }) - 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(); - }); - }); - }); - - 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(); - }); - }); - }); -}); + 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() + } + ) + } + ) + }) + + 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/js/EditingAMessageTests.js b/services/chat/test/acceptance/js/EditingAMessageTests.js index de39aa47a1..bf107412ed 100644 --- a/services/chat/test/acceptance/js/EditingAMessageTests.js +++ b/services/chat/test/acceptance/js/EditingAMessageTests.js @@ -9,47 +9,64 @@ * 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 { ObjectId } = require('../../../app/js/mongojs') +const { expect } = require('chai') -const ChatClient = require("./helpers/ChatClient"); -const ChatApp = require("./helpers/ChatApp"); +const ChatClient = require('./helpers/ChatClient') +const ChatApp = require('./helpers/ChatApp') -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('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) + }) - 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(); - }); - }); - }); - - 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 + 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() + } + ) + } + ) + }) + + 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() + } + ) + }) + }) +}) diff --git a/services/chat/test/acceptance/js/GettingMessagesTests.js b/services/chat/test/acceptance/js/GettingMessagesTests.js index d84eab01b5..0fe17a5c7c 100644 --- a/services/chat/test/acceptance/js/GettingMessagesTests.js +++ b/services/chat/test/acceptance/js/GettingMessagesTests.js @@ -10,77 +10,129 @@ * 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"); +const { ObjectId } = require('../../../app/js/mongojs') +const { expect } = require('chai') +const async = require('async') +const crypto = require('crypto') -const ChatClient = require("./helpers/ChatClient"); -const ChatApp = require("./helpers/ChatApp"); +const ChatClient = require('./helpers/ChatClient') +const ChatApp = require('./helpers/ChatApp') -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('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", 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); - }); - - 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('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 + ) + }) - 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); - }); - - 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(this.user_id1); - expect(thread1.messages[1].content).to.equal("three"); - expect(thread1.messages[1].user_id).to.equal(this.user_id1); + 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() + } + ) + }) + }) - 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(); - }); - }); - }); -}); + 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 + ) + }) + + 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(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(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/js/ResolvingAThreadTests.js b/services/chat/test/acceptance/js/ResolvingAThreadTests.js index fd4522c7ab..255a1fc5e1 100644 --- a/services/chat/test/acceptance/js/ResolvingAThreadTests.js +++ b/services/chat/test/acceptance/js/ResolvingAThreadTests.js @@ -10,95 +10,138 @@ * 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"); +const { ObjectId } = require('../../../app/js/mongojs') +const { expect } = require('chai') +const crypto = require('crypto') -const ChatClient = require("./helpers/ChatClient"); -const ChatApp = require("./helpers/ChatApp"); +const ChatClient = require('./helpers/ChatClient') +const ChatApp = require('./helpers/ChatApp') -describe("Resolving a thread", function() { - before(function(done) { - this.project_id = ObjectId().toString(); - this.user_id = ObjectId().toString(); - return 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", 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(); - }); - }); - }); - - 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('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() + } + ) + } + ) + }) - 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(); - }); - }); - - 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(); - }); - }); - }); - - 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(); - }); - }); - }); - }); - - 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(); - }); - }); - }); -}); + 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', 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() + } + ) + }) + + 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() + } + ) + }) + }) + + 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() + } + ) + } + ) + } + ) + }) + + 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/js/SendingAMessageTests.js b/services/chat/test/acceptance/js/SendingAMessageTests.js index 153b4c13a5..f837a2edd5 100644 --- a/services/chat/test/acceptance/js/SendingAMessageTests.js +++ b/services/chat/test/acceptance/js/SendingAMessageTests.js @@ -11,133 +11,180 @@ * 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 { ObjectId } = require('../../../app/js/mongojs') +const { expect } = require('chai') -const ChatClient = require("./helpers/ChatClient"); -const ChatApp = require("./helpers/ChatApp"); +const ChatClient = require('./helpers/ChatClient') +const ChatApp = require('./helpers/ChatApp') -describe("Sending a message", function() { - before(done => ChatApp.ensureRunning(done)); +describe('Sending a message', function() { + before(done => ChatApp.ensureRunning(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(); - }); - }); - - 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('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() + } + ) + }) - 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", 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(); - }); - }); - - 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(); - }); - }); - }); - - 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", 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", 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", 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", 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(); - }); - }) - ); - - 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 + 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', 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', 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() + } + ) + }) + + 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() + } + ) + }) + }) + + 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', 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', 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', 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', 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() + } + ) + })) + + 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() + } + ) + })) + }) +}) diff --git a/services/chat/test/acceptance/js/helpers/ChatApp.js b/services/chat/test/acceptance/js/helpers/ChatApp.js index 7dc5e78b21..4967dc1d51 100644 --- a/services/chat/test/acceptance/js/helpers/ChatApp.js +++ b/services/chat/test/acceptance/js/helpers/ChatApp.js @@ -11,33 +11,37 @@ * 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"); +const app = require('../../../../app') +require('logger-sharelatex').logger.level('error') 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 + 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 + })() + }) + } + } +} diff --git a/services/chat/test/acceptance/js/helpers/ChatClient.js b/services/chat/test/acceptance/js/helpers/ChatClient.js index 7c866d8ac5..932e6cc651 100644 --- a/services/chat/test/acceptance/js/helpers/ChatClient.js +++ b/services/chat/test/acceptance/js/helpers/ChatClient.js @@ -9,76 +9,105 @@ * 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"}); +const request = require('request').defaults({ + baseUrl: 'http://localhost:3010' +}) module.exports = { - sendGlobalMessage(project_id, user_id, content, callback) { - return request.post({ - url: `/project/${project_id}/messages`, - json: { - user_id, - content - } - }, callback); - }, - - getGlobalMessages(project_id, callback) { - return request.get({ - url: `/project/${project_id}/messages`, - json: true - }, callback); - }, + sendGlobalMessage(project_id, user_id, content, callback) { + return request.post( + { + url: `/project/${project_id}/messages`, + json: { + user_id, + content + } + }, + 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); - }, + getGlobalMessages(project_id, callback) { + return request.get( + { + url: `/project/${project_id}/messages`, + json: true + }, + callback + ) + }, - reopenThread(project_id, thread_id, callback) { - return 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 + ) + }, - deleteThread(project_id, thread_id, callback) { - return request.del({ - url: `/project/${project_id}/thread/${thread_id}`, - }, callback); - }, + getThreads(project_id, callback) { + return request.get( + { + url: `/project/${project_id}/threads`, + json: true + }, + 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); - }, + resolveThread(project_id, thread_id, user_id, callback) { + return request.post( + { + url: `/project/${project_id}/thread/${thread_id}/resolve`, + json: { + user_id + } + }, + callback + ) + }, - deleteMessage(project_id, thread_id, message_id, callback) { - return request.del({ - url: `/project/${project_id}/thread/${thread_id}/messages/${message_id}`, - }, callback); - } -}; + reopenThread(project_id, thread_id, callback) { + return request.post( + { + url: `/project/${project_id}/thread/${thread_id}/reopen` + }, + callback + ) + }, + + deleteThread(project_id, thread_id, callback) { + return request.del( + { + url: `/project/${project_id}/thread/${thread_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 + ) + } +}