decaffeinate: Convert DeletingAMessageTests.coffee and 7 other files to JS

This commit is contained in:
decaffeinate 2018-12-20 14:14:05 -05:00 committed by Nate Stemen
parent c34b906598
commit 41eed6df4e
8 changed files with 519 additions and 365 deletions

View file

@ -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" const ChatClient = require("./helpers/ChatClient");
ChatApp = require "./helpers/ChatApp" const ChatApp = require("./helpers/ChatApp");
describe "Deleting a message", -> describe("Deleting a message", function() {
before (done) -> before(function(done) {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
@user_id = ObjectId().toString() this.user_id = ObjectId().toString();
@thread_id = ObjectId().toString() this.thread_id = ObjectId().toString();
ChatApp.ensureRunning done return ChatApp.ensureRunning(done);
});
describe "in a thread", -> return describe("in a thread", function() {
before (done) -> before(function(done) {
ChatClient.sendMessage @project_id, @thread_id, @user_id, "first message", (error, response, @message) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, "first message", (error, response, message) => {
expect(error).to.be.null this.message = message;
expect(response.statusCode).to.equal 201 expect(error).to.be.null;
ChatClient.sendMessage @project_id, @thread_id, @user_id, "deleted message", (error, response, @message) => expect(response.statusCode).to.equal(201);
expect(error).to.be.null return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, "deleted message", (error, response, message1) => {
expect(response.statusCode).to.equal 201 this.message = message1;
ChatClient.deleteMessage @project_id, @thread_id, @message.id, (error, response, body) => expect(error).to.be.null;
expect(error).to.be.null expect(response.statusCode).to.equal(201);
expect(response.statusCode).to.equal 204 return ChatClient.deleteMessage(this.project_id, this.thread_id, this.message.id, (error, response, body) => {
done() expect(error).to.be.null;
expect(response.statusCode).to.equal(204);
return done();
});
});
});
});
it "should then remove the message from the threads", (done) -> return it("should then remove the message from the threads", function(done) {
ChatClient.getThreads @project_id, (error, response, threads) => return ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(threads[@thread_id].messages.length).to.equal 1 expect(threads[this.thread_id].messages.length).to.equal(1);
done() return done();
});
});
});
});

View file

@ -1,31 +1,44 @@
{ObjectId} = require "../../../app/js/mongojs" /*
expect = require("chai").expect * decaffeinate suggestions:
crypto = require "crypto" * 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" const ChatClient = require("./helpers/ChatClient");
ChatApp = require "./helpers/ChatApp" const ChatApp = require("./helpers/ChatApp");
describe "Deleting a thread", -> describe("Deleting a thread", function() {
before (done) -> before(function(done) {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
@user_id = ObjectId().toString() this.user_id = ObjectId().toString();
ChatApp.ensureRunning done return ChatApp.ensureRunning(done);
});
describe "with a thread that is deleted", -> return describe("with a thread that is deleted", function() {
before (done) -> before(function(done) {
@thread_id = ObjectId().toString() this.thread_id = ObjectId().toString();
@content = "deleted thread message" this.content = "deleted thread message";
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 201 expect(response.statusCode).to.equal(201);
ChatClient.deleteThread @project_id, @thread_id, (error, response, body) => return ChatClient.deleteThread(this.project_id, this.thread_id, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 204 expect(response.statusCode).to.equal(204);
done() return done();
});
});
});
it "should then not list the thread for the project", (done) -> return it("should then not list the thread for the project", function(done) {
ChatClient.getThreads @project_id, (error, response, threads) => return ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(Object.keys(threads).length).to.equal 0 expect(Object.keys(threads).length).to.equal(0);
done() return done();
});
});
});
});

View file

@ -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" const ChatClient = require("./helpers/ChatClient");
ChatApp = require "./helpers/ChatApp" const ChatApp = require("./helpers/ChatApp");
describe "Editing a message", -> describe("Editing a message", function() {
before (done) -> before(function(done) {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
@user_id = ObjectId().toString() this.user_id = ObjectId().toString();
@thread_id = ObjectId().toString() this.thread_id = ObjectId().toString();
ChatApp.ensureRunning done return ChatApp.ensureRunning(done);
});
describe "in a thread", -> return describe("in a thread", function() {
before (done) -> before(function(done) {
@content = "thread message" this.content = "thread message";
@new_content = "updated thread message" this.new_content = "updated thread message";
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, @message) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, message) => {
expect(error).to.be.null this.message = message;
expect(response.statusCode).to.equal 201 expect(error).to.be.null;
expect(@message.id).to.exist expect(response.statusCode).to.equal(201);
expect(@message.content).to.equal @content expect(this.message.id).to.exist;
ChatClient.editMessage @project_id, @thread_id, @message.id, @new_content, (error, response, @new_message) => expect(this.message.content).to.equal(this.content);
expect(error).to.be.null return ChatClient.editMessage(this.project_id, this.thread_id, this.message.id, this.new_content, (error, response, new_message) => {
expect(response.statusCode).to.equal 204 this.new_message = new_message;
done() expect(error).to.be.null;
expect(response.statusCode).to.equal(204);
return done();
});
});
});
it "should then list the updated message in the threads", (done) -> return it("should then list the updated message in the threads", function(done) {
ChatClient.getThreads @project_id, (error, response, threads) => return ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(threads[@thread_id].messages.length).to.equal 1 expect(threads[this.thread_id].messages.length).to.equal(1);
expect(threads[@thread_id].messages[0].content).to.equal @new_content expect(threads[this.thread_id].messages[0].content).to.equal(this.new_content);
done() return done();
});
});
});
});

View file

@ -1,64 +1,79 @@
{ObjectId} = require "../../../app/js/mongojs" /*
expect = require("chai").expect * decaffeinate suggestions:
async = require "async" * DS102: Remove unnecessary code created because of implicit returns
crypto = require "crypto" * 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" const ChatClient = require("./helpers/ChatClient");
ChatApp = require "./helpers/ChatApp" const ChatApp = require("./helpers/ChatApp");
describe "Getting messages", -> describe("Getting messages", function() {
before (done) -> before(function(done) {
@user_id1 = ObjectId().toString() this.user_id1 = ObjectId().toString();
@user_id2 = ObjectId().toString() this.user_id2 = ObjectId().toString();
@content1 = "foo bar" this.content1 = "foo bar";
@content2 = "hello world" this.content2 = "hello world";
ChatApp.ensureRunning done return ChatApp.ensureRunning(done);
});
describe "globally", -> describe("globally", function() {
before (done) -> before(function(done) {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
async.series [ return async.series([
(cb) => ChatClient.sendGlobalMessage @project_id, @user_id1, @content1, cb cb => ChatClient.sendGlobalMessage(this.project_id, this.user_id1, this.content1, cb),
(cb) => ChatClient.sendGlobalMessage @project_id, @user_id2, @content2, cb cb => ChatClient.sendGlobalMessage(this.project_id, this.user_id2, this.content2, cb)
], done ], done);
});
it "should contain the messages and populated users when getting the messages", (done) -> return it("should contain the messages and populated users when getting the messages", function(done) {
ChatClient.getGlobalMessages @project_id, (error, response, messages) => return ChatClient.getGlobalMessages(this.project_id, (error, response, messages) => {
expect(messages.length).to.equal 2 expect(messages.length).to.equal(2);
messages.reverse() messages.reverse();
expect(messages[0].content).to.equal @content1 expect(messages[0].content).to.equal(this.content1);
expect(messages[0].user_id).to.equal @user_id1 expect(messages[0].user_id).to.equal(this.user_id1);
expect(messages[1].content).to.equal @content2 expect(messages[1].content).to.equal(this.content2);
expect(messages[1].user_id).to.equal @user_id2 expect(messages[1].user_id).to.equal(this.user_id2);
done() return done();
});
});
});
describe "from all the threads", -> return describe("from all the threads", function() {
before (done) -> before(function(done) {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
@thread_id1 = ObjectId().toString() this.thread_id1 = ObjectId().toString();
@thread_id2 = ObjectId().toString() this.thread_id2 = ObjectId().toString();
async.series [ return async.series([
(cb) => ChatClient.sendMessage @project_id, @thread_id1, @user_id1, "one", cb cb => ChatClient.sendMessage(this.project_id, this.thread_id1, this.user_id1, "one", cb),
(cb) => ChatClient.sendMessage @project_id, @thread_id2, @user_id2, "two", cb cb => ChatClient.sendMessage(this.project_id, this.thread_id2, this.user_id2, "two", cb),
(cb) => ChatClient.sendMessage @project_id, @thread_id1, @user_id1, "three", cb cb => ChatClient.sendMessage(this.project_id, this.thread_id1, this.user_id1, "three", cb),
(cb) => ChatClient.sendMessage @project_id, @thread_id2, @user_id2, "four", cb cb => ChatClient.sendMessage(this.project_id, this.thread_id2, this.user_id2, "four", cb)
], done ], done);
});
it "should contain a dictionary of threads with messages with populated users", (done) -> return it("should contain a dictionary of threads with messages with populated users", function(done) {
ChatClient.getThreads @project_id, (error, response, threads) => return ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(Object.keys(threads).length).to.equal 2 expect(Object.keys(threads).length).to.equal(2);
thread1 = threads[@thread_id1] const thread1 = threads[this.thread_id1];
expect(thread1.messages.length).to.equal 2 expect(thread1.messages.length).to.equal(2);
thread2 = threads[@thread_id2] const thread2 = threads[this.thread_id2];
expect(thread2.messages.length).to.equal 2 expect(thread2.messages.length).to.equal(2);
expect(thread1.messages[0].content).to.equal "one" expect(thread1.messages[0].content).to.equal("one");
expect(thread1.messages[0].user_id).to.equal @user_id1 expect(thread1.messages[0].user_id).to.equal(this.user_id1);
expect(thread1.messages[1].content).to.equal "three" expect(thread1.messages[1].content).to.equal("three");
expect(thread1.messages[1].user_id).to.equal @user_id1 expect(thread1.messages[1].user_id).to.equal(this.user_id1);
expect(thread2.messages[0].content).to.equal "two" expect(thread2.messages[0].content).to.equal("two");
expect(thread2.messages[0].user_id).to.equal @user_id2 expect(thread2.messages[0].user_id).to.equal(this.user_id2);
expect(thread2.messages[1].content).to.equal "four" expect(thread2.messages[1].content).to.equal("four");
expect(thread2.messages[1].user_id).to.equal @user_id2 expect(thread2.messages[1].user_id).to.equal(this.user_id2);
done() return done();
});
});
});
});

View file

@ -1,72 +1,97 @@
{ObjectId} = require "../../../app/js/mongojs" /*
expect = require("chai").expect * decaffeinate suggestions:
crypto = require "crypto" * 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" const ChatClient = require("./helpers/ChatClient");
ChatApp = require "./helpers/ChatApp" const ChatApp = require("./helpers/ChatApp");
describe "Resolving a thread", -> describe("Resolving a thread", function() {
before (done) -> before(function(done) {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
@user_id = ObjectId().toString() this.user_id = ObjectId().toString();
ChatApp.ensureRunning done return ChatApp.ensureRunning(done);
});
describe "with a resolved thread", -> describe("with a resolved thread", function() {
before (done) -> before(function(done) {
@thread_id = ObjectId().toString() this.thread_id = ObjectId().toString();
@content = "resolved message" this.content = "resolved message";
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 201 expect(response.statusCode).to.equal(201);
ChatClient.resolveThread @project_id, @thread_id, @user_id, (error, response, body) => return ChatClient.resolveThread(this.project_id, this.thread_id, this.user_id, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 204 expect(response.statusCode).to.equal(204);
done() return done();
});
});
});
it "should then list the thread as resolved", (done) -> return it("should then list the thread as resolved", function(done) {
ChatClient.getThreads @project_id, (error, response, threads) => return ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(threads[@thread_id].resolved).to.equal true expect(threads[this.thread_id].resolved).to.equal(true);
expect(threads[@thread_id].resolved_by_user_id).to.equal @user_id expect(threads[this.thread_id].resolved_by_user_id).to.equal(this.user_id);
resolved_at = new Date(threads[@thread_id].resolved_at) const resolved_at = new Date(threads[this.thread_id].resolved_at);
expect(new Date() - resolved_at).to.be.below 1000 expect(new Date() - resolved_at).to.be.below(1000);
done() return done();
});
});
});
describe "when a thread is not resolved", -> describe("when a thread is not resolved", function() {
before (done) -> before(function(done) {
@thread_id = ObjectId().toString() this.thread_id = ObjectId().toString();
@content = "open message" this.content = "open message";
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 201 expect(response.statusCode).to.equal(201);
done() return done();
});
});
it "should not list the thread as resolved", (done) -> return it("should not list the thread as resolved", function(done) {
ChatClient.getThreads @project_id, (error, response, threads) => return ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(threads[@thread_id].resolved).to.be.undefined expect(threads[this.thread_id].resolved).to.be.undefined;
done() return done();
});
});
});
describe "when a thread is resolved then reopened", -> return describe("when a thread is resolved then reopened", function() {
before (done) -> before(function(done) {
@thread_id = ObjectId().toString() this.thread_id = ObjectId().toString();
@content = "resolved message" this.content = "resolved message";
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 201 expect(response.statusCode).to.equal(201);
ChatClient.resolveThread @project_id, @thread_id, @user_id, (error, response, body) => return ChatClient.resolveThread(this.project_id, this.thread_id, this.user_id, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 204 expect(response.statusCode).to.equal(204);
ChatClient.reopenThread @project_id, @thread_id, (error, response, body) => return ChatClient.reopenThread(this.project_id, this.thread_id, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 204 expect(response.statusCode).to.equal(204);
done() return done();
});
});
});
});
it "should not list the thread as resolved", (done) -> return it("should not list the thread as resolved", function(done) {
ChatClient.getThreads @project_id, (error, response, threads) => return ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(threads[@thread_id].resolved).to.be.undefined expect(threads[this.thread_id].resolved).to.be.undefined;
done() return done();
});
});
});
});

View file

@ -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" const ChatClient = require("./helpers/ChatClient");
ChatApp = require "./helpers/ChatApp" const ChatApp = require("./helpers/ChatApp");
describe "Sending a message", -> describe("Sending a message", function() {
before (done) -> before(done => ChatApp.ensureRunning(done));
ChatApp.ensureRunning done
describe "globally", -> describe("globally", function() {
before (done) -> before(function(done) {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
@user_id = ObjectId().toString() this.user_id = ObjectId().toString();
@content = "global message" this.content = "global message";
ChatClient.sendGlobalMessage @project_id, @user_id, @content, (error, response, body) => return ChatClient.sendGlobalMessage(this.project_id, this.user_id, this.content, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 201 expect(response.statusCode).to.equal(201);
expect(body.content).to.equal @content expect(body.content).to.equal(this.content);
expect(body.user_id).to.equal @user_id expect(body.user_id).to.equal(this.user_id);
expect(body.room_id).to.equal @project_id expect(body.room_id).to.equal(this.project_id);
done() return done();
});
});
it "should then list the message in the project messages", (done) -> return it("should then list the message in the project messages", function(done) {
ChatClient.getGlobalMessages @project_id, (error, response, messages) => return ChatClient.getGlobalMessages(this.project_id, (error, response, messages) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(messages.length).to.equal 1 expect(messages.length).to.equal(1);
expect(messages[0].content).to.equal @content expect(messages[0].content).to.equal(this.content);
done() return done();
});
});
});
describe "to a thread", -> describe("to a thread", function() {
before (done) -> before(function(done) {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
@user_id = ObjectId().toString() this.user_id = ObjectId().toString();
@thread_id = ObjectId().toString() this.thread_id = ObjectId().toString();
@content = "thread message" this.content = "thread message";
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 201 expect(response.statusCode).to.equal(201);
expect(body.content).to.equal @content expect(body.content).to.equal(this.content);
expect(body.user_id).to.equal @user_id expect(body.user_id).to.equal(this.user_id);
expect(body.room_id).to.equal @project_id expect(body.room_id).to.equal(this.project_id);
done() return done();
});
});
it "should then list the message in the threads", (done) -> it("should then list the message in the threads", function(done) {
ChatClient.getThreads @project_id, (error, response, threads) => return ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(threads[@thread_id].messages.length).to.equal 1 expect(threads[this.thread_id].messages.length).to.equal(1);
expect(threads[@thread_id].messages[0].content).to.equal @content expect(threads[this.thread_id].messages[0].content).to.equal(this.content);
done() return done();
});
});
it "should not appear in the global messages", (done) -> return it("should not appear in the global messages", function(done) {
ChatClient.getGlobalMessages @project_id, (error, response, messages) => return ChatClient.getGlobalMessages(this.project_id, (error, response, messages) => {
expect(error).to.be.null expect(error).to.be.null;
expect(response.statusCode).to.equal 200 expect(response.statusCode).to.equal(200);
expect(messages.length).to.equal 0 expect(messages.length).to.equal(0);
done() return done();
});
});
});
describe "failure cases", -> return describe("failure cases", function() {
before () -> before(function() {
@project_id = ObjectId().toString() this.project_id = ObjectId().toString();
@user_id = ObjectId().toString() this.user_id = ObjectId().toString();
@thread_id = ObjectId().toString() return this.thread_id = ObjectId().toString();
});
describe "with a malformed user_id", -> describe("with a malformed user_id", () =>
it "should return a graceful error", (done) -> it("should return a graceful error", function(done) {
ChatClient.sendMessage @project_id, @thread_id, "malformed-user", "content", (error, response, body) => return ChatClient.sendMessage(this.project_id, this.thread_id, "malformed-user", "content", (error, response, body) => {
expect(response.statusCode).to.equal 400 expect(response.statusCode).to.equal(400);
expect(body).to.equal "Invalid user_id" expect(body).to.equal("Invalid user_id");
done() return done();
});
})
);
describe "with a malformed project_id", -> describe("with a malformed project_id", () =>
it "should return a graceful error", (done) -> it("should return a graceful error", function(done) {
ChatClient.sendMessage "malformed-project", @thread_id, @user_id, "content", (error, response, body) => return ChatClient.sendMessage("malformed-project", this.thread_id, this.user_id, "content", (error, response, body) => {
expect(response.statusCode).to.equal 400 expect(response.statusCode).to.equal(400);
expect(body).to.equal "Invalid project_id" expect(body).to.equal("Invalid project_id");
done() return done();
});
})
);
describe "with a malformed thread_id", -> describe("with a malformed thread_id", () =>
it "should return a graceful error", (done) -> it("should return a graceful error", function(done) {
ChatClient.sendMessage @project_id, "malformed-thread-id", @user_id, "content", (error, response, body) => return ChatClient.sendMessage(this.project_id, "malformed-thread-id", this.user_id, "content", (error, response, body) => {
expect(response.statusCode).to.equal 400 expect(response.statusCode).to.equal(400);
expect(body).to.equal "Invalid thread_id" expect(body).to.equal("Invalid thread_id");
done() return done();
});
})
);
describe "with no content", -> describe("with no content", () =>
it "should return a graceful error", (done) -> it("should return a graceful error", function(done) {
ChatClient.sendMessage @project_id, @thread_id, @user_id, null, (error, response, body) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, null, (error, response, body) => {
expect(response.statusCode).to.equal 400 expect(response.statusCode).to.equal(400);
expect(body).to.equal "No content provided" expect(body).to.equal("No content provided");
done() return done();
});
})
);
describe "with very long content", -> return describe("with very long content", () =>
it "should return a graceful error", (done) -> it("should return a graceful error", function(done) {
content = new Buffer(10240).toString("hex") const content = new Buffer(10240).toString("hex");
ChatClient.sendMessage @project_id, @thread_id, @user_id, content, (error, response, body) => return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, content, (error, response, body) => {
expect(response.statusCode).to.equal 400 expect(response.statusCode).to.equal(400);
expect(body).to.equal "Content too long (> 10240 bytes)" expect(body).to.equal("Content too long (> 10240 bytes)");
done() return done();
});
})
);
});
});

View file

@ -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 = module.exports = {
running: false running: false,
initing: false initing: false,
callbacks: [] callbacks: [],
ensureRunning: (callback = (error) ->) -> ensureRunning(callback) {
if @running if (callback == null) { callback = function(error) {}; }
return callback() if (this.running) {
else if @initing return callback();
@callbacks.push callback } else if (this.initing) {
else return this.callbacks.push(callback);
@initing = true } else {
@callbacks.push callback this.initing = true;
app.listen 3010, "localhost", (error) => this.callbacks.push(callback);
throw error if error? return app.listen(3010, "localhost", error => {
@running = true if (error != null) { throw error; }
for callback in @callbacks this.running = true;
callback() return (() => {
const result = [];
for (callback of Array.from(this.callbacks)) {
result.push(callback());
}
return result;
})();
});
}
}
};

View file

@ -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 = module.exports = {
sendGlobalMessage: (project_id, user_id, content, callback) -> sendGlobalMessage(project_id, user_id, content, callback) {
request.post { return request.post({
url: "/project/#{project_id}/messages" 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",
json: { json: {
user_id: user_id user_id,
content
} }
}, callback }, callback);
},
reopenThread: (project_id, thread_id, callback) -> getGlobalMessages(project_id, callback) {
request.post { return request.get({
url: "/project/#{project_id}/thread/#{thread_id}/reopen", url: `/project/${project_id}/messages`,
}, callback json: true
}, callback);
},
deleteThread: (project_id, thread_id, callback) -> sendMessage(project_id, thread_id, user_id, content, callback) {
request.del { return request.post({
url: "/project/#{project_id}/thread/#{thread_id}", url: `/project/${project_id}/thread/${thread_id}/messages`,
}, callback json: {
user_id,
content
}
}, callback);
},
editMessage: (project_id, thread_id, message_id, content, callback) -> getThreads(project_id, callback) {
request.post { return request.get({
url: "/project/#{project_id}/thread/#{thread_id}/messages/#{message_id}/edit" url: `/project/${project_id}/threads`,
json: json: true
content: content }, callback);
}, callback },
deleteMessage: (project_id, thread_id, message_id, callback) -> resolveThread(project_id, thread_id, user_id, callback) {
request.del { return request.post({
url: "/project/#{project_id}/thread/#{thread_id}/messages/#{message_id}", url: `/project/${project_id}/thread/${thread_id}/resolve`,
}, callback json: {
user_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);
}
};