decaf cleanup: remove unnecessary code created because of implicit returns

GitOrigin-RevId: 9717a14d34a662c9740aa50446d0699c6afd3222
This commit is contained in:
Tim Alby 2022-01-07 11:41:23 +01:00 committed by Copybot
parent d56b49d529
commit 0a0722a8f8
15 changed files with 191 additions and 298 deletions

View file

@ -1,6 +1,5 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
@ -31,7 +30,7 @@ if (!module.parent) {
logger.fatal({ err }, `Cannot bind to ${host}:${port}. Exiting.`)
process.exit(1)
}
return logger.info(`Chat starting up, listening on ${host}:${port}`)
logger.info(`Chat starting up, listening on ${host}:${port}`)
})
})
.catch(err => {

View file

@ -3,7 +3,6 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/

View file

@ -2,7 +2,6 @@
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -18,7 +17,7 @@ module.exports = MessageHttpController = {
MAX_MESSAGE_LENGTH: 10 * 1024, // 10kb, about 1,500 words
getGlobalMessages(req, res, next) {
return MessageHttpController._getMessages(
MessageHttpController._getMessages(
ThreadManager.GLOBAL_THREAD,
req,
res,
@ -27,7 +26,7 @@ module.exports = MessageHttpController = {
},
sendGlobalMessage(req, res, next) {
return MessageHttpController._sendMessage(
MessageHttpController._sendMessage(
ThreadManager.GLOBAL_THREAD,
req,
res,
@ -36,23 +35,18 @@ module.exports = MessageHttpController = {
},
sendThreadMessage(req, res, next) {
return MessageHttpController._sendMessage(
req.params.threadId,
req,
res,
next
)
MessageHttpController._sendMessage(req.params.threadId, req, res, next)
},
getAllThreads(req, res, next) {
const { projectId } = req.params
logger.log({ projectId }, 'getting all threads')
return ThreadManager.findAllThreadRooms(projectId, function (error, rooms) {
ThreadManager.findAllThreadRooms(projectId, function (error, rooms) {
if (error != null) {
return next(error)
}
const roomIds = rooms.map(r => r._id)
return MessageManager.findAllMessagesInRooms(
MessageManager.findAllMessagesInRooms(
roomIds,
function (error, messages) {
if (error != null) {
@ -62,7 +56,7 @@ module.exports = MessageHttpController = {
rooms,
messages
)
return res.json(threads)
res.json(threads)
}
)
})
@ -72,62 +66,53 @@ module.exports = MessageHttpController = {
const { projectId, threadId } = req.params
const { user_id: userId } = req.body
logger.log({ userId, projectId, threadId }, 'marking thread as resolved')
return ThreadManager.resolveThread(
projectId,
threadId,
userId,
function (error) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
ThreadManager.resolveThread(projectId, threadId, userId, function (error) {
if (error != null) {
return next(error)
}
)
res.sendStatus(204)
})
}, // No content
reopenThread(req, res, next) {
const { projectId, threadId } = req.params
logger.log({ projectId, threadId }, 'reopening thread')
return ThreadManager.reopenThread(projectId, threadId, function (error) {
ThreadManager.reopenThread(projectId, threadId, function (error) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
res.sendStatus(204)
})
}, // No content
deleteThread(req, res, next) {
const { projectId, threadId } = req.params
logger.log({ projectId, threadId }, 'deleting thread')
return ThreadManager.deleteThread(
projectId,
threadId,
function (error, roomId) {
ThreadManager.deleteThread(projectId, threadId, function (error, roomId) {
if (error != null) {
return next(error)
}
MessageManager.deleteAllMessagesInRoom(roomId, function (error) {
if (error != null) {
return next(error)
}
return MessageManager.deleteAllMessagesInRoom(roomId, function (error) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
})
}
)
res.sendStatus(204)
})
})
}, // No content
editMessage(req, res, next) {
const { content } = req != null ? req.body : undefined
const { projectId, threadId, messageId } = req.params
logger.log({ projectId, threadId, messageId, content }, 'editing message')
return ThreadManager.findOrCreateThread(
ThreadManager.findOrCreateThread(
projectId,
threadId,
function (error, room) {
if (error != null) {
return next(error)
}
return MessageManager.updateMessage(
MessageManager.updateMessage(
room._id,
messageId,
content,
@ -136,7 +121,7 @@ module.exports = MessageHttpController = {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
res.sendStatus(204)
}
)
}
@ -146,21 +131,21 @@ module.exports = MessageHttpController = {
deleteMessage(req, res, next) {
const { projectId, threadId, messageId } = req.params
logger.log({ projectId, threadId, messageId }, 'deleting message')
return ThreadManager.findOrCreateThread(
ThreadManager.findOrCreateThread(
projectId,
threadId,
function (error, room) {
if (error != null) {
return next(error)
}
return MessageManager.deleteMessage(
MessageManager.deleteMessage(
room._id,
messageId,
function (error, message) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
res.sendStatus(204)
}
)
}
@ -185,14 +170,14 @@ module.exports = MessageHttpController = {
{ clientThreadId, projectId, userId, content },
'new message received'
)
return ThreadManager.findOrCreateThread(
ThreadManager.findOrCreateThread(
projectId,
clientThreadId,
function (error, thread) {
if (error != null) {
return next(error)
}
return MessageManager.createMessage(
MessageManager.createMessage(
thread._id,
userId,
content,
@ -203,7 +188,7 @@ module.exports = MessageHttpController = {
}
message = MessageFormatter.formatMessageForClientSide(message)
message.room_id = projectId
return res.status(201).send(message)
res.status(201).send(message)
}
)
}
@ -227,7 +212,7 @@ module.exports = MessageHttpController = {
{ limit, before, projectId, clientThreadId },
'get message request received'
)
return ThreadManager.findOrCreateThread(
ThreadManager.findOrCreateThread(
projectId,
clientThreadId,
function (error, thread) {
@ -239,7 +224,7 @@ module.exports = MessageHttpController = {
{ limit, before, projectId, clientThreadId, threadObjectId },
'found or created thread'
)
return MessageManager.getMessages(
MessageManager.getMessages(
threadObjectId,
limit,
before,
@ -249,7 +234,7 @@ module.exports = MessageHttpController = {
}
messages = MessageFormatter.formatMessagesForClientSide(messages)
logger.log({ projectId, messages }, 'got messages')
return res.status(200).send(messages)
res.status(200).send(messages)
}
)
}

View file

@ -2,7 +2,6 @@
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/

View file

@ -2,7 +2,6 @@
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -117,7 +116,7 @@ module.exports = ThreadManager = {
if (callback == null) {
callback = function () {}
}
return this.findOrCreateThread(projectId, threadId, function (error, room) {
this.findOrCreateThread(projectId, threadId, function (error, room) {
if (error != null) {
return callback(error)
}
@ -129,7 +128,7 @@ module.exports = ThreadManager = {
if (error != null) {
return callback(error)
}
return callback(null, room._id)
callback(null, room._id)
}
)
})

View file

@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const MessageHttpController = require('./Features/Messages/MessageHttpController')
const { ObjectId } = require('./mongodb')
@ -12,17 +5,17 @@ module.exports = {
route(app) {
app.param('projectId', function (req, res, next, projectId) {
if (ObjectId.isValid(projectId)) {
return next()
next()
} else {
return res.status(400).send('Invalid projectId')
res.status(400).send('Invalid projectId')
}
})
app.param('threadId', function (req, res, next, threadId) {
if (ObjectId.isValid(threadId)) {
return next()
next()
} else {
return res.status(400).send('Invalid threadId')
res.status(400).send('Invalid threadId')
}
})
@ -73,6 +66,6 @@ module.exports = {
MessageHttpController.deleteThread
)
return app.get('/status', (req, res, next) => res.send('chat is alive'))
app.get('/status', (req, res, next) => res.send('chat is alive'))
},
}

View file

@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const metrics = require('@overleaf/metrics')
metrics.initialize('chat')
const logger = require('@overleaf/logger')

View file

@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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/mongodb')
const { expect } = require('chai')
@ -16,12 +9,12 @@ describe('Deleting a message', function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
this.thread_id = ObjectId().toString()
return ChatApp.ensureRunning(done)
ChatApp.ensureRunning(done)
})
return describe('in a thread', function () {
describe('in a thread', function () {
before(function (done) {
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -30,7 +23,7 @@ describe('Deleting a message', function () {
this.message = message
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -39,14 +32,14 @@ describe('Deleting a message', function () {
this.message = message1
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
return ChatClient.deleteMessage(
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()
done()
}
)
}
@ -55,16 +48,13 @@ describe('Deleting a message', function () {
)
})
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()
}
)
it('should then remove the message from the threads', function (done) {
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)
done()
})
})
})
})

View file

@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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/mongodb')
const { expect } = require('chai')
@ -15,14 +8,14 @@ describe('Deleting a thread', function () {
before(function (done) {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
return ChatApp.ensureRunning(done)
ChatApp.ensureRunning(done)
})
return describe('with a thread that is deleted', function () {
describe('with a thread that is deleted', function () {
before(function (done) {
this.thread_id = ObjectId().toString()
this.content = 'deleted thread message'
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -30,29 +23,26 @@ describe('Deleting a thread', function () {
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
return ChatClient.deleteThread(
ChatClient.deleteThread(
this.project_id,
this.thread_id,
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(204)
return done()
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()
}
)
it('should then not list the thread for the project', function (done) {
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)
done()
})
})
})
})

View file

@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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/mongodb')
const { expect } = require('chai')
@ -16,14 +9,14 @@ describe('Editing a message', function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
this.thread_id = ObjectId().toString()
return ChatApp.ensureRunning(done)
ChatApp.ensureRunning(done)
})
return describe('in a thread', function () {
describe('in a thread', function () {
before(function (done) {
this.content = 'thread message'
this.new_content = 'updated thread message'
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -34,7 +27,7 @@ describe('Editing a message', function () {
expect(response.statusCode).to.equal(201)
expect(this.message.id).to.exist
expect(this.message.content).to.equal(this.content)
return ChatClient.editMessage(
ChatClient.editMessage(
this.project_id,
this.thread_id,
this.message.id,
@ -43,26 +36,23 @@ describe('Editing a message', function () {
this.new_message = newMessage
expect(error).to.be.null
expect(response.statusCode).to.equal(204)
return done()
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()
}
)
it('should then list the updated message in the threads', function (done) {
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
)
done()
})
})
})
})

View file

@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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/mongodb')
const { expect } = require('chai')
const async = require('async')
@ -18,13 +11,13 @@ describe('Getting messages', function () {
this.user_id2 = ObjectId().toString()
this.content1 = 'foo bar'
this.content2 = 'hello world'
return ChatApp.ensureRunning(done)
ChatApp.ensureRunning(done)
})
describe('globally', function () {
before(function (done) {
this.project_id = ObjectId().toString()
return async.series(
async.series(
[
cb =>
ChatClient.sendGlobalMessage(
@ -45,8 +38,8 @@ describe('Getting messages', function () {
)
})
return it('should contain the messages and populated users when getting the messages', function (done) {
return ChatClient.getGlobalMessages(
it('should contain the messages and populated users when getting the messages', function (done) {
ChatClient.getGlobalMessages(
this.project_id,
(error, response, messages) => {
if (error) return done(error)
@ -56,18 +49,18 @@ describe('Getting messages', function () {
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()
done()
}
)
})
})
return describe('from all the threads', function () {
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(
async.series(
[
cb =>
ChatClient.sendMessage(
@ -106,29 +99,26 @@ describe('Getting messages', function () {
)
})
return it('should contain a dictionary of threads with messages with populated users', function (done) {
return ChatClient.getThreads(
this.project_id,
(error, response, threads) => {
if (error) return done(error)
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)
it('should contain a dictionary of threads with messages with populated users', function (done) {
ChatClient.getThreads(this.project_id, (error, response, threads) => {
if (error) return done(error)
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(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()
}
)
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)
done()
})
})
})
})

View file

@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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/mongodb')
const { expect } = require('chai')
@ -15,14 +8,14 @@ describe('Resolving a thread', function () {
before(function (done) {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
return ChatApp.ensureRunning(done)
ChatApp.ensureRunning(done)
})
describe('with a resolved thread', function () {
before(function (done) {
this.thread_id = ObjectId().toString()
this.content = 'resolved message'
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -30,35 +23,32 @@ describe('Resolving a thread', function () {
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
return ChatClient.resolveThread(
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()
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 resolvedAt = new Date(threads[this.thread_id].resolved_at)
expect(new Date() - resolvedAt).to.be.below(1000)
return done()
}
)
it('should then list the thread as resolved', function (done) {
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 resolvedAt = new Date(threads[this.thread_id].resolved_at)
expect(new Date() - resolvedAt).to.be.below(1000)
done()
})
})
})
@ -66,7 +56,7 @@ describe('Resolving a thread', function () {
before(function (done) {
this.thread_id = ObjectId().toString()
this.content = 'open message'
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -74,29 +64,26 @@ describe('Resolving a thread', function () {
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
return done()
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()
}
)
it('should not list the thread as resolved', function (done) {
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
done()
})
})
})
return describe('when a thread is resolved then reopened', function () {
describe('when a thread is resolved then reopened', function () {
before(function (done) {
this.thread_id = ObjectId().toString()
this.content = 'resolved message'
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -104,20 +91,20 @@ describe('Resolving a thread', function () {
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
return ChatClient.resolveThread(
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(
ChatClient.reopenThread(
this.project_id,
this.thread_id,
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(204)
return done()
done()
}
)
}
@ -126,16 +113,13 @@ describe('Resolving a thread', function () {
)
})
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()
}
)
it('should not list the thread as resolved', function (done) {
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
done()
})
})
})
})

View file

@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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/mongodb')
const { expect } = require('chai')
@ -13,7 +6,7 @@ const ChatApp = require('./helpers/ChatApp')
describe('Sending a message', function () {
before(function (done) {
return ChatApp.ensureRunning(done)
ChatApp.ensureRunning(done)
})
describe('globally', function () {
@ -21,7 +14,7 @@ describe('Sending a message', function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
this.content = 'global message'
return ChatClient.sendGlobalMessage(
ChatClient.sendGlobalMessage(
this.project_id,
this.user_id,
this.content,
@ -31,20 +24,20 @@ describe('Sending a message', function () {
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()
done()
}
)
})
return it('should then list the message in the project messages', function (done) {
return ChatClient.getGlobalMessages(
it('should then list the message in the project messages', function (done) {
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()
done()
}
)
})
@ -56,7 +49,7 @@ describe('Sending a message', function () {
this.user_id = ObjectId().toString()
this.thread_id = ObjectId().toString()
this.content = 'thread message'
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -67,49 +60,46 @@ describe('Sending a message', function () {
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()
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()
}
)
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
)
done()
})
})
return it('should not appear in the global messages', function (done) {
return ChatClient.getGlobalMessages(
it('should not appear in the global messages', function (done) {
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()
done()
}
)
})
})
return describe('failure cases', function () {
describe('failure cases', function () {
before(function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
return (this.thread_id = ObjectId().toString())
this.thread_id = ObjectId().toString()
})
describe('with a malformed user_id', function () {
return it('should return a graceful error', function (done) {
return ChatClient.sendMessage(
it('should return a graceful error', function (done) {
ChatClient.sendMessage(
this.project_id,
this.thread_id,
'malformed-user',
@ -118,15 +108,15 @@ describe('Sending a message', function () {
if (error) return done(error)
expect(response.statusCode).to.equal(400)
expect(body).to.equal('Invalid userId')
return done()
done()
}
)
})
})
describe('with a malformed project_id', function () {
return it('should return a graceful error', function (done) {
return ChatClient.sendMessage(
it('should return a graceful error', function (done) {
ChatClient.sendMessage(
'malformed-project',
this.thread_id,
this.user_id,
@ -135,15 +125,15 @@ describe('Sending a message', function () {
if (error) return done(error)
expect(response.statusCode).to.equal(400)
expect(body).to.equal('Invalid projectId')
return done()
done()
}
)
})
})
describe('with a malformed thread_id', function () {
return it('should return a graceful error', function (done) {
return ChatClient.sendMessage(
it('should return a graceful error', function (done) {
ChatClient.sendMessage(
this.project_id,
'malformed-thread-id',
this.user_id,
@ -152,15 +142,15 @@ describe('Sending a message', function () {
if (error) return done(error)
expect(response.statusCode).to.equal(400)
expect(body).to.equal('Invalid threadId')
return done()
done()
}
)
})
})
describe('with no content', function () {
return it('should return a graceful error', function (done) {
return ChatClient.sendMessage(
it('should return a graceful error', function (done) {
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -169,16 +159,16 @@ describe('Sending a message', function () {
if (error) return done(error)
expect(response.statusCode).to.equal(400)
expect(body).to.equal('No content provided')
return done()
done()
}
)
})
})
return describe('with very long content', function () {
return it('should return a graceful error', function (done) {
describe('with very long content', function () {
it('should return a graceful error', function (done) {
const content = '-'.repeat(10 * 1024 + 1)
return ChatClient.sendMessage(
ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
@ -187,7 +177,7 @@ describe('Sending a message', function () {
if (error) return done(error)
expect(response.statusCode).to.equal(400)
expect(body).to.equal('Content too long (> 10240 bytes)')
return done()
done()
}
)
})

View file

@ -3,7 +3,6 @@
/*
* 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
@ -27,7 +26,7 @@ module.exports = {
this.initing = true
this.callbacks.push(callback)
waitForDb().then(() => {
return app.listen(3010, 'localhost', error => {
app.listen(3010, 'localhost', error => {
if (error != null) {
throw error
}

View file

@ -1,17 +1,10 @@
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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(projectId, userId, content, callback) {
return request.post(
request.post(
{
url: `/project/${projectId}/messages`,
json: {
@ -24,7 +17,7 @@ module.exports = {
},
getGlobalMessages(projectId, callback) {
return request.get(
request.get(
{
url: `/project/${projectId}/messages`,
json: true,
@ -34,7 +27,7 @@ module.exports = {
},
sendMessage(projectId, threadId, userId, content, callback) {
return request.post(
request.post(
{
url: `/project/${projectId}/thread/${threadId}/messages`,
json: {
@ -47,7 +40,7 @@ module.exports = {
},
getThreads(projectId, callback) {
return request.get(
request.get(
{
url: `/project/${projectId}/threads`,
json: true,
@ -57,7 +50,7 @@ module.exports = {
},
resolveThread(projectId, threadId, userId, callback) {
return request.post(
request.post(
{
url: `/project/${projectId}/thread/${threadId}/resolve`,
json: {
@ -69,7 +62,7 @@ module.exports = {
},
reopenThread(projectId, threadId, callback) {
return request.post(
request.post(
{
url: `/project/${projectId}/thread/${threadId}/reopen`,
},
@ -78,7 +71,7 @@ module.exports = {
},
deleteThread(projectId, threadId, callback) {
return request.del(
request.del(
{
url: `/project/${projectId}/thread/${threadId}`,
},
@ -87,7 +80,7 @@ module.exports = {
},
editMessage(projectId, threadId, messageId, content, callback) {
return request.post(
request.post(
{
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
json: {
@ -99,7 +92,7 @@ module.exports = {
},
deleteMessage(projectId, threadId, messageId, callback) {
return request.del(
request.del(
{
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}`,
},