mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
remove uses of this in tests
GitOrigin-RevId: 2eea02c91358a7bb5e1d32c8990f793d6f794ac4
This commit is contained in:
parent
5798011bce
commit
d5c574360f
6 changed files with 167 additions and 190 deletions
|
@ -5,46 +5,43 @@ const ChatClient = require('./helpers/ChatClient')
|
||||||
const ChatApp = require('./helpers/ChatApp')
|
const ChatApp = require('./helpers/ChatApp')
|
||||||
|
|
||||||
describe('Deleting a message', async function () {
|
describe('Deleting a message', async function () {
|
||||||
|
const projectId = ObjectId().toString()
|
||||||
|
const userId = ObjectId().toString()
|
||||||
|
const threadId = ObjectId().toString()
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.project_id = ObjectId().toString()
|
|
||||||
this.user_id = ObjectId().toString()
|
|
||||||
this.thread_id = ObjectId().toString()
|
|
||||||
await ChatApp.ensureRunning()
|
await ChatApp.ensureRunning()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('in a thread', async function () {
|
describe('in a thread', async function () {
|
||||||
before(async function () {
|
before(async function () {
|
||||||
const { response, body: message } = await ChatClient.sendMessage(
|
const { response } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
'first message'
|
'first message'
|
||||||
)
|
)
|
||||||
this.message = message
|
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
const { response: response2, body: message2 } =
|
const { response: response2, body: message } =
|
||||||
await ChatClient.sendMessage(
|
await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
'deleted message'
|
'deleted message'
|
||||||
)
|
)
|
||||||
this.message = message2
|
|
||||||
expect(response2.statusCode).to.equal(201)
|
expect(response2.statusCode).to.equal(201)
|
||||||
const { response: response3 } = await ChatClient.deleteMessage(
|
const { response: response3 } = await ChatClient.deleteMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.message.id
|
message.id
|
||||||
)
|
)
|
||||||
expect(response3.statusCode).to.equal(204)
|
expect(response3.statusCode).to.equal(204)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should then remove the message from the threads', async function () {
|
it('should then remove the message from the threads', async function () {
|
||||||
const { response, body: threads } = await ChatClient.getThreads(
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
||||||
this.project_id
|
|
||||||
)
|
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(threads[this.thread_id].messages.length).to.equal(1)
|
expect(threads[threadId].messages.length).to.equal(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,34 +5,32 @@ const ChatClient = require('./helpers/ChatClient')
|
||||||
const ChatApp = require('./helpers/ChatApp')
|
const ChatApp = require('./helpers/ChatApp')
|
||||||
|
|
||||||
describe('Deleting a thread', async function () {
|
describe('Deleting a thread', async function () {
|
||||||
|
const projectId = ObjectId().toString()
|
||||||
|
const userId = ObjectId().toString()
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.project_id = ObjectId().toString()
|
|
||||||
this.user_id = ObjectId().toString()
|
|
||||||
await ChatApp.ensureRunning()
|
await ChatApp.ensureRunning()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with a thread that is deleted', async function () {
|
describe('with a thread that is deleted', async function () {
|
||||||
|
const threadId = ObjectId().toString()
|
||||||
|
const content = 'deleted thread message'
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.thread_id = ObjectId().toString()
|
|
||||||
this.content = 'deleted thread message'
|
|
||||||
const { response } = await ChatClient.sendMessage(
|
const { response } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
this.content
|
content
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
const { response: response2 } = await ChatClient.deleteThread(
|
const { response: response2 } = await ChatClient.deleteThread(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id
|
threadId
|
||||||
)
|
)
|
||||||
expect(response2.statusCode).to.equal(204)
|
expect(response2.statusCode).to.equal(204)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should then not list the thread for the project', async function () {
|
it('should then not list the thread for the project', async function () {
|
||||||
const { response, body: threads } = await ChatClient.getThreads(
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
||||||
this.project_id
|
|
||||||
)
|
|
||||||
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)
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,47 +5,40 @@ const ChatClient = require('./helpers/ChatClient')
|
||||||
const ChatApp = require('./helpers/ChatApp')
|
const ChatApp = require('./helpers/ChatApp')
|
||||||
|
|
||||||
describe('Editing a message', async function () {
|
describe('Editing a message', async function () {
|
||||||
|
const projectId = ObjectId().toString()
|
||||||
|
const userId = ObjectId().toString()
|
||||||
|
const threadId = ObjectId().toString()
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.project_id = ObjectId().toString()
|
|
||||||
this.user_id = ObjectId().toString()
|
|
||||||
this.thread_id = ObjectId().toString()
|
|
||||||
await ChatApp.ensureRunning()
|
await ChatApp.ensureRunning()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('in a thread', async function () {
|
describe('in a thread', async function () {
|
||||||
|
const content = 'thread message'
|
||||||
|
const newContent = 'updated thread message'
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.content = 'thread message'
|
|
||||||
this.new_content = 'updated thread message'
|
|
||||||
const { response, body: message } = await ChatClient.sendMessage(
|
const { response, body: message } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
this.content
|
content
|
||||||
)
|
)
|
||||||
this.message = message
|
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
expect(this.message.id).to.exist
|
expect(message.id).to.exist
|
||||||
expect(this.message.content).to.equal(this.content)
|
expect(message.content).to.equal(content)
|
||||||
const { response: response2, body: newMessage } =
|
const { response: response2 } = await ChatClient.editMessage(
|
||||||
await ChatClient.editMessage(
|
projectId,
|
||||||
this.project_id,
|
threadId,
|
||||||
this.thread_id,
|
message.id,
|
||||||
this.message.id,
|
newContent
|
||||||
this.new_content
|
)
|
||||||
)
|
|
||||||
this.new_message = newMessage
|
|
||||||
expect(response2.statusCode).to.equal(204)
|
expect(response2.statusCode).to.equal(204)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should then list the updated message in the threads', async function () {
|
it('should then list the updated message in the threads', async function () {
|
||||||
const { response, body: threads } = await ChatClient.getThreads(
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
||||||
this.project_id
|
|
||||||
)
|
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(threads[this.thread_id].messages.length).to.equal(1)
|
expect(threads[threadId].messages.length).to.equal(1)
|
||||||
expect(threads[this.thread_id].messages[0].content).to.equal(
|
expect(threads[threadId].messages[0].content).to.equal(newContent)
|
||||||
this.new_content
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,100 +5,99 @@ const ChatClient = require('./helpers/ChatClient')
|
||||||
const ChatApp = require('./helpers/ChatApp')
|
const ChatApp = require('./helpers/ChatApp')
|
||||||
|
|
||||||
describe('Getting messages', async function () {
|
describe('Getting messages', async function () {
|
||||||
|
const userId1 = ObjectId().toString()
|
||||||
|
const userId2 = ObjectId().toString()
|
||||||
|
const content1 = 'foo bar'
|
||||||
|
const content2 = 'hello world'
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.user_id1 = ObjectId().toString()
|
|
||||||
this.user_id2 = ObjectId().toString()
|
|
||||||
this.content1 = 'foo bar'
|
|
||||||
this.content2 = 'hello world'
|
|
||||||
await ChatApp.ensureRunning()
|
await ChatApp.ensureRunning()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('globally', async function () {
|
describe('globally', async function () {
|
||||||
|
const projectId = ObjectId().toString()
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.project_id = ObjectId().toString()
|
|
||||||
const { response } = await ChatClient.sendGlobalMessage(
|
const { response } = await ChatClient.sendGlobalMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.user_id1,
|
userId1,
|
||||||
this.content1
|
content1
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
const { response: response2 } = await ChatClient.sendGlobalMessage(
|
const { response: response2 } = await ChatClient.sendGlobalMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.user_id2,
|
userId2,
|
||||||
this.content2
|
content2
|
||||||
)
|
)
|
||||||
expect(response2.statusCode).to.equal(201)
|
expect(response2.statusCode).to.equal(201)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should contain the messages and populated users when getting the messages', async function () {
|
it('should contain the messages and populated users when getting the messages', async function () {
|
||||||
const { response, body: messages } = await ChatClient.getGlobalMessages(
|
const { response, body: messages } = await ChatClient.getGlobalMessages(
|
||||||
this.project_id
|
projectId
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(messages.length).to.equal(2)
|
expect(messages.length).to.equal(2)
|
||||||
messages.reverse()
|
messages.reverse()
|
||||||
expect(messages[0].content).to.equal(this.content1)
|
expect(messages[0].content).to.equal(content1)
|
||||||
expect(messages[0].user_id).to.equal(this.user_id1)
|
expect(messages[0].user_id).to.equal(userId1)
|
||||||
expect(messages[1].content).to.equal(this.content2)
|
expect(messages[1].content).to.equal(content2)
|
||||||
expect(messages[1].user_id).to.equal(this.user_id2)
|
expect(messages[1].user_id).to.equal(userId2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('from all the threads', async function () {
|
describe('from all the threads', async function () {
|
||||||
|
const projectId = ObjectId().toString()
|
||||||
|
const threadId1 = ObjectId().toString()
|
||||||
|
const threadId2 = ObjectId().toString()
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.project_id = ObjectId().toString()
|
|
||||||
this.thread_id1 = ObjectId().toString()
|
|
||||||
this.thread_id2 = ObjectId().toString()
|
|
||||||
const { response } = await ChatClient.sendMessage(
|
const { response } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id1,
|
threadId1,
|
||||||
this.user_id1,
|
userId1,
|
||||||
'one'
|
'one'
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
const { response: response2 } = await ChatClient.sendMessage(
|
const { response: response2 } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id2,
|
threadId2,
|
||||||
this.user_id2,
|
userId2,
|
||||||
'two'
|
'two'
|
||||||
)
|
)
|
||||||
expect(response2.statusCode).to.equal(201)
|
expect(response2.statusCode).to.equal(201)
|
||||||
const { response: response3 } = await ChatClient.sendMessage(
|
const { response: response3 } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id1,
|
threadId1,
|
||||||
this.user_id1,
|
userId1,
|
||||||
'three'
|
'three'
|
||||||
)
|
)
|
||||||
expect(response3.statusCode).to.equal(201)
|
expect(response3.statusCode).to.equal(201)
|
||||||
const { response: response4 } = await ChatClient.sendMessage(
|
const { response: response4 } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id2,
|
threadId2,
|
||||||
this.user_id2,
|
userId2,
|
||||||
'four'
|
'four'
|
||||||
)
|
)
|
||||||
expect(response4.statusCode).to.equal(201)
|
expect(response4.statusCode).to.equal(201)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should contain a dictionary of threads with messages with populated users', async function () {
|
it('should contain a dictionary of threads with messages with populated users', async function () {
|
||||||
const { response, body: threads } = await ChatClient.getThreads(
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
||||||
this.project_id
|
|
||||||
)
|
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(Object.keys(threads).length).to.equal(2)
|
expect(Object.keys(threads).length).to.equal(2)
|
||||||
const thread1 = threads[this.thread_id1]
|
const thread1 = threads[threadId1]
|
||||||
expect(thread1.messages.length).to.equal(2)
|
expect(thread1.messages.length).to.equal(2)
|
||||||
const thread2 = threads[this.thread_id2]
|
const thread2 = threads[threadId2]
|
||||||
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(this.user_id1)
|
expect(thread1.messages[0].user_id).to.equal(userId1)
|
||||||
expect(thread1.messages[1].content).to.equal('three')
|
expect(thread1.messages[1].content).to.equal('three')
|
||||||
expect(thread1.messages[1].user_id).to.equal(this.user_id1)
|
expect(thread1.messages[1].user_id).to.equal(userId1)
|
||||||
|
|
||||||
expect(thread2.messages[0].content).to.equal('two')
|
expect(thread2.messages[0].content).to.equal('two')
|
||||||
expect(thread2.messages[0].user_id).to.equal(this.user_id2)
|
expect(thread2.messages[0].user_id).to.equal(userId2)
|
||||||
expect(thread2.messages[1].content).to.equal('four')
|
expect(thread2.messages[1].content).to.equal('four')
|
||||||
expect(thread2.messages[1].user_id).to.equal(this.user_id2)
|
expect(thread2.messages[1].user_id).to.equal(userId2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,95 +5,89 @@ const ChatClient = require('./helpers/ChatClient')
|
||||||
const ChatApp = require('./helpers/ChatApp')
|
const ChatApp = require('./helpers/ChatApp')
|
||||||
|
|
||||||
describe('Resolving a thread', async function () {
|
describe('Resolving a thread', async function () {
|
||||||
|
const projectId = ObjectId().toString()
|
||||||
|
const userId = ObjectId().toString()
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.project_id = ObjectId().toString()
|
|
||||||
this.user_id = ObjectId().toString()
|
|
||||||
await ChatApp.ensureRunning()
|
await ChatApp.ensureRunning()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with a resolved thread', async function () {
|
describe('with a resolved thread', async function () {
|
||||||
|
const threadId = ObjectId().toString()
|
||||||
|
const content = 'resolved message'
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.thread_id = ObjectId().toString()
|
|
||||||
this.content = 'resolved message'
|
|
||||||
const { response } = await ChatClient.sendMessage(
|
const { response } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
this.content
|
content
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
const { response: response2 } = await ChatClient.resolveThread(
|
const { response: response2 } = await ChatClient.resolveThread(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id
|
userId
|
||||||
)
|
)
|
||||||
expect(response2.statusCode).to.equal(204)
|
expect(response2.statusCode).to.equal(204)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should then list the thread as resolved', async function () {
|
it('should then list the thread as resolved', async function () {
|
||||||
const { response, body: threads } = await ChatClient.getThreads(
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
||||||
this.project_id
|
|
||||||
)
|
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(threads[this.thread_id].resolved).to.equal(true)
|
expect(threads[threadId].resolved).to.equal(true)
|
||||||
expect(threads[this.thread_id].resolved_by_user_id).to.equal(this.user_id)
|
expect(threads[threadId].resolved_by_user_id).to.equal(userId)
|
||||||
const resolvedAt = new Date(threads[this.thread_id].resolved_at)
|
const resolvedAt = new Date(threads[threadId].resolved_at)
|
||||||
expect(new Date() - resolvedAt).to.be.below(1000)
|
expect(new Date() - resolvedAt).to.be.below(1000)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when a thread is not resolved', async function () {
|
describe('when a thread is not resolved', async function () {
|
||||||
|
const threadId = ObjectId().toString()
|
||||||
|
const content = 'open message'
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.thread_id = ObjectId().toString()
|
|
||||||
this.content = 'open message'
|
|
||||||
const { response } = await ChatClient.sendMessage(
|
const { response } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
this.content
|
content
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not list the thread as resolved', async function () {
|
it('should not list the thread as resolved', async function () {
|
||||||
const { response, body: threads } = await ChatClient.getThreads(
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
||||||
this.project_id
|
|
||||||
)
|
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(threads[this.thread_id].resolved).to.be.undefined
|
expect(threads[threadId].resolved).to.be.undefined
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when a thread is resolved then reopened', async function () {
|
describe('when a thread is resolved then reopened', async function () {
|
||||||
|
const threadId = ObjectId().toString()
|
||||||
|
const content = 'resolved message'
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.thread_id = ObjectId().toString()
|
|
||||||
this.content = 'resolved message'
|
|
||||||
const { response } = await ChatClient.sendMessage(
|
const { response } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
this.content
|
content
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
const { response: response2 } = await ChatClient.resolveThread(
|
const { response: response2 } = await ChatClient.resolveThread(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id
|
userId
|
||||||
)
|
)
|
||||||
expect(response2.statusCode).to.equal(204)
|
expect(response2.statusCode).to.equal(204)
|
||||||
const { response: response3 } = await ChatClient.reopenThread(
|
const { response: response3 } = await ChatClient.reopenThread(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id
|
threadId
|
||||||
)
|
)
|
||||||
expect(response3.statusCode).to.equal(204)
|
expect(response3.statusCode).to.equal(204)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not list the thread as resolved', async function () {
|
it('should not list the thread as resolved', async function () {
|
||||||
const { response, body: threads } = await ChatClient.getThreads(
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
||||||
this.project_id
|
|
||||||
)
|
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(threads[this.thread_id].resolved).to.be.undefined
|
expect(threads[threadId].resolved).to.be.undefined
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,61 +10,59 @@ describe('Sending a message', async function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('globally', async function () {
|
describe('globally', async function () {
|
||||||
|
const projectId = ObjectId().toString()
|
||||||
|
const userId = ObjectId().toString()
|
||||||
|
const content = 'global message'
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.project_id = ObjectId().toString()
|
|
||||||
this.user_id = ObjectId().toString()
|
|
||||||
this.content = 'global message'
|
|
||||||
const { response, body } = await ChatClient.sendGlobalMessage(
|
const { response, body } = await ChatClient.sendGlobalMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.user_id,
|
userId,
|
||||||
this.content
|
content
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
expect(body.content).to.equal(this.content)
|
expect(body.content).to.equal(content)
|
||||||
expect(body.user_id).to.equal(this.user_id)
|
expect(body.user_id).to.equal(userId)
|
||||||
expect(body.room_id).to.equal(this.project_id)
|
expect(body.room_id).to.equal(projectId)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should then list the message in the project messages', async function () {
|
it('should then list the message in the project messages', async function () {
|
||||||
const { response, body: messages } = await ChatClient.getGlobalMessages(
|
const { response, body: messages } = await ChatClient.getGlobalMessages(
|
||||||
this.project_id
|
projectId
|
||||||
)
|
)
|
||||||
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(this.content)
|
expect(messages[0].content).to.equal(content)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('to a thread', async function () {
|
describe('to a thread', async function () {
|
||||||
|
const projectId = ObjectId().toString()
|
||||||
|
const userId = ObjectId().toString()
|
||||||
|
const threadId = ObjectId().toString()
|
||||||
|
const content = 'thread message'
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.project_id = ObjectId().toString()
|
|
||||||
this.user_id = ObjectId().toString()
|
|
||||||
this.thread_id = ObjectId().toString()
|
|
||||||
this.content = 'thread message'
|
|
||||||
const { response, body } = await ChatClient.sendMessage(
|
const { response, body } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
this.content
|
content
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(201)
|
expect(response.statusCode).to.equal(201)
|
||||||
expect(body.content).to.equal(this.content)
|
expect(body.content).to.equal(content)
|
||||||
expect(body.user_id).to.equal(this.user_id)
|
expect(body.user_id).to.equal(userId)
|
||||||
expect(body.room_id).to.equal(this.project_id)
|
expect(body.room_id).to.equal(projectId)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should then list the message in the threads', async function () {
|
it('should then list the message in the threads', async function () {
|
||||||
const { response, body: threads } = await ChatClient.getThreads(
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
||||||
this.project_id
|
|
||||||
)
|
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(threads[this.thread_id].messages.length).to.equal(1)
|
expect(threads[threadId].messages.length).to.equal(1)
|
||||||
expect(threads[this.thread_id].messages[0].content).to.equal(this.content)
|
expect(threads[threadId].messages[0].content).to.equal(content)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not appear in the global messages', async function () {
|
it('should not appear in the global messages', async function () {
|
||||||
const { response, body: messages } = await ChatClient.getGlobalMessages(
|
const { response, body: messages } = await ChatClient.getGlobalMessages(
|
||||||
this.project_id
|
projectId
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(200)
|
expect(response.statusCode).to.equal(200)
|
||||||
expect(messages.length).to.equal(0)
|
expect(messages.length).to.equal(0)
|
||||||
|
@ -72,17 +70,15 @@ describe('Sending a message', async function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('failure cases', async function () {
|
describe('failure cases', async function () {
|
||||||
before(async function () {
|
const projectId = ObjectId().toString()
|
||||||
this.project_id = ObjectId().toString()
|
const userId = ObjectId().toString()
|
||||||
this.user_id = ObjectId().toString()
|
const threadId = ObjectId().toString()
|
||||||
this.thread_id = ObjectId().toString()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('with a malformed user_id', async function () {
|
describe('with a malformed userId', async function () {
|
||||||
it('should return a graceful error', async function () {
|
it('should return a graceful error', async function () {
|
||||||
const { response, body } = await ChatClient.sendMessage(
|
const { response, body } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
'malformed-user',
|
'malformed-user',
|
||||||
'content'
|
'content'
|
||||||
)
|
)
|
||||||
|
@ -91,12 +87,12 @@ describe('Sending a message', async function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with a malformed project_id', async function () {
|
describe('with a malformed projectId', async function () {
|
||||||
it('should return a graceful error', async function () {
|
it('should return a graceful error', async function () {
|
||||||
const { response, body } = await ChatClient.sendMessage(
|
const { response, body } = await ChatClient.sendMessage(
|
||||||
'malformed-project',
|
'malformed-project',
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
'content'
|
'content'
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(400)
|
expect(response.statusCode).to.equal(400)
|
||||||
|
@ -104,12 +100,12 @@ describe('Sending a message', async function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with a malformed thread_id', async function () {
|
describe('with a malformed threadId', async function () {
|
||||||
it('should return a graceful error', async function () {
|
it('should return a graceful error', async function () {
|
||||||
const { response, body } = await ChatClient.sendMessage(
|
const { response, body } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
'malformed-thread-id',
|
'malformed-thread-id',
|
||||||
this.user_id,
|
userId,
|
||||||
'content'
|
'content'
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(400)
|
expect(response.statusCode).to.equal(400)
|
||||||
|
@ -120,9 +116,9 @@ describe('Sending a message', async function () {
|
||||||
describe('with no content', async function () {
|
describe('with no content', async function () {
|
||||||
it('should return a graceful error', async function () {
|
it('should return a graceful error', async function () {
|
||||||
const { response, body } = await ChatClient.sendMessage(
|
const { response, body } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(400)
|
expect(response.statusCode).to.equal(400)
|
||||||
|
@ -134,9 +130,9 @@ describe('Sending a message', async function () {
|
||||||
it('should return a graceful error', async function () {
|
it('should return a graceful error', async function () {
|
||||||
const content = '-'.repeat(10 * 1024 + 1)
|
const content = '-'.repeat(10 * 1024 + 1)
|
||||||
const { response, body } = await ChatClient.sendMessage(
|
const { response, body } = await ChatClient.sendMessage(
|
||||||
this.project_id,
|
projectId,
|
||||||
this.thread_id,
|
threadId,
|
||||||
this.user_id,
|
userId,
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
expect(response.statusCode).to.equal(400)
|
expect(response.statusCode).to.equal(400)
|
||||||
|
|
Loading…
Reference in a new issue